Skip to content

Commit

Permalink
fix missing
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Qu authored and Victor Qu committed Nov 26, 2024
1 parent 2f4a520 commit 08ef441
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ProjectCommon.targets
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
<Version>0.0.2.13</Version>
<Version>0.0.2.14</Version>
<AssemblyVersion>$(Version)</AssemblyVersion>
<FileVersion>$(Version)</FileVersion>
<Version Condition=" '$(VersionSuffix)' != '' ">$(Version)$(VersionSuffix)</Version>
Expand Down
1 change: 1 addition & 0 deletions src/SV.Db.Analyzers/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ private SourceState TransformFunc(GeneratorSyntaxContext ctx, CancellationToken
case "Query":
case "QueryAsync":
case "ExecuteInsertAsync":
case "ExecuteUpdateAsync":
hasResultType = true;
break;

Expand Down
11 changes: 10 additions & 1 deletion src/SV.Db.Sloth/DbEntityInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,16 @@ public static DbEntityInfo Get()
var structFields = ups.Where(i =>
{
var f = fields.First(x => x.Name.Equals(i.Key, StringComparison.OrdinalIgnoreCase));
return f.DeclaringType.IsValueType && Nullable.GetUnderlyingType(f.DeclaringType) is null;
Type t = null;
if (f is PropertyInfo p)
{
t = p.PropertyType;
}
else if (f is FieldInfo field)
{
t = field.FieldType;
}
return t != null && t.IsValueType && Nullable.GetUnderlyingType(t) is null;
}).Select(i => new KeyValuePair<string, string>(i.Key, i.Value.Field)).ToArray();
var checkUps = ups.Select(i =>
{
Expand Down
43 changes: 43 additions & 0 deletions test/RestfulSample/Controllers/WeatherForecastController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using SV.Db.Sloth;
using SV.Db.Sloth.Attributes;
using SV.Db.Sloth.Swagger;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Text.Json;

namespace RestfulSample.Controllers
{
Expand Down Expand Up @@ -87,6 +89,21 @@ public async Task<object> QueryUserInfo()
{
return await this.QueryByParamsAsync<UserInfo>();
}

[HttpPost("account/profile")]
public async Task<object> UpdateAccountProfile([FromBody, Required] AccountProfile accountProfile)
{
return await factory.ExecuteUpdateAsync<AccountProfile>(accountProfile);
//return await factory.ExecuteInsertAsync(accountProfile);
//var has = (await factory.From<AccountProfile>().Where(i => i.AccountId == accountProfile.AccountId && i.Key == accountProfile.Key).Select(nameof(AccountProfile.AccountId)).Limit(1).ExecuteQueryAsync<int>()).Rows?.Count > 0;
//if (has)
//{
// return await factory.ExecuteUpdateAsync(accountProfile);
//}
//else
//{
//}
}
}

[Db(StaticInfo.Demo)]
Expand Down Expand Up @@ -148,4 +165,30 @@ public class UserInfo
[Select("a.InDate"), OrderBy, Where, Column(Name = "InDate", Type = DbType.Int64), Update]
public long InDate { get; set; }
}

[Db(StaticInfo.Demo)]
[Table("""
select {Fields}
FROM account_profile a
{where}
""", UpdateTable = "account_profile")]
public class AccountProfile
{
[Select("a.AccountId"), OrderBy, Where, Column(Name = "AccountId", Type = DbType.Int32), Update(PrimaryKey = true)]
public int AccountId { get; set; }

[Select("a.Key"), OrderBy, Where, Column(Name = "Key"), Update(PrimaryKey = true)]
public string Key { get; set; }

[Select("a.Value"), OrderBy, Where, Column(Name = "Value", Type = DbType.String, IsJson = true, CustomConvertToDbMethod = "RestfulSample.Controllers.AccountProfile.ToJsonString"), Update]
public object Value { get; set; }

[Select("a.LastEditDate"), OrderBy, Where, Column(Name = "LastEditDate", Type = DbType.Int64), Update]
public long LastEditDate { get; set; }

public static string? ToJsonString(object? v)
{
return v == null ? null : JsonSerializer.Serialize(v);
}
}
}
9 changes: 8 additions & 1 deletion test/RestfulSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ CREATE TABLE Weather (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
value text
)
);
CREATE TABLE account_profile (
AccountId INTEGER,
Key TEXT,
Value text,
LastEditDate INTEGER
);
""");
a.ExecuteNonQuery("""
INSERT INTO Weather
Expand Down

0 comments on commit 08ef441

Please sign in to comment.