diff options
| author | crupest <crupest@outlook.com> | 2022-12-11 12:42:21 +0800 | 
|---|---|---|
| committer | crupest <crupest@outlook.com> | 2022-12-20 20:32:53 +0800 | 
| commit | 137ddf2386fb17133b081cb6f1d5e8095c5ec2c6 (patch) | |
| tree | 8e3af035c27ce874c4c94161e3300826f566786f /docker/crupest-api/CrupestApi/CrupestApi.Commons | |
| parent | 8243498d2a201616239c6f4c48fa68737175978c (diff) | |
| download | crupest-137ddf2386fb17133b081cb6f1d5e8095c5ec2c6.tar.gz crupest-137ddf2386fb17133b081cb6f1d5e8095c5ec2c6.tar.bz2 crupest-137ddf2386fb17133b081cb6f1d5e8095c5ec2c6.zip  | |
Develop secret api. v28
Diffstat (limited to 'docker/crupest-api/CrupestApi/CrupestApi.Commons')
3 files changed, 11 insertions, 21 deletions
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/ColumnInfo.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/ColumnInfo.cs index 4a594bb..9a6b549 100644 --- a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/ColumnInfo.cs +++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/ColumnInfo.cs @@ -18,10 +18,11 @@ public class ColumnHooks      /// <summary>Called after SELECT. Please use multicast if you want to customize it because there are many default behavior in it.</summary       public ColumnHookAction AfterSelect; -    /// <summary>Called before INSERT. Please use multicast if you want to customize it because there are many default behavior in it.</summary  +    /// <summary>Called before INSERT. Please use multicast if you want to customize it because there are many default behavior in it.</summary>      public ColumnHookAction BeforeInsert;      /// <summary>Called before UPDATE. Please use multicast if you want to customize it because there are many default behavior in it.</summary  +    /// <remarks>Set value to null to delete the update item so it will not change. Set value to <see cref="DbNullValue"/> to update the column to  NULL.</remarks>      public ColumnHookAction BeforeUpdate;  } diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/ParamMap.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/ParamMap.cs index fe8d2a0..841ba40 100644 --- a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/ParamMap.cs +++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/ParamMap.cs @@ -4,7 +4,7 @@ using System.Diagnostics;  namespace CrupestApi.Commons.Crud;  /// <summary> -/// Null value will be thrown. Please use <see cref="DbNullValue.Instance"/>. +/// <see cref="ColumnName"/> is an optional column name related to the param. You may use it to do some column related things. Like use a more accurate conversion.  /// </summary>  public record ParamInfo(string Name, object? Value, string? ColumnName = null); diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/TableInfo.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/TableInfo.cs index d2f48c6..61cd04f 100644 --- a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/TableInfo.cs +++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/TableInfo.cs @@ -367,12 +367,7 @@ CREATE TABLE {tableName}(          var result = new DynamicParameters();          foreach (var param in parameters)          { -            if (param.Value is null) -            { -                continue; -            } - -            if (param.Value is DbNullValue) +            if (param.Value is null || param.Value is DbNullValue)              {                  result.Add(param.Name, null);                  continue; @@ -455,17 +450,14 @@ CREATE TABLE {tableName}(          {              InsertItem? item = insert.Items.FirstOrDefault(i => i.ColumnName == column.ColumnName);              object? value = null; -            if (item is null || item.Value is null) -            { -                column.Hooks.BeforeInsert(column, , ); -            }              if (item is null)              { +                column.Hooks.BeforeInsert(column, ref value, false);                  item = new InsertItem(column.ColumnName, value); -                insert.Items.Add(item);              }              else              { +                column.Hooks.BeforeInsert(column, ref value, true);                  item.Value = value;              } @@ -490,19 +482,16 @@ CREATE TABLE {tableName}(      {          var (sql, parameters) = GenerateUpdateSql(where, update); +        var readUpdateClause = UpdateClause.Create(); +          foreach (var column in ColumnInfos)          {              UpdateItem? item = update.Items.FirstOrDefault(i => i.ColumnName == column.ColumnName);              var value = item?.Value; -            column.Hooks.BeforeUpdate(column, ref value); -            if (item is null) -            { -                if (value is not null) -                    update.Items.Add(new UpdateItem(column.ColumnName, value)); -            } -            else +            column.Hooks.BeforeUpdate(column, ref value, item is null ? false : true); +            if (value is not null)              { -                item.Value = value; +                readUpdateClause.Add(column.ColumnName, value);              }          }  | 
