From acb7d817856134c42230bbc605fa64f3f946e6c5 Mon Sep 17 00:00:00 2001 From: Doron Eli Rachman Date: Sat, 1 Nov 2025 16:52:55 +0200 Subject: [PATCH 1/7] working multi-line sql generation --- CodeGenerator/Generators/QueriesGen.cs | 26 +- .../MySqlConnectorDapperExample/QuerySql.cs | 202 ++++++++++- .../QuerySql.cs | 202 ++++++++++- examples/MySqlConnectorExample/QuerySql.cs | 202 ++++++++++- .../MySqlConnectorLegacyExample/QuerySql.cs | 202 ++++++++++- examples/NpgsqlDapperExample/QuerySql.cs | 313 ++++++++++++++++-- .../NpgsqlDapperLegacyExample/QuerySql.cs | 313 ++++++++++++++++-- examples/NpgsqlExample/QuerySql.cs | 313 ++++++++++++++++-- examples/NpgsqlLegacyExample/QuerySql.cs | 313 ++++++++++++++++-- examples/QuickStartMySqlDalGen/QuerySql.cs | 27 +- examples/QuickStartPostgresDalGen/QuerySql.cs | 49 ++- examples/QuickStartSqliteDalGen/QuerySql.cs | 40 ++- examples/QuickStartSqliteDalGen/request.json | 2 +- .../QuickStartSqliteDalGen/request.message | Bin 5115 -> 5131 bytes examples/SqliteDapperExample/QuerySql.cs | 85 ++++- examples/SqliteDapperExample/request.json | 2 +- examples/SqliteDapperExample/request.message | Bin 10852 -> 10868 bytes .../SqliteDapperLegacyExample/QuerySql.cs | 85 ++++- .../SqliteDapperLegacyExample/request.json | 2 +- .../SqliteDapperLegacyExample/request.message | Bin 10886 -> 10902 bytes examples/SqliteExample/QuerySql.cs | 85 ++++- examples/SqliteExample/request.json | 2 +- examples/SqliteExample/request.message | Bin 10836 -> 10852 bytes examples/SqliteLegacyExample/QuerySql.cs | 85 ++++- examples/SqliteLegacyExample/request.json | 2 +- examples/SqliteLegacyExample/request.message | Bin 10870 -> 10886 bytes examples/config/sqlite/authors/query.sql | 2 +- 27 files changed, 2281 insertions(+), 273 deletions(-) diff --git a/CodeGenerator/Generators/QueriesGen.cs b/CodeGenerator/Generators/QueriesGen.cs index 35988432..65ba6f6e 100644 --- a/CodeGenerator/Generators/QueriesGen.cs +++ b/CodeGenerator/Generators/QueriesGen.cs @@ -137,11 +137,29 @@ private IEnumerable GetMembersForSingleQuery(Query quer if (transformedQueryText == string.Empty) return null; - var singleLineQueryText = LongWhitespaceRegex().Replace(transformedQueryText, " "); + var memberName = ClassMember.Sql.Name(query.Name); + if (transformedQueryText.IndexOfAny(['\r', '\n']) >= 0) + { + var queryWithEscapedQuotes = transformedQueryText.Replace("\"", "\"\""); + var declarationStart = $"private const string {memberName} = @\""; + var lines = queryWithEscapedQuotes.TrimEnd().Split(["\r\n", "\r", "\n"], StringSplitOptions.None); + var firstLine = lines[0]; + var firstCharIndex = firstLine.TakeWhile(char.IsWhiteSpace).Count(); + var baseIndent = new string(' ', 4); // Assuming a standard 4-space indentation for members + var indent = new string(' ', baseIndent.Length + declarationStart.Length + firstCharIndex); + + var indentedQuery = string.Join( + Environment.NewLine + indent, + lines); + + return ParseMemberDeclaration( + $"{baseIndent}{declarationStart}{indentedQuery}\";")! + .AppendNewLine(); + } + + var singleLineQueryText = LongWhitespaceRegex().Replace(transformedQueryText, " ").Replace("\"", "\"\""); return ParseMemberDeclaration( - $""" - private const string {ClassMember.Sql.Name(query.Name)} = "{singleLineQueryText}"; - """)! + $"""private const string {memberName} = "{singleLineQueryText}";""")! .AppendNewLine(); } diff --git a/examples/MySqlConnectorDapperExample/QuerySql.cs b/examples/MySqlConnectorDapperExample/QuerySql.cs index a133ac09..59acb538 100644 --- a/examples/MySqlConnectorDapperExample/QuerySql.cs +++ b/examples/MySqlConnectorDapperExample/QuerySql.cs @@ -75,7 +75,10 @@ public class GetAuthorArgs return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetAuthorSql, queryParams, transaction: this.Transaction); } - private const string ListAuthorsSql = "SELECT id, name, bio FROM authors ORDER BY name LIMIT @limit OFFSET @offset"; + private const string ListAuthorsSql = @"SELECT id, name, bio + FROM authors + ORDER BY name + LIMIT @limit OFFSET @offset"; public class ListAuthorsRow { public required long Id { get; init; } @@ -182,7 +185,8 @@ public class GetAuthorByIdArgs return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetAuthorByIdSql, queryParams, transaction: this.Transaction); } - private const string GetAuthorByNamePatternSql = "SELECT id, name, bio FROM authors WHERE name LIKE COALESCE(@name_pattern, '%')"; + private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors + WHERE name LIKE COALESCE(@name_pattern, '%')"; public class GetAuthorByNamePatternRow { public required long Id { get; init; } @@ -211,7 +215,8 @@ public async Task> GetAuthorByNamePattern(GetAut return (await this.Transaction.Connection.QueryAsync(GetAuthorByNamePatternSql, queryParams, transaction: this.Transaction)).AsList(); } - private const string DeleteAuthorSql = "DELETE FROM authors WHERE name = @name"; + private const string DeleteAuthorSql = @"DELETE FROM authors + WHERE name = @name"; public class DeleteAuthorArgs { public required string Name { get; init; } @@ -247,7 +252,9 @@ public async Task DeleteAllAuthors() await this.Transaction.Connection.ExecuteAsync(DeleteAllAuthorsSql, transaction: this.Transaction); } - private const string UpdateAuthorsSql = "UPDATE authors SET bio = @bio WHERE bio IS NOT NULL"; + private const string UpdateAuthorsSql = @"UPDATE authors + SET bio = @bio + WHERE bio IS NOT NULL"; public class UpdateAuthorsArgs { public string? Bio { get; init; } @@ -357,7 +364,9 @@ public async Task CreateBook(CreateBookArgs args) return await this.Transaction.Connection.QuerySingleAsync(CreateBookSql, queryParams, transaction: this.Transaction); } - private const string ListAllAuthorsBooksSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors JOIN books ON authors.id = books.author_id ORDER BY authors.name"; + private const string ListAllAuthorsBooksSql = @"SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description + FROM authors JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public class ListAllAuthorsBooksRow { public required Author? Author { get; init; } @@ -399,7 +408,9 @@ public async Task> ListAllAuthorsBooks() } } - private const string GetDuplicateAuthorsSql = "SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio FROM authors authors1 JOIN authors authors2 ON authors1.name = authors2.name WHERE authors1.id < authors2.id"; + private const string GetDuplicateAuthorsSql = @"SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio + FROM authors authors1 JOIN authors authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public class GetDuplicateAuthorsRow { public required Author? Author { get; init; } @@ -441,7 +452,9 @@ public async Task> GetDuplicateAuthors() } } - private const string GetAuthorsByBookNameSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors JOIN books ON authors.id = books.author_id WHERE books.name = @name"; + private const string GetAuthorsByBookNameSql = @"SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description + FROM authors JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public class GetAuthorsByBookNameRow { public required long Id { get; init; } @@ -563,7 +576,26 @@ public async Task TruncateExtendedBios() await this.Transaction.Connection.ExecuteAsync(TruncateExtendedBiosSql, transaction: this.Transaction); } - private const string InsertMysqlNumericTypesSql = " INSERT INTO mysql_numeric_types ( c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_decimal, c_dec, c_numeric, c_fixed, c_float, c_double, c_double_precision ) VALUES (@c_bool, @c_boolean, @c_tinyint, @c_smallint, @c_mediumint, @c_int, @c_integer, @c_bigint, @c_decimal, @c_dec, @c_numeric, @c_fixed, @c_float, @c_double, @c_double_precision)"; + private const string InsertMysqlNumericTypesSql = @" + INSERT INTO mysql_numeric_types + ( + c_bool, + c_boolean, + c_tinyint, + c_smallint, + c_mediumint, + c_int, + c_integer, + c_bigint, + c_decimal, + c_dec, + c_numeric, + c_fixed, + c_float, + c_double, + c_double_precision + ) + VALUES (@c_bool, @c_boolean, @c_tinyint, @c_smallint, @c_mediumint, @c_int, @c_integer, @c_bigint, @c_decimal, @c_dec, @c_numeric, @c_fixed, @c_float, @c_double, @c_double_precision)"; public class InsertMysqlNumericTypesArgs { public bool? CBool { get; init; } @@ -716,7 +748,41 @@ public class GetMysqlNumericTypesRow return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlNumericTypesSql, transaction: this.Transaction); } - private const string GetMysqlNumericTypesCntSql = "SELECT COUNT(*) AS cnt, c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_numeric, c_decimal, c_dec, c_fixed, c_double, c_double_precision FROM mysql_numeric_types GROUP BY c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_numeric, c_decimal, c_dec, c_fixed, c_double, c_double_precision LIMIT 1"; + private const string GetMysqlNumericTypesCntSql = @"SELECT + COUNT(*) AS cnt, + c_bool, + c_boolean, + c_tinyint, + c_smallint, + c_mediumint, + c_int, + c_integer, + c_bigint, + c_float, + c_numeric, + c_decimal, + c_dec, + c_fixed, + c_double, + c_double_precision + FROM mysql_numeric_types + GROUP BY + c_bool, + c_boolean, + c_tinyint, + c_smallint, + c_mediumint, + c_int, + c_integer, + c_bigint, + c_float, + c_numeric, + c_decimal, + c_dec, + c_fixed, + c_double, + c_double_precision + LIMIT 1"; public class GetMysqlNumericTypesCntRow { public required long Cnt { get; init; } @@ -767,7 +833,23 @@ public async Task TruncateMysqlNumericTypes() await this.Transaction.Connection.ExecuteAsync(TruncateMysqlNumericTypesSql, transaction: this.Transaction); } - private const string InsertMysqlStringTypesSql = " INSERT INTO mysql_string_types ( c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, c_json, c_json_string_override, c_enum, c_set ) VALUES (@c_char, @c_nchar, @c_national_char, @c_varchar, @c_tinytext, @c_mediumtext, @c_text, @c_longtext, @c_json, @c_json_string_override, @c_enum, @c_set)"; + private const string InsertMysqlStringTypesSql = @" + INSERT INTO mysql_string_types + ( + c_char, + c_nchar, + c_national_char, + c_varchar, + c_tinytext, + c_mediumtext, + c_text, + c_longtext, + c_json, + c_json_string_override, + c_enum, + c_set + ) + VALUES (@c_char, @c_nchar, @c_national_char, @c_varchar, @c_tinytext, @c_mediumtext, @c_text, @c_longtext, @c_json, @c_json_string_override, @c_enum, @c_set)"; public class InsertMysqlStringTypesArgs { public string? CChar { get; init; } @@ -906,7 +988,35 @@ public class GetMysqlStringTypesRow return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlStringTypesSql, transaction: this.Transaction); } - private const string GetMysqlStringTypesCntSql = "SELECT COUNT(*) AS cnt, c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, c_json, c_json_string_override, c_enum, c_set FROM mysql_string_types GROUP BY c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, c_json, c_json_string_override, c_enum, c_set LIMIT 1"; + private const string GetMysqlStringTypesCntSql = @"SELECT + COUNT(*) AS cnt, + c_char, + c_nchar, + c_national_char, + c_varchar, + c_tinytext, + c_mediumtext, + c_text, + c_longtext, + c_json, + c_json_string_override, + c_enum, + c_set + FROM mysql_string_types + GROUP BY + c_char, + c_nchar, + c_national_char, + c_varchar, + c_tinytext, + c_mediumtext, + c_text, + c_longtext, + c_json, + c_json_string_override, + c_enum, + c_set + LIMIT 1"; public class GetMysqlStringTypesCntRow { public required long Cnt { get; init; } @@ -954,7 +1064,17 @@ public async Task TruncateMysqlStringTypes() await this.Transaction.Connection.ExecuteAsync(TruncateMysqlStringTypesSql, transaction: this.Transaction); } - private const string InsertMysqlDatetimeTypesSql = " INSERT INTO mysql_datetime_types ( c_year, c_date, c_datetime, c_timestamp, c_time, c_timestamp_noda_instant_override ) VALUES (@c_year, @c_date, @c_datetime, @c_timestamp, @c_time, @c_timestamp_noda_instant_override)"; + private const string InsertMysqlDatetimeTypesSql = @" + INSERT INTO mysql_datetime_types + ( + c_year, + c_date, + c_datetime, + c_timestamp, + c_time, + c_timestamp_noda_instant_override + ) + VALUES (@c_year, @c_date, @c_datetime, @c_timestamp, @c_time, @c_timestamp_noda_instant_override)"; public class InsertMysqlDatetimeTypesArgs { public short? CYear { get; init; } @@ -1066,7 +1186,21 @@ public class GetMysqlDatetimeTypesRow return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlDatetimeTypesSql, transaction: this.Transaction); } - private const string GetMysqlDatetimeTypesCntSql = "SELECT COUNT(*) AS cnt, c_year, c_date, c_datetime, c_timestamp, c_time FROM mysql_datetime_types GROUP BY c_year, c_date, c_datetime, c_timestamp, c_time LIMIT 1"; + private const string GetMysqlDatetimeTypesCntSql = @"SELECT + COUNT(*) AS cnt, + c_year, + c_date, + c_datetime, + c_timestamp, + c_time + FROM mysql_datetime_types + GROUP BY + c_year, + c_date, + c_datetime, + c_timestamp, + c_time + LIMIT 1"; public class GetMysqlDatetimeTypesCntRow { public required long Cnt { get; init; } @@ -1107,7 +1241,18 @@ public async Task TruncateMysqlDatetimeTypes() await this.Transaction.Connection.ExecuteAsync(TruncateMysqlDatetimeTypesSql, transaction: this.Transaction); } - private const string InsertMysqlBinaryTypesSql = " INSERT INTO mysql_binary_types ( c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob ) VALUES (@c_bit, @c_binary, @c_varbinary, @c_tinyblob, @c_blob, @c_mediumblob, @c_longblob)"; + private const string InsertMysqlBinaryTypesSql = @" + INSERT INTO mysql_binary_types + ( + c_bit, + c_binary, + c_varbinary, + c_tinyblob, + c_blob, + c_mediumblob, + c_longblob + ) + VALUES (@c_bit, @c_binary, @c_varbinary, @c_tinyblob, @c_blob, @c_mediumblob, @c_longblob)"; public class InsertMysqlBinaryTypesArgs { public byte? CBit { get; init; } @@ -1225,7 +1370,25 @@ public class GetMysqlBinaryTypesRow return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlBinaryTypesSql, transaction: this.Transaction); } - private const string GetMysqlBinaryTypesCntSql = "SELECT COUNT(*) AS cnt, c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_binary_types GROUP BY c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob LIMIT 1"; + private const string GetMysqlBinaryTypesCntSql = @"SELECT + COUNT(*) AS cnt, + c_bit, + c_binary, + c_varbinary, + c_tinyblob, + c_blob, + c_mediumblob, + c_longblob + FROM mysql_binary_types + GROUP BY + c_bit, + c_binary, + c_varbinary, + c_tinyblob, + c_blob, + c_mediumblob, + c_longblob + LIMIT 1"; public class GetMysqlBinaryTypesCntRow { public required long Cnt { get; init; } @@ -1268,7 +1431,14 @@ public async Task TruncateMysqlBinaryTypes() await this.Transaction.Connection.ExecuteAsync(TruncateMysqlBinaryTypesSql, transaction: this.Transaction); } - private const string GetMysqlFunctionsSql = " SELECT MAX(c_int) AS max_int, MAX(c_varchar) AS max_varchar, MAX(c_timestamp) AS max_timestamp FROM mysql_numeric_types CROSS JOIN mysql_string_types CROSS JOIN mysql_datetime_types"; + private const string GetMysqlFunctionsSql = @" + SELECT + MAX(c_int) AS max_int, + MAX(c_varchar) AS max_varchar, + MAX(c_timestamp) AS max_timestamp + FROM mysql_numeric_types + CROSS JOIN mysql_string_types + CROSS JOIN mysql_datetime_types"; public class GetMysqlFunctionsRow { public int? MaxInt { get; init; } diff --git a/examples/MySqlConnectorDapperLegacyExample/QuerySql.cs b/examples/MySqlConnectorDapperLegacyExample/QuerySql.cs index 754ae049..0c6c4211 100644 --- a/examples/MySqlConnectorDapperLegacyExample/QuerySql.cs +++ b/examples/MySqlConnectorDapperLegacyExample/QuerySql.cs @@ -76,7 +76,10 @@ public async Task GetAuthor(GetAuthorArgs args) return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetAuthorSql, queryParams, transaction: this.Transaction); } - private const string ListAuthorsSql = "SELECT id, name, bio FROM authors ORDER BY name LIMIT @limit OFFSET @offset"; + private const string ListAuthorsSql = @"SELECT id, name, bio + FROM authors + ORDER BY name + LIMIT @limit OFFSET @offset"; public class ListAuthorsRow { public long Id { get; set; } @@ -183,7 +186,8 @@ public async Task GetAuthorById(GetAuthorByIdArgs args) return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetAuthorByIdSql, queryParams, transaction: this.Transaction); } - private const string GetAuthorByNamePatternSql = "SELECT id, name, bio FROM authors WHERE name LIKE COALESCE(@name_pattern, '%')"; + private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors + WHERE name LIKE COALESCE(@name_pattern, '%')"; public class GetAuthorByNamePatternRow { public long Id { get; set; } @@ -212,7 +216,8 @@ public async Task> GetAuthorByNamePattern(GetAut return (await this.Transaction.Connection.QueryAsync(GetAuthorByNamePatternSql, queryParams, transaction: this.Transaction)).AsList(); } - private const string DeleteAuthorSql = "DELETE FROM authors WHERE name = @name"; + private const string DeleteAuthorSql = @"DELETE FROM authors + WHERE name = @name"; public class DeleteAuthorArgs { public string Name { get; set; } @@ -248,7 +253,9 @@ public async Task DeleteAllAuthors() await this.Transaction.Connection.ExecuteAsync(DeleteAllAuthorsSql, transaction: this.Transaction); } - private const string UpdateAuthorsSql = "UPDATE authors SET bio = @bio WHERE bio IS NOT NULL"; + private const string UpdateAuthorsSql = @"UPDATE authors + SET bio = @bio + WHERE bio IS NOT NULL"; public class UpdateAuthorsArgs { public string Bio { get; set; } @@ -358,7 +365,9 @@ public async Task CreateBook(CreateBookArgs args) return await this.Transaction.Connection.QuerySingleAsync(CreateBookSql, queryParams, transaction: this.Transaction); } - private const string ListAllAuthorsBooksSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors JOIN books ON authors.id = books.author_id ORDER BY authors.name"; + private const string ListAllAuthorsBooksSql = @"SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description + FROM authors JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public class ListAllAuthorsBooksRow { public Author Author { get; set; } @@ -400,7 +409,9 @@ public async Task> ListAllAuthorsBooks() } } - private const string GetDuplicateAuthorsSql = "SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio FROM authors authors1 JOIN authors authors2 ON authors1.name = authors2.name WHERE authors1.id < authors2.id"; + private const string GetDuplicateAuthorsSql = @"SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio + FROM authors authors1 JOIN authors authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public class GetDuplicateAuthorsRow { public Author Author { get; set; } @@ -442,7 +453,9 @@ public async Task> GetDuplicateAuthors() } } - private const string GetAuthorsByBookNameSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors JOIN books ON authors.id = books.author_id WHERE books.name = @name"; + private const string GetAuthorsByBookNameSql = @"SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description + FROM authors JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public class GetAuthorsByBookNameRow { public long Id { get; set; } @@ -564,7 +577,26 @@ public async Task TruncateExtendedBios() await this.Transaction.Connection.ExecuteAsync(TruncateExtendedBiosSql, transaction: this.Transaction); } - private const string InsertMysqlNumericTypesSql = " INSERT INTO mysql_numeric_types ( c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_decimal, c_dec, c_numeric, c_fixed, c_float, c_double, c_double_precision ) VALUES (@c_bool, @c_boolean, @c_tinyint, @c_smallint, @c_mediumint, @c_int, @c_integer, @c_bigint, @c_decimal, @c_dec, @c_numeric, @c_fixed, @c_float, @c_double, @c_double_precision)"; + private const string InsertMysqlNumericTypesSql = @" + INSERT INTO mysql_numeric_types + ( + c_bool, + c_boolean, + c_tinyint, + c_smallint, + c_mediumint, + c_int, + c_integer, + c_bigint, + c_decimal, + c_dec, + c_numeric, + c_fixed, + c_float, + c_double, + c_double_precision + ) + VALUES (@c_bool, @c_boolean, @c_tinyint, @c_smallint, @c_mediumint, @c_int, @c_integer, @c_bigint, @c_decimal, @c_dec, @c_numeric, @c_fixed, @c_float, @c_double, @c_double_precision)"; public class InsertMysqlNumericTypesArgs { public bool? CBool { get; set; } @@ -717,7 +749,41 @@ public async Task GetMysqlNumericTypes() return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlNumericTypesSql, transaction: this.Transaction); } - private const string GetMysqlNumericTypesCntSql = "SELECT COUNT(*) AS cnt, c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_numeric, c_decimal, c_dec, c_fixed, c_double, c_double_precision FROM mysql_numeric_types GROUP BY c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_numeric, c_decimal, c_dec, c_fixed, c_double, c_double_precision LIMIT 1"; + private const string GetMysqlNumericTypesCntSql = @"SELECT + COUNT(*) AS cnt, + c_bool, + c_boolean, + c_tinyint, + c_smallint, + c_mediumint, + c_int, + c_integer, + c_bigint, + c_float, + c_numeric, + c_decimal, + c_dec, + c_fixed, + c_double, + c_double_precision + FROM mysql_numeric_types + GROUP BY + c_bool, + c_boolean, + c_tinyint, + c_smallint, + c_mediumint, + c_int, + c_integer, + c_bigint, + c_float, + c_numeric, + c_decimal, + c_dec, + c_fixed, + c_double, + c_double_precision + LIMIT 1"; public class GetMysqlNumericTypesCntRow { public long Cnt { get; set; } @@ -768,7 +834,23 @@ public async Task TruncateMysqlNumericTypes() await this.Transaction.Connection.ExecuteAsync(TruncateMysqlNumericTypesSql, transaction: this.Transaction); } - private const string InsertMysqlStringTypesSql = " INSERT INTO mysql_string_types ( c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, c_json, c_json_string_override, c_enum, c_set ) VALUES (@c_char, @c_nchar, @c_national_char, @c_varchar, @c_tinytext, @c_mediumtext, @c_text, @c_longtext, @c_json, @c_json_string_override, @c_enum, @c_set)"; + private const string InsertMysqlStringTypesSql = @" + INSERT INTO mysql_string_types + ( + c_char, + c_nchar, + c_national_char, + c_varchar, + c_tinytext, + c_mediumtext, + c_text, + c_longtext, + c_json, + c_json_string_override, + c_enum, + c_set + ) + VALUES (@c_char, @c_nchar, @c_national_char, @c_varchar, @c_tinytext, @c_mediumtext, @c_text, @c_longtext, @c_json, @c_json_string_override, @c_enum, @c_set)"; public class InsertMysqlStringTypesArgs { public string CChar { get; set; } @@ -906,7 +988,35 @@ public async Task GetMysqlStringTypes() return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlStringTypesSql, transaction: this.Transaction); } - private const string GetMysqlStringTypesCntSql = "SELECT COUNT(*) AS cnt, c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, c_json, c_json_string_override, c_enum, c_set FROM mysql_string_types GROUP BY c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, c_json, c_json_string_override, c_enum, c_set LIMIT 1"; + private const string GetMysqlStringTypesCntSql = @"SELECT + COUNT(*) AS cnt, + c_char, + c_nchar, + c_national_char, + c_varchar, + c_tinytext, + c_mediumtext, + c_text, + c_longtext, + c_json, + c_json_string_override, + c_enum, + c_set + FROM mysql_string_types + GROUP BY + c_char, + c_nchar, + c_national_char, + c_varchar, + c_tinytext, + c_mediumtext, + c_text, + c_longtext, + c_json, + c_json_string_override, + c_enum, + c_set + LIMIT 1"; public class GetMysqlStringTypesCntRow { public long Cnt { get; set; } @@ -954,7 +1064,17 @@ public async Task TruncateMysqlStringTypes() await this.Transaction.Connection.ExecuteAsync(TruncateMysqlStringTypesSql, transaction: this.Transaction); } - private const string InsertMysqlDatetimeTypesSql = " INSERT INTO mysql_datetime_types ( c_year, c_date, c_datetime, c_timestamp, c_time, c_timestamp_noda_instant_override ) VALUES (@c_year, @c_date, @c_datetime, @c_timestamp, @c_time, @c_timestamp_noda_instant_override)"; + private const string InsertMysqlDatetimeTypesSql = @" + INSERT INTO mysql_datetime_types + ( + c_year, + c_date, + c_datetime, + c_timestamp, + c_time, + c_timestamp_noda_instant_override + ) + VALUES (@c_year, @c_date, @c_datetime, @c_timestamp, @c_time, @c_timestamp_noda_instant_override)"; public class InsertMysqlDatetimeTypesArgs { public short? CYear { get; set; } @@ -1066,7 +1186,21 @@ public async Task GetMysqlDatetimeTypes() return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlDatetimeTypesSql, transaction: this.Transaction); } - private const string GetMysqlDatetimeTypesCntSql = "SELECT COUNT(*) AS cnt, c_year, c_date, c_datetime, c_timestamp, c_time FROM mysql_datetime_types GROUP BY c_year, c_date, c_datetime, c_timestamp, c_time LIMIT 1"; + private const string GetMysqlDatetimeTypesCntSql = @"SELECT + COUNT(*) AS cnt, + c_year, + c_date, + c_datetime, + c_timestamp, + c_time + FROM mysql_datetime_types + GROUP BY + c_year, + c_date, + c_datetime, + c_timestamp, + c_time + LIMIT 1"; public class GetMysqlDatetimeTypesCntRow { public long Cnt { get; set; } @@ -1107,7 +1241,18 @@ public async Task TruncateMysqlDatetimeTypes() await this.Transaction.Connection.ExecuteAsync(TruncateMysqlDatetimeTypesSql, transaction: this.Transaction); } - private const string InsertMysqlBinaryTypesSql = " INSERT INTO mysql_binary_types ( c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob ) VALUES (@c_bit, @c_binary, @c_varbinary, @c_tinyblob, @c_blob, @c_mediumblob, @c_longblob)"; + private const string InsertMysqlBinaryTypesSql = @" + INSERT INTO mysql_binary_types + ( + c_bit, + c_binary, + c_varbinary, + c_tinyblob, + c_blob, + c_mediumblob, + c_longblob + ) + VALUES (@c_bit, @c_binary, @c_varbinary, @c_tinyblob, @c_blob, @c_mediumblob, @c_longblob)"; public class InsertMysqlBinaryTypesArgs { public byte? CBit { get; set; } @@ -1224,7 +1369,25 @@ public async Task GetMysqlBinaryTypes() return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlBinaryTypesSql, transaction: this.Transaction); } - private const string GetMysqlBinaryTypesCntSql = "SELECT COUNT(*) AS cnt, c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_binary_types GROUP BY c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob LIMIT 1"; + private const string GetMysqlBinaryTypesCntSql = @"SELECT + COUNT(*) AS cnt, + c_bit, + c_binary, + c_varbinary, + c_tinyblob, + c_blob, + c_mediumblob, + c_longblob + FROM mysql_binary_types + GROUP BY + c_bit, + c_binary, + c_varbinary, + c_tinyblob, + c_blob, + c_mediumblob, + c_longblob + LIMIT 1"; public class GetMysqlBinaryTypesCntRow { public long Cnt { get; set; } @@ -1267,7 +1430,14 @@ public async Task TruncateMysqlBinaryTypes() await this.Transaction.Connection.ExecuteAsync(TruncateMysqlBinaryTypesSql, transaction: this.Transaction); } - private const string GetMysqlFunctionsSql = " SELECT MAX(c_int) AS max_int, MAX(c_varchar) AS max_varchar, MAX(c_timestamp) AS max_timestamp FROM mysql_numeric_types CROSS JOIN mysql_string_types CROSS JOIN mysql_datetime_types"; + private const string GetMysqlFunctionsSql = @" + SELECT + MAX(c_int) AS max_int, + MAX(c_varchar) AS max_varchar, + MAX(c_timestamp) AS max_timestamp + FROM mysql_numeric_types + CROSS JOIN mysql_string_types + CROSS JOIN mysql_datetime_types"; public class GetMysqlFunctionsRow { public int? MaxInt { get; set; } diff --git a/examples/MySqlConnectorExample/QuerySql.cs b/examples/MySqlConnectorExample/QuerySql.cs index ea54a03d..5a0fde31 100644 --- a/examples/MySqlConnectorExample/QuerySql.cs +++ b/examples/MySqlConnectorExample/QuerySql.cs @@ -98,7 +98,10 @@ public static QuerySql WithTransaction(MySqlTransaction transaction) return null; } - private const string ListAuthorsSql = "SELECT id, name, bio FROM authors ORDER BY name LIMIT @limit OFFSET @offset"; + private const string ListAuthorsSql = @"SELECT id, name, bio + FROM authors + ORDER BY name + LIMIT @limit OFFSET @offset"; public readonly record struct ListAuthorsRow(long Id, string Name, string? Bio); public readonly record struct ListAuthorsArgs(int Limit, int Offset); public async Task> ListAuthors(ListAuthorsArgs args) @@ -262,7 +265,8 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) return null; } - private const string GetAuthorByNamePatternSql = "SELECT id, name, bio FROM authors WHERE name LIKE COALESCE(@name_pattern, '%')"; + private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors + WHERE name LIKE COALESCE(@name_pattern, '%')"; public readonly record struct GetAuthorByNamePatternRow(long Id, string Name, string? Bio); public readonly record struct GetAuthorByNamePatternArgs(string? NamePattern); public async Task> GetAuthorByNamePattern(GetAuthorByNamePatternArgs args) @@ -303,7 +307,8 @@ public async Task> GetAuthorByNamePattern(GetAut } } - private const string DeleteAuthorSql = "DELETE FROM authors WHERE name = @name"; + private const string DeleteAuthorSql = @"DELETE FROM authors + WHERE name = @name"; public readonly record struct DeleteAuthorArgs(string Name); public async Task DeleteAuthor(DeleteAuthorArgs args) { @@ -360,7 +365,9 @@ public async Task DeleteAllAuthors() } } - private const string UpdateAuthorsSql = "UPDATE authors SET bio = @bio WHERE bio IS NOT NULL"; + private const string UpdateAuthorsSql = @"UPDATE authors + SET bio = @bio + WHERE bio IS NOT NULL"; public readonly record struct UpdateAuthorsArgs(string? Bio); public async Task UpdateAuthors(UpdateAuthorsArgs args) { @@ -515,7 +522,9 @@ public async Task CreateBook(CreateBookArgs args) } } - private const string ListAllAuthorsBooksSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors JOIN books ON authors.id = books.author_id ORDER BY authors.name"; + private const string ListAllAuthorsBooksSql = @"SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description + FROM authors JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public readonly record struct ListAllAuthorsBooksRow(Author? Author, Book? Book); public async Task> ListAllAuthorsBooks() { @@ -553,7 +562,9 @@ public async Task> ListAllAuthorsBooks() } } - private const string GetDuplicateAuthorsSql = "SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio FROM authors authors1 JOIN authors authors2 ON authors1.name = authors2.name WHERE authors1.id < authors2.id"; + private const string GetDuplicateAuthorsSql = @"SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio + FROM authors authors1 JOIN authors authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public readonly record struct GetDuplicateAuthorsRow(Author? Author, Author? Author2); public async Task> GetDuplicateAuthors() { @@ -591,7 +602,9 @@ public async Task> GetDuplicateAuthors() } } - private const string GetAuthorsByBookNameSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors JOIN books ON authors.id = books.author_id WHERE books.name = @name"; + private const string GetAuthorsByBookNameSql = @"SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description + FROM authors JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public readonly record struct GetAuthorsByBookNameRow(long Id, string Name, string? Bio, Book? Book); public readonly record struct GetAuthorsByBookNameArgs(string Name); public async Task> GetAuthorsByBookName(GetAuthorsByBookNameArgs args) @@ -752,7 +765,26 @@ public async Task TruncateExtendedBios() } } - private const string InsertMysqlNumericTypesSql = " INSERT INTO mysql_numeric_types ( c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_decimal, c_dec, c_numeric, c_fixed, c_float, c_double, c_double_precision ) VALUES (@c_bool, @c_boolean, @c_tinyint, @c_smallint, @c_mediumint, @c_int, @c_integer, @c_bigint, @c_decimal, @c_dec, @c_numeric, @c_fixed, @c_float, @c_double, @c_double_precision)"; + private const string InsertMysqlNumericTypesSql = @" + INSERT INTO mysql_numeric_types + ( + c_bool, + c_boolean, + c_tinyint, + c_smallint, + c_mediumint, + c_int, + c_integer, + c_bigint, + c_decimal, + c_dec, + c_numeric, + c_fixed, + c_float, + c_double, + c_double_precision + ) + VALUES (@c_bool, @c_boolean, @c_tinyint, @c_smallint, @c_mediumint, @c_int, @c_integer, @c_bigint, @c_decimal, @c_dec, @c_numeric, @c_fixed, @c_float, @c_double, @c_double_precision)"; public readonly record struct InsertMysqlNumericTypesArgs(bool? CBool, bool? CBoolean, short? CTinyint, short? CSmallint, int? CMediumint, int? CInt, int? CInteger, long? CBigint, decimal? CDecimal, decimal? CDec, decimal? CNumeric, decimal? CFixed, double? CFloat, double? CDouble, double? CDoublePrecision); public async Task InsertMysqlNumericTypes(InsertMysqlNumericTypesArgs args) { @@ -938,7 +970,41 @@ public async Task InsertMysqlNumericTypesBatch(List GetMysqlNumericTypesCnt() { @@ -1043,7 +1109,23 @@ public async Task TruncateMysqlNumericTypes() } } - private const string InsertMysqlStringTypesSql = " INSERT INTO mysql_string_types ( c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, c_json, c_json_string_override, c_enum, c_set ) VALUES (@c_char, @c_nchar, @c_national_char, @c_varchar, @c_tinytext, @c_mediumtext, @c_text, @c_longtext, @c_json, @c_json_string_override, @c_enum, @c_set)"; + private const string InsertMysqlStringTypesSql = @" + INSERT INTO mysql_string_types + ( + c_char, + c_nchar, + c_national_char, + c_varchar, + c_tinytext, + c_mediumtext, + c_text, + c_longtext, + c_json, + c_json_string_override, + c_enum, + c_set + ) + VALUES (@c_char, @c_nchar, @c_national_char, @c_varchar, @c_tinytext, @c_mediumtext, @c_text, @c_longtext, @c_json, @c_json_string_override, @c_enum, @c_set)"; public readonly record struct InsertMysqlStringTypesArgs(string? CChar, string? CNchar, string? CNationalChar, string? CVarchar, string? CTinytext, string? CMediumtext, string? CText, string? CLongtext, JsonElement? CJson, string? CJsonStringOverride, MysqlStringTypesCEnum? CEnum, HashSet? CSet); public async Task InsertMysqlStringTypes(InsertMysqlStringTypesArgs args) { @@ -1215,7 +1297,35 @@ public async Task InsertMysqlStringTypesBatch(List? CSet); public async Task GetMysqlStringTypesCnt() { @@ -1314,7 +1424,17 @@ public async Task TruncateMysqlStringTypes() } } - private const string InsertMysqlDatetimeTypesSql = " INSERT INTO mysql_datetime_types ( c_year, c_date, c_datetime, c_timestamp, c_time, c_timestamp_noda_instant_override ) VALUES (@c_year, @c_date, @c_datetime, @c_timestamp, @c_time, @c_timestamp_noda_instant_override)"; + private const string InsertMysqlDatetimeTypesSql = @" + INSERT INTO mysql_datetime_types + ( + c_year, + c_date, + c_datetime, + c_timestamp, + c_time, + c_timestamp_noda_instant_override + ) + VALUES (@c_year, @c_date, @c_datetime, @c_timestamp, @c_time, @c_timestamp_noda_instant_override)"; public readonly record struct InsertMysqlDatetimeTypesArgs(short? CYear, DateTime? CDate, DateTime? CDatetime, DateTime? CTimestamp, TimeSpan? CTime, Instant? CTimestampNodaInstantOverride); public async Task InsertMysqlDatetimeTypes(InsertMysqlDatetimeTypesArgs args) { @@ -1472,7 +1592,21 @@ public async Task InsertMysqlDatetimeTypesBatch(List GetMysqlDatetimeTypesCnt() { @@ -1557,7 +1691,18 @@ public async Task TruncateMysqlDatetimeTypes() } } - private const string InsertMysqlBinaryTypesSql = " INSERT INTO mysql_binary_types ( c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob ) VALUES (@c_bit, @c_binary, @c_varbinary, @c_tinyblob, @c_blob, @c_mediumblob, @c_longblob)"; + private const string InsertMysqlBinaryTypesSql = @" + INSERT INTO mysql_binary_types + ( + c_bit, + c_binary, + c_varbinary, + c_tinyblob, + c_blob, + c_mediumblob, + c_longblob + ) + VALUES (@c_bit, @c_binary, @c_varbinary, @c_tinyblob, @c_blob, @c_mediumblob, @c_longblob)"; public readonly record struct InsertMysqlBinaryTypesArgs(byte? CBit, byte[]? CBinary, byte[]? CVarbinary, byte[]? CTinyblob, byte[]? CBlob, byte[]? CMediumblob, byte[]? CLongblob); public async Task InsertMysqlBinaryTypes(InsertMysqlBinaryTypesArgs args) { @@ -1708,7 +1853,25 @@ public async Task InsertMysqlBinaryTypesBatch(List GetMysqlBinaryTypesCnt() { @@ -1797,7 +1960,14 @@ public async Task TruncateMysqlBinaryTypes() } } - private const string GetMysqlFunctionsSql = " SELECT MAX(c_int) AS max_int, MAX(c_varchar) AS max_varchar, MAX(c_timestamp) AS max_timestamp FROM mysql_numeric_types CROSS JOIN mysql_string_types CROSS JOIN mysql_datetime_types"; + private const string GetMysqlFunctionsSql = @" + SELECT + MAX(c_int) AS max_int, + MAX(c_varchar) AS max_varchar, + MAX(c_timestamp) AS max_timestamp + FROM mysql_numeric_types + CROSS JOIN mysql_string_types + CROSS JOIN mysql_datetime_types"; public readonly record struct GetMysqlFunctionsRow(int? MaxInt, string? MaxVarchar, DateTime MaxTimestamp); public async Task GetMysqlFunctions() { diff --git a/examples/MySqlConnectorLegacyExample/QuerySql.cs b/examples/MySqlConnectorLegacyExample/QuerySql.cs index 43e26188..febdac73 100644 --- a/examples/MySqlConnectorLegacyExample/QuerySql.cs +++ b/examples/MySqlConnectorLegacyExample/QuerySql.cs @@ -107,7 +107,10 @@ public async Task GetAuthor(GetAuthorArgs args) return null; } - private const string ListAuthorsSql = "SELECT id, name, bio FROM authors ORDER BY name LIMIT @limit OFFSET @offset"; + private const string ListAuthorsSql = @"SELECT id, name, bio + FROM authors + ORDER BY name + LIMIT @limit OFFSET @offset"; public class ListAuthorsRow { public long Id { get; set; } @@ -297,7 +300,8 @@ public async Task GetAuthorById(GetAuthorByIdArgs args) return null; } - private const string GetAuthorByNamePatternSql = "SELECT id, name, bio FROM authors WHERE name LIKE COALESCE(@name_pattern, '%')"; + private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors + WHERE name LIKE COALESCE(@name_pattern, '%')"; public class GetAuthorByNamePatternRow { public long Id { get; set; } @@ -346,7 +350,8 @@ public async Task> GetAuthorByNamePattern(GetAut } } - private const string DeleteAuthorSql = "DELETE FROM authors WHERE name = @name"; + private const string DeleteAuthorSql = @"DELETE FROM authors + WHERE name = @name"; public class DeleteAuthorArgs { public string Name { get; set; } @@ -406,7 +411,9 @@ public async Task DeleteAllAuthors() } } - private const string UpdateAuthorsSql = "UPDATE authors SET bio = @bio WHERE bio IS NOT NULL"; + private const string UpdateAuthorsSql = @"UPDATE authors + SET bio = @bio + WHERE bio IS NOT NULL"; public class UpdateAuthorsArgs { public string Bio { get; set; } @@ -585,7 +592,9 @@ public async Task CreateBook(CreateBookArgs args) } } - private const string ListAllAuthorsBooksSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors JOIN books ON authors.id = books.author_id ORDER BY authors.name"; + private const string ListAllAuthorsBooksSql = @"SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description + FROM authors JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public class ListAllAuthorsBooksRow { public Author Author { get; set; } @@ -627,7 +636,9 @@ public async Task> ListAllAuthorsBooks() } } - private const string GetDuplicateAuthorsSql = "SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio FROM authors authors1 JOIN authors authors2 ON authors1.name = authors2.name WHERE authors1.id < authors2.id"; + private const string GetDuplicateAuthorsSql = @"SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio + FROM authors authors1 JOIN authors authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public class GetDuplicateAuthorsRow { public Author Author { get; set; } @@ -669,7 +680,9 @@ public async Task> GetDuplicateAuthors() } } - private const string GetAuthorsByBookNameSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors JOIN books ON authors.id = books.author_id WHERE books.name = @name"; + private const string GetAuthorsByBookNameSql = @"SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description + FROM authors JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public class GetAuthorsByBookNameRow { public long Id { get; set; } @@ -854,7 +867,26 @@ public async Task TruncateExtendedBios() } } - private const string InsertMysqlNumericTypesSql = " INSERT INTO mysql_numeric_types ( c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_decimal, c_dec, c_numeric, c_fixed, c_float, c_double, c_double_precision ) VALUES (@c_bool, @c_boolean, @c_tinyint, @c_smallint, @c_mediumint, @c_int, @c_integer, @c_bigint, @c_decimal, @c_dec, @c_numeric, @c_fixed, @c_float, @c_double, @c_double_precision)"; + private const string InsertMysqlNumericTypesSql = @" + INSERT INTO mysql_numeric_types + ( + c_bool, + c_boolean, + c_tinyint, + c_smallint, + c_mediumint, + c_int, + c_integer, + c_bigint, + c_decimal, + c_dec, + c_numeric, + c_fixed, + c_float, + c_double, + c_double_precision + ) + VALUES (@c_bool, @c_boolean, @c_tinyint, @c_smallint, @c_mediumint, @c_int, @c_integer, @c_bigint, @c_decimal, @c_dec, @c_numeric, @c_fixed, @c_float, @c_double, @c_double_precision)"; public class InsertMysqlNumericTypesArgs { public bool? CBool { get; set; } @@ -1091,7 +1123,41 @@ public async Task GetMysqlNumericTypes() return null; } - private const string GetMysqlNumericTypesCntSql = "SELECT COUNT(*) AS cnt, c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_numeric, c_decimal, c_dec, c_fixed, c_double, c_double_precision FROM mysql_numeric_types GROUP BY c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_numeric, c_decimal, c_dec, c_fixed, c_double, c_double_precision LIMIT 1"; + private const string GetMysqlNumericTypesCntSql = @"SELECT + COUNT(*) AS cnt, + c_bool, + c_boolean, + c_tinyint, + c_smallint, + c_mediumint, + c_int, + c_integer, + c_bigint, + c_float, + c_numeric, + c_decimal, + c_dec, + c_fixed, + c_double, + c_double_precision + FROM mysql_numeric_types + GROUP BY + c_bool, + c_boolean, + c_tinyint, + c_smallint, + c_mediumint, + c_int, + c_integer, + c_bigint, + c_float, + c_numeric, + c_decimal, + c_dec, + c_fixed, + c_double, + c_double_precision + LIMIT 1"; public class GetMysqlNumericTypesCntRow { public long Cnt { get; set; } @@ -1214,7 +1280,23 @@ public async Task TruncateMysqlNumericTypes() } } - private const string InsertMysqlStringTypesSql = " INSERT INTO mysql_string_types ( c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, c_json, c_json_string_override, c_enum, c_set ) VALUES (@c_char, @c_nchar, @c_national_char, @c_varchar, @c_tinytext, @c_mediumtext, @c_text, @c_longtext, @c_json, @c_json_string_override, @c_enum, @c_set)"; + private const string InsertMysqlStringTypesSql = @" + INSERT INTO mysql_string_types + ( + c_char, + c_nchar, + c_national_char, + c_varchar, + c_tinytext, + c_mediumtext, + c_text, + c_longtext, + c_json, + c_json_string_override, + c_enum, + c_set + ) + VALUES (@c_char, @c_nchar, @c_national_char, @c_varchar, @c_tinytext, @c_mediumtext, @c_text, @c_longtext, @c_json, @c_json_string_override, @c_enum, @c_set)"; public class InsertMysqlStringTypesArgs { public string CChar { get; set; } @@ -1427,7 +1509,35 @@ public async Task GetMysqlStringTypes() return null; } - private const string GetMysqlStringTypesCntSql = "SELECT COUNT(*) AS cnt, c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, c_json, c_json_string_override, c_enum, c_set FROM mysql_string_types GROUP BY c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, c_json, c_json_string_override, c_enum, c_set LIMIT 1"; + private const string GetMysqlStringTypesCntSql = @"SELECT + COUNT(*) AS cnt, + c_char, + c_nchar, + c_national_char, + c_varchar, + c_tinytext, + c_mediumtext, + c_text, + c_longtext, + c_json, + c_json_string_override, + c_enum, + c_set + FROM mysql_string_types + GROUP BY + c_char, + c_nchar, + c_national_char, + c_varchar, + c_tinytext, + c_mediumtext, + c_text, + c_longtext, + c_json, + c_json_string_override, + c_enum, + c_set + LIMIT 1"; public class GetMysqlStringTypesCntRow { public long Cnt { get; set; } @@ -1541,7 +1651,17 @@ public async Task TruncateMysqlStringTypes() } } - private const string InsertMysqlDatetimeTypesSql = " INSERT INTO mysql_datetime_types ( c_year, c_date, c_datetime, c_timestamp, c_time, c_timestamp_noda_instant_override ) VALUES (@c_year, @c_date, @c_datetime, @c_timestamp, @c_time, @c_timestamp_noda_instant_override)"; + private const string InsertMysqlDatetimeTypesSql = @" + INSERT INTO mysql_datetime_types + ( + c_year, + c_date, + c_datetime, + c_timestamp, + c_time, + c_timestamp_noda_instant_override + ) + VALUES (@c_year, @c_date, @c_datetime, @c_timestamp, @c_time, @c_timestamp_noda_instant_override)"; public class InsertMysqlDatetimeTypesArgs { public short? CYear { get; set; } @@ -1722,7 +1842,21 @@ public async Task GetMysqlDatetimeTypes() return null; } - private const string GetMysqlDatetimeTypesCntSql = "SELECT COUNT(*) AS cnt, c_year, c_date, c_datetime, c_timestamp, c_time FROM mysql_datetime_types GROUP BY c_year, c_date, c_datetime, c_timestamp, c_time LIMIT 1"; + private const string GetMysqlDatetimeTypesCntSql = @"SELECT + COUNT(*) AS cnt, + c_year, + c_date, + c_datetime, + c_timestamp, + c_time + FROM mysql_datetime_types + GROUP BY + c_year, + c_date, + c_datetime, + c_timestamp, + c_time + LIMIT 1"; public class GetMysqlDatetimeTypesCntRow { public long Cnt { get; set; } @@ -1815,7 +1949,18 @@ public async Task TruncateMysqlDatetimeTypes() } } - private const string InsertMysqlBinaryTypesSql = " INSERT INTO mysql_binary_types ( c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob ) VALUES (@c_bit, @c_binary, @c_varbinary, @c_tinyblob, @c_blob, @c_mediumblob, @c_longblob)"; + private const string InsertMysqlBinaryTypesSql = @" + INSERT INTO mysql_binary_types + ( + c_bit, + c_binary, + c_varbinary, + c_tinyblob, + c_blob, + c_mediumblob, + c_longblob + ) + VALUES (@c_bit, @c_binary, @c_varbinary, @c_tinyblob, @c_blob, @c_mediumblob, @c_longblob)"; public class InsertMysqlBinaryTypesArgs { public byte? CBit { get; set; } @@ -1992,7 +2137,25 @@ public async Task GetMysqlBinaryTypes() return null; } - private const string GetMysqlBinaryTypesCntSql = "SELECT COUNT(*) AS cnt, c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_binary_types GROUP BY c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob LIMIT 1"; + private const string GetMysqlBinaryTypesCntSql = @"SELECT + COUNT(*) AS cnt, + c_bit, + c_binary, + c_varbinary, + c_tinyblob, + c_blob, + c_mediumblob, + c_longblob + FROM mysql_binary_types + GROUP BY + c_bit, + c_binary, + c_varbinary, + c_tinyblob, + c_blob, + c_mediumblob, + c_longblob + LIMIT 1"; public class GetMysqlBinaryTypesCntRow { public long Cnt { get; set; } @@ -2091,7 +2254,14 @@ public async Task TruncateMysqlBinaryTypes() } } - private const string GetMysqlFunctionsSql = " SELECT MAX(c_int) AS max_int, MAX(c_varchar) AS max_varchar, MAX(c_timestamp) AS max_timestamp FROM mysql_numeric_types CROSS JOIN mysql_string_types CROSS JOIN mysql_datetime_types"; + private const string GetMysqlFunctionsSql = @" + SELECT + MAX(c_int) AS max_int, + MAX(c_varchar) AS max_varchar, + MAX(c_timestamp) AS max_timestamp + FROM mysql_numeric_types + CROSS JOIN mysql_string_types + CROSS JOIN mysql_datetime_types"; public class GetMysqlFunctionsRow { public int? MaxInt { get; set; } diff --git a/examples/NpgsqlDapperExample/QuerySql.cs b/examples/NpgsqlDapperExample/QuerySql.cs index 8f9aa0e7..5d653873 100644 --- a/examples/NpgsqlDapperExample/QuerySql.cs +++ b/examples/NpgsqlDapperExample/QuerySql.cs @@ -45,7 +45,8 @@ public static QuerySql WithTransaction(NpgsqlTransaction transaction) private NpgsqlTransaction? Transaction { get; } private string? ConnectionString { get; } - private const string GetAuthorSql = "SELECT id, name, bio FROM authors WHERE name = @name LIMIT 1"; + private const string GetAuthorSql = @"SELECT id, name, bio FROM authors + WHERE name = @name LIMIT 1"; public class GetAuthorRow { public required long Id { get; init; } @@ -74,7 +75,11 @@ public class GetAuthorArgs return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetAuthorSql, queryParams, transaction: this.Transaction); } - private const string ListAuthorsSql = "SELECT id, name, bio FROM authors ORDER BY name LIMIT @limit OFFSET @offset"; + private const string ListAuthorsSql = @"SELECT id, name, bio + FROM authors + ORDER BY name + LIMIT @limit + OFFSET @offset"; public class ListAuthorsRow { public required long Id { get; init; } @@ -164,7 +169,8 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) return await this.Transaction.Connection.QuerySingleAsync(CreateAuthorReturnIdSql, queryParams, transaction: this.Transaction); } - private const string GetAuthorByIdSql = "SELECT id, name, bio FROM authors WHERE id = @id LIMIT 1"; + private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors + WHERE id = @id LIMIT 1"; public class GetAuthorByIdRow { public required long Id { get; init; } @@ -193,7 +199,8 @@ public class GetAuthorByIdArgs return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetAuthorByIdSql, queryParams, transaction: this.Transaction); } - private const string GetAuthorByNamePatternSql = "SELECT id, name, bio FROM authors WHERE name LIKE COALESCE(@name_pattern, '%')"; + private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors + WHERE name LIKE COALESCE(@name_pattern, '%')"; public class GetAuthorByNamePatternRow { public required long Id { get; init; } @@ -222,7 +229,8 @@ public async Task> GetAuthorByNamePattern(GetAut return (await this.Transaction.Connection.QueryAsync(GetAuthorByNamePatternSql, queryParams, transaction: this.Transaction)).AsList(); } - private const string DeleteAuthorSql = "DELETE FROM authors WHERE name = @name"; + private const string DeleteAuthorSql = @"DELETE FROM authors + WHERE name = @name"; public class DeleteAuthorArgs { public required string Name { get; init; } @@ -258,7 +266,9 @@ public async Task TruncateAuthors() await this.Transaction.Connection.ExecuteAsync(TruncateAuthorsSql, transaction: this.Transaction); } - private const string UpdateAuthorsSql = "UPDATE authors SET bio = @bio WHERE bio IS NOT NULL"; + private const string UpdateAuthorsSql = @"UPDATE authors + SET bio = @bio + WHERE bio IS NOT NULL"; public class UpdateAuthorsArgs { public string? Bio { get; init; } @@ -278,7 +288,8 @@ public async Task UpdateAuthors(UpdateAuthorsArgs args) return await this.Transaction.Connection.ExecuteAsync(UpdateAuthorsSql, queryParams, transaction: this.Transaction); } - private const string GetAuthorsByIdsSql = "SELECT id, name, bio FROM authors WHERE id = ANY(@longArr_1::BIGINT [])"; + private const string GetAuthorsByIdsSql = @"SELECT id, name, bio FROM authors + WHERE id = ANY(@longArr_1::BIGINT [])"; public class GetAuthorsByIdsRow { public required long Id { get; init; } @@ -307,7 +318,9 @@ public async Task> GetAuthorsByIds(GetAuthorsByIdsArgs return (await this.Transaction.Connection.QueryAsync(GetAuthorsByIdsSql, queryParams, transaction: this.Transaction)).AsList(); } - private const string GetAuthorsByIdsAndNamesSql = "SELECT id, name, bio FROM authors WHERE id = ANY(@longArr_1::BIGINT []) AND name = ANY(@stringArr_2::TEXT [])"; + private const string GetAuthorsByIdsAndNamesSql = @"SELECT id, name, bio + FROM authors + WHERE id = ANY(@longArr_1::BIGINT []) AND name = ANY(@stringArr_2::TEXT [])"; public class GetAuthorsByIdsAndNamesRow { public required long Id { get; init; } @@ -364,7 +377,12 @@ public async Task CreateBook(CreateBookArgs args) return await this.Transaction.Connection.QuerySingleAsync(CreateBookSql, queryParams, transaction: this.Transaction); } - private const string ListAllAuthorsBooksSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors INNER JOIN books ON authors.id = books.author_id ORDER BY authors.name"; + private const string ListAllAuthorsBooksSql = @"SELECT + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors + INNER JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public class ListAllAuthorsBooksRow { public required Author? Author { get; init; } @@ -405,7 +423,12 @@ public async Task> ListAllAuthorsBooks() } } - private const string GetDuplicateAuthorsSql = "SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio FROM authors AS authors1 INNER JOIN authors AS authors2 ON authors1.name = authors2.name WHERE authors1.id < authors2.id"; + private const string GetDuplicateAuthorsSql = @"SELECT + authors1.id, authors1.name, authors1.bio, + authors2.id, authors2.name, authors2.bio + FROM authors AS authors1 + INNER JOIN authors AS authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public class GetDuplicateAuthorsRow { public required Author? Author { get; init; } @@ -446,7 +469,11 @@ public async Task> GetDuplicateAuthors() } } - private const string GetAuthorsByBookNameSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors INNER JOIN books ON authors.id = books.author_id WHERE books.name = @name"; + private const string GetAuthorsByBookNameSql = @"SELECT + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public class GetAuthorsByBookNameRow { public required long Id { get; init; } @@ -564,7 +591,13 @@ public async Task TruncateExtendedBios() await this.Transaction.Connection.ExecuteAsync(TruncateExtendedBiosSql, transaction: this.Transaction); } - private const string GetPostgresFunctionsSql = "SELECT MAX(c_integer) AS max_integer, MAX(c_varchar) AS max_varchar, MAX(c_timestamp) AS max_timestamp FROM postgres_datetime_types CROSS JOIN postgres_numeric_types CROSS JOIN postgres_string_types"; + private const string GetPostgresFunctionsSql = @"SELECT + MAX(c_integer) AS max_integer, + MAX(c_varchar) AS max_varchar, + MAX(c_timestamp) AS max_timestamp + FROM postgres_datetime_types + CROSS JOIN postgres_numeric_types + CROSS JOIN postgres_string_types"; public class GetPostgresFunctionsRow { public int? MaxInteger { get; init; } @@ -587,7 +620,21 @@ public class GetPostgresFunctionsRow return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresFunctionsSql, transaction: this.Transaction); } - private const string InsertPostgresNumericTypesSql = " INSERT INTO postgres_numeric_types ( c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money ) VALUES (@c_boolean, @c_bit, @c_smallint, @c_integer, @c_bigint, @c_decimal, @c_numeric, @c_real, @c_double_precision, @c_money)"; + private const string InsertPostgresNumericTypesSql = @" + INSERT INTO postgres_numeric_types + ( + c_boolean, + c_bit, + c_smallint, + c_integer, + c_bigint, + c_decimal, + c_numeric, + c_real, + c_double_precision, + c_money + ) + VALUES (@c_boolean, @c_bit, @c_smallint, @c_integer, @c_bigint, @c_decimal, @c_numeric, @c_real, @c_double_precision, @c_money)"; public class InsertPostgresNumericTypesArgs { public bool? CBoolean { get; init; } @@ -671,7 +718,31 @@ public async Task TruncatePostgresNumericTypes() await this.Transaction.Connection.ExecuteAsync(TruncatePostgresNumericTypesSql, transaction: this.Transaction); } - private const string GetPostgresNumericTypesCntSql = "SELECT c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money, COUNT(*) AS cnt FROM postgres_numeric_types GROUP BY c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money LIMIT 1"; + private const string GetPostgresNumericTypesCntSql = @"SELECT + c_boolean, + c_bit, + c_smallint, + c_integer, + c_bigint, + c_decimal, + c_numeric, + c_real, + c_double_precision, + c_money, + COUNT(*) AS cnt + FROM postgres_numeric_types + GROUP BY + c_boolean, + c_bit, + c_smallint, + c_integer, + c_bigint, + c_decimal, + c_numeric, + c_real, + c_double_precision, + c_money + LIMIT 1"; public class GetPostgresNumericTypesCntRow { public bool? CBoolean { get; init; } @@ -745,7 +816,16 @@ public async Task InsertPostgresNumericTypesBatch(List(GetPostgresStringTypesCntSql, transaction: this.Transaction); } - private const string GetPostgresStringTypesTextSearchSql = "WITH txt_query AS ( SELECT c_text, to_tsquery('english', @to_tsquery) AS query, to_tsvector('english', c_text) AS tsv FROM postgres_string_types WHERE c_text @@ to_tsquery('english', @to_tsquery) ) SELECT txt_query.c_text, txt_query.query, txt_query.tsv, ts_rank(tsv, query) AS rnk FROM txt_query ORDER BY rnk DESC LIMIT 1"; + private const string GetPostgresStringTypesTextSearchSql = @"WITH txt_query AS ( + SELECT + c_text, + to_tsquery('english', @to_tsquery) AS query, + to_tsvector('english', c_text) AS tsv + FROM postgres_string_types + WHERE c_text @@ to_tsquery('english', @to_tsquery) + ) + + SELECT txt_query.c_text, txt_query.query, txt_query.tsv, ts_rank(tsv, query) AS rnk + FROM txt_query + ORDER BY rnk DESC + LIMIT 1"; public class GetPostgresStringTypesTextSearchRow { public string? CText { get; init; } @@ -903,7 +1009,16 @@ public class GetPostgresStringTypesTextSearchArgs return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresStringTypesTextSearchSql, queryParams, transaction: this.Transaction); } - private const string InsertPostgresDateTimeTypesSql = " INSERT INTO postgres_datetime_types ( c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_timestamp_noda_instant_override ) VALUES (@c_date, @c_time, @c_timestamp, @c_timestamp_with_tz, @c_interval, @c_timestamp_noda_instant_override)"; + private const string InsertPostgresDateTimeTypesSql = @" + INSERT INTO postgres_datetime_types + ( + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval, + c_timestamp_noda_instant_override + ) VALUES (@c_date, @c_time, @c_timestamp, @c_timestamp_with_tz, @c_interval, @c_timestamp_noda_instant_override)"; public class InsertPostgresDateTimeTypesArgs { public DateTime? CDate { get; init; } @@ -975,7 +1090,21 @@ public async Task TruncatePostgresDateTimeTypes() await this.Transaction.Connection.ExecuteAsync(TruncatePostgresDateTimeTypesSql, transaction: this.Transaction); } - private const string GetPostgresDateTimeTypesCntSql = "SELECT c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, COUNT(*) AS cnt FROM postgres_datetime_types GROUP BY c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval LIMIT 1"; + private const string GetPostgresDateTimeTypesCntSql = @"SELECT + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval, + COUNT(*) AS cnt + FROM postgres_datetime_types + GROUP BY + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval + LIMIT 1"; public class GetPostgresDateTimeTypesCntRow { public DateTime? CDate { get; init; } @@ -1034,7 +1163,19 @@ public async Task InsertPostgresDateTimeTypesBatch(List(GetPostgresSpecialTypesCntSql, transaction: this.Transaction); } - private const string InsertPostgresArrayTypesSql = " INSERT INTO postgres_array_types ( c_bytea, c_boolean_array, c_text_array, c_integer_array, c_decimal_array, c_date_array, c_timestamp_array ) VALUES (@c_bytea, @c_boolean_array, @c_text_array, @c_integer_array, @c_decimal_array, @c_date_array, @c_timestamp_array)"; + private const string InsertPostgresArrayTypesSql = @" + INSERT INTO postgres_array_types + ( + c_bytea, + c_boolean_array, + c_text_array, + c_integer_array, + c_decimal_array, + c_date_array, + c_timestamp_array + ) + VALUES (@c_bytea, @c_boolean_array, @c_text_array, @c_integer_array, @c_decimal_array, @c_date_array, @c_timestamp_array)"; public class InsertPostgresArrayTypesArgs { public byte[]? CBytea { get; init; } @@ -1436,7 +1663,23 @@ public async Task InsertPostgresArrayTypesBatch(List GetAuthor(GetAuthorArgs args) return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetAuthorSql, queryParams, transaction: this.Transaction); } - private const string ListAuthorsSql = "SELECT id, name, bio FROM authors ORDER BY name LIMIT @limit OFFSET @offset"; + private const string ListAuthorsSql = @"SELECT id, name, bio + FROM authors + ORDER BY name + LIMIT @limit + OFFSET @offset"; public class ListAuthorsRow { public long Id { get; set; } @@ -165,7 +170,8 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) return await this.Transaction.Connection.QuerySingleAsync(CreateAuthorReturnIdSql, queryParams, transaction: this.Transaction); } - private const string GetAuthorByIdSql = "SELECT id, name, bio FROM authors WHERE id = @id LIMIT 1"; + private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors + WHERE id = @id LIMIT 1"; public class GetAuthorByIdRow { public long Id { get; set; } @@ -194,7 +200,8 @@ public async Task GetAuthorById(GetAuthorByIdArgs args) return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetAuthorByIdSql, queryParams, transaction: this.Transaction); } - private const string GetAuthorByNamePatternSql = "SELECT id, name, bio FROM authors WHERE name LIKE COALESCE(@name_pattern, '%')"; + private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors + WHERE name LIKE COALESCE(@name_pattern, '%')"; public class GetAuthorByNamePatternRow { public long Id { get; set; } @@ -223,7 +230,8 @@ public async Task> GetAuthorByNamePattern(GetAut return (await this.Transaction.Connection.QueryAsync(GetAuthorByNamePatternSql, queryParams, transaction: this.Transaction)).AsList(); } - private const string DeleteAuthorSql = "DELETE FROM authors WHERE name = @name"; + private const string DeleteAuthorSql = @"DELETE FROM authors + WHERE name = @name"; public class DeleteAuthorArgs { public string Name { get; set; } @@ -259,7 +267,9 @@ public async Task TruncateAuthors() await this.Transaction.Connection.ExecuteAsync(TruncateAuthorsSql, transaction: this.Transaction); } - private const string UpdateAuthorsSql = "UPDATE authors SET bio = @bio WHERE bio IS NOT NULL"; + private const string UpdateAuthorsSql = @"UPDATE authors + SET bio = @bio + WHERE bio IS NOT NULL"; public class UpdateAuthorsArgs { public string Bio { get; set; } @@ -279,7 +289,8 @@ public async Task UpdateAuthors(UpdateAuthorsArgs args) return await this.Transaction.Connection.ExecuteAsync(UpdateAuthorsSql, queryParams, transaction: this.Transaction); } - private const string GetAuthorsByIdsSql = "SELECT id, name, bio FROM authors WHERE id = ANY(@longArr_1::BIGINT [])"; + private const string GetAuthorsByIdsSql = @"SELECT id, name, bio FROM authors + WHERE id = ANY(@longArr_1::BIGINT [])"; public class GetAuthorsByIdsRow { public long Id { get; set; } @@ -308,7 +319,9 @@ public async Task> GetAuthorsByIds(GetAuthorsByIdsArgs return (await this.Transaction.Connection.QueryAsync(GetAuthorsByIdsSql, queryParams, transaction: this.Transaction)).AsList(); } - private const string GetAuthorsByIdsAndNamesSql = "SELECT id, name, bio FROM authors WHERE id = ANY(@longArr_1::BIGINT []) AND name = ANY(@stringArr_2::TEXT [])"; + private const string GetAuthorsByIdsAndNamesSql = @"SELECT id, name, bio + FROM authors + WHERE id = ANY(@longArr_1::BIGINT []) AND name = ANY(@stringArr_2::TEXT [])"; public class GetAuthorsByIdsAndNamesRow { public long Id { get; set; } @@ -365,7 +378,12 @@ public async Task CreateBook(CreateBookArgs args) return await this.Transaction.Connection.QuerySingleAsync(CreateBookSql, queryParams, transaction: this.Transaction); } - private const string ListAllAuthorsBooksSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors INNER JOIN books ON authors.id = books.author_id ORDER BY authors.name"; + private const string ListAllAuthorsBooksSql = @"SELECT + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors + INNER JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public class ListAllAuthorsBooksRow { public Author Author { get; set; } @@ -406,7 +424,12 @@ public async Task> ListAllAuthorsBooks() } } - private const string GetDuplicateAuthorsSql = "SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio FROM authors AS authors1 INNER JOIN authors AS authors2 ON authors1.name = authors2.name WHERE authors1.id < authors2.id"; + private const string GetDuplicateAuthorsSql = @"SELECT + authors1.id, authors1.name, authors1.bio, + authors2.id, authors2.name, authors2.bio + FROM authors AS authors1 + INNER JOIN authors AS authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public class GetDuplicateAuthorsRow { public Author Author { get; set; } @@ -447,7 +470,11 @@ public async Task> GetDuplicateAuthors() } } - private const string GetAuthorsByBookNameSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors INNER JOIN books ON authors.id = books.author_id WHERE books.name = @name"; + private const string GetAuthorsByBookNameSql = @"SELECT + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public class GetAuthorsByBookNameRow { public long Id { get; set; } @@ -565,7 +592,13 @@ public async Task TruncateExtendedBios() await this.Transaction.Connection.ExecuteAsync(TruncateExtendedBiosSql, transaction: this.Transaction); } - private const string GetPostgresFunctionsSql = "SELECT MAX(c_integer) AS max_integer, MAX(c_varchar) AS max_varchar, MAX(c_timestamp) AS max_timestamp FROM postgres_datetime_types CROSS JOIN postgres_numeric_types CROSS JOIN postgres_string_types"; + private const string GetPostgresFunctionsSql = @"SELECT + MAX(c_integer) AS max_integer, + MAX(c_varchar) AS max_varchar, + MAX(c_timestamp) AS max_timestamp + FROM postgres_datetime_types + CROSS JOIN postgres_numeric_types + CROSS JOIN postgres_string_types"; public class GetPostgresFunctionsRow { public int? MaxInteger { get; set; } @@ -588,7 +621,21 @@ public async Task GetPostgresFunctions() return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresFunctionsSql, transaction: this.Transaction); } - private const string InsertPostgresNumericTypesSql = " INSERT INTO postgres_numeric_types ( c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money ) VALUES (@c_boolean, @c_bit, @c_smallint, @c_integer, @c_bigint, @c_decimal, @c_numeric, @c_real, @c_double_precision, @c_money)"; + private const string InsertPostgresNumericTypesSql = @" + INSERT INTO postgres_numeric_types + ( + c_boolean, + c_bit, + c_smallint, + c_integer, + c_bigint, + c_decimal, + c_numeric, + c_real, + c_double_precision, + c_money + ) + VALUES (@c_boolean, @c_bit, @c_smallint, @c_integer, @c_bigint, @c_decimal, @c_numeric, @c_real, @c_double_precision, @c_money)"; public class InsertPostgresNumericTypesArgs { public bool? CBoolean { get; set; } @@ -672,7 +719,31 @@ public async Task TruncatePostgresNumericTypes() await this.Transaction.Connection.ExecuteAsync(TruncatePostgresNumericTypesSql, transaction: this.Transaction); } - private const string GetPostgresNumericTypesCntSql = "SELECT c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money, COUNT(*) AS cnt FROM postgres_numeric_types GROUP BY c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money LIMIT 1"; + private const string GetPostgresNumericTypesCntSql = @"SELECT + c_boolean, + c_bit, + c_smallint, + c_integer, + c_bigint, + c_decimal, + c_numeric, + c_real, + c_double_precision, + c_money, + COUNT(*) AS cnt + FROM postgres_numeric_types + GROUP BY + c_boolean, + c_bit, + c_smallint, + c_integer, + c_bigint, + c_decimal, + c_numeric, + c_real, + c_double_precision, + c_money + LIMIT 1"; public class GetPostgresNumericTypesCntRow { public bool? CBoolean { get; set; } @@ -746,7 +817,16 @@ public async Task InsertPostgresNumericTypesBatch(List GetPostgresStringTypesCnt() return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresStringTypesCntSql, transaction: this.Transaction); } - private const string GetPostgresStringTypesTextSearchSql = "WITH txt_query AS ( SELECT c_text, to_tsquery('english', @to_tsquery) AS query, to_tsvector('english', c_text) AS tsv FROM postgres_string_types WHERE c_text @@ to_tsquery('english', @to_tsquery) ) SELECT txt_query.c_text, txt_query.query, txt_query.tsv, ts_rank(tsv, query) AS rnk FROM txt_query ORDER BY rnk DESC LIMIT 1"; + private const string GetPostgresStringTypesTextSearchSql = @"WITH txt_query AS ( + SELECT + c_text, + to_tsquery('english', @to_tsquery) AS query, + to_tsvector('english', c_text) AS tsv + FROM postgres_string_types + WHERE c_text @@ to_tsquery('english', @to_tsquery) + ) + + SELECT txt_query.c_text, txt_query.query, txt_query.tsv, ts_rank(tsv, query) AS rnk + FROM txt_query + ORDER BY rnk DESC + LIMIT 1"; public class GetPostgresStringTypesTextSearchRow { public string CText { get; set; } @@ -904,7 +1010,16 @@ public async Task GetPostgresStringTypesTex return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresStringTypesTextSearchSql, queryParams, transaction: this.Transaction); } - private const string InsertPostgresDateTimeTypesSql = " INSERT INTO postgres_datetime_types ( c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_timestamp_noda_instant_override ) VALUES (@c_date, @c_time, @c_timestamp, @c_timestamp_with_tz, @c_interval, @c_timestamp_noda_instant_override)"; + private const string InsertPostgresDateTimeTypesSql = @" + INSERT INTO postgres_datetime_types + ( + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval, + c_timestamp_noda_instant_override + ) VALUES (@c_date, @c_time, @c_timestamp, @c_timestamp_with_tz, @c_interval, @c_timestamp_noda_instant_override)"; public class InsertPostgresDateTimeTypesArgs { public DateTime? CDate { get; set; } @@ -976,7 +1091,21 @@ public async Task TruncatePostgresDateTimeTypes() await this.Transaction.Connection.ExecuteAsync(TruncatePostgresDateTimeTypesSql, transaction: this.Transaction); } - private const string GetPostgresDateTimeTypesCntSql = "SELECT c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, COUNT(*) AS cnt FROM postgres_datetime_types GROUP BY c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval LIMIT 1"; + private const string GetPostgresDateTimeTypesCntSql = @"SELECT + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval, + COUNT(*) AS cnt + FROM postgres_datetime_types + GROUP BY + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval + LIMIT 1"; public class GetPostgresDateTimeTypesCntRow { public DateTime? CDate { get; set; } @@ -1035,7 +1164,19 @@ public async Task InsertPostgresDateTimeTypesBatch(List GetPostgresSpecialTypesCnt() return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresSpecialTypesCntSql, transaction: this.Transaction); } - private const string InsertPostgresArrayTypesSql = " INSERT INTO postgres_array_types ( c_bytea, c_boolean_array, c_text_array, c_integer_array, c_decimal_array, c_date_array, c_timestamp_array ) VALUES (@c_bytea, @c_boolean_array, @c_text_array, @c_integer_array, @c_decimal_array, @c_date_array, @c_timestamp_array)"; + private const string InsertPostgresArrayTypesSql = @" + INSERT INTO postgres_array_types + ( + c_bytea, + c_boolean_array, + c_text_array, + c_integer_array, + c_decimal_array, + c_date_array, + c_timestamp_array + ) + VALUES (@c_bytea, @c_boolean_array, @c_text_array, @c_integer_array, @c_decimal_array, @c_date_array, @c_timestamp_array)"; public class InsertPostgresArrayTypesArgs { public byte[] CBytea { get; set; } @@ -1437,7 +1664,23 @@ public async Task InsertPostgresArrayTypesBatch(List GetAuthor(GetAuthorArgs args) @@ -96,7 +97,11 @@ public static QuerySql WithTransaction(NpgsqlTransaction transaction) return null; } - private const string ListAuthorsSql = "SELECT id, name, bio FROM authors ORDER BY name LIMIT @limit OFFSET @offset"; + private const string ListAuthorsSql = @"SELECT id, name, bio + FROM authors + ORDER BY name + LIMIT @limit + OFFSET @offset"; public readonly record struct ListAuthorsRow(long Id, string Name, string? Bio); public readonly record struct ListAuthorsArgs(int Offset, int Limit); public async Task> ListAuthors(ListAuthorsArgs args) @@ -228,7 +233,8 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } } - private const string GetAuthorByIdSql = "SELECT id, name, bio FROM authors WHERE id = @id LIMIT 1"; + private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors + WHERE id = @id LIMIT 1"; public readonly record struct GetAuthorByIdRow(long Id, string Name, string? Bio); public readonly record struct GetAuthorByIdArgs(long Id); public async Task GetAuthorById(GetAuthorByIdArgs args) @@ -282,7 +288,8 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) return null; } - private const string GetAuthorByNamePatternSql = "SELECT id, name, bio FROM authors WHERE name LIKE COALESCE(@name_pattern, '%')"; + private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors + WHERE name LIKE COALESCE(@name_pattern, '%')"; public readonly record struct GetAuthorByNamePatternRow(long Id, string Name, string? Bio); public readonly record struct GetAuthorByNamePatternArgs(string? NamePattern); public async Task> GetAuthorByNamePattern(GetAuthorByNamePatternArgs args) @@ -322,7 +329,8 @@ public async Task> GetAuthorByNamePattern(GetAut } } - private const string DeleteAuthorSql = "DELETE FROM authors WHERE name = @name"; + private const string DeleteAuthorSql = @"DELETE FROM authors + WHERE name = @name"; public readonly record struct DeleteAuthorArgs(string Name); public async Task DeleteAuthor(DeleteAuthorArgs args) { @@ -377,7 +385,9 @@ public async Task TruncateAuthors() } } - private const string UpdateAuthorsSql = "UPDATE authors SET bio = @bio WHERE bio IS NOT NULL"; + private const string UpdateAuthorsSql = @"UPDATE authors + SET bio = @bio + WHERE bio IS NOT NULL"; public readonly record struct UpdateAuthorsArgs(string? Bio); public async Task UpdateAuthors(UpdateAuthorsArgs args) { @@ -404,7 +414,8 @@ public async Task UpdateAuthors(UpdateAuthorsArgs args) } } - private const string GetAuthorsByIdsSql = "SELECT id, name, bio FROM authors WHERE id = ANY(@longArr_1::BIGINT [])"; + private const string GetAuthorsByIdsSql = @"SELECT id, name, bio FROM authors + WHERE id = ANY(@longArr_1::BIGINT [])"; public readonly record struct GetAuthorsByIdsRow(long Id, string Name, string? Bio); public readonly record struct GetAuthorsByIdsArgs(long[] LongArr1); public async Task> GetAuthorsByIds(GetAuthorsByIdsArgs args) @@ -444,7 +455,9 @@ public async Task> GetAuthorsByIds(GetAuthorsByIdsArgs } } - private const string GetAuthorsByIdsAndNamesSql = "SELECT id, name, bio FROM authors WHERE id = ANY(@longArr_1::BIGINT []) AND name = ANY(@stringArr_2::TEXT [])"; + private const string GetAuthorsByIdsAndNamesSql = @"SELECT id, name, bio + FROM authors + WHERE id = ANY(@longArr_1::BIGINT []) AND name = ANY(@stringArr_2::TEXT [])"; public readonly record struct GetAuthorsByIdsAndNamesRow(long Id, string Name, string? Bio); public readonly record struct GetAuthorsByIdsAndNamesArgs(long[] LongArr1, string[] StringArr2); public async Task> GetAuthorsByIdsAndNames(GetAuthorsByIdsAndNamesArgs args) @@ -518,7 +531,12 @@ public async Task CreateBook(CreateBookArgs args) } } - private const string ListAllAuthorsBooksSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors INNER JOIN books ON authors.id = books.author_id ORDER BY authors.name"; + private const string ListAllAuthorsBooksSql = @"SELECT + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors + INNER JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public readonly record struct ListAllAuthorsBooksRow(Author? Author, Book? Book); public async Task> ListAllAuthorsBooks() { @@ -555,7 +573,12 @@ public async Task> ListAllAuthorsBooks() } } - private const string GetDuplicateAuthorsSql = "SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio FROM authors AS authors1 INNER JOIN authors AS authors2 ON authors1.name = authors2.name WHERE authors1.id < authors2.id"; + private const string GetDuplicateAuthorsSql = @"SELECT + authors1.id, authors1.name, authors1.bio, + authors2.id, authors2.name, authors2.bio + FROM authors AS authors1 + INNER JOIN authors AS authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public readonly record struct GetDuplicateAuthorsRow(Author? Author, Author? Author2); public async Task> GetDuplicateAuthors() { @@ -592,7 +615,11 @@ public async Task> GetDuplicateAuthors() } } - private const string GetAuthorsByBookNameSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors INNER JOIN books ON authors.id = books.author_id WHERE books.name = @name"; + private const string GetAuthorsByBookNameSql = @"SELECT + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public readonly record struct GetAuthorsByBookNameRow(long Id, string Name, string? Bio, Book? Book); public readonly record struct GetAuthorsByBookNameArgs(string Name); public async Task> GetAuthorsByBookName(GetAuthorsByBookNameArgs args) @@ -745,7 +772,13 @@ public async Task TruncateExtendedBios() } } - private const string GetPostgresFunctionsSql = "SELECT MAX(c_integer) AS max_integer, MAX(c_varchar) AS max_varchar, MAX(c_timestamp) AS max_timestamp FROM postgres_datetime_types CROSS JOIN postgres_numeric_types CROSS JOIN postgres_string_types"; + private const string GetPostgresFunctionsSql = @"SELECT + MAX(c_integer) AS max_integer, + MAX(c_varchar) AS max_varchar, + MAX(c_timestamp) AS max_timestamp + FROM postgres_datetime_types + CROSS JOIN postgres_numeric_types + CROSS JOIN postgres_string_types"; public readonly record struct GetPostgresFunctionsRow(int? MaxInteger, string? MaxVarchar, DateTime MaxTimestamp); public async Task GetPostgresFunctions() { @@ -796,7 +829,21 @@ public async Task TruncateExtendedBios() return null; } - private const string InsertPostgresNumericTypesSql = " INSERT INTO postgres_numeric_types ( c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money ) VALUES (@c_boolean, @c_bit, @c_smallint, @c_integer, @c_bigint, @c_decimal, @c_numeric, @c_real, @c_double_precision, @c_money)"; + private const string InsertPostgresNumericTypesSql = @" + INSERT INTO postgres_numeric_types + ( + c_boolean, + c_bit, + c_smallint, + c_integer, + c_bigint, + c_decimal, + c_numeric, + c_real, + c_double_precision, + c_money + ) + VALUES (@c_boolean, @c_bit, @c_smallint, @c_integer, @c_bigint, @c_decimal, @c_numeric, @c_real, @c_double_precision, @c_money)"; public readonly record struct InsertPostgresNumericTypesArgs(bool? CBoolean, byte[]? CBit, short? CSmallint, int? CInteger, long? CBigint, decimal? CDecimal, decimal? CNumeric, float? CReal, double? CDoublePrecision, decimal? CMoney); public async Task InsertPostgresNumericTypes(InsertPostgresNumericTypesArgs args) { @@ -934,7 +981,31 @@ public async Task TruncatePostgresNumericTypes() } } - private const string GetPostgresNumericTypesCntSql = "SELECT c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money, COUNT(*) AS cnt FROM postgres_numeric_types GROUP BY c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money LIMIT 1"; + private const string GetPostgresNumericTypesCntSql = @"SELECT + c_boolean, + c_bit, + c_smallint, + c_integer, + c_bigint, + c_decimal, + c_numeric, + c_real, + c_double_precision, + c_money, + COUNT(*) AS cnt + FROM postgres_numeric_types + GROUP BY + c_boolean, + c_bit, + c_smallint, + c_integer, + c_bigint, + c_decimal, + c_numeric, + c_real, + c_double_precision, + c_money + LIMIT 1"; public readonly record struct GetPostgresNumericTypesCntRow(bool? CBoolean, byte[]? CBit, short? CSmallint, int? CInteger, long? CBigint, decimal? CDecimal, decimal? CNumeric, float? CReal, double? CDoublePrecision, decimal? CMoney, long Cnt); public async Task GetPostgresNumericTypesCnt() { @@ -1032,7 +1103,16 @@ public async Task InsertPostgresNumericTypesBatch(List GetPostgresStringTypesCnt() { @@ -1233,7 +1327,19 @@ public async Task TruncatePostgresStringTypes() return null; } - private const string GetPostgresStringTypesTextSearchSql = "WITH txt_query AS ( SELECT c_text, to_tsquery('english', @to_tsquery) AS query, to_tsvector('english', c_text) AS tsv FROM postgres_string_types WHERE c_text @@ to_tsquery('english', @to_tsquery) ) SELECT txt_query.c_text, txt_query.query, txt_query.tsv, ts_rank(tsv, query) AS rnk FROM txt_query ORDER BY rnk DESC LIMIT 1"; + private const string GetPostgresStringTypesTextSearchSql = @"WITH txt_query AS ( + SELECT + c_text, + to_tsquery('english', @to_tsquery) AS query, + to_tsvector('english', c_text) AS tsv + FROM postgres_string_types + WHERE c_text @@ to_tsquery('english', @to_tsquery) + ) + + SELECT txt_query.c_text, txt_query.query, txt_query.tsv, ts_rank(tsv, query) AS rnk + FROM txt_query + ORDER BY rnk DESC + LIMIT 1"; public readonly record struct GetPostgresStringTypesTextSearchRow(string? CText, NpgsqlTsQuery Query, NpgsqlTsVector Tsv, float Rnk); public readonly record struct GetPostgresStringTypesTextSearchArgs(string ToTsquery); public async Task GetPostgresStringTypesTextSearch(GetPostgresStringTypesTextSearchArgs args) @@ -1289,7 +1395,16 @@ public async Task TruncatePostgresStringTypes() return null; } - private const string InsertPostgresDateTimeTypesSql = " INSERT INTO postgres_datetime_types ( c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_timestamp_noda_instant_override ) VALUES (@c_date, @c_time, @c_timestamp, @c_timestamp_with_tz, @c_interval, @c_timestamp_noda_instant_override)"; + private const string InsertPostgresDateTimeTypesSql = @" + INSERT INTO postgres_datetime_types + ( + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval, + c_timestamp_noda_instant_override + ) VALUES (@c_date, @c_time, @c_timestamp, @c_timestamp_with_tz, @c_interval, @c_timestamp_noda_instant_override)"; public readonly record struct InsertPostgresDateTimeTypesArgs(DateTime? CDate, TimeSpan? CTime, DateTime? CTimestamp, DateTime? CTimestampWithTz, TimeSpan? CInterval, Instant? CTimestampNodaInstantOverride); public async Task InsertPostgresDateTimeTypes(InsertPostgresDateTimeTypesArgs args) { @@ -1423,7 +1538,21 @@ public async Task TruncatePostgresDateTimeTypes() } } - private const string GetPostgresDateTimeTypesCntSql = "SELECT c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, COUNT(*) AS cnt FROM postgres_datetime_types GROUP BY c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval LIMIT 1"; + private const string GetPostgresDateTimeTypesCntSql = @"SELECT + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval, + COUNT(*) AS cnt + FROM postgres_datetime_types + GROUP BY + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval + LIMIT 1"; public readonly record struct GetPostgresDateTimeTypesCntRow(DateTime? CDate, TimeSpan? CTime, DateTime? CTimestamp, DateTime? CTimestampWithTz, TimeSpan? CInterval, long Cnt); public async Task GetPostgresDateTimeTypesCnt() { @@ -1506,7 +1635,19 @@ public async Task InsertPostgresDateTimeTypesBatch(List GetPostgresNetworkTypes() { @@ -1620,7 +1767,17 @@ public async Task TruncatePostgresNetworkTypes() } } - private const string GetPostgresNetworkTypesCntSql = "SELECT c_cidr, c_inet, c_macaddr, COUNT(*) AS cnt FROM postgres_network_types GROUP BY c_cidr, c_inet, c_macaddr LIMIT 1"; + private const string GetPostgresNetworkTypesCntSql = @"SELECT + c_cidr, + c_inet, + c_macaddr, + COUNT(*) AS cnt + FROM postgres_network_types + GROUP BY + c_cidr, + c_inet, + c_macaddr + LIMIT 1"; public readonly record struct GetPostgresNetworkTypesCntRow(NpgsqlCidr? CCidr, IPAddress? CInet, PhysicalAddress? CMacaddr, long Cnt); public async Task GetPostgresNetworkTypesCnt() { @@ -1697,7 +1854,28 @@ public async Task InsertPostgresNetworkTypesBatch(List GetPostgresNotNullTypes() { @@ -1842,7 +2029,17 @@ public async Task TruncatePostgresNotNullTypes() } } - private const string GetPostgresSpecialTypesSql = "SELECT c_json, c_json_string_override, c_jsonb, c_jsonpath, c_xml, c_xml_string_override, c_uuid, c_enum FROM postgres_special_types LIMIT 1"; + private const string GetPostgresSpecialTypesSql = @"SELECT + c_json, + c_json_string_override, + c_jsonb, + c_jsonpath, + c_xml, + c_xml_string_override, + c_uuid, + c_enum + FROM postgres_special_types + LIMIT 1"; public readonly record struct GetPostgresSpecialTypesRow(JsonElement? CJson, string? CJsonStringOverride, JsonElement? CJsonb, string? CJsonpath, XmlDocument? CXml, string? CXmlStringOverride, Guid? CUuid, CEnum? CEnum); public async Task GetPostgresSpecialTypes() { @@ -1963,7 +2160,26 @@ public async Task InsertPostgresSpecialTypesBatch(List GetPostgresSpecialTypesCnt() { @@ -2016,7 +2232,18 @@ public async Task InsertPostgresSpecialTypesBatch(List GetPostgresArrayTypesCnt() { @@ -2228,7 +2471,17 @@ public async Task TruncatePostgresArrayTypes() } } - private const string InsertPostgresGeoTypesSql = " INSERT INTO postgres_geometric_types ( c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle ) VALUES (@c_point, @c_line, @c_lseg, @c_box, @c_path, @c_polygon, @c_circle)"; + private const string InsertPostgresGeoTypesSql = @" + INSERT INTO postgres_geometric_types ( + c_point, + c_line, + c_lseg, + c_box, + c_path, + c_polygon, + c_circle + ) + VALUES (@c_point, @c_line, @c_lseg, @c_box, @c_path, @c_polygon, @c_circle)"; public readonly record struct InsertPostgresGeoTypesArgs(NpgsqlPoint? CPoint, NpgsqlLine? CLine, NpgsqlLSeg? CLseg, NpgsqlBox? CBox, NpgsqlPath? CPath, NpgsqlPolygon? CPolygon, NpgsqlCircle? CCircle); public async Task InsertPostgresGeoTypes(InsertPostgresGeoTypesArgs args) { diff --git a/examples/NpgsqlLegacyExample/QuerySql.cs b/examples/NpgsqlLegacyExample/QuerySql.cs index 9f156b89..def94498 100644 --- a/examples/NpgsqlLegacyExample/QuerySql.cs +++ b/examples/NpgsqlLegacyExample/QuerySql.cs @@ -43,7 +43,8 @@ public static QuerySql WithTransaction(NpgsqlTransaction transaction) private NpgsqlTransaction Transaction { get; } private string ConnectionString { get; } - private const string GetAuthorSql = "SELECT id, name, bio FROM authors WHERE name = @name LIMIT 1"; + private const string GetAuthorSql = @"SELECT id, name, bio FROM authors + WHERE name = @name LIMIT 1"; public class GetAuthorRow { public long Id { get; set; } @@ -105,7 +106,11 @@ public async Task GetAuthor(GetAuthorArgs args) return null; } - private const string ListAuthorsSql = "SELECT id, name, bio FROM authors ORDER BY name LIMIT @limit OFFSET @offset"; + private const string ListAuthorsSql = @"SELECT id, name, bio + FROM authors + ORDER BY name + LIMIT @limit + OFFSET @offset"; public class ListAuthorsRow { public long Id { get; set; } @@ -263,7 +268,8 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } } - private const string GetAuthorByIdSql = "SELECT id, name, bio FROM authors WHERE id = @id LIMIT 1"; + private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors + WHERE id = @id LIMIT 1"; public class GetAuthorByIdRow { public long Id { get; set; } @@ -325,7 +331,8 @@ public async Task GetAuthorById(GetAuthorByIdArgs args) return null; } - private const string GetAuthorByNamePatternSql = "SELECT id, name, bio FROM authors WHERE name LIKE COALESCE(@name_pattern, '%')"; + private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors + WHERE name LIKE COALESCE(@name_pattern, '%')"; public class GetAuthorByNamePatternRow { public long Id { get; set; } @@ -373,7 +380,8 @@ public async Task> GetAuthorByNamePattern(GetAut } } - private const string DeleteAuthorSql = "DELETE FROM authors WHERE name = @name"; + private const string DeleteAuthorSql = @"DELETE FROM authors + WHERE name = @name"; public class DeleteAuthorArgs { public string Name { get; set; } @@ -431,7 +439,9 @@ public async Task TruncateAuthors() } } - private const string UpdateAuthorsSql = "UPDATE authors SET bio = @bio WHERE bio IS NOT NULL"; + private const string UpdateAuthorsSql = @"UPDATE authors + SET bio = @bio + WHERE bio IS NOT NULL"; public class UpdateAuthorsArgs { public string Bio { get; set; } @@ -461,7 +471,8 @@ public async Task UpdateAuthors(UpdateAuthorsArgs args) } } - private const string GetAuthorsByIdsSql = "SELECT id, name, bio FROM authors WHERE id = ANY(@longArr_1::BIGINT [])"; + private const string GetAuthorsByIdsSql = @"SELECT id, name, bio FROM authors + WHERE id = ANY(@longArr_1::BIGINT [])"; public class GetAuthorsByIdsRow { public long Id { get; set; } @@ -509,7 +520,9 @@ public async Task> GetAuthorsByIds(GetAuthorsByIdsArgs } } - private const string GetAuthorsByIdsAndNamesSql = "SELECT id, name, bio FROM authors WHERE id = ANY(@longArr_1::BIGINT []) AND name = ANY(@stringArr_2::TEXT [])"; + private const string GetAuthorsByIdsAndNamesSql = @"SELECT id, name, bio + FROM authors + WHERE id = ANY(@longArr_1::BIGINT []) AND name = ANY(@stringArr_2::TEXT [])"; public class GetAuthorsByIdsAndNamesRow { public long Id { get; set; } @@ -599,7 +612,12 @@ public async Task CreateBook(CreateBookArgs args) } } - private const string ListAllAuthorsBooksSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors INNER JOIN books ON authors.id = books.author_id ORDER BY authors.name"; + private const string ListAllAuthorsBooksSql = @"SELECT + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors + INNER JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public class ListAllAuthorsBooksRow { public Author Author { get; set; } @@ -640,7 +658,12 @@ public async Task> ListAllAuthorsBooks() } } - private const string GetDuplicateAuthorsSql = "SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio FROM authors AS authors1 INNER JOIN authors AS authors2 ON authors1.name = authors2.name WHERE authors1.id < authors2.id"; + private const string GetDuplicateAuthorsSql = @"SELECT + authors1.id, authors1.name, authors1.bio, + authors2.id, authors2.name, authors2.bio + FROM authors AS authors1 + INNER JOIN authors AS authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public class GetDuplicateAuthorsRow { public Author Author { get; set; } @@ -681,7 +704,11 @@ public async Task> GetDuplicateAuthors() } } - private const string GetAuthorsByBookNameSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors INNER JOIN books ON authors.id = books.author_id WHERE books.name = @name"; + private const string GetAuthorsByBookNameSql = @"SELECT + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public class GetAuthorsByBookNameRow { public long Id { get; set; } @@ -856,7 +883,13 @@ public async Task TruncateExtendedBios() } } - private const string GetPostgresFunctionsSql = "SELECT MAX(c_integer) AS max_integer, MAX(c_varchar) AS max_varchar, MAX(c_timestamp) AS max_timestamp FROM postgres_datetime_types CROSS JOIN postgres_numeric_types CROSS JOIN postgres_string_types"; + private const string GetPostgresFunctionsSql = @"SELECT + MAX(c_integer) AS max_integer, + MAX(c_varchar) AS max_varchar, + MAX(c_timestamp) AS max_timestamp + FROM postgres_datetime_types + CROSS JOIN postgres_numeric_types + CROSS JOIN postgres_string_types"; public class GetPostgresFunctionsRow { public int? MaxInteger { get; set; } @@ -912,7 +945,21 @@ public async Task GetPostgresFunctions() return null; } - private const string InsertPostgresNumericTypesSql = " INSERT INTO postgres_numeric_types ( c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money ) VALUES (@c_boolean, @c_bit, @c_smallint, @c_integer, @c_bigint, @c_decimal, @c_numeric, @c_real, @c_double_precision, @c_money)"; + private const string InsertPostgresNumericTypesSql = @" + INSERT INTO postgres_numeric_types + ( + c_boolean, + c_bit, + c_smallint, + c_integer, + c_bigint, + c_decimal, + c_numeric, + c_real, + c_double_precision, + c_money + ) + VALUES (@c_boolean, @c_bit, @c_smallint, @c_integer, @c_bigint, @c_decimal, @c_numeric, @c_real, @c_double_precision, @c_money)"; public class InsertPostgresNumericTypesArgs { public bool? CBoolean { get; set; } @@ -1074,7 +1121,31 @@ public async Task TruncatePostgresNumericTypes() } } - private const string GetPostgresNumericTypesCntSql = "SELECT c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money, COUNT(*) AS cnt FROM postgres_numeric_types GROUP BY c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money LIMIT 1"; + private const string GetPostgresNumericTypesCntSql = @"SELECT + c_boolean, + c_bit, + c_smallint, + c_integer, + c_bigint, + c_decimal, + c_numeric, + c_real, + c_double_precision, + c_money, + COUNT(*) AS cnt + FROM postgres_numeric_types + GROUP BY + c_boolean, + c_bit, + c_smallint, + c_integer, + c_bigint, + c_decimal, + c_numeric, + c_real, + c_double_precision, + c_money + LIMIT 1"; public class GetPostgresNumericTypesCntRow { public bool? CBoolean { get; set; } @@ -1197,7 +1268,16 @@ public async Task InsertPostgresNumericTypesBatch(List GetPostgresStringTypesCnt() return null; } - private const string GetPostgresStringTypesTextSearchSql = "WITH txt_query AS ( SELECT c_text, to_tsquery('english', @to_tsquery) AS query, to_tsvector('english', c_text) AS tsv FROM postgres_string_types WHERE c_text @@ to_tsquery('english', @to_tsquery) ) SELECT txt_query.c_text, txt_query.query, txt_query.tsv, ts_rank(tsv, query) AS rnk FROM txt_query ORDER BY rnk DESC LIMIT 1"; + private const string GetPostgresStringTypesTextSearchSql = @"WITH txt_query AS ( + SELECT + c_text, + to_tsquery('english', @to_tsquery) AS query, + to_tsvector('english', c_text) AS tsv + FROM postgres_string_types + WHERE c_text @@ to_tsquery('english', @to_tsquery) + ) + + SELECT txt_query.c_text, txt_query.query, txt_query.tsv, ts_rank(tsv, query) AS rnk + FROM txt_query + ORDER BY rnk DESC + LIMIT 1"; public class GetPostgresStringTypesTextSearchRow { public string CText { get; set; } @@ -1492,7 +1598,16 @@ public async Task GetPostgresStringTypesTex return null; } - private const string InsertPostgresDateTimeTypesSql = " INSERT INTO postgres_datetime_types ( c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_timestamp_noda_instant_override ) VALUES (@c_date, @c_time, @c_timestamp, @c_timestamp_with_tz, @c_interval, @c_timestamp_noda_instant_override)"; + private const string InsertPostgresDateTimeTypesSql = @" + INSERT INTO postgres_datetime_types + ( + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval, + c_timestamp_noda_instant_override + ) VALUES (@c_date, @c_time, @c_timestamp, @c_timestamp_with_tz, @c_interval, @c_timestamp_noda_instant_override)"; public class InsertPostgresDateTimeTypesArgs { public DateTime? CDate { get; set; } @@ -1642,7 +1757,21 @@ public async Task TruncatePostgresDateTimeTypes() } } - private const string GetPostgresDateTimeTypesCntSql = "SELECT c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, COUNT(*) AS cnt FROM postgres_datetime_types GROUP BY c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval LIMIT 1"; + private const string GetPostgresDateTimeTypesCntSql = @"SELECT + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval, + COUNT(*) AS cnt + FROM postgres_datetime_types + GROUP BY + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval + LIMIT 1"; public class GetPostgresDateTimeTypesCntRow { public DateTime? CDate { get; set; } @@ -1740,7 +1869,19 @@ public async Task InsertPostgresDateTimeTypesBatch(List GetPostgresSpecialTypesCnt() return null; } - private const string InsertPostgresArrayTypesSql = " INSERT INTO postgres_array_types ( c_bytea, c_boolean_array, c_text_array, c_integer_array, c_decimal_array, c_date_array, c_timestamp_array ) VALUES (@c_bytea, @c_boolean_array, @c_text_array, @c_integer_array, @c_decimal_array, @c_date_array, @c_timestamp_array)"; + private const string InsertPostgresArrayTypesSql = @" + INSERT INTO postgres_array_types + ( + c_bytea, + c_boolean_array, + c_text_array, + c_integer_array, + c_decimal_array, + c_date_array, + c_timestamp_array + ) + VALUES (@c_bytea, @c_boolean_array, @c_text_array, @c_integer_array, @c_decimal_array, @c_date_array, @c_timestamp_array)"; public class InsertPostgresArrayTypesArgs { public byte[] CBytea { get; set; } @@ -2463,7 +2690,23 @@ public async Task InsertPostgresArrayTypesBatch(List> ListAuthors(ListAuthorsArgs args) @@ -256,7 +259,8 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) return null; } - private const string GetAuthorByNamePatternSql = "SELECT id, name, bio FROM authors WHERE name LIKE COALESCE(@name_pattern, '%')"; + private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors + WHERE name LIKE COALESCE(@name_pattern, '%')"; public readonly record struct GetAuthorByNamePatternRow(long Id, string Name, string? Bio); public readonly record struct GetAuthorByNamePatternArgs(string? NamePattern); public async Task> GetAuthorByNamePattern(GetAuthorByNamePatternArgs args) @@ -297,7 +301,8 @@ public async Task> GetAuthorByNamePattern(GetAut } } - private const string DeleteAuthorSql = "DELETE FROM authors WHERE name = @name"; + private const string DeleteAuthorSql = @"DELETE FROM authors + WHERE name = @name"; public readonly record struct DeleteAuthorArgs(string Name); public async Task DeleteAuthor(DeleteAuthorArgs args) { @@ -354,7 +359,9 @@ public async Task DeleteAllAuthors() } } - private const string UpdateAuthorsSql = "UPDATE authors SET bio = @bio WHERE bio IS NOT NULL"; + private const string UpdateAuthorsSql = @"UPDATE authors + SET bio = @bio + WHERE bio IS NOT NULL"; public readonly record struct UpdateAuthorsArgs(string? Bio); public async Task UpdateAuthors(UpdateAuthorsArgs args) { @@ -509,7 +516,9 @@ public async Task CreateBook(CreateBookArgs args) } } - private const string ListAllAuthorsBooksSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors JOIN books ON authors.id = books.author_id ORDER BY authors.name"; + private const string ListAllAuthorsBooksSql = @"SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description + FROM authors JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public readonly record struct ListAllAuthorsBooksRow(Author? Author, Book? Book); public async Task> ListAllAuthorsBooks() { @@ -547,7 +556,9 @@ public async Task> ListAllAuthorsBooks() } } - private const string GetDuplicateAuthorsSql = "SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio FROM authors authors1 JOIN authors authors2 ON authors1.name = authors2.name WHERE authors1.id < authors2.id"; + private const string GetDuplicateAuthorsSql = @"SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio + FROM authors authors1 JOIN authors authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public readonly record struct GetDuplicateAuthorsRow(Author? Author, Author? Author2); public async Task> GetDuplicateAuthors() { @@ -585,7 +596,9 @@ public async Task> GetDuplicateAuthors() } } - private const string GetAuthorsByBookNameSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors JOIN books ON authors.id = books.author_id WHERE books.name = @name"; + private const string GetAuthorsByBookNameSql = @"SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description + FROM authors JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public readonly record struct GetAuthorsByBookNameRow(long Id, string Name, string? Bio, Book? Book); public readonly record struct GetAuthorsByBookNameArgs(string Name); public async Task> GetAuthorsByBookName(GetAuthorsByBookNameArgs args) diff --git a/examples/QuickStartPostgresDalGen/QuerySql.cs b/examples/QuickStartPostgresDalGen/QuerySql.cs index 4ac546d6..728dded3 100644 --- a/examples/QuickStartPostgresDalGen/QuerySql.cs +++ b/examples/QuickStartPostgresDalGen/QuerySql.cs @@ -35,7 +35,8 @@ public static QuerySql WithTransaction(NpgsqlTransaction transaction) private NpgsqlTransaction? Transaction { get; } private string? ConnectionString { get; } - private const string GetAuthorSql = "SELECT id, name, bio FROM authors WHERE name = @name LIMIT 1"; + private const string GetAuthorSql = @"SELECT id, name, bio FROM authors + WHERE name = @name LIMIT 1"; public readonly record struct GetAuthorRow(long Id, string Name, string? Bio); public readonly record struct GetAuthorArgs(string Name); public async Task GetAuthor(GetAuthorArgs args) @@ -89,7 +90,11 @@ public static QuerySql WithTransaction(NpgsqlTransaction transaction) return null; } - private const string ListAuthorsSql = "SELECT id, name, bio FROM authors ORDER BY name LIMIT @limit OFFSET @offset"; + private const string ListAuthorsSql = @"SELECT id, name, bio + FROM authors + ORDER BY name + LIMIT @limit + OFFSET @offset"; public readonly record struct ListAuthorsRow(long Id, string Name, string? Bio); public readonly record struct ListAuthorsArgs(int Offset, int Limit); public async Task> ListAuthors(ListAuthorsArgs args) @@ -221,7 +226,8 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } } - private const string GetAuthorByIdSql = "SELECT id, name, bio FROM authors WHERE id = @id LIMIT 1"; + private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors + WHERE id = @id LIMIT 1"; public readonly record struct GetAuthorByIdRow(long Id, string Name, string? Bio); public readonly record struct GetAuthorByIdArgs(long Id); public async Task GetAuthorById(GetAuthorByIdArgs args) @@ -275,7 +281,8 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) return null; } - private const string GetAuthorByNamePatternSql = "SELECT id, name, bio FROM authors WHERE name LIKE COALESCE(@name_pattern, '%')"; + private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors + WHERE name LIKE COALESCE(@name_pattern, '%')"; public readonly record struct GetAuthorByNamePatternRow(long Id, string Name, string? Bio); public readonly record struct GetAuthorByNamePatternArgs(string? NamePattern); public async Task> GetAuthorByNamePattern(GetAuthorByNamePatternArgs args) @@ -315,7 +322,8 @@ public async Task> GetAuthorByNamePattern(GetAut } } - private const string DeleteAuthorSql = "DELETE FROM authors WHERE name = @name"; + private const string DeleteAuthorSql = @"DELETE FROM authors + WHERE name = @name"; public readonly record struct DeleteAuthorArgs(string Name); public async Task DeleteAuthor(DeleteAuthorArgs args) { @@ -370,7 +378,9 @@ public async Task TruncateAuthors() } } - private const string UpdateAuthorsSql = "UPDATE authors SET bio = @bio WHERE bio IS NOT NULL"; + private const string UpdateAuthorsSql = @"UPDATE authors + SET bio = @bio + WHERE bio IS NOT NULL"; public readonly record struct UpdateAuthorsArgs(string? Bio); public async Task UpdateAuthors(UpdateAuthorsArgs args) { @@ -397,7 +407,8 @@ public async Task UpdateAuthors(UpdateAuthorsArgs args) } } - private const string GetAuthorsByIdsSql = "SELECT id, name, bio FROM authors WHERE id = ANY(@longArr_1::BIGINT [])"; + private const string GetAuthorsByIdsSql = @"SELECT id, name, bio FROM authors + WHERE id = ANY(@longArr_1::BIGINT [])"; public readonly record struct GetAuthorsByIdsRow(long Id, string Name, string? Bio); public readonly record struct GetAuthorsByIdsArgs(long[] LongArr1); public async Task> GetAuthorsByIds(GetAuthorsByIdsArgs args) @@ -437,7 +448,9 @@ public async Task> GetAuthorsByIds(GetAuthorsByIdsArgs } } - private const string GetAuthorsByIdsAndNamesSql = "SELECT id, name, bio FROM authors WHERE id = ANY(@longArr_1::BIGINT []) AND name = ANY(@stringArr_2::TEXT [])"; + private const string GetAuthorsByIdsAndNamesSql = @"SELECT id, name, bio + FROM authors + WHERE id = ANY(@longArr_1::BIGINT []) AND name = ANY(@stringArr_2::TEXT [])"; public readonly record struct GetAuthorsByIdsAndNamesRow(long Id, string Name, string? Bio); public readonly record struct GetAuthorsByIdsAndNamesArgs(long[] LongArr1, string[] StringArr2); public async Task> GetAuthorsByIdsAndNames(GetAuthorsByIdsAndNamesArgs args) @@ -511,7 +524,12 @@ public async Task CreateBook(CreateBookArgs args) } } - private const string ListAllAuthorsBooksSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors INNER JOIN books ON authors.id = books.author_id ORDER BY authors.name"; + private const string ListAllAuthorsBooksSql = @"SELECT + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors + INNER JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public readonly record struct ListAllAuthorsBooksRow(Author? Author, Book? Book); public async Task> ListAllAuthorsBooks() { @@ -548,7 +566,12 @@ public async Task> ListAllAuthorsBooks() } } - private const string GetDuplicateAuthorsSql = "SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio FROM authors AS authors1 INNER JOIN authors AS authors2 ON authors1.name = authors2.name WHERE authors1.id < authors2.id"; + private const string GetDuplicateAuthorsSql = @"SELECT + authors1.id, authors1.name, authors1.bio, + authors2.id, authors2.name, authors2.bio + FROM authors AS authors1 + INNER JOIN authors AS authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public readonly record struct GetDuplicateAuthorsRow(Author? Author, Author? Author2); public async Task> GetDuplicateAuthors() { @@ -585,7 +608,11 @@ public async Task> GetDuplicateAuthors() } } - private const string GetAuthorsByBookNameSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors INNER JOIN books ON authors.id = books.author_id WHERE books.name = @name"; + private const string GetAuthorsByBookNameSql = @"SELECT + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public readonly record struct GetAuthorsByBookNameRow(long Id, string Name, string? Bio, Book? Book); public readonly record struct GetAuthorsByBookNameArgs(string Name); public async Task> GetAuthorsByBookName(GetAuthorsByBookNameArgs args) diff --git a/examples/QuickStartSqliteDalGen/QuerySql.cs b/examples/QuickStartSqliteDalGen/QuerySql.cs index 72948995..7dac2dc3 100644 --- a/examples/QuickStartSqliteDalGen/QuerySql.cs +++ b/examples/QuickStartSqliteDalGen/QuerySql.cs @@ -34,7 +34,8 @@ public static QuerySql WithTransaction(SqliteTransaction transaction) private SqliteTransaction? Transaction { get; } private string? ConnectionString { get; } - private const string GetAuthorSql = "SELECT id, name, bio FROM authors WHERE name = @name LIMIT 1"; + private const string GetAuthorSql = @"SELECT id, name, bio FROM authors + WHERE name = @name LIMIT 1"; public readonly record struct GetAuthorRow(int Id, string Name, string? Bio); public readonly record struct GetAuthorArgs(string Name); public async Task GetAuthor(GetAuthorArgs args) @@ -89,7 +90,10 @@ public static QuerySql WithTransaction(SqliteTransaction transaction) return null; } - private const string ListAuthorsSql = "SELECT id, name, bio FROM authors ORDER BY name LIMIT @limit OFFSET @offset"; + private const string ListAuthorsSql = @"SELECT id, name, bio + FROM authors + ORDER BY name + LIMIT @limit OFFSET @offset"; public readonly record struct ListAuthorsRow(int Id, string Name, string? Bio); public readonly record struct ListAuthorsArgs(int Offset, int Limit); public async Task> ListAuthors(ListAuthorsArgs args) @@ -199,7 +203,8 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } } - private const string GetAuthorByIdSql = "SELECT id, name, bio FROM authors WHERE id = @id LIMIT 1"; + private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors -- test comment + WHERE id = @id LIMIT 1"; public readonly record struct GetAuthorByIdRow(int Id, string Name, string? Bio); public readonly record struct GetAuthorByIdArgs(int Id); public async Task GetAuthorById(GetAuthorByIdArgs args) @@ -311,7 +316,8 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) return null; } - private const string GetAuthorByNamePatternSql = "SELECT id, name, bio FROM authors WHERE name LIKE COALESCE(@name_pattern, '%')"; + private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors + WHERE name LIKE COALESCE(@name_pattern, '%')"; public readonly record struct GetAuthorByNamePatternRow(int Id, string Name, string? Bio); public readonly record struct GetAuthorByNamePatternArgs(string? NamePattern); public async Task> GetAuthorByNamePattern(GetAuthorByNamePatternArgs args) @@ -352,7 +358,9 @@ public async Task> GetAuthorByNamePattern(GetAut } } - private const string UpdateAuthorsSql = "UPDATE authors SET bio = @bio WHERE bio IS NOT NULL"; + private const string UpdateAuthorsSql = @"UPDATE authors + SET bio = @bio + WHERE bio IS NOT NULL"; public readonly record struct UpdateAuthorsArgs(string? Bio); public async Task UpdateAuthors(UpdateAuthorsArgs args) { @@ -475,7 +483,8 @@ public async Task> GetAuthorsByIdsAndNames(GetA } } - private const string DeleteAuthorSql = "DELETE FROM authors WHERE name = @name"; + private const string DeleteAuthorSql = @"DELETE FROM authors + WHERE name = @name"; public readonly record struct DeleteAuthorArgs(string Name); public async Task DeleteAuthor(DeleteAuthorArgs args) { @@ -538,7 +547,11 @@ public async Task CreateBook(CreateBookArgs args) } } - private const string ListAllAuthorsBooksSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors INNER JOIN books ON authors.id = books.author_id ORDER BY authors.name"; + private const string ListAllAuthorsBooksSql = @"SELECT + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public readonly record struct ListAllAuthorsBooksRow(Author? Author, Book? Book); public async Task> ListAllAuthorsBooks() { @@ -576,7 +589,12 @@ public async Task> ListAllAuthorsBooks() } } - private const string GetDuplicateAuthorsSql = "SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio FROM authors AS authors1 INNER JOIN authors AS authors2 ON authors1.name = authors2.name WHERE authors1.id < authors2.id"; + private const string GetDuplicateAuthorsSql = @"SELECT + authors1.id, authors1.name, authors1.bio, + authors2.id, authors2.name, authors2.bio + FROM authors AS authors1 + INNER JOIN authors AS authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public readonly record struct GetDuplicateAuthorsRow(Author? Author, Author? Author2); public async Task> GetDuplicateAuthors() { @@ -614,7 +632,11 @@ public async Task> GetDuplicateAuthors() } } - private const string GetAuthorsByBookNameSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors INNER JOIN books ON authors.id = books.author_id WHERE books.name = @name"; + private const string GetAuthorsByBookNameSql = @"SELECT + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public readonly record struct GetAuthorsByBookNameRow(int Id, string Name, string? Bio, Book? Book); public readonly record struct GetAuthorsByBookNameArgs(string Name); public async Task> GetAuthorsByBookName(GetAuthorsByBookNameArgs args) diff --git a/examples/QuickStartSqliteDalGen/request.json b/examples/QuickStartSqliteDalGen/request.json index cc8626b5..5abcf639 100644 --- a/examples/QuickStartSqliteDalGen/request.json +++ b/examples/QuickStartSqliteDalGen/request.json @@ -361,7 +361,7 @@ } }, { - "text": "SELECT id, name, bio FROM authors\nWHERE id = ? LIMIT 1", + "text": "SELECT id, name, bio FROM authors -- test comment\nWHERE id = ? LIMIT 1", "name": "GetAuthorById", "cmd": ":one", "columns": [ diff --git a/examples/QuickStartSqliteDalGen/request.message b/examples/QuickStartSqliteDalGen/request.message index 3770a0e241c548343311063be033475c21ed37aa..975aceb9b5772ac1464323f7e0dc2a3cab7b7fe5 100644 GIT binary patch delta 37 scmeyZ-mS4Ajg4g<6PMfMYIY@lU0sEe)Z!9_(GetAuthorSql, queryParams, transaction: this.Transaction); } - private const string ListAuthorsSql = "SELECT id, name, bio FROM authors ORDER BY name LIMIT @limit OFFSET @offset"; + private const string ListAuthorsSql = @"SELECT id, name, bio + FROM authors + ORDER BY name + LIMIT @limit OFFSET @offset"; public class ListAuthorsRow { public required int Id { get; init; } @@ -151,7 +155,8 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) return await this.Transaction.Connection.QuerySingleAsync(CreateAuthorReturnIdSql, queryParams, transaction: this.Transaction); } - private const string GetAuthorByIdSql = "SELECT id, name, bio FROM authors WHERE id = @id LIMIT 1"; + private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors -- test comment + WHERE id = @id LIMIT 1"; public class GetAuthorByIdRow { public required int Id { get; init; } @@ -211,7 +216,8 @@ public class GetAuthorByIdWithMultipleNamedParamArgs return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetAuthorByIdWithMultipleNamedParamSql, queryParams, transaction: this.Transaction); } - private const string GetAuthorByNamePatternSql = "SELECT id, name, bio FROM authors WHERE name LIKE COALESCE(@name_pattern, '%')"; + private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors + WHERE name LIKE COALESCE(@name_pattern, '%')"; public class GetAuthorByNamePatternRow { public required int Id { get; init; } @@ -240,7 +246,9 @@ public async Task> GetAuthorByNamePattern(GetAut return (await this.Transaction.Connection.QueryAsync(GetAuthorByNamePatternSql, queryParams, transaction: this.Transaction)).AsList(); } - private const string UpdateAuthorsSql = "UPDATE authors SET bio = @bio WHERE bio IS NOT NULL"; + private const string UpdateAuthorsSql = @"UPDATE authors + SET bio = @bio + WHERE bio IS NOT NULL"; public class UpdateAuthorsArgs { public string? Bio { get; init; } @@ -328,7 +336,8 @@ public async Task> GetAuthorsByIdsAndNames(GetA return (await this.Transaction.Connection.QueryAsync(transformedSql, queryParams, transaction: this.Transaction)).AsList(); } - private const string DeleteAuthorSql = "DELETE FROM authors WHERE name = @name"; + private const string DeleteAuthorSql = @"DELETE FROM authors + WHERE name = @name"; public class DeleteAuthorArgs { public required string Name { get; init; } @@ -375,7 +384,11 @@ public async Task CreateBook(CreateBookArgs args) return await this.Transaction.Connection.QuerySingleAsync(CreateBookSql, queryParams, transaction: this.Transaction); } - private const string ListAllAuthorsBooksSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors INNER JOIN books ON authors.id = books.author_id ORDER BY authors.name"; + private const string ListAllAuthorsBooksSql = @"SELECT + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public class ListAllAuthorsBooksRow { public required Author? Author { get; init; } @@ -417,7 +430,12 @@ public async Task> ListAllAuthorsBooks() } } - private const string GetDuplicateAuthorsSql = "SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio FROM authors AS authors1 INNER JOIN authors AS authors2 ON authors1.name = authors2.name WHERE authors1.id < authors2.id"; + private const string GetDuplicateAuthorsSql = @"SELECT + authors1.id, authors1.name, authors1.bio, + authors2.id, authors2.name, authors2.bio + FROM authors AS authors1 + INNER JOIN authors AS authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public class GetDuplicateAuthorsRow { public required Author? Author { get; init; } @@ -459,7 +477,11 @@ public async Task> GetDuplicateAuthors() } } - private const string GetAuthorsByBookNameSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors INNER JOIN books ON authors.id = books.author_id WHERE books.name = @name"; + private const string GetAuthorsByBookNameSql = @"SELECT + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public class GetAuthorsByBookNameRow { public required int Id { get; init; } @@ -524,7 +546,20 @@ public async Task DeleteAllAuthors() await this.Transaction.Connection.ExecuteAsync(DeleteAllAuthorsSql, transaction: this.Transaction); } - private const string InsertSqliteTypesSql = "INSERT INTO types_sqlite ( c_integer, c_real, c_text, c_blob, c_text_datetime_override, c_integer_datetime_override, c_text_noda_instant_override, c_integer_noda_instant_override, c_text_bool_override, c_integer_bool_override ) VALUES (@c_integer, @c_real, @c_text, @c_blob, @c_text_datetime_override, @c_integer_datetime_override, @c_text_noda_instant_override, @c_integer_noda_instant_override, @c_text_bool_override, @c_integer_bool_override)"; + private const string InsertSqliteTypesSql = @"INSERT INTO types_sqlite + ( + c_integer, + c_real, + c_text, + c_blob, + c_text_datetime_override, + c_integer_datetime_override, + c_text_noda_instant_override, + c_integer_noda_instant_override, + c_text_bool_override, + c_integer_bool_override + ) + VALUES (@c_integer, @c_real, @c_text, @c_blob, @c_text_datetime_override, @c_integer_datetime_override, @c_text_noda_instant_override, @c_integer_noda_instant_override, @c_text_bool_override, @c_integer_bool_override)"; public class InsertSqliteTypesArgs { public int? CInteger { get; init; } @@ -590,7 +625,19 @@ public async Task InsertSqliteTypesBatch(List args) } } - private const string GetSqliteTypesSql = "SELECT c_integer, c_real, c_text, c_blob, c_text_datetime_override, c_integer_datetime_override, c_text_noda_instant_override, c_integer_noda_instant_override, c_text_bool_override, c_integer_bool_override FROM types_sqlite LIMIT 1"; + private const string GetSqliteTypesSql = @"SELECT + c_integer, + c_real, + c_text, + c_blob, + c_text_datetime_override, + c_integer_datetime_override, + c_text_noda_instant_override, + c_integer_noda_instant_override, + c_text_bool_override, + c_integer_bool_override + FROM types_sqlite + LIMIT 1"; public class GetSqliteTypesRow { public int? CInteger { get; init; } @@ -620,7 +667,15 @@ public class GetSqliteTypesRow return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetSqliteTypesSql, transaction: this.Transaction); } - private const string GetSqliteTypesCntSql = "SELECT c_integer, c_real, c_text, c_blob, count(*) AS cnt FROM types_sqlite GROUP BY c_integer, c_real, c_text, c_blob LIMIT 1"; + private const string GetSqliteTypesCntSql = @"SELECT + c_integer, + c_real, + c_text, + c_blob, + count(*) AS cnt + FROM types_sqlite + GROUP BY c_integer, c_real, c_text, c_blob + LIMIT 1"; public class GetSqliteTypesCntRow { public int? CInteger { get; init; } @@ -645,7 +700,11 @@ public class GetSqliteTypesCntRow return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetSqliteTypesCntSql, transaction: this.Transaction); } - private const string GetSqliteFunctionsSql = "SELECT max(c_integer) AS max_integer, max(c_real) AS max_real, max(c_text) AS max_text FROM types_sqlite"; + private const string GetSqliteFunctionsSql = @"SELECT + max(c_integer) AS max_integer, + max(c_real) AS max_real, + max(c_text) AS max_text + FROM types_sqlite"; public class GetSqliteFunctionsRow { public int? MaxInteger { get; init; } diff --git a/examples/SqliteDapperExample/request.json b/examples/SqliteDapperExample/request.json index db9051cb..b9d70cd3 100644 --- a/examples/SqliteDapperExample/request.json +++ b/examples/SqliteDapperExample/request.json @@ -470,7 +470,7 @@ } }, { - "text": "SELECT id, name, bio FROM authors\nWHERE id = ? LIMIT 1", + "text": "SELECT id, name, bio FROM authors -- test comment\nWHERE id = ? LIMIT 1", "name": "GetAuthorById", "cmd": ":one", "columns": [ diff --git a/examples/SqliteDapperExample/request.message b/examples/SqliteDapperExample/request.message index c844d6f70995405c06db44af35d5a1164b33f51e..e3898eef6c6d8a69fcbaa77680cba8dd0f32e95d 100644 GIT binary patch delta 37 scmaD7@+D-05)aEfCN8(h=DbS$y1EJ_sl_D<$@#gtsd*)v-Fal?0PeF3=>Px# delta 21 ccmewo@+4$~5)Vrs6PMX!cV5NK;XJZ(09Wh=i~s-t diff --git a/examples/SqliteDapperLegacyExample/QuerySql.cs b/examples/SqliteDapperLegacyExample/QuerySql.cs index e754db3c..cfd82d8e 100644 --- a/examples/SqliteDapperLegacyExample/QuerySql.cs +++ b/examples/SqliteDapperLegacyExample/QuerySql.cs @@ -41,7 +41,8 @@ public static QuerySql WithTransaction(SqliteTransaction transaction) private SqliteTransaction Transaction { get; } private string ConnectionString { get; } - private const string GetAuthorSql = "SELECT id, name, bio FROM authors WHERE name = @name LIMIT 1"; + private const string GetAuthorSql = @"SELECT id, name, bio FROM authors + WHERE name = @name LIMIT 1"; public class GetAuthorRow { public int Id { get; set; } @@ -70,7 +71,10 @@ public async Task GetAuthor(GetAuthorArgs args) return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetAuthorSql, queryParams, transaction: this.Transaction); } - private const string ListAuthorsSql = "SELECT id, name, bio FROM authors ORDER BY name LIMIT @limit OFFSET @offset"; + private const string ListAuthorsSql = @"SELECT id, name, bio + FROM authors + ORDER BY name + LIMIT @limit OFFSET @offset"; public class ListAuthorsRow { public int Id { get; set; } @@ -152,7 +156,8 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) return await this.Transaction.Connection.QuerySingleAsync(CreateAuthorReturnIdSql, queryParams, transaction: this.Transaction); } - private const string GetAuthorByIdSql = "SELECT id, name, bio FROM authors WHERE id = @id LIMIT 1"; + private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors -- test comment + WHERE id = @id LIMIT 1"; public class GetAuthorByIdRow { public int Id { get; set; } @@ -212,7 +217,8 @@ public async Task GetAuthorByIdWithMulti return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetAuthorByIdWithMultipleNamedParamSql, queryParams, transaction: this.Transaction); } - private const string GetAuthorByNamePatternSql = "SELECT id, name, bio FROM authors WHERE name LIKE COALESCE(@name_pattern, '%')"; + private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors + WHERE name LIKE COALESCE(@name_pattern, '%')"; public class GetAuthorByNamePatternRow { public int Id { get; set; } @@ -241,7 +247,9 @@ public async Task> GetAuthorByNamePattern(GetAut return (await this.Transaction.Connection.QueryAsync(GetAuthorByNamePatternSql, queryParams, transaction: this.Transaction)).AsList(); } - private const string UpdateAuthorsSql = "UPDATE authors SET bio = @bio WHERE bio IS NOT NULL"; + private const string UpdateAuthorsSql = @"UPDATE authors + SET bio = @bio + WHERE bio IS NOT NULL"; public class UpdateAuthorsArgs { public string Bio { get; set; } @@ -329,7 +337,8 @@ public async Task> GetAuthorsByIdsAndNames(GetA return (await this.Transaction.Connection.QueryAsync(transformedSql, queryParams, transaction: this.Transaction)).AsList(); } - private const string DeleteAuthorSql = "DELETE FROM authors WHERE name = @name"; + private const string DeleteAuthorSql = @"DELETE FROM authors + WHERE name = @name"; public class DeleteAuthorArgs { public string Name { get; set; } @@ -376,7 +385,11 @@ public async Task CreateBook(CreateBookArgs args) return await this.Transaction.Connection.QuerySingleAsync(CreateBookSql, queryParams, transaction: this.Transaction); } - private const string ListAllAuthorsBooksSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors INNER JOIN books ON authors.id = books.author_id ORDER BY authors.name"; + private const string ListAllAuthorsBooksSql = @"SELECT + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public class ListAllAuthorsBooksRow { public Author Author { get; set; } @@ -418,7 +431,12 @@ public async Task> ListAllAuthorsBooks() } } - private const string GetDuplicateAuthorsSql = "SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio FROM authors AS authors1 INNER JOIN authors AS authors2 ON authors1.name = authors2.name WHERE authors1.id < authors2.id"; + private const string GetDuplicateAuthorsSql = @"SELECT + authors1.id, authors1.name, authors1.bio, + authors2.id, authors2.name, authors2.bio + FROM authors AS authors1 + INNER JOIN authors AS authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public class GetDuplicateAuthorsRow { public Author Author { get; set; } @@ -460,7 +478,11 @@ public async Task> GetDuplicateAuthors() } } - private const string GetAuthorsByBookNameSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors INNER JOIN books ON authors.id = books.author_id WHERE books.name = @name"; + private const string GetAuthorsByBookNameSql = @"SELECT + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public class GetAuthorsByBookNameRow { public int Id { get; set; } @@ -525,7 +547,20 @@ public async Task DeleteAllAuthors() await this.Transaction.Connection.ExecuteAsync(DeleteAllAuthorsSql, transaction: this.Transaction); } - private const string InsertSqliteTypesSql = "INSERT INTO types_sqlite ( c_integer, c_real, c_text, c_blob, c_text_datetime_override, c_integer_datetime_override, c_text_noda_instant_override, c_integer_noda_instant_override, c_text_bool_override, c_integer_bool_override ) VALUES (@c_integer, @c_real, @c_text, @c_blob, @c_text_datetime_override, @c_integer_datetime_override, @c_text_noda_instant_override, @c_integer_noda_instant_override, @c_text_bool_override, @c_integer_bool_override)"; + private const string InsertSqliteTypesSql = @"INSERT INTO types_sqlite + ( + c_integer, + c_real, + c_text, + c_blob, + c_text_datetime_override, + c_integer_datetime_override, + c_text_noda_instant_override, + c_integer_noda_instant_override, + c_text_bool_override, + c_integer_bool_override + ) + VALUES (@c_integer, @c_real, @c_text, @c_blob, @c_text_datetime_override, @c_integer_datetime_override, @c_text_noda_instant_override, @c_integer_noda_instant_override, @c_text_bool_override, @c_integer_bool_override)"; public class InsertSqliteTypesArgs { public int? CInteger { get; set; } @@ -591,7 +626,19 @@ public async Task InsertSqliteTypesBatch(List args) } } - private const string GetSqliteTypesSql = "SELECT c_integer, c_real, c_text, c_blob, c_text_datetime_override, c_integer_datetime_override, c_text_noda_instant_override, c_integer_noda_instant_override, c_text_bool_override, c_integer_bool_override FROM types_sqlite LIMIT 1"; + private const string GetSqliteTypesSql = @"SELECT + c_integer, + c_real, + c_text, + c_blob, + c_text_datetime_override, + c_integer_datetime_override, + c_text_noda_instant_override, + c_integer_noda_instant_override, + c_text_bool_override, + c_integer_bool_override + FROM types_sqlite + LIMIT 1"; public class GetSqliteTypesRow { public int? CInteger { get; set; } @@ -621,7 +668,15 @@ public async Task GetSqliteTypes() return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetSqliteTypesSql, transaction: this.Transaction); } - private const string GetSqliteTypesCntSql = "SELECT c_integer, c_real, c_text, c_blob, count(*) AS cnt FROM types_sqlite GROUP BY c_integer, c_real, c_text, c_blob LIMIT 1"; + private const string GetSqliteTypesCntSql = @"SELECT + c_integer, + c_real, + c_text, + c_blob, + count(*) AS cnt + FROM types_sqlite + GROUP BY c_integer, c_real, c_text, c_blob + LIMIT 1"; public class GetSqliteTypesCntRow { public int? CInteger { get; set; } @@ -646,7 +701,11 @@ public async Task GetSqliteTypesCnt() return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetSqliteTypesCntSql, transaction: this.Transaction); } - private const string GetSqliteFunctionsSql = "SELECT max(c_integer) AS max_integer, max(c_real) AS max_real, max(c_text) AS max_text FROM types_sqlite"; + private const string GetSqliteFunctionsSql = @"SELECT + max(c_integer) AS max_integer, + max(c_real) AS max_real, + max(c_text) AS max_text + FROM types_sqlite"; public class GetSqliteFunctionsRow { public int? MaxInteger { get; set; } diff --git a/examples/SqliteDapperLegacyExample/request.json b/examples/SqliteDapperLegacyExample/request.json index e59603ef..1e634382 100644 --- a/examples/SqliteDapperLegacyExample/request.json +++ b/examples/SqliteDapperLegacyExample/request.json @@ -470,7 +470,7 @@ } }, { - "text": "SELECT id, name, bio FROM authors\nWHERE id = ? LIMIT 1", + "text": "SELECT id, name, bio FROM authors -- test comment\nWHERE id = ? LIMIT 1", "name": "GetAuthorById", "cmd": ":one", "columns": [ diff --git a/examples/SqliteDapperLegacyExample/request.message b/examples/SqliteDapperLegacyExample/request.message index fae4db7a9b330d2eb0acb750e63c6ce0fce45369..b7d6c4c6ff944a6a1143672676b3aac6ffe0d76a 100644 GIT binary patch delta 37 scmZn*off*mjE7|&6PMd$Z(b#SU0sEe)Z!9_n+a delta 21 ccmbOh+7`OOjEAL GetAuthor(GetAuthorArgs args) @@ -92,7 +93,10 @@ public static QuerySql WithTransaction(SqliteTransaction transaction) return null; } - private const string ListAuthorsSql = "SELECT id, name, bio FROM authors ORDER BY name LIMIT @limit OFFSET @offset"; + private const string ListAuthorsSql = @"SELECT id, name, bio + FROM authors + ORDER BY name + LIMIT @limit OFFSET @offset"; public readonly record struct ListAuthorsRow(int Id, string Name, string? Bio); public readonly record struct ListAuthorsArgs(int Offset, int Limit); public async Task> ListAuthors(ListAuthorsArgs args) @@ -202,7 +206,8 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } } - private const string GetAuthorByIdSql = "SELECT id, name, bio FROM authors WHERE id = @id LIMIT 1"; + private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors -- test comment + WHERE id = @id LIMIT 1"; public readonly record struct GetAuthorByIdRow(int Id, string Name, string? Bio); public readonly record struct GetAuthorByIdArgs(int Id); public async Task GetAuthorById(GetAuthorByIdArgs args) @@ -314,7 +319,8 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) return null; } - private const string GetAuthorByNamePatternSql = "SELECT id, name, bio FROM authors WHERE name LIKE COALESCE(@name_pattern, '%')"; + private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors + WHERE name LIKE COALESCE(@name_pattern, '%')"; public readonly record struct GetAuthorByNamePatternRow(int Id, string Name, string? Bio); public readonly record struct GetAuthorByNamePatternArgs(string? NamePattern); public async Task> GetAuthorByNamePattern(GetAuthorByNamePatternArgs args) @@ -355,7 +361,9 @@ public async Task> GetAuthorByNamePattern(GetAut } } - private const string UpdateAuthorsSql = "UPDATE authors SET bio = @bio WHERE bio IS NOT NULL"; + private const string UpdateAuthorsSql = @"UPDATE authors + SET bio = @bio + WHERE bio IS NOT NULL"; public readonly record struct UpdateAuthorsArgs(string? Bio); public async Task UpdateAuthors(UpdateAuthorsArgs args) { @@ -478,7 +486,8 @@ public async Task> GetAuthorsByIdsAndNames(GetA } } - private const string DeleteAuthorSql = "DELETE FROM authors WHERE name = @name"; + private const string DeleteAuthorSql = @"DELETE FROM authors + WHERE name = @name"; public readonly record struct DeleteAuthorArgs(string Name); public async Task DeleteAuthor(DeleteAuthorArgs args) { @@ -541,7 +550,11 @@ public async Task CreateBook(CreateBookArgs args) } } - private const string ListAllAuthorsBooksSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors INNER JOIN books ON authors.id = books.author_id ORDER BY authors.name"; + private const string ListAllAuthorsBooksSql = @"SELECT + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public readonly record struct ListAllAuthorsBooksRow(Author? Author, Book? Book); public async Task> ListAllAuthorsBooks() { @@ -579,7 +592,12 @@ public async Task> ListAllAuthorsBooks() } } - private const string GetDuplicateAuthorsSql = "SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio FROM authors AS authors1 INNER JOIN authors AS authors2 ON authors1.name = authors2.name WHERE authors1.id < authors2.id"; + private const string GetDuplicateAuthorsSql = @"SELECT + authors1.id, authors1.name, authors1.bio, + authors2.id, authors2.name, authors2.bio + FROM authors AS authors1 + INNER JOIN authors AS authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public readonly record struct GetDuplicateAuthorsRow(Author? Author, Author? Author2); public async Task> GetDuplicateAuthors() { @@ -617,7 +635,11 @@ public async Task> GetDuplicateAuthors() } } - private const string GetAuthorsByBookNameSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors INNER JOIN books ON authors.id = books.author_id WHERE books.name = @name"; + private const string GetAuthorsByBookNameSql = @"SELECT + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public readonly record struct GetAuthorsByBookNameRow(int Id, string Name, string? Bio, Book? Book); public readonly record struct GetAuthorsByBookNameArgs(string Name); public async Task> GetAuthorsByBookName(GetAuthorsByBookNameArgs args) @@ -685,7 +707,20 @@ public async Task DeleteAllAuthors() } } - private const string InsertSqliteTypesSql = "INSERT INTO types_sqlite ( c_integer, c_real, c_text, c_blob, c_text_datetime_override, c_integer_datetime_override, c_text_noda_instant_override, c_integer_noda_instant_override, c_text_bool_override, c_integer_bool_override ) VALUES (@c_integer, @c_real, @c_text, @c_blob, @c_text_datetime_override, @c_integer_datetime_override, @c_text_noda_instant_override, @c_integer_noda_instant_override, @c_text_bool_override, @c_integer_bool_override)"; + private const string InsertSqliteTypesSql = @"INSERT INTO types_sqlite + ( + c_integer, + c_real, + c_text, + c_blob, + c_text_datetime_override, + c_integer_datetime_override, + c_text_noda_instant_override, + c_integer_noda_instant_override, + c_text_bool_override, + c_integer_bool_override + ) + VALUES (@c_integer, @c_real, @c_text, @c_blob, @c_text_datetime_override, @c_integer_datetime_override, @c_text_noda_instant_override, @c_integer_noda_instant_override, @c_text_bool_override, @c_integer_bool_override)"; public readonly record struct InsertSqliteTypesArgs(int? CInteger, decimal? CReal, string? CText, byte[]? CBlob, DateTime? CTextDatetimeOverride, DateTime? CIntegerDatetimeOverride, Instant? CTextNodaInstantOverride, Instant? CIntegerNodaInstantOverride, bool? CTextBoolOverride, bool? CIntegerBoolOverride); public async Task InsertSqliteTypes(InsertSqliteTypesArgs args) { @@ -755,7 +790,19 @@ public async Task InsertSqliteTypesBatch(List args) } } - private const string GetSqliteTypesSql = "SELECT c_integer, c_real, c_text, c_blob, c_text_datetime_override, c_integer_datetime_override, c_text_noda_instant_override, c_integer_noda_instant_override, c_text_bool_override, c_integer_bool_override FROM types_sqlite LIMIT 1"; + private const string GetSqliteTypesSql = @"SELECT + c_integer, + c_real, + c_text, + c_blob, + c_text_datetime_override, + c_integer_datetime_override, + c_text_noda_instant_override, + c_integer_noda_instant_override, + c_text_bool_override, + c_integer_bool_override + FROM types_sqlite + LIMIT 1"; public readonly record struct GetSqliteTypesRow(int? CInteger, decimal? CReal, string? CText, byte[]? CBlob, DateTime? CTextDatetimeOverride, DateTime? CIntegerDatetimeOverride, Instant? CTextNodaInstantOverride, Instant? CIntegerNodaInstantOverride, bool? CTextBoolOverride, bool? CIntegerBoolOverride); public async Task GetSqliteTypes() { @@ -821,7 +868,15 @@ public async Task InsertSqliteTypesBatch(List args) return null; } - private const string GetSqliteTypesCntSql = "SELECT c_integer, c_real, c_text, c_blob, count(*) AS cnt FROM types_sqlite GROUP BY c_integer, c_real, c_text, c_blob LIMIT 1"; + private const string GetSqliteTypesCntSql = @"SELECT + c_integer, + c_real, + c_text, + c_blob, + count(*) AS cnt + FROM types_sqlite + GROUP BY c_integer, c_real, c_text, c_blob + LIMIT 1"; public readonly record struct GetSqliteTypesCntRow(int? CInteger, decimal? CReal, string? CText, byte[]? CBlob, int Cnt); public async Task GetSqliteTypesCnt() { @@ -877,7 +932,11 @@ public async Task InsertSqliteTypesBatch(List args) return null; } - private const string GetSqliteFunctionsSql = "SELECT max(c_integer) AS max_integer, max(c_real) AS max_real, max(c_text) AS max_text FROM types_sqlite"; + private const string GetSqliteFunctionsSql = @"SELECT + max(c_integer) AS max_integer, + max(c_real) AS max_real, + max(c_text) AS max_text + FROM types_sqlite"; public readonly record struct GetSqliteFunctionsRow(int? MaxInteger, decimal? MaxReal, object? MaxText); public async Task GetSqliteFunctions() { diff --git a/examples/SqliteExample/request.json b/examples/SqliteExample/request.json index 28c62ae4..236c9690 100644 --- a/examples/SqliteExample/request.json +++ b/examples/SqliteExample/request.json @@ -470,7 +470,7 @@ } }, { - "text": "SELECT id, name, bio FROM authors\nWHERE id = ? LIMIT 1", + "text": "SELECT id, name, bio FROM authors -- test comment\nWHERE id = ? LIMIT 1", "name": "GetAuthorById", "cmd": ":one", "columns": [ diff --git a/examples/SqliteExample/request.message b/examples/SqliteExample/request.message index 1f9f990a0a74a52ec43576674e1213f37abe7140..022ee0e4f637141f61b2d815b49eeafe715bfc50 100644 GIT binary patch delta 37 scmcZ-@+4$~I1kG_CN8(hI=o8!y1EJ_sl_D<$@#gtsd*)vZFnT)0OyqpqW}N^ delta 21 ccmaD7awTMgI1fu76PMX!8(ziDK0Fd~08}mpMgRZ+ diff --git a/examples/SqliteLegacyExample/QuerySql.cs b/examples/SqliteLegacyExample/QuerySql.cs index 628160f0..b4216267 100644 --- a/examples/SqliteLegacyExample/QuerySql.cs +++ b/examples/SqliteLegacyExample/QuerySql.cs @@ -38,7 +38,8 @@ public static QuerySql WithTransaction(SqliteTransaction transaction) private SqliteTransaction Transaction { get; } private string ConnectionString { get; } - private const string GetAuthorSql = "SELECT id, name, bio FROM authors WHERE name = @name LIMIT 1"; + private const string GetAuthorSql = @"SELECT id, name, bio FROM authors + WHERE name = @name LIMIT 1"; public class GetAuthorRow { public int Id { get; set; } @@ -101,7 +102,10 @@ public async Task GetAuthor(GetAuthorArgs args) return null; } - private const string ListAuthorsSql = "SELECT id, name, bio FROM authors ORDER BY name LIMIT @limit OFFSET @offset"; + private const string ListAuthorsSql = @"SELECT id, name, bio + FROM authors + ORDER BY name + LIMIT @limit OFFSET @offset"; public class ListAuthorsRow { public int Id { get; set; } @@ -232,7 +236,8 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } } - private const string GetAuthorByIdSql = "SELECT id, name, bio FROM authors WHERE id = @id LIMIT 1"; + private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors -- test comment + WHERE id = @id LIMIT 1"; public class GetAuthorByIdRow { public int Id { get; set; } @@ -361,7 +366,8 @@ public async Task GetAuthorByIdWithMulti return null; } - private const string GetAuthorByNamePatternSql = "SELECT id, name, bio FROM authors WHERE name LIKE COALESCE(@name_pattern, '%')"; + private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors + WHERE name LIKE COALESCE(@name_pattern, '%')"; public class GetAuthorByNamePatternRow { public int Id { get; set; } @@ -410,7 +416,9 @@ public async Task> GetAuthorByNamePattern(GetAut } } - private const string UpdateAuthorsSql = "UPDATE authors SET bio = @bio WHERE bio IS NOT NULL"; + private const string UpdateAuthorsSql = @"UPDATE authors + SET bio = @bio + WHERE bio IS NOT NULL"; public class UpdateAuthorsArgs { public string Bio { get; set; } @@ -553,7 +561,8 @@ public async Task> GetAuthorsByIdsAndNames(GetA } } - private const string DeleteAuthorSql = "DELETE FROM authors WHERE name = @name"; + private const string DeleteAuthorSql = @"DELETE FROM authors + WHERE name = @name"; public class DeleteAuthorArgs { public string Name { get; set; } @@ -626,7 +635,11 @@ public async Task CreateBook(CreateBookArgs args) } } - private const string ListAllAuthorsBooksSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors INNER JOIN books ON authors.id = books.author_id ORDER BY authors.name"; + private const string ListAllAuthorsBooksSql = @"SELECT + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public class ListAllAuthorsBooksRow { public Author Author { get; set; } @@ -668,7 +681,12 @@ public async Task> ListAllAuthorsBooks() } } - private const string GetDuplicateAuthorsSql = "SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio FROM authors AS authors1 INNER JOIN authors AS authors2 ON authors1.name = authors2.name WHERE authors1.id < authors2.id"; + private const string GetDuplicateAuthorsSql = @"SELECT + authors1.id, authors1.name, authors1.bio, + authors2.id, authors2.name, authors2.bio + FROM authors AS authors1 + INNER JOIN authors AS authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public class GetDuplicateAuthorsRow { public Author Author { get; set; } @@ -710,7 +728,11 @@ public async Task> GetDuplicateAuthors() } } - private const string GetAuthorsByBookNameSql = "SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description FROM authors INNER JOIN books ON authors.id = books.author_id WHERE books.name = @name"; + private const string GetAuthorsByBookNameSql = @"SELECT + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public class GetAuthorsByBookNameRow { public int Id { get; set; } @@ -787,7 +809,20 @@ public async Task DeleteAllAuthors() } } - private const string InsertSqliteTypesSql = "INSERT INTO types_sqlite ( c_integer, c_real, c_text, c_blob, c_text_datetime_override, c_integer_datetime_override, c_text_noda_instant_override, c_integer_noda_instant_override, c_text_bool_override, c_integer_bool_override ) VALUES (@c_integer, @c_real, @c_text, @c_blob, @c_text_datetime_override, @c_integer_datetime_override, @c_text_noda_instant_override, @c_integer_noda_instant_override, @c_text_bool_override, @c_integer_bool_override)"; + private const string InsertSqliteTypesSql = @"INSERT INTO types_sqlite + ( + c_integer, + c_real, + c_text, + c_blob, + c_text_datetime_override, + c_integer_datetime_override, + c_text_noda_instant_override, + c_integer_noda_instant_override, + c_text_bool_override, + c_integer_bool_override + ) + VALUES (@c_integer, @c_real, @c_text, @c_blob, @c_text_datetime_override, @c_integer_datetime_override, @c_text_noda_instant_override, @c_integer_noda_instant_override, @c_text_bool_override, @c_integer_bool_override)"; public class InsertSqliteTypesArgs { public int? CInteger { get; set; } @@ -874,7 +909,19 @@ public async Task InsertSqliteTypesBatch(List args) } } - private const string GetSqliteTypesSql = "SELECT c_integer, c_real, c_text, c_blob, c_text_datetime_override, c_integer_datetime_override, c_text_noda_instant_override, c_integer_noda_instant_override, c_text_bool_override, c_integer_bool_override FROM types_sqlite LIMIT 1"; + private const string GetSqliteTypesSql = @"SELECT + c_integer, + c_real, + c_text, + c_blob, + c_text_datetime_override, + c_integer_datetime_override, + c_text_noda_instant_override, + c_integer_noda_instant_override, + c_text_bool_override, + c_integer_bool_override + FROM types_sqlite + LIMIT 1"; public class GetSqliteTypesRow { public int? CInteger { get; set; } @@ -952,7 +999,15 @@ public async Task GetSqliteTypes() return null; } - private const string GetSqliteTypesCntSql = "SELECT c_integer, c_real, c_text, c_blob, count(*) AS cnt FROM types_sqlite GROUP BY c_integer, c_real, c_text, c_blob LIMIT 1"; + private const string GetSqliteTypesCntSql = @"SELECT + c_integer, + c_real, + c_text, + c_blob, + count(*) AS cnt + FROM types_sqlite + GROUP BY c_integer, c_real, c_text, c_blob + LIMIT 1"; public class GetSqliteTypesCntRow { public int? CInteger { get; set; } @@ -1015,7 +1070,11 @@ public async Task GetSqliteTypesCnt() return null; } - private const string GetSqliteFunctionsSql = "SELECT max(c_integer) AS max_integer, max(c_real) AS max_real, max(c_text) AS max_text FROM types_sqlite"; + private const string GetSqliteFunctionsSql = @"SELECT + max(c_integer) AS max_integer, + max(c_real) AS max_real, + max(c_text) AS max_text + FROM types_sqlite"; public class GetSqliteFunctionsRow { public int? MaxInteger { get; set; } diff --git a/examples/SqliteLegacyExample/request.json b/examples/SqliteLegacyExample/request.json index 780a3346..63f98a4b 100644 --- a/examples/SqliteLegacyExample/request.json +++ b/examples/SqliteLegacyExample/request.json @@ -470,7 +470,7 @@ } }, { - "text": "SELECT id, name, bio FROM authors\nWHERE id = ? LIMIT 1", + "text": "SELECT id, name, bio FROM authors -- test comment\nWHERE id = ? LIMIT 1", "name": "GetAuthorById", "cmd": ":one", "columns": [ diff --git a/examples/SqliteLegacyExample/request.message b/examples/SqliteLegacyExample/request.message index 175ae5c3c030a6409c9a0099011082a5b6b58f55..0f2aaad4b18cee4e5ef3c66836ad2e05db90cd16 100644 GIT binary patch delta 37 scmews(iXZwn}=l{6PMd$2VNz9U0sEe)Z!9_V!Z diff --git a/examples/config/sqlite/authors/query.sql b/examples/config/sqlite/authors/query.sql index 19b241ae..a52f961c 100644 --- a/examples/config/sqlite/authors/query.sql +++ b/examples/config/sqlite/authors/query.sql @@ -15,7 +15,7 @@ INSERT INTO authors (id, name, bio) VALUES (?, ?, ?); INSERT INTO authors (name, bio) VALUES (?, ?) RETURNING id; -- name: GetAuthorById :one -SELECT * FROM authors +SELECT * FROM authors -- test comment WHERE id = ? LIMIT 1; -- name: GetAuthorByIdWithMultipleNamedParam :one From 388582be5713866d28d1ff830dd481b082be10bb Mon Sep 17 00:00:00 2001 From: Doron Eli Rachman Date: Sat, 1 Nov 2025 16:57:56 +0200 Subject: [PATCH 2/7] fix comment name --- examples/config/sqlite/authors/query.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/config/sqlite/authors/query.sql b/examples/config/sqlite/authors/query.sql index a52f961c..1e57a39c 100644 --- a/examples/config/sqlite/authors/query.sql +++ b/examples/config/sqlite/authors/query.sql @@ -15,7 +15,7 @@ INSERT INTO authors (id, name, bio) VALUES (?, ?, ?); INSERT INTO authors (name, bio) VALUES (?, ?) RETURNING id; -- name: GetAuthorById :one -SELECT * FROM authors -- test comment +SELECT * FROM authors -- test rest of line comment WHERE id = ? LIMIT 1; -- name: GetAuthorByIdWithMultipleNamedParam :one From 2286ddcf71b79d64659e1da517217ac9a82b8fe7 Mon Sep 17 00:00:00 2001 From: Doron Eli Rachman Date: Sat, 1 Nov 2025 17:02:16 +0200 Subject: [PATCH 3/7] fix generated code --- examples/QuickStartSqliteDalGen/QuerySql.cs | 2 +- examples/QuickStartSqliteDalGen/request.json | 2 +- .../QuickStartSqliteDalGen/request.message | Bin 5131 -> 5144 bytes examples/SqliteDapperExample/QuerySql.cs | 2 +- examples/SqliteDapperExample/request.json | 2 +- examples/SqliteDapperExample/request.message | Bin 10868 -> 10881 bytes .../SqliteDapperLegacyExample/QuerySql.cs | 2 +- .../SqliteDapperLegacyExample/request.json | 2 +- .../SqliteDapperLegacyExample/request.message | Bin 10902 -> 10915 bytes examples/SqliteExample/QuerySql.cs | 2 +- examples/SqliteExample/request.json | 2 +- examples/SqliteExample/request.message | Bin 10852 -> 10865 bytes examples/SqliteLegacyExample/QuerySql.cs | 2 +- examples/SqliteLegacyExample/request.json | 2 +- examples/SqliteLegacyExample/request.message | Bin 10886 -> 10899 bytes 15 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/QuickStartSqliteDalGen/QuerySql.cs b/examples/QuickStartSqliteDalGen/QuerySql.cs index 7dac2dc3..8577870d 100644 --- a/examples/QuickStartSqliteDalGen/QuerySql.cs +++ b/examples/QuickStartSqliteDalGen/QuerySql.cs @@ -203,7 +203,7 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } } - private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors -- test comment + private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors -- test rest of line comment WHERE id = @id LIMIT 1"; public readonly record struct GetAuthorByIdRow(int Id, string Name, string? Bio); public readonly record struct GetAuthorByIdArgs(int Id); diff --git a/examples/QuickStartSqliteDalGen/request.json b/examples/QuickStartSqliteDalGen/request.json index 5abcf639..982f89e2 100644 --- a/examples/QuickStartSqliteDalGen/request.json +++ b/examples/QuickStartSqliteDalGen/request.json @@ -361,7 +361,7 @@ } }, { - "text": "SELECT id, name, bio FROM authors -- test comment\nWHERE id = ? LIMIT 1", + "text": "SELECT id, name, bio FROM authors -- test rest of line comment\nWHERE id = ? LIMIT 1", "name": "GetAuthorById", "cmd": ":one", "columns": [ diff --git a/examples/QuickStartSqliteDalGen/request.message b/examples/QuickStartSqliteDalGen/request.message index 975aceb9b5772ac1464323f7e0dc2a3cab7b7fe5..6ed92dd055b412bba19b66852e865637a668b729 100644 GIT binary patch delta 38 ucmeCyn4z&Djg4hB6Ibx$Zg!=~J!~92MXALl3i)XYIhlE>n CreateAuthorReturnId(CreateAuthorReturnIdArgs args) return await this.Transaction.Connection.QuerySingleAsync(CreateAuthorReturnIdSql, queryParams, transaction: this.Transaction); } - private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors -- test comment + private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors -- test rest of line comment WHERE id = @id LIMIT 1"; public class GetAuthorByIdRow { diff --git a/examples/SqliteDapperExample/request.json b/examples/SqliteDapperExample/request.json index b9d70cd3..4a41f823 100644 --- a/examples/SqliteDapperExample/request.json +++ b/examples/SqliteDapperExample/request.json @@ -470,7 +470,7 @@ } }, { - "text": "SELECT id, name, bio FROM authors -- test comment\nWHERE id = ? LIMIT 1", + "text": "SELECT id, name, bio FROM authors -- test rest of line comment\nWHERE id = ? LIMIT 1", "name": "GetAuthorById", "cmd": ":one", "columns": [ diff --git a/examples/SqliteDapperExample/request.message b/examples/SqliteDapperExample/request.message index e3898eef6c6d8a69fcbaa77680cba8dd0f32e95d..39cdfc0dfbb41ed51c104a9b214f80ef476b9041 100644 GIT binary patch delta 42 vcmewo(iplyiHBu16IbwLcU~nCU0sEe)Z!9_A`p?ErjV1Fm%7=XM^z30C1?#! delta 21 ccmZn+{SvZ4iHBt#6PMd$H6E?au{ CreateAuthorReturnId(CreateAuthorReturnIdArgs args) return await this.Transaction.Connection.QuerySingleAsync(CreateAuthorReturnIdSql, queryParams, transaction: this.Transaction); } - private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors -- test comment + private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors -- test rest of line comment WHERE id = @id LIMIT 1"; public class GetAuthorByIdRow { diff --git a/examples/SqliteDapperLegacyExample/request.json b/examples/SqliteDapperLegacyExample/request.json index 1e634382..8c18860b 100644 --- a/examples/SqliteDapperLegacyExample/request.json +++ b/examples/SqliteDapperLegacyExample/request.json @@ -470,7 +470,7 @@ } }, { - "text": "SELECT id, name, bio FROM authors -- test comment\nWHERE id = ? LIMIT 1", + "text": "SELECT id, name, bio FROM authors -- test rest of line comment\nWHERE id = ? LIMIT 1", "name": "GetAuthorById", "cmd": ":one", "columns": [ diff --git a/examples/SqliteDapperLegacyExample/request.message b/examples/SqliteDapperLegacyExample/request.message index b7d6c4c6ff944a6a1143672676b3aac6ffe0d76a..59136a5a1c3deb0c43d46827e1467819d034597a 100644 GIT binary patch delta 38 ucmbOhx;S)$84t^9Ca&Pg(Y#8NV|X}tic*V96!Oy)ax(K$Hz)HL%K-rI<_rD+ delta 21 ccmZ1+IxTdA84t@mCN8(hRy08Xq1O#lD@ diff --git a/examples/SqliteExample/QuerySql.cs b/examples/SqliteExample/QuerySql.cs index 2550be7e..28dae146 100644 --- a/examples/SqliteExample/QuerySql.cs +++ b/examples/SqliteExample/QuerySql.cs @@ -206,7 +206,7 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } } - private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors -- test comment + private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors -- test rest of line comment WHERE id = @id LIMIT 1"; public readonly record struct GetAuthorByIdRow(int Id, string Name, string? Bio); public readonly record struct GetAuthorByIdArgs(int Id); diff --git a/examples/SqliteExample/request.json b/examples/SqliteExample/request.json index 236c9690..086cb9f2 100644 --- a/examples/SqliteExample/request.json +++ b/examples/SqliteExample/request.json @@ -470,7 +470,7 @@ } }, { - "text": "SELECT id, name, bio FROM authors -- test comment\nWHERE id = ? LIMIT 1", + "text": "SELECT id, name, bio FROM authors -- test rest of line comment\nWHERE id = ? LIMIT 1", "name": "GetAuthorById", "cmd": ":one", "columns": [ diff --git a/examples/SqliteExample/request.message b/examples/SqliteExample/request.message index 022ee0e4f637141f61b2d815b49eeafe715bfc50..336ca56eb6e9d4d02e2bfb779621b7fe647e5b57 100644 GIT binary patch delta 38 ucmaD7@-bwCI1kHeCa&PgHoQucZFx9&ic*V96!Oy)ax(K$H@omC$N>QR_Y4UD delta 21 ccmewu@+4$~I1kG_CN8(h(mYz5gLvfS09PyqcK`qY diff --git a/examples/SqliteLegacyExample/QuerySql.cs b/examples/SqliteLegacyExample/QuerySql.cs index b4216267..54deb8f2 100644 --- a/examples/SqliteLegacyExample/QuerySql.cs +++ b/examples/SqliteLegacyExample/QuerySql.cs @@ -236,7 +236,7 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } } - private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors -- test comment + private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors -- test rest of line comment WHERE id = @id LIMIT 1"; public class GetAuthorByIdRow { diff --git a/examples/SqliteLegacyExample/request.json b/examples/SqliteLegacyExample/request.json index 63f98a4b..07aad6d0 100644 --- a/examples/SqliteLegacyExample/request.json +++ b/examples/SqliteLegacyExample/request.json @@ -470,7 +470,7 @@ } }, { - "text": "SELECT id, name, bio FROM authors -- test comment\nWHERE id = ? LIMIT 1", + "text": "SELECT id, name, bio FROM authors -- test rest of line comment\nWHERE id = ? LIMIT 1", "name": "GetAuthorById", "cmd": ":one", "columns": [ diff --git a/examples/SqliteLegacyExample/request.message b/examples/SqliteLegacyExample/request.message index 0f2aaad4b18cee4e5ef3c66836ad2e05db90cd16..3942d1b038acb1773ee0d73593fc1a3132b8472f 100644 GIT binary patch delta 42 vcmZn*ogBJBn}=mJ6Ibx$0A3{#U0sEe)Z!9_A`p?ErjV1Fm%2HEM^6p_7~KsQ delta 21 ccmbOn+7`M&n}=l{6PMd$eIBjNX*{}e07~u#2LJ#7 From 231ba103ab2c1264db359e2e6c0bdd849eb61432 Mon Sep 17 00:00:00 2001 From: Doron Eli Rachman Date: Sat, 1 Nov 2025 22:45:37 +0200 Subject: [PATCH 4/7] remove unneeded single double convertor --- CodeGenerator/Generators/QueriesGen.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CodeGenerator/Generators/QueriesGen.cs b/CodeGenerator/Generators/QueriesGen.cs index 65ba6f6e..dab25596 100644 --- a/CodeGenerator/Generators/QueriesGen.cs +++ b/CodeGenerator/Generators/QueriesGen.cs @@ -157,7 +157,7 @@ private IEnumerable GetMembersForSingleQuery(Query quer .AppendNewLine(); } - var singleLineQueryText = LongWhitespaceRegex().Replace(transformedQueryText, " ").Replace("\"", "\"\""); + var singleLineQueryText = LongWhitespaceRegex().Replace(transformedQueryText, " "); return ParseMemberDeclaration( $"""private const string {memberName} = "{singleLineQueryText}";""")! .AppendNewLine(); From 20c62589d92ff82c133a404d8f8e5ff1dd7775bb Mon Sep 17 00:00:00 2001 From: Doron Eli Rachman Date: Sat, 15 Nov 2025 12:28:17 +0200 Subject: [PATCH 5/7] fix indentation --- CodeGenerator/Generators/QueriesGen.cs | 28 +- .../QuerySql.cs | 340 ++++++------ .../MySqlConnectorLegacyExample/QuerySql.cs | 340 ++++++------ .../NpgsqlDapperLegacyExample/QuerySql.cs | 506 +++++++++--------- examples/NpgsqlLegacyExample/QuerySql.cs | 506 +++++++++--------- .../SqliteDapperLegacyExample/QuerySql.cs | 118 ++-- examples/SqliteLegacyExample/QuerySql.cs | 118 ++-- 7 files changed, 979 insertions(+), 977 deletions(-) diff --git a/CodeGenerator/Generators/QueriesGen.cs b/CodeGenerator/Generators/QueriesGen.cs index dab25596..f30b9afd 100644 --- a/CodeGenerator/Generators/QueriesGen.cs +++ b/CodeGenerator/Generators/QueriesGen.cs @@ -140,21 +140,23 @@ private IEnumerable GetMembersForSingleQuery(Query quer var memberName = ClassMember.Sql.Name(query.Name); if (transformedQueryText.IndexOfAny(['\r', '\n']) >= 0) { - var queryWithEscapedQuotes = transformedQueryText.Replace("\"", "\"\""); - var declarationStart = $"private const string {memberName} = @\""; - var lines = queryWithEscapedQuotes.TrimEnd().Split(["\r\n", "\r", "\n"], StringSplitOptions.None); - var firstLine = lines[0]; - var firstCharIndex = firstLine.TakeWhile(char.IsWhiteSpace).Count(); - var baseIndent = new string(' ', 4); // Assuming a standard 4-space indentation for members - var indent = new string(' ', baseIndent.Length + declarationStart.Length + firstCharIndex); - - var indentedQuery = string.Join( - Environment.NewLine + indent, - lines); + var queryText = transformedQueryText.Replace("\"", "\"\""); + var lines = queryText.TrimEnd().Split(["\r\n", "\r", "\n"], StringSplitOptions.None); + + // The indentation of the constant declaration itself. for legacy generation it 8 indents and for modern it 4. + string memberIndentPrefix = dbDriver.Options.DotnetFramework.IsDotnetLegacy() ? " " : " "; + var declaration = $"private const string {memberName} = @\""; + + // We need to calculate the indentation for subsequent lines so they align with the first. + // This is based on the member indent, the declaration length, and any leading space on the first SQL line. + var firstLineLeadingSpaceCount = lines[0].TakeWhile(char.IsWhiteSpace).Count(); + var subsequentLineIndent = new string(' ', memberIndentPrefix.Length + declaration.Length + firstLineLeadingSpaceCount); + + var indentedLines = lines.Skip(1).Select(line => subsequentLineIndent + line); + var fullQueryString = string.Join(Environment.NewLine, [lines[0], ..indentedLines]); return ParseMemberDeclaration( - $"{baseIndent}{declarationStart}{indentedQuery}\";")! - .AppendNewLine(); + $"{memberIndentPrefix}{declaration}{fullQueryString}\";")!; } var singleLineQueryText = LongWhitespaceRegex().Replace(transformedQueryText, " "); diff --git a/examples/MySqlConnectorDapperLegacyExample/QuerySql.cs b/examples/MySqlConnectorDapperLegacyExample/QuerySql.cs index 0c6c4211..06527794 100644 --- a/examples/MySqlConnectorDapperLegacyExample/QuerySql.cs +++ b/examples/MySqlConnectorDapperLegacyExample/QuerySql.cs @@ -77,9 +77,9 @@ public async Task GetAuthor(GetAuthorArgs args) } private const string ListAuthorsSql = @"SELECT id, name, bio - FROM authors - ORDER BY name - LIMIT @limit OFFSET @offset"; + FROM authors + ORDER BY name + LIMIT @limit OFFSET @offset"; public class ListAuthorsRow { public long Id { get; set; } @@ -187,7 +187,7 @@ public async Task GetAuthorById(GetAuthorByIdArgs args) } private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors - WHERE name LIKE COALESCE(@name_pattern, '%')"; + WHERE name LIKE COALESCE(@name_pattern, '%')"; public class GetAuthorByNamePatternRow { public long Id { get; set; } @@ -217,7 +217,7 @@ public async Task> GetAuthorByNamePattern(GetAut } private const string DeleteAuthorSql = @"DELETE FROM authors - WHERE name = @name"; + WHERE name = @name"; public class DeleteAuthorArgs { public string Name { get; set; } @@ -254,8 +254,8 @@ public async Task DeleteAllAuthors() } private const string UpdateAuthorsSql = @"UPDATE authors - SET bio = @bio - WHERE bio IS NOT NULL"; + SET bio = @bio + WHERE bio IS NOT NULL"; public class UpdateAuthorsArgs { public string Bio { get; set; } @@ -366,8 +366,8 @@ public async Task CreateBook(CreateBookArgs args) } private const string ListAllAuthorsBooksSql = @"SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description - FROM authors JOIN books ON authors.id = books.author_id - ORDER BY authors.name"; + FROM authors JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public class ListAllAuthorsBooksRow { public Author Author { get; set; } @@ -410,8 +410,8 @@ public async Task> ListAllAuthorsBooks() } private const string GetDuplicateAuthorsSql = @"SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio - FROM authors authors1 JOIN authors authors2 ON authors1.name = authors2.name - WHERE authors1.id < authors2.id"; + FROM authors authors1 JOIN authors authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public class GetDuplicateAuthorsRow { public Author Author { get; set; } @@ -454,8 +454,8 @@ public async Task> GetDuplicateAuthors() } private const string GetAuthorsByBookNameSql = @"SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description - FROM authors JOIN books ON authors.id = books.author_id - WHERE books.name = @name"; + FROM authors JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public class GetAuthorsByBookNameRow { public long Id { get; set; } @@ -578,25 +578,25 @@ public async Task TruncateExtendedBios() } private const string InsertMysqlNumericTypesSql = @" - INSERT INTO mysql_numeric_types - ( - c_bool, - c_boolean, - c_tinyint, - c_smallint, - c_mediumint, - c_int, - c_integer, - c_bigint, - c_decimal, - c_dec, - c_numeric, - c_fixed, - c_float, - c_double, - c_double_precision - ) - VALUES (@c_bool, @c_boolean, @c_tinyint, @c_smallint, @c_mediumint, @c_int, @c_integer, @c_bigint, @c_decimal, @c_dec, @c_numeric, @c_fixed, @c_float, @c_double, @c_double_precision)"; + INSERT INTO mysql_numeric_types + ( + c_bool, + c_boolean, + c_tinyint, + c_smallint, + c_mediumint, + c_int, + c_integer, + c_bigint, + c_decimal, + c_dec, + c_numeric, + c_fixed, + c_float, + c_double, + c_double_precision + ) + VALUES (@c_bool, @c_boolean, @c_tinyint, @c_smallint, @c_mediumint, @c_int, @c_integer, @c_bigint, @c_decimal, @c_dec, @c_numeric, @c_fixed, @c_float, @c_double, @c_double_precision)"; public class InsertMysqlNumericTypesArgs { public bool? CBool { get; set; } @@ -750,40 +750,40 @@ public async Task GetMysqlNumericTypes() } private const string GetMysqlNumericTypesCntSql = @"SELECT - COUNT(*) AS cnt, - c_bool, - c_boolean, - c_tinyint, - c_smallint, - c_mediumint, - c_int, - c_integer, - c_bigint, - c_float, - c_numeric, - c_decimal, - c_dec, - c_fixed, - c_double, - c_double_precision - FROM mysql_numeric_types - GROUP BY - c_bool, - c_boolean, - c_tinyint, - c_smallint, - c_mediumint, - c_int, - c_integer, - c_bigint, - c_float, - c_numeric, - c_decimal, - c_dec, - c_fixed, - c_double, - c_double_precision - LIMIT 1"; + COUNT(*) AS cnt, + c_bool, + c_boolean, + c_tinyint, + c_smallint, + c_mediumint, + c_int, + c_integer, + c_bigint, + c_float, + c_numeric, + c_decimal, + c_dec, + c_fixed, + c_double, + c_double_precision + FROM mysql_numeric_types + GROUP BY + c_bool, + c_boolean, + c_tinyint, + c_smallint, + c_mediumint, + c_int, + c_integer, + c_bigint, + c_float, + c_numeric, + c_decimal, + c_dec, + c_fixed, + c_double, + c_double_precision + LIMIT 1"; public class GetMysqlNumericTypesCntRow { public long Cnt { get; set; } @@ -835,22 +835,22 @@ public async Task TruncateMysqlNumericTypes() } private const string InsertMysqlStringTypesSql = @" - INSERT INTO mysql_string_types - ( - c_char, - c_nchar, - c_national_char, - c_varchar, - c_tinytext, - c_mediumtext, - c_text, - c_longtext, - c_json, - c_json_string_override, - c_enum, - c_set - ) - VALUES (@c_char, @c_nchar, @c_national_char, @c_varchar, @c_tinytext, @c_mediumtext, @c_text, @c_longtext, @c_json, @c_json_string_override, @c_enum, @c_set)"; + INSERT INTO mysql_string_types + ( + c_char, + c_nchar, + c_national_char, + c_varchar, + c_tinytext, + c_mediumtext, + c_text, + c_longtext, + c_json, + c_json_string_override, + c_enum, + c_set + ) + VALUES (@c_char, @c_nchar, @c_national_char, @c_varchar, @c_tinytext, @c_mediumtext, @c_text, @c_longtext, @c_json, @c_json_string_override, @c_enum, @c_set)"; public class InsertMysqlStringTypesArgs { public string CChar { get; set; } @@ -989,34 +989,34 @@ public async Task GetMysqlStringTypes() } private const string GetMysqlStringTypesCntSql = @"SELECT - COUNT(*) AS cnt, - c_char, - c_nchar, - c_national_char, - c_varchar, - c_tinytext, - c_mediumtext, - c_text, - c_longtext, - c_json, - c_json_string_override, - c_enum, - c_set - FROM mysql_string_types - GROUP BY - c_char, - c_nchar, - c_national_char, - c_varchar, - c_tinytext, - c_mediumtext, - c_text, - c_longtext, - c_json, - c_json_string_override, - c_enum, - c_set - LIMIT 1"; + COUNT(*) AS cnt, + c_char, + c_nchar, + c_national_char, + c_varchar, + c_tinytext, + c_mediumtext, + c_text, + c_longtext, + c_json, + c_json_string_override, + c_enum, + c_set + FROM mysql_string_types + GROUP BY + c_char, + c_nchar, + c_national_char, + c_varchar, + c_tinytext, + c_mediumtext, + c_text, + c_longtext, + c_json, + c_json_string_override, + c_enum, + c_set + LIMIT 1"; public class GetMysqlStringTypesCntRow { public long Cnt { get; set; } @@ -1065,16 +1065,16 @@ public async Task TruncateMysqlStringTypes() } private const string InsertMysqlDatetimeTypesSql = @" - INSERT INTO mysql_datetime_types - ( - c_year, - c_date, - c_datetime, - c_timestamp, - c_time, - c_timestamp_noda_instant_override - ) - VALUES (@c_year, @c_date, @c_datetime, @c_timestamp, @c_time, @c_timestamp_noda_instant_override)"; + INSERT INTO mysql_datetime_types + ( + c_year, + c_date, + c_datetime, + c_timestamp, + c_time, + c_timestamp_noda_instant_override + ) + VALUES (@c_year, @c_date, @c_datetime, @c_timestamp, @c_time, @c_timestamp_noda_instant_override)"; public class InsertMysqlDatetimeTypesArgs { public short? CYear { get; set; } @@ -1187,20 +1187,20 @@ public async Task GetMysqlDatetimeTypes() } private const string GetMysqlDatetimeTypesCntSql = @"SELECT - COUNT(*) AS cnt, - c_year, - c_date, - c_datetime, - c_timestamp, - c_time - FROM mysql_datetime_types - GROUP BY - c_year, - c_date, - c_datetime, - c_timestamp, - c_time - LIMIT 1"; + COUNT(*) AS cnt, + c_year, + c_date, + c_datetime, + c_timestamp, + c_time + FROM mysql_datetime_types + GROUP BY + c_year, + c_date, + c_datetime, + c_timestamp, + c_time + LIMIT 1"; public class GetMysqlDatetimeTypesCntRow { public long Cnt { get; set; } @@ -1242,17 +1242,17 @@ public async Task TruncateMysqlDatetimeTypes() } private const string InsertMysqlBinaryTypesSql = @" - INSERT INTO mysql_binary_types - ( - c_bit, - c_binary, - c_varbinary, - c_tinyblob, - c_blob, - c_mediumblob, - c_longblob - ) - VALUES (@c_bit, @c_binary, @c_varbinary, @c_tinyblob, @c_blob, @c_mediumblob, @c_longblob)"; + INSERT INTO mysql_binary_types + ( + c_bit, + c_binary, + c_varbinary, + c_tinyblob, + c_blob, + c_mediumblob, + c_longblob + ) + VALUES (@c_bit, @c_binary, @c_varbinary, @c_tinyblob, @c_blob, @c_mediumblob, @c_longblob)"; public class InsertMysqlBinaryTypesArgs { public byte? CBit { get; set; } @@ -1370,24 +1370,24 @@ public async Task GetMysqlBinaryTypes() } private const string GetMysqlBinaryTypesCntSql = @"SELECT - COUNT(*) AS cnt, - c_bit, - c_binary, - c_varbinary, - c_tinyblob, - c_blob, - c_mediumblob, - c_longblob - FROM mysql_binary_types - GROUP BY - c_bit, - c_binary, - c_varbinary, - c_tinyblob, - c_blob, - c_mediumblob, - c_longblob - LIMIT 1"; + COUNT(*) AS cnt, + c_bit, + c_binary, + c_varbinary, + c_tinyblob, + c_blob, + c_mediumblob, + c_longblob + FROM mysql_binary_types + GROUP BY + c_bit, + c_binary, + c_varbinary, + c_tinyblob, + c_blob, + c_mediumblob, + c_longblob + LIMIT 1"; public class GetMysqlBinaryTypesCntRow { public long Cnt { get; set; } @@ -1431,13 +1431,13 @@ public async Task TruncateMysqlBinaryTypes() } private const string GetMysqlFunctionsSql = @" - SELECT - MAX(c_int) AS max_int, - MAX(c_varchar) AS max_varchar, - MAX(c_timestamp) AS max_timestamp - FROM mysql_numeric_types - CROSS JOIN mysql_string_types - CROSS JOIN mysql_datetime_types"; + SELECT + MAX(c_int) AS max_int, + MAX(c_varchar) AS max_varchar, + MAX(c_timestamp) AS max_timestamp + FROM mysql_numeric_types + CROSS JOIN mysql_string_types + CROSS JOIN mysql_datetime_types"; public class GetMysqlFunctionsRow { public int? MaxInt { get; set; } diff --git a/examples/MySqlConnectorLegacyExample/QuerySql.cs b/examples/MySqlConnectorLegacyExample/QuerySql.cs index febdac73..775f5884 100644 --- a/examples/MySqlConnectorLegacyExample/QuerySql.cs +++ b/examples/MySqlConnectorLegacyExample/QuerySql.cs @@ -108,9 +108,9 @@ public async Task GetAuthor(GetAuthorArgs args) } private const string ListAuthorsSql = @"SELECT id, name, bio - FROM authors - ORDER BY name - LIMIT @limit OFFSET @offset"; + FROM authors + ORDER BY name + LIMIT @limit OFFSET @offset"; public class ListAuthorsRow { public long Id { get; set; } @@ -301,7 +301,7 @@ public async Task GetAuthorById(GetAuthorByIdArgs args) } private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors - WHERE name LIKE COALESCE(@name_pattern, '%')"; + WHERE name LIKE COALESCE(@name_pattern, '%')"; public class GetAuthorByNamePatternRow { public long Id { get; set; } @@ -351,7 +351,7 @@ public async Task> GetAuthorByNamePattern(GetAut } private const string DeleteAuthorSql = @"DELETE FROM authors - WHERE name = @name"; + WHERE name = @name"; public class DeleteAuthorArgs { public string Name { get; set; } @@ -412,8 +412,8 @@ public async Task DeleteAllAuthors() } private const string UpdateAuthorsSql = @"UPDATE authors - SET bio = @bio - WHERE bio IS NOT NULL"; + SET bio = @bio + WHERE bio IS NOT NULL"; public class UpdateAuthorsArgs { public string Bio { get; set; } @@ -593,8 +593,8 @@ public async Task CreateBook(CreateBookArgs args) } private const string ListAllAuthorsBooksSql = @"SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description - FROM authors JOIN books ON authors.id = books.author_id - ORDER BY authors.name"; + FROM authors JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public class ListAllAuthorsBooksRow { public Author Author { get; set; } @@ -637,8 +637,8 @@ public async Task> ListAllAuthorsBooks() } private const string GetDuplicateAuthorsSql = @"SELECT authors1.id, authors1.name, authors1.bio, authors2.id, authors2.name, authors2.bio - FROM authors authors1 JOIN authors authors2 ON authors1.name = authors2.name - WHERE authors1.id < authors2.id"; + FROM authors authors1 JOIN authors authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public class GetDuplicateAuthorsRow { public Author Author { get; set; } @@ -681,8 +681,8 @@ public async Task> GetDuplicateAuthors() } private const string GetAuthorsByBookNameSql = @"SELECT authors.id, authors.name, authors.bio, books.id, books.name, books.author_id, books.description - FROM authors JOIN books ON authors.id = books.author_id - WHERE books.name = @name"; + FROM authors JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public class GetAuthorsByBookNameRow { public long Id { get; set; } @@ -868,25 +868,25 @@ public async Task TruncateExtendedBios() } private const string InsertMysqlNumericTypesSql = @" - INSERT INTO mysql_numeric_types - ( - c_bool, - c_boolean, - c_tinyint, - c_smallint, - c_mediumint, - c_int, - c_integer, - c_bigint, - c_decimal, - c_dec, - c_numeric, - c_fixed, - c_float, - c_double, - c_double_precision - ) - VALUES (@c_bool, @c_boolean, @c_tinyint, @c_smallint, @c_mediumint, @c_int, @c_integer, @c_bigint, @c_decimal, @c_dec, @c_numeric, @c_fixed, @c_float, @c_double, @c_double_precision)"; + INSERT INTO mysql_numeric_types + ( + c_bool, + c_boolean, + c_tinyint, + c_smallint, + c_mediumint, + c_int, + c_integer, + c_bigint, + c_decimal, + c_dec, + c_numeric, + c_fixed, + c_float, + c_double, + c_double_precision + ) + VALUES (@c_bool, @c_boolean, @c_tinyint, @c_smallint, @c_mediumint, @c_int, @c_integer, @c_bigint, @c_decimal, @c_dec, @c_numeric, @c_fixed, @c_float, @c_double, @c_double_precision)"; public class InsertMysqlNumericTypesArgs { public bool? CBool { get; set; } @@ -1124,40 +1124,40 @@ public async Task GetMysqlNumericTypes() } private const string GetMysqlNumericTypesCntSql = @"SELECT - COUNT(*) AS cnt, - c_bool, - c_boolean, - c_tinyint, - c_smallint, - c_mediumint, - c_int, - c_integer, - c_bigint, - c_float, - c_numeric, - c_decimal, - c_dec, - c_fixed, - c_double, - c_double_precision - FROM mysql_numeric_types - GROUP BY - c_bool, - c_boolean, - c_tinyint, - c_smallint, - c_mediumint, - c_int, - c_integer, - c_bigint, - c_float, - c_numeric, - c_decimal, - c_dec, - c_fixed, - c_double, - c_double_precision - LIMIT 1"; + COUNT(*) AS cnt, + c_bool, + c_boolean, + c_tinyint, + c_smallint, + c_mediumint, + c_int, + c_integer, + c_bigint, + c_float, + c_numeric, + c_decimal, + c_dec, + c_fixed, + c_double, + c_double_precision + FROM mysql_numeric_types + GROUP BY + c_bool, + c_boolean, + c_tinyint, + c_smallint, + c_mediumint, + c_int, + c_integer, + c_bigint, + c_float, + c_numeric, + c_decimal, + c_dec, + c_fixed, + c_double, + c_double_precision + LIMIT 1"; public class GetMysqlNumericTypesCntRow { public long Cnt { get; set; } @@ -1281,22 +1281,22 @@ public async Task TruncateMysqlNumericTypes() } private const string InsertMysqlStringTypesSql = @" - INSERT INTO mysql_string_types - ( - c_char, - c_nchar, - c_national_char, - c_varchar, - c_tinytext, - c_mediumtext, - c_text, - c_longtext, - c_json, - c_json_string_override, - c_enum, - c_set - ) - VALUES (@c_char, @c_nchar, @c_national_char, @c_varchar, @c_tinytext, @c_mediumtext, @c_text, @c_longtext, @c_json, @c_json_string_override, @c_enum, @c_set)"; + INSERT INTO mysql_string_types + ( + c_char, + c_nchar, + c_national_char, + c_varchar, + c_tinytext, + c_mediumtext, + c_text, + c_longtext, + c_json, + c_json_string_override, + c_enum, + c_set + ) + VALUES (@c_char, @c_nchar, @c_national_char, @c_varchar, @c_tinytext, @c_mediumtext, @c_text, @c_longtext, @c_json, @c_json_string_override, @c_enum, @c_set)"; public class InsertMysqlStringTypesArgs { public string CChar { get; set; } @@ -1510,34 +1510,34 @@ public async Task GetMysqlStringTypes() } private const string GetMysqlStringTypesCntSql = @"SELECT - COUNT(*) AS cnt, - c_char, - c_nchar, - c_national_char, - c_varchar, - c_tinytext, - c_mediumtext, - c_text, - c_longtext, - c_json, - c_json_string_override, - c_enum, - c_set - FROM mysql_string_types - GROUP BY - c_char, - c_nchar, - c_national_char, - c_varchar, - c_tinytext, - c_mediumtext, - c_text, - c_longtext, - c_json, - c_json_string_override, - c_enum, - c_set - LIMIT 1"; + COUNT(*) AS cnt, + c_char, + c_nchar, + c_national_char, + c_varchar, + c_tinytext, + c_mediumtext, + c_text, + c_longtext, + c_json, + c_json_string_override, + c_enum, + c_set + FROM mysql_string_types + GROUP BY + c_char, + c_nchar, + c_national_char, + c_varchar, + c_tinytext, + c_mediumtext, + c_text, + c_longtext, + c_json, + c_json_string_override, + c_enum, + c_set + LIMIT 1"; public class GetMysqlStringTypesCntRow { public long Cnt { get; set; } @@ -1652,16 +1652,16 @@ public async Task TruncateMysqlStringTypes() } private const string InsertMysqlDatetimeTypesSql = @" - INSERT INTO mysql_datetime_types - ( - c_year, - c_date, - c_datetime, - c_timestamp, - c_time, - c_timestamp_noda_instant_override - ) - VALUES (@c_year, @c_date, @c_datetime, @c_timestamp, @c_time, @c_timestamp_noda_instant_override)"; + INSERT INTO mysql_datetime_types + ( + c_year, + c_date, + c_datetime, + c_timestamp, + c_time, + c_timestamp_noda_instant_override + ) + VALUES (@c_year, @c_date, @c_datetime, @c_timestamp, @c_time, @c_timestamp_noda_instant_override)"; public class InsertMysqlDatetimeTypesArgs { public short? CYear { get; set; } @@ -1843,20 +1843,20 @@ public async Task GetMysqlDatetimeTypes() } private const string GetMysqlDatetimeTypesCntSql = @"SELECT - COUNT(*) AS cnt, - c_year, - c_date, - c_datetime, - c_timestamp, - c_time - FROM mysql_datetime_types - GROUP BY - c_year, - c_date, - c_datetime, - c_timestamp, - c_time - LIMIT 1"; + COUNT(*) AS cnt, + c_year, + c_date, + c_datetime, + c_timestamp, + c_time + FROM mysql_datetime_types + GROUP BY + c_year, + c_date, + c_datetime, + c_timestamp, + c_time + LIMIT 1"; public class GetMysqlDatetimeTypesCntRow { public long Cnt { get; set; } @@ -1950,17 +1950,17 @@ public async Task TruncateMysqlDatetimeTypes() } private const string InsertMysqlBinaryTypesSql = @" - INSERT INTO mysql_binary_types - ( - c_bit, - c_binary, - c_varbinary, - c_tinyblob, - c_blob, - c_mediumblob, - c_longblob - ) - VALUES (@c_bit, @c_binary, @c_varbinary, @c_tinyblob, @c_blob, @c_mediumblob, @c_longblob)"; + INSERT INTO mysql_binary_types + ( + c_bit, + c_binary, + c_varbinary, + c_tinyblob, + c_blob, + c_mediumblob, + c_longblob + ) + VALUES (@c_bit, @c_binary, @c_varbinary, @c_tinyblob, @c_blob, @c_mediumblob, @c_longblob)"; public class InsertMysqlBinaryTypesArgs { public byte? CBit { get; set; } @@ -2138,24 +2138,24 @@ public async Task GetMysqlBinaryTypes() } private const string GetMysqlBinaryTypesCntSql = @"SELECT - COUNT(*) AS cnt, - c_bit, - c_binary, - c_varbinary, - c_tinyblob, - c_blob, - c_mediumblob, - c_longblob - FROM mysql_binary_types - GROUP BY - c_bit, - c_binary, - c_varbinary, - c_tinyblob, - c_blob, - c_mediumblob, - c_longblob - LIMIT 1"; + COUNT(*) AS cnt, + c_bit, + c_binary, + c_varbinary, + c_tinyblob, + c_blob, + c_mediumblob, + c_longblob + FROM mysql_binary_types + GROUP BY + c_bit, + c_binary, + c_varbinary, + c_tinyblob, + c_blob, + c_mediumblob, + c_longblob + LIMIT 1"; public class GetMysqlBinaryTypesCntRow { public long Cnt { get; set; } @@ -2255,13 +2255,13 @@ public async Task TruncateMysqlBinaryTypes() } private const string GetMysqlFunctionsSql = @" - SELECT - MAX(c_int) AS max_int, - MAX(c_varchar) AS max_varchar, - MAX(c_timestamp) AS max_timestamp - FROM mysql_numeric_types - CROSS JOIN mysql_string_types - CROSS JOIN mysql_datetime_types"; + SELECT + MAX(c_int) AS max_int, + MAX(c_varchar) AS max_varchar, + MAX(c_timestamp) AS max_timestamp + FROM mysql_numeric_types + CROSS JOIN mysql_string_types + CROSS JOIN mysql_datetime_types"; public class GetMysqlFunctionsRow { public int? MaxInt { get; set; } diff --git a/examples/NpgsqlDapperLegacyExample/QuerySql.cs b/examples/NpgsqlDapperLegacyExample/QuerySql.cs index 802aacec..b4a1fd1a 100644 --- a/examples/NpgsqlDapperLegacyExample/QuerySql.cs +++ b/examples/NpgsqlDapperLegacyExample/QuerySql.cs @@ -47,7 +47,7 @@ public static QuerySql WithTransaction(NpgsqlTransaction transaction) private string ConnectionString { get; } private const string GetAuthorSql = @"SELECT id, name, bio FROM authors - WHERE name = @name LIMIT 1"; + WHERE name = @name LIMIT 1"; public class GetAuthorRow { public long Id { get; set; } @@ -77,10 +77,10 @@ public async Task GetAuthor(GetAuthorArgs args) } private const string ListAuthorsSql = @"SELECT id, name, bio - FROM authors - ORDER BY name - LIMIT @limit - OFFSET @offset"; + FROM authors + ORDER BY name + LIMIT @limit + OFFSET @offset"; public class ListAuthorsRow { public long Id { get; set; } @@ -171,7 +171,7 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors - WHERE id = @id LIMIT 1"; + WHERE id = @id LIMIT 1"; public class GetAuthorByIdRow { public long Id { get; set; } @@ -201,7 +201,7 @@ public async Task GetAuthorById(GetAuthorByIdArgs args) } private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors - WHERE name LIKE COALESCE(@name_pattern, '%')"; + WHERE name LIKE COALESCE(@name_pattern, '%')"; public class GetAuthorByNamePatternRow { public long Id { get; set; } @@ -231,7 +231,7 @@ public async Task> GetAuthorByNamePattern(GetAut } private const string DeleteAuthorSql = @"DELETE FROM authors - WHERE name = @name"; + WHERE name = @name"; public class DeleteAuthorArgs { public string Name { get; set; } @@ -268,8 +268,8 @@ public async Task TruncateAuthors() } private const string UpdateAuthorsSql = @"UPDATE authors - SET bio = @bio - WHERE bio IS NOT NULL"; + SET bio = @bio + WHERE bio IS NOT NULL"; public class UpdateAuthorsArgs { public string Bio { get; set; } @@ -290,7 +290,7 @@ public async Task UpdateAuthors(UpdateAuthorsArgs args) } private const string GetAuthorsByIdsSql = @"SELECT id, name, bio FROM authors - WHERE id = ANY(@longArr_1::BIGINT [])"; + WHERE id = ANY(@longArr_1::BIGINT [])"; public class GetAuthorsByIdsRow { public long Id { get; set; } @@ -320,8 +320,8 @@ public async Task> GetAuthorsByIds(GetAuthorsByIdsArgs } private const string GetAuthorsByIdsAndNamesSql = @"SELECT id, name, bio - FROM authors - WHERE id = ANY(@longArr_1::BIGINT []) AND name = ANY(@stringArr_2::TEXT [])"; + FROM authors + WHERE id = ANY(@longArr_1::BIGINT []) AND name = ANY(@stringArr_2::TEXT [])"; public class GetAuthorsByIdsAndNamesRow { public long Id { get; set; } @@ -379,11 +379,11 @@ public async Task CreateBook(CreateBookArgs args) } private const string ListAllAuthorsBooksSql = @"SELECT - authors.id, authors.name, authors.bio, - books.id, books.name, books.author_id, books.description - FROM authors - INNER JOIN books ON authors.id = books.author_id - ORDER BY authors.name"; + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors + INNER JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public class ListAllAuthorsBooksRow { public Author Author { get; set; } @@ -425,11 +425,11 @@ public async Task> ListAllAuthorsBooks() } private const string GetDuplicateAuthorsSql = @"SELECT - authors1.id, authors1.name, authors1.bio, - authors2.id, authors2.name, authors2.bio - FROM authors AS authors1 - INNER JOIN authors AS authors2 ON authors1.name = authors2.name - WHERE authors1.id < authors2.id"; + authors1.id, authors1.name, authors1.bio, + authors2.id, authors2.name, authors2.bio + FROM authors AS authors1 + INNER JOIN authors AS authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public class GetDuplicateAuthorsRow { public Author Author { get; set; } @@ -471,10 +471,10 @@ public async Task> GetDuplicateAuthors() } private const string GetAuthorsByBookNameSql = @"SELECT - authors.id, authors.name, authors.bio, - books.id, books.name, books.author_id, books.description - FROM authors INNER JOIN books ON authors.id = books.author_id - WHERE books.name = @name"; + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public class GetAuthorsByBookNameRow { public long Id { get; set; } @@ -593,12 +593,12 @@ public async Task TruncateExtendedBios() } private const string GetPostgresFunctionsSql = @"SELECT - MAX(c_integer) AS max_integer, - MAX(c_varchar) AS max_varchar, - MAX(c_timestamp) AS max_timestamp - FROM postgres_datetime_types - CROSS JOIN postgres_numeric_types - CROSS JOIN postgres_string_types"; + MAX(c_integer) AS max_integer, + MAX(c_varchar) AS max_varchar, + MAX(c_timestamp) AS max_timestamp + FROM postgres_datetime_types + CROSS JOIN postgres_numeric_types + CROSS JOIN postgres_string_types"; public class GetPostgresFunctionsRow { public int? MaxInteger { get; set; } @@ -622,20 +622,20 @@ public async Task GetPostgresFunctions() } private const string InsertPostgresNumericTypesSql = @" - INSERT INTO postgres_numeric_types - ( - c_boolean, - c_bit, - c_smallint, - c_integer, - c_bigint, - c_decimal, - c_numeric, - c_real, - c_double_precision, - c_money - ) - VALUES (@c_boolean, @c_bit, @c_smallint, @c_integer, @c_bigint, @c_decimal, @c_numeric, @c_real, @c_double_precision, @c_money)"; + INSERT INTO postgres_numeric_types + ( + c_boolean, + c_bit, + c_smallint, + c_integer, + c_bigint, + c_decimal, + c_numeric, + c_real, + c_double_precision, + c_money + ) + VALUES (@c_boolean, @c_bit, @c_smallint, @c_integer, @c_bigint, @c_decimal, @c_numeric, @c_real, @c_double_precision, @c_money)"; public class InsertPostgresNumericTypesArgs { public bool? CBoolean { get; set; } @@ -720,30 +720,30 @@ public async Task TruncatePostgresNumericTypes() } private const string GetPostgresNumericTypesCntSql = @"SELECT - c_boolean, - c_bit, - c_smallint, - c_integer, - c_bigint, - c_decimal, - c_numeric, - c_real, - c_double_precision, - c_money, - COUNT(*) AS cnt - FROM postgres_numeric_types - GROUP BY - c_boolean, - c_bit, - c_smallint, - c_integer, - c_bigint, - c_decimal, - c_numeric, - c_real, - c_double_precision, - c_money - LIMIT 1"; + c_boolean, + c_bit, + c_smallint, + c_integer, + c_bigint, + c_decimal, + c_numeric, + c_real, + c_double_precision, + c_money, + COUNT(*) AS cnt + FROM postgres_numeric_types + GROUP BY + c_boolean, + c_bit, + c_smallint, + c_integer, + c_bigint, + c_decimal, + c_numeric, + c_real, + c_double_precision, + c_money + LIMIT 1"; public class GetPostgresNumericTypesCntRow { public bool? CBoolean { get; set; } @@ -818,15 +818,15 @@ public async Task InsertPostgresNumericTypesBatch(List GetPostgresStringTypesCnt() } private const string GetPostgresStringTypesTextSearchSql = @"WITH txt_query AS ( - SELECT - c_text, - to_tsquery('english', @to_tsquery) AS query, - to_tsvector('english', c_text) AS tsv - FROM postgres_string_types - WHERE c_text @@ to_tsquery('english', @to_tsquery) - ) - - SELECT txt_query.c_text, txt_query.query, txt_query.tsv, ts_rank(tsv, query) AS rnk - FROM txt_query - ORDER BY rnk DESC - LIMIT 1"; + SELECT + c_text, + to_tsquery('english', @to_tsquery) AS query, + to_tsvector('english', c_text) AS tsv + FROM postgres_string_types + WHERE c_text @@ to_tsquery('english', @to_tsquery) + ) + + SELECT txt_query.c_text, txt_query.query, txt_query.tsv, ts_rank(tsv, query) AS rnk + FROM txt_query + ORDER BY rnk DESC + LIMIT 1"; public class GetPostgresStringTypesTextSearchRow { public string CText { get; set; } @@ -1011,15 +1011,15 @@ public async Task GetPostgresStringTypesTex } private const string InsertPostgresDateTimeTypesSql = @" - INSERT INTO postgres_datetime_types - ( - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - c_timestamp_noda_instant_override - ) VALUES (@c_date, @c_time, @c_timestamp, @c_timestamp_with_tz, @c_interval, @c_timestamp_noda_instant_override)"; + INSERT INTO postgres_datetime_types + ( + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval, + c_timestamp_noda_instant_override + ) VALUES (@c_date, @c_time, @c_timestamp, @c_timestamp_with_tz, @c_interval, @c_timestamp_noda_instant_override)"; public class InsertPostgresDateTimeTypesArgs { public DateTime? CDate { get; set; } @@ -1092,20 +1092,20 @@ public async Task TruncatePostgresDateTimeTypes() } private const string GetPostgresDateTimeTypesCntSql = @"SELECT - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - COUNT(*) AS cnt - FROM postgres_datetime_types - GROUP BY - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval - LIMIT 1"; + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval, + COUNT(*) AS cnt + FROM postgres_datetime_types + GROUP BY + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval + LIMIT 1"; public class GetPostgresDateTimeTypesCntRow { public DateTime? CDate { get; set; } @@ -1165,18 +1165,18 @@ public async Task InsertPostgresDateTimeTypesBatch(List GetPostgresSpecialTypesCnt() } private const string InsertPostgresArrayTypesSql = @" - INSERT INTO postgres_array_types - ( - c_bytea, - c_boolean_array, - c_text_array, - c_integer_array, - c_decimal_array, - c_date_array, - c_timestamp_array - ) - VALUES (@c_bytea, @c_boolean_array, @c_text_array, @c_integer_array, @c_decimal_array, @c_date_array, @c_timestamp_array)"; + INSERT INTO postgres_array_types + ( + c_bytea, + c_boolean_array, + c_text_array, + c_integer_array, + c_decimal_array, + c_date_array, + c_timestamp_array + ) + VALUES (@c_bytea, @c_boolean_array, @c_text_array, @c_integer_array, @c_decimal_array, @c_date_array, @c_timestamp_array)"; public class InsertPostgresArrayTypesArgs { public byte[] CBytea { get; set; } @@ -1665,22 +1665,22 @@ public async Task InsertPostgresArrayTypesBatch(List GetAuthor(GetAuthorArgs args) } private const string ListAuthorsSql = @"SELECT id, name, bio - FROM authors - ORDER BY name - LIMIT @limit - OFFSET @offset"; + FROM authors + ORDER BY name + LIMIT @limit + OFFSET @offset"; public class ListAuthorsRow { public long Id { get; set; } @@ -269,7 +269,7 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors - WHERE id = @id LIMIT 1"; + WHERE id = @id LIMIT 1"; public class GetAuthorByIdRow { public long Id { get; set; } @@ -332,7 +332,7 @@ public async Task GetAuthorById(GetAuthorByIdArgs args) } private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors - WHERE name LIKE COALESCE(@name_pattern, '%')"; + WHERE name LIKE COALESCE(@name_pattern, '%')"; public class GetAuthorByNamePatternRow { public long Id { get; set; } @@ -381,7 +381,7 @@ public async Task> GetAuthorByNamePattern(GetAut } private const string DeleteAuthorSql = @"DELETE FROM authors - WHERE name = @name"; + WHERE name = @name"; public class DeleteAuthorArgs { public string Name { get; set; } @@ -440,8 +440,8 @@ public async Task TruncateAuthors() } private const string UpdateAuthorsSql = @"UPDATE authors - SET bio = @bio - WHERE bio IS NOT NULL"; + SET bio = @bio + WHERE bio IS NOT NULL"; public class UpdateAuthorsArgs { public string Bio { get; set; } @@ -472,7 +472,7 @@ public async Task UpdateAuthors(UpdateAuthorsArgs args) } private const string GetAuthorsByIdsSql = @"SELECT id, name, bio FROM authors - WHERE id = ANY(@longArr_1::BIGINT [])"; + WHERE id = ANY(@longArr_1::BIGINT [])"; public class GetAuthorsByIdsRow { public long Id { get; set; } @@ -521,8 +521,8 @@ public async Task> GetAuthorsByIds(GetAuthorsByIdsArgs } private const string GetAuthorsByIdsAndNamesSql = @"SELECT id, name, bio - FROM authors - WHERE id = ANY(@longArr_1::BIGINT []) AND name = ANY(@stringArr_2::TEXT [])"; + FROM authors + WHERE id = ANY(@longArr_1::BIGINT []) AND name = ANY(@stringArr_2::TEXT [])"; public class GetAuthorsByIdsAndNamesRow { public long Id { get; set; } @@ -613,11 +613,11 @@ public async Task CreateBook(CreateBookArgs args) } private const string ListAllAuthorsBooksSql = @"SELECT - authors.id, authors.name, authors.bio, - books.id, books.name, books.author_id, books.description - FROM authors - INNER JOIN books ON authors.id = books.author_id - ORDER BY authors.name"; + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors + INNER JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public class ListAllAuthorsBooksRow { public Author Author { get; set; } @@ -659,11 +659,11 @@ public async Task> ListAllAuthorsBooks() } private const string GetDuplicateAuthorsSql = @"SELECT - authors1.id, authors1.name, authors1.bio, - authors2.id, authors2.name, authors2.bio - FROM authors AS authors1 - INNER JOIN authors AS authors2 ON authors1.name = authors2.name - WHERE authors1.id < authors2.id"; + authors1.id, authors1.name, authors1.bio, + authors2.id, authors2.name, authors2.bio + FROM authors AS authors1 + INNER JOIN authors AS authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public class GetDuplicateAuthorsRow { public Author Author { get; set; } @@ -705,10 +705,10 @@ public async Task> GetDuplicateAuthors() } private const string GetAuthorsByBookNameSql = @"SELECT - authors.id, authors.name, authors.bio, - books.id, books.name, books.author_id, books.description - FROM authors INNER JOIN books ON authors.id = books.author_id - WHERE books.name = @name"; + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public class GetAuthorsByBookNameRow { public long Id { get; set; } @@ -884,12 +884,12 @@ public async Task TruncateExtendedBios() } private const string GetPostgresFunctionsSql = @"SELECT - MAX(c_integer) AS max_integer, - MAX(c_varchar) AS max_varchar, - MAX(c_timestamp) AS max_timestamp - FROM postgres_datetime_types - CROSS JOIN postgres_numeric_types - CROSS JOIN postgres_string_types"; + MAX(c_integer) AS max_integer, + MAX(c_varchar) AS max_varchar, + MAX(c_timestamp) AS max_timestamp + FROM postgres_datetime_types + CROSS JOIN postgres_numeric_types + CROSS JOIN postgres_string_types"; public class GetPostgresFunctionsRow { public int? MaxInteger { get; set; } @@ -946,20 +946,20 @@ public async Task GetPostgresFunctions() } private const string InsertPostgresNumericTypesSql = @" - INSERT INTO postgres_numeric_types - ( - c_boolean, - c_bit, - c_smallint, - c_integer, - c_bigint, - c_decimal, - c_numeric, - c_real, - c_double_precision, - c_money - ) - VALUES (@c_boolean, @c_bit, @c_smallint, @c_integer, @c_bigint, @c_decimal, @c_numeric, @c_real, @c_double_precision, @c_money)"; + INSERT INTO postgres_numeric_types + ( + c_boolean, + c_bit, + c_smallint, + c_integer, + c_bigint, + c_decimal, + c_numeric, + c_real, + c_double_precision, + c_money + ) + VALUES (@c_boolean, @c_bit, @c_smallint, @c_integer, @c_bigint, @c_decimal, @c_numeric, @c_real, @c_double_precision, @c_money)"; public class InsertPostgresNumericTypesArgs { public bool? CBoolean { get; set; } @@ -1122,30 +1122,30 @@ public async Task TruncatePostgresNumericTypes() } private const string GetPostgresNumericTypesCntSql = @"SELECT - c_boolean, - c_bit, - c_smallint, - c_integer, - c_bigint, - c_decimal, - c_numeric, - c_real, - c_double_precision, - c_money, - COUNT(*) AS cnt - FROM postgres_numeric_types - GROUP BY - c_boolean, - c_bit, - c_smallint, - c_integer, - c_bigint, - c_decimal, - c_numeric, - c_real, - c_double_precision, - c_money - LIMIT 1"; + c_boolean, + c_bit, + c_smallint, + c_integer, + c_bigint, + c_decimal, + c_numeric, + c_real, + c_double_precision, + c_money, + COUNT(*) AS cnt + FROM postgres_numeric_types + GROUP BY + c_boolean, + c_bit, + c_smallint, + c_integer, + c_bigint, + c_decimal, + c_numeric, + c_real, + c_double_precision, + c_money + LIMIT 1"; public class GetPostgresNumericTypesCntRow { public bool? CBoolean { get; set; } @@ -1269,15 +1269,15 @@ public async Task InsertPostgresNumericTypesBatch(List GetPostgresStringTypesCnt() } private const string GetPostgresStringTypesTextSearchSql = @"WITH txt_query AS ( - SELECT - c_text, - to_tsquery('english', @to_tsquery) AS query, - to_tsvector('english', c_text) AS tsv - FROM postgres_string_types - WHERE c_text @@ to_tsquery('english', @to_tsquery) - ) - - SELECT txt_query.c_text, txt_query.query, txt_query.tsv, ts_rank(tsv, query) AS rnk - FROM txt_query - ORDER BY rnk DESC - LIMIT 1"; + SELECT + c_text, + to_tsquery('english', @to_tsquery) AS query, + to_tsvector('english', c_text) AS tsv + FROM postgres_string_types + WHERE c_text @@ to_tsquery('english', @to_tsquery) + ) + + SELECT txt_query.c_text, txt_query.query, txt_query.tsv, ts_rank(tsv, query) AS rnk + FROM txt_query + ORDER BY rnk DESC + LIMIT 1"; public class GetPostgresStringTypesTextSearchRow { public string CText { get; set; } @@ -1599,15 +1599,15 @@ public async Task GetPostgresStringTypesTex } private const string InsertPostgresDateTimeTypesSql = @" - INSERT INTO postgres_datetime_types - ( - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - c_timestamp_noda_instant_override - ) VALUES (@c_date, @c_time, @c_timestamp, @c_timestamp_with_tz, @c_interval, @c_timestamp_noda_instant_override)"; + INSERT INTO postgres_datetime_types + ( + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval, + c_timestamp_noda_instant_override + ) VALUES (@c_date, @c_time, @c_timestamp, @c_timestamp_with_tz, @c_interval, @c_timestamp_noda_instant_override)"; public class InsertPostgresDateTimeTypesArgs { public DateTime? CDate { get; set; } @@ -1758,20 +1758,20 @@ public async Task TruncatePostgresDateTimeTypes() } private const string GetPostgresDateTimeTypesCntSql = @"SELECT - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - COUNT(*) AS cnt - FROM postgres_datetime_types - GROUP BY - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval - LIMIT 1"; + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval, + COUNT(*) AS cnt + FROM postgres_datetime_types + GROUP BY + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval + LIMIT 1"; public class GetPostgresDateTimeTypesCntRow { public DateTime? CDate { get; set; } @@ -1870,18 +1870,18 @@ public async Task InsertPostgresDateTimeTypesBatch(List GetPostgresSpecialTypesCnt() } private const string InsertPostgresArrayTypesSql = @" - INSERT INTO postgres_array_types - ( - c_bytea, - c_boolean_array, - c_text_array, - c_integer_array, - c_decimal_array, - c_date_array, - c_timestamp_array - ) - VALUES (@c_bytea, @c_boolean_array, @c_text_array, @c_integer_array, @c_decimal_array, @c_date_array, @c_timestamp_array)"; + INSERT INTO postgres_array_types + ( + c_bytea, + c_boolean_array, + c_text_array, + c_integer_array, + c_decimal_array, + c_date_array, + c_timestamp_array + ) + VALUES (@c_bytea, @c_boolean_array, @c_text_array, @c_integer_array, @c_decimal_array, @c_date_array, @c_timestamp_array)"; public class InsertPostgresArrayTypesArgs { public byte[] CBytea { get; set; } @@ -2691,22 +2691,22 @@ public async Task InsertPostgresArrayTypesBatch(List GetAuthor(GetAuthorArgs args) } private const string ListAuthorsSql = @"SELECT id, name, bio - FROM authors - ORDER BY name - LIMIT @limit OFFSET @offset"; + FROM authors + ORDER BY name + LIMIT @limit OFFSET @offset"; public class ListAuthorsRow { public int Id { get; set; } @@ -157,7 +157,7 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors -- test rest of line comment - WHERE id = @id LIMIT 1"; + WHERE id = @id LIMIT 1"; public class GetAuthorByIdRow { public int Id { get; set; } @@ -218,7 +218,7 @@ public async Task GetAuthorByIdWithMulti } private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors - WHERE name LIKE COALESCE(@name_pattern, '%')"; + WHERE name LIKE COALESCE(@name_pattern, '%')"; public class GetAuthorByNamePatternRow { public int Id { get; set; } @@ -248,8 +248,8 @@ public async Task> GetAuthorByNamePattern(GetAut } private const string UpdateAuthorsSql = @"UPDATE authors - SET bio = @bio - WHERE bio IS NOT NULL"; + SET bio = @bio + WHERE bio IS NOT NULL"; public class UpdateAuthorsArgs { public string Bio { get; set; } @@ -338,7 +338,7 @@ public async Task> GetAuthorsByIdsAndNames(GetA } private const string DeleteAuthorSql = @"DELETE FROM authors - WHERE name = @name"; + WHERE name = @name"; public class DeleteAuthorArgs { public string Name { get; set; } @@ -386,10 +386,10 @@ public async Task CreateBook(CreateBookArgs args) } private const string ListAllAuthorsBooksSql = @"SELECT - authors.id, authors.name, authors.bio, - books.id, books.name, books.author_id, books.description - FROM authors INNER JOIN books ON authors.id = books.author_id - ORDER BY authors.name"; + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public class ListAllAuthorsBooksRow { public Author Author { get; set; } @@ -432,11 +432,11 @@ public async Task> ListAllAuthorsBooks() } private const string GetDuplicateAuthorsSql = @"SELECT - authors1.id, authors1.name, authors1.bio, - authors2.id, authors2.name, authors2.bio - FROM authors AS authors1 - INNER JOIN authors AS authors2 ON authors1.name = authors2.name - WHERE authors1.id < authors2.id"; + authors1.id, authors1.name, authors1.bio, + authors2.id, authors2.name, authors2.bio + FROM authors AS authors1 + INNER JOIN authors AS authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public class GetDuplicateAuthorsRow { public Author Author { get; set; } @@ -479,10 +479,10 @@ public async Task> GetDuplicateAuthors() } private const string GetAuthorsByBookNameSql = @"SELECT - authors.id, authors.name, authors.bio, - books.id, books.name, books.author_id, books.description - FROM authors INNER JOIN books ON authors.id = books.author_id - WHERE books.name = @name"; + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public class GetAuthorsByBookNameRow { public int Id { get; set; } @@ -548,19 +548,19 @@ public async Task DeleteAllAuthors() } private const string InsertSqliteTypesSql = @"INSERT INTO types_sqlite - ( - c_integer, - c_real, - c_text, - c_blob, - c_text_datetime_override, - c_integer_datetime_override, - c_text_noda_instant_override, - c_integer_noda_instant_override, - c_text_bool_override, - c_integer_bool_override - ) - VALUES (@c_integer, @c_real, @c_text, @c_blob, @c_text_datetime_override, @c_integer_datetime_override, @c_text_noda_instant_override, @c_integer_noda_instant_override, @c_text_bool_override, @c_integer_bool_override)"; + ( + c_integer, + c_real, + c_text, + c_blob, + c_text_datetime_override, + c_integer_datetime_override, + c_text_noda_instant_override, + c_integer_noda_instant_override, + c_text_bool_override, + c_integer_bool_override + ) + VALUES (@c_integer, @c_real, @c_text, @c_blob, @c_text_datetime_override, @c_integer_datetime_override, @c_text_noda_instant_override, @c_integer_noda_instant_override, @c_text_bool_override, @c_integer_bool_override)"; public class InsertSqliteTypesArgs { public int? CInteger { get; set; } @@ -627,18 +627,18 @@ public async Task InsertSqliteTypesBatch(List args) } private const string GetSqliteTypesSql = @"SELECT - c_integer, - c_real, - c_text, - c_blob, - c_text_datetime_override, - c_integer_datetime_override, - c_text_noda_instant_override, - c_integer_noda_instant_override, - c_text_bool_override, - c_integer_bool_override - FROM types_sqlite - LIMIT 1"; + c_integer, + c_real, + c_text, + c_blob, + c_text_datetime_override, + c_integer_datetime_override, + c_text_noda_instant_override, + c_integer_noda_instant_override, + c_text_bool_override, + c_integer_bool_override + FROM types_sqlite + LIMIT 1"; public class GetSqliteTypesRow { public int? CInteger { get; set; } @@ -669,14 +669,14 @@ public async Task GetSqliteTypes() } private const string GetSqliteTypesCntSql = @"SELECT - c_integer, - c_real, - c_text, - c_blob, - count(*) AS cnt - FROM types_sqlite - GROUP BY c_integer, c_real, c_text, c_blob - LIMIT 1"; + c_integer, + c_real, + c_text, + c_blob, + count(*) AS cnt + FROM types_sqlite + GROUP BY c_integer, c_real, c_text, c_blob + LIMIT 1"; public class GetSqliteTypesCntRow { public int? CInteger { get; set; } @@ -702,10 +702,10 @@ public async Task GetSqliteTypesCnt() } private const string GetSqliteFunctionsSql = @"SELECT - max(c_integer) AS max_integer, - max(c_real) AS max_real, - max(c_text) AS max_text - FROM types_sqlite"; + max(c_integer) AS max_integer, + max(c_real) AS max_real, + max(c_text) AS max_text + FROM types_sqlite"; public class GetSqliteFunctionsRow { public int? MaxInteger { get; set; } diff --git a/examples/SqliteLegacyExample/QuerySql.cs b/examples/SqliteLegacyExample/QuerySql.cs index 54deb8f2..844da110 100644 --- a/examples/SqliteLegacyExample/QuerySql.cs +++ b/examples/SqliteLegacyExample/QuerySql.cs @@ -39,7 +39,7 @@ public static QuerySql WithTransaction(SqliteTransaction transaction) private string ConnectionString { get; } private const string GetAuthorSql = @"SELECT id, name, bio FROM authors - WHERE name = @name LIMIT 1"; + WHERE name = @name LIMIT 1"; public class GetAuthorRow { public int Id { get; set; } @@ -103,9 +103,9 @@ public async Task GetAuthor(GetAuthorArgs args) } private const string ListAuthorsSql = @"SELECT id, name, bio - FROM authors - ORDER BY name - LIMIT @limit OFFSET @offset"; + FROM authors + ORDER BY name + LIMIT @limit OFFSET @offset"; public class ListAuthorsRow { public int Id { get; set; } @@ -237,7 +237,7 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } private const string GetAuthorByIdSql = @"SELECT id, name, bio FROM authors -- test rest of line comment - WHERE id = @id LIMIT 1"; + WHERE id = @id LIMIT 1"; public class GetAuthorByIdRow { public int Id { get; set; } @@ -367,7 +367,7 @@ public async Task GetAuthorByIdWithMulti } private const string GetAuthorByNamePatternSql = @"SELECT id, name, bio FROM authors - WHERE name LIKE COALESCE(@name_pattern, '%')"; + WHERE name LIKE COALESCE(@name_pattern, '%')"; public class GetAuthorByNamePatternRow { public int Id { get; set; } @@ -417,8 +417,8 @@ public async Task> GetAuthorByNamePattern(GetAut } private const string UpdateAuthorsSql = @"UPDATE authors - SET bio = @bio - WHERE bio IS NOT NULL"; + SET bio = @bio + WHERE bio IS NOT NULL"; public class UpdateAuthorsArgs { public string Bio { get; set; } @@ -562,7 +562,7 @@ public async Task> GetAuthorsByIdsAndNames(GetA } private const string DeleteAuthorSql = @"DELETE FROM authors - WHERE name = @name"; + WHERE name = @name"; public class DeleteAuthorArgs { public string Name { get; set; } @@ -636,10 +636,10 @@ public async Task CreateBook(CreateBookArgs args) } private const string ListAllAuthorsBooksSql = @"SELECT - authors.id, authors.name, authors.bio, - books.id, books.name, books.author_id, books.description - FROM authors INNER JOIN books ON authors.id = books.author_id - ORDER BY authors.name"; + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + ORDER BY authors.name"; public class ListAllAuthorsBooksRow { public Author Author { get; set; } @@ -682,11 +682,11 @@ public async Task> ListAllAuthorsBooks() } private const string GetDuplicateAuthorsSql = @"SELECT - authors1.id, authors1.name, authors1.bio, - authors2.id, authors2.name, authors2.bio - FROM authors AS authors1 - INNER JOIN authors AS authors2 ON authors1.name = authors2.name - WHERE authors1.id < authors2.id"; + authors1.id, authors1.name, authors1.bio, + authors2.id, authors2.name, authors2.bio + FROM authors AS authors1 + INNER JOIN authors AS authors2 ON authors1.name = authors2.name + WHERE authors1.id < authors2.id"; public class GetDuplicateAuthorsRow { public Author Author { get; set; } @@ -729,10 +729,10 @@ public async Task> GetDuplicateAuthors() } private const string GetAuthorsByBookNameSql = @"SELECT - authors.id, authors.name, authors.bio, - books.id, books.name, books.author_id, books.description - FROM authors INNER JOIN books ON authors.id = books.author_id - WHERE books.name = @name"; + authors.id, authors.name, authors.bio, + books.id, books.name, books.author_id, books.description + FROM authors INNER JOIN books ON authors.id = books.author_id + WHERE books.name = @name"; public class GetAuthorsByBookNameRow { public int Id { get; set; } @@ -810,19 +810,19 @@ public async Task DeleteAllAuthors() } private const string InsertSqliteTypesSql = @"INSERT INTO types_sqlite - ( - c_integer, - c_real, - c_text, - c_blob, - c_text_datetime_override, - c_integer_datetime_override, - c_text_noda_instant_override, - c_integer_noda_instant_override, - c_text_bool_override, - c_integer_bool_override - ) - VALUES (@c_integer, @c_real, @c_text, @c_blob, @c_text_datetime_override, @c_integer_datetime_override, @c_text_noda_instant_override, @c_integer_noda_instant_override, @c_text_bool_override, @c_integer_bool_override)"; + ( + c_integer, + c_real, + c_text, + c_blob, + c_text_datetime_override, + c_integer_datetime_override, + c_text_noda_instant_override, + c_integer_noda_instant_override, + c_text_bool_override, + c_integer_bool_override + ) + VALUES (@c_integer, @c_real, @c_text, @c_blob, @c_text_datetime_override, @c_integer_datetime_override, @c_text_noda_instant_override, @c_integer_noda_instant_override, @c_text_bool_override, @c_integer_bool_override)"; public class InsertSqliteTypesArgs { public int? CInteger { get; set; } @@ -910,18 +910,18 @@ public async Task InsertSqliteTypesBatch(List args) } private const string GetSqliteTypesSql = @"SELECT - c_integer, - c_real, - c_text, - c_blob, - c_text_datetime_override, - c_integer_datetime_override, - c_text_noda_instant_override, - c_integer_noda_instant_override, - c_text_bool_override, - c_integer_bool_override - FROM types_sqlite - LIMIT 1"; + c_integer, + c_real, + c_text, + c_blob, + c_text_datetime_override, + c_integer_datetime_override, + c_text_noda_instant_override, + c_integer_noda_instant_override, + c_text_bool_override, + c_integer_bool_override + FROM types_sqlite + LIMIT 1"; public class GetSqliteTypesRow { public int? CInteger { get; set; } @@ -1000,14 +1000,14 @@ public async Task GetSqliteTypes() } private const string GetSqliteTypesCntSql = @"SELECT - c_integer, - c_real, - c_text, - c_blob, - count(*) AS cnt - FROM types_sqlite - GROUP BY c_integer, c_real, c_text, c_blob - LIMIT 1"; + c_integer, + c_real, + c_text, + c_blob, + count(*) AS cnt + FROM types_sqlite + GROUP BY c_integer, c_real, c_text, c_blob + LIMIT 1"; public class GetSqliteTypesCntRow { public int? CInteger { get; set; } @@ -1071,10 +1071,10 @@ public async Task GetSqliteTypesCnt() } private const string GetSqliteFunctionsSql = @"SELECT - max(c_integer) AS max_integer, - max(c_real) AS max_real, - max(c_text) AS max_text - FROM types_sqlite"; + max(c_integer) AS max_integer, + max(c_real) AS max_real, + max(c_text) AS max_text + FROM types_sqlite"; public class GetSqliteFunctionsRow { public int? MaxInteger { get; set; } From c746c915f4ff601690e1d10a35917a3c57f4648a Mon Sep 17 00:00:00 2001 From: Doron Eli Rachman Date: Sat, 15 Nov 2025 12:31:02 +0200 Subject: [PATCH 6/7] regenerate --- .../QuickStartSqliteDalGen/request.message | Bin 5144 -> 5180 bytes examples/SqliteDapperExample/request.message | Bin 10881 -> 10917 bytes .../SqliteDapperLegacyExample/request.message | Bin 10915 -> 10951 bytes examples/SqliteExample/request.message | Bin 10865 -> 10901 bytes examples/SqliteLegacyExample/request.message | Bin 10899 -> 10935 bytes 5 files changed, 0 insertions(+), 0 deletions(-) diff --git a/examples/QuickStartSqliteDalGen/request.message b/examples/QuickStartSqliteDalGen/request.message index 6ed92dd055b412bba19b66852e865637a668b729..6601628171580d2740ee742c04e1d73d98d714de 100644 GIT binary patch delta 51 zcmbQCu}5P=vM}TI$tl8{Rdtj~i&LFb^Gb>ma{>~RvlG)(eG~J5WG+xl$to=|r#Q71 E0Qu(=b^rhX delta 15 Wcmdm^F+*cRvM}T3$tl8{8EXMBD+Rg$ diff --git a/examples/SqliteDapperExample/request.message b/examples/SqliteDapperExample/request.message index 39cdfc0dfbb41ed51c104a9b214f80ef476b9041..0502bc91e560bf0aac275f8771afd1a0faf98b33 100644 GIT binary patch delta 53 zcmZn+T^hP!f*R9gj?I(Q-Z87{D3uncI;ZB96eZ>aBqnDkrlex;S*h5;dm3?38ZYnc|bB3D5hkUmY7qV GS_=R){}hD) delta 17 YcmbOl`Y~ifs~XcQ_RZ~TFPRx@0Z2**NB{r; diff --git a/examples/SqliteLegacyExample/request.message b/examples/SqliteLegacyExample/request.message index 3942d1b038acb1773ee0d73593fc1a3132b8472f..efdd72410e1efd37b013ac250d7341c7613b2d65 100644 GIT binary patch delta 53 zcmbOnx;=EmOf{xC9GhpWeP>qHQ7SD?bxzGIDN4) Date: Sat, 15 Nov 2025 12:41:39 +0200 Subject: [PATCH 7/7] fix lint --- CodeGenerator/Generators/QueriesGen.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CodeGenerator/Generators/QueriesGen.cs b/CodeGenerator/Generators/QueriesGen.cs index f30b9afd..68464168 100644 --- a/CodeGenerator/Generators/QueriesGen.cs +++ b/CodeGenerator/Generators/QueriesGen.cs @@ -142,7 +142,7 @@ private IEnumerable GetMembersForSingleQuery(Query quer { var queryText = transformedQueryText.Replace("\"", "\"\""); var lines = queryText.TrimEnd().Split(["\r\n", "\r", "\n"], StringSplitOptions.None); - + // The indentation of the constant declaration itself. for legacy generation it 8 indents and for modern it 4. string memberIndentPrefix = dbDriver.Options.DotnetFramework.IsDotnetLegacy() ? " " : " "; var declaration = $"private const string {memberName} = @\""; @@ -153,7 +153,7 @@ private IEnumerable GetMembersForSingleQuery(Query quer var subsequentLineIndent = new string(' ', memberIndentPrefix.Length + declaration.Length + firstLineLeadingSpaceCount); var indentedLines = lines.Skip(1).Select(line => subsequentLineIndent + line); - var fullQueryString = string.Join(Environment.NewLine, [lines[0], ..indentedLines]); + var fullQueryString = string.Join(Environment.NewLine, [lines[0], .. indentedLines]); return ParseMemberDeclaration( $"{memberIndentPrefix}{declaration}{fullQueryString}\";")!;