- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 199
json functions support #392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| Could you please check this out, @sebastienros? | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very useful feature that
In any case in scenarios where the amount of data is not very large he would be very helpful, this gives us another option
I don't know about the performance, maybe we should include it in the performance test code
| @sebastienros could you please have a look to this | 
| { | ||
| arguments[id] = TransformPathExpression(arguments[id]); | ||
| } | ||
| return String.Format(_template, arguments); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return String.Format(_template, arguments); | |
| return String.Format(_template, arguments); | 
| Methods.Add("month", new TemplateFunction("extract(month from {0})")); | ||
| Methods.Add("year", new TemplateFunction("extract(year from {0})")); | ||
| Methods.Add("now", new TemplateFunction("now() at time zone 'utc'")); | ||
|  | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| { | ||
| AddTypeHandler<TimeSpan, long>(x => x.Ticks); | ||
| Methods.Add("now", new TemplateFunction("UTC_TIMESTAMP()")); | ||
|  | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Methods.Add("month", new TemplateFunction("cast(strftime('%m', {0}) as int)")); | ||
| Methods.Add("year", new TemplateFunction("cast(strftime('%Y', {0}) as int)")); | ||
| Methods.Add("now", new TemplateFunction("DATETIME('now')")); | ||
|  | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| string result; | ||
|  | ||
| using (var connection = _store.Configuration.ConnectionFactory.CreateConnection()) | ||
| { | ||
| await connection.OpenAsync(); | ||
| var dialect = _store.Configuration.SqlDialect; | ||
| var sql = "SELECT " + dialect.RenderMethod(method, json, jsonPathExpression); | ||
| result = await connection.QueryFirstOrDefaultAsync<string>(sql); | ||
| } | ||
|  | ||
| Assert.Equal(expected, result); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| string result; | |
| using (var connection = _store.Configuration.ConnectionFactory.CreateConnection()) | |
| { | |
| await connection.OpenAsync(); | |
| var dialect = _store.Configuration.SqlDialect; | |
| var sql = "SELECT " + dialect.RenderMethod(method, json, jsonPathExpression); | |
| result = await connection.QueryFirstOrDefaultAsync<string>(sql); | |
| } | |
| Assert.Equal(expected, result); | |
| // Arrange & Act | |
| string result; | |
| using (var connection = _store.Configuration.ConnectionFactory.CreateConnection()) | |
| { | |
| await connection.OpenAsync(); | |
| var dialect = _store.Configuration.SqlDialect; | |
| var sql = $"SELECT {dialect.RenderMethod(method, json, jsonPathExpression)}" ; | |
| result = await connection.QueryFirstOrDefaultAsync<string>(sql); | |
| } | |
| // Assert | |
| Assert.Equal(expected, result); | 
| string result; | ||
|  | ||
| using (var connection = _store.Configuration.ConnectionFactory.CreateConnection()) | ||
| { | ||
| await connection.OpenAsync(); | ||
|  | ||
| var dialect = _store.Configuration.SqlDialect; | ||
| var sql = "SELECT " + dialect.RenderMethod(method, json, jsonPathExpression, newValue); | ||
| result = await connection.QueryFirstOrDefaultAsync<string>(sql); | ||
| } | ||
| //we are getting rid of unnecessary JSON formatting | ||
| Assert.Equal(expected, result.Replace(": ", ":").Replace(" :", ":").Replace(", ", ",").Replace("{ ", "{").Replace(" }", "}")); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| string result; | |
| using (var connection = _store.Configuration.ConnectionFactory.CreateConnection()) | |
| { | |
| await connection.OpenAsync(); | |
| var dialect = _store.Configuration.SqlDialect; | |
| var sql = "SELECT " + dialect.RenderMethod(method, json, jsonPathExpression, newValue); | |
| result = await connection.QueryFirstOrDefaultAsync<string>(sql); | |
| } | |
| //we are getting rid of unnecessary JSON formatting | |
| Assert.Equal(expected, result.Replace(": ", ":").Replace(" :", ":").Replace(", ", ",").Replace("{ ", "{").Replace(" }", "}")); | |
| // Arrange & Act | |
| string result; | |
| using (var connection = _store.Configuration.ConnectionFactory.CreateConnection()) | |
| { | |
| await connection.OpenAsync(); | |
| var dialect = _store.Configuration.SqlDialect; | |
| var sql = $"SELECT {dialect.RenderMethod(method, json, jsonPathExpression, newValue)}"; | |
| result = await connection.QueryFirstOrDefaultAsync<string>(sql); | |
| } | |
| // Assert | |
| Assert.Equal(expected, result.Replace(": ", ":").Replace(" :", ":").Replace(", ", ",").Replace("{ ", "{").Replace(" }", "}")); //we are getting rid of unnecessary JSON formatting | 
|  | ||
| private string TransformPathExpression(string jsonPathExpression) | ||
| { | ||
| return jsonPathExpression | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we might need to think about better way here
JSON_VALUE and JSON_MODIFY support