diff options
author | crupest <crupest@outlook.com> | 2022-12-18 20:07:29 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-12-20 20:32:53 +0800 |
commit | f73342cb6b0592d3a6310f9a12fd40b4bf218e5c (patch) | |
tree | 705eac7dd02e4335816a4b048b1b14d08cea24a4 /docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs | |
parent | 7407875fb75bcd90f6f7ef54573483fe2f3cfb84 (diff) | |
download | crupest-f73342cb6b0592d3a6310f9a12fd40b4bf218e5c.tar.gz crupest-f73342cb6b0592d3a6310f9a12fd40b4bf218e5c.tar.bz2 crupest-f73342cb6b0592d3a6310f9a12fd40b4bf218e5c.zip |
Develop secret api. v42
Diffstat (limited to 'docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs')
-rw-r--r-- | docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs index d371c84..184ac0a 100644 --- a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs +++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs @@ -20,15 +20,20 @@ public class CrudService<TEntity> : IDisposable where TEntity : class _jsonHelper = jsonHelper; _logger = loggerFactory.CreateLogger<CrudService<TEntity>>(); - if (!_table.CheckExistence(_dbConnection)) - { - DoInitializeDatabase(_dbConnection); - } + CheckDatabase(_dbConnection); } public EntityJsonHelper<TEntity> JsonHelper => _jsonHelper; - public virtual void DoInitializeDatabase(IDbConnection connection) + protected virtual void CheckDatabase(IDbConnection dbConnection) + { + if (!_table.CheckExistence(dbConnection)) + { + DoInitializeDatabase(dbConnection); + } + } + + private void DoInitializeDatabase(IDbConnection connection) { using var transaction = connection.BeginTransaction(); connection.Execute(_table.GenerateCreateTableSql(), transaction: transaction); @@ -59,7 +64,7 @@ public class CrudService<TEntity> : IDisposable where TEntity : class return (string)key; } - public void Update(object key, JsonElement jsonElement) + public void UpdateByKey(object key, JsonElement jsonElement) { var updateClauses = _jsonHelper.ConvertJsonElementToUpdateClause(jsonElement); _table.Update(_dbConnection, WhereClause.Create().Eq(_table.KeyColumn.ColumnName, key), updateClauses); |