Skip to content

Commit

Permalink
JsonMap
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Aug 19, 2024
1 parent 0c7d438 commit 3335a84
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
17 changes: 16 additions & 1 deletion Examples/base_entity/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ static void Main(string[] args)

//.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;min pool size=1;Max pool size=3;AllowLoadLocalInfile=true")

.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3;TrustServerCertificate=true")
//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3;TrustServerCertificate=true")
//.UseAdoConnectionPool(false)
//.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=127.0.0.1;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=2")
////.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=127.0.0.1;Port=5432;Username=postgres;Password=123456;Database=toc;Pooling=true;Maximum Pool Size=2")
Expand Down Expand Up @@ -619,6 +619,9 @@ static void Main(string[] args)
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
#endregion

fsql.UseJsonMap();

fsql.Select<Table11>().Where(a => a.Options.Value1 == 100 && a.Options.Value2 == "xx").ToList();

var usergroupRepository = fsql.GetAggregateRootRepository<UserGroup>();
usergroupRepository.Delete(a => true);
Expand Down Expand Up @@ -3311,4 +3314,16 @@ public override DateTimeOffset Deserialize(object value)
{
return DateTimeOffset.TryParse((string)value, out var dts) ? dts : DateTimeOffset.MinValue;
}
}
class Table11
{
public int Id { get; set; }

[JsonMap, Column(DbType = "json")]
public TableOptions Options { get; set; }
}
class TableOptions
{
public int Value1 { get; set; }
public string Value2 { get; set; }
}
23 changes: 11 additions & 12 deletions Extensions/FreeSql.Extensions.JsonMap/JsonMapCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ public static void UseJsonMap(this IFreeSql fsql, JsonSerializerSettings setting
case DataType.OdbcOracle:
case DataType.CustomOracle:
case DataType.Dameng:
case DataType.PostgreSQL:
case DataType.OdbcPostgreSQL:
case DataType.CustomPostgreSQL:
case DataType.KingbaseES:
case DataType.ShenTong:
fsql.Aop.ParseExpression += (_, e) =>
{
//if (e.Expression is MethodCallExpression callExp)
Expand Down Expand Up @@ -170,13 +165,7 @@ public static void UseJsonMap(this IFreeSql fsql, JsonSerializerSettings setting
StyleJsonValue();
return;
}
while (parentMemExps.Any())
{
memExp = parentMemExps.Pop();
var opt = parentMemExps.Any() ? "->" : $"->>{(memExp.Type.IsArrayOrList() ? "/*json array*/" : "")}";
result = $"{result}{opt}'{memExp.Member.Name}'";
}
e.Result = result;
StylePgJson();
return;
void StyleJsonExtract()
Expand All @@ -197,6 +186,16 @@ void StyleJsonValue()
}
e.Result = $"json_value({result},'${jsonPath}')";
}
void StylePgJson()
{
while (parentMemExps.Any())
{
memExp = parentMemExps.Pop();
var opt = parentMemExps.Any() ? "->" : $"->>{(memExp.Type.IsArrayOrList() ? "/*json array*/" : "")}";
result = $"{result}{opt}'{memExp.Member.Name}'";
}
e.Result = result;
}
}
}
}
Expand Down
9 changes: 0 additions & 9 deletions FreeSql.DbContext/FreeSql.DbContext.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3335a84

Please sign in to comment.