Skip to content

Conversation

@lampersky
Copy link
Contributor

JSON_VALUE and JSON_MODIFY support

@lampersky lampersky marked this pull request as ready for review May 20, 2021 06:53
@Piedone
Copy link
Contributor

Piedone commented May 21, 2024

Could you please check this out, @sebastienros?

Copy link
Contributor

@hyzx86 hyzx86 left a 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

@hishamco
Copy link
Contributor

@sebastienros could you please have a look to this

{
arguments[id] = TransformPathExpression(arguments[id]);
}
return String.Format(_template, arguments);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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'"));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

{
AddTypeHandler<TimeSpan, long>(x => x.Ticks);
Methods.Add("now", new TemplateFunction("UTC_TIMESTAMP()"));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

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')"));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines +4381 to +4391
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);

Comment on lines +4400 to +4411
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(" }", "}"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants