diff --git a/CodeGenerator/Generators/QueriesGen.cs b/CodeGenerator/Generators/QueriesGen.cs index 35988432..68464168 100644 --- a/CodeGenerator/Generators/QueriesGen.cs +++ b/CodeGenerator/Generators/QueriesGen.cs @@ -137,11 +137,31 @@ private IEnumerable GetMembersForSingleQuery(Query quer if (transformedQueryText == string.Empty) return null; + var memberName = ClassMember.Sql.Name(query.Name); + if (transformedQueryText.IndexOfAny(['\r', '\n']) >= 0) + { + 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( + $"{memberIndentPrefix}{declaration}{fullQueryString}\";")!; + } + var singleLineQueryText = LongWhitespaceRegex().Replace(transformedQueryText, " "); 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..06527794 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..775f5884 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..4323634b 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..8577870d 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 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); 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 46252dc6..b349a1ff 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 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 75db6705..66016281 100644 Binary files a/examples/QuickStartSqliteDalGen/request.message and b/examples/QuickStartSqliteDalGen/request.message differ diff --git a/examples/SqliteDapperExample/QuerySql.cs b/examples/SqliteDapperExample/QuerySql.cs index 087befc5..df85f28b 100644 --- a/examples/SqliteDapperExample/QuerySql.cs +++ b/examples/SqliteDapperExample/QuerySql.cs @@ -40,7 +40,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 required int Id { get; init; } @@ -69,7 +70,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 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 rest of line 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 c69f67f4..597f4c15 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 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 64d13cb0..0502bc91 100644 Binary files a/examples/SqliteDapperExample/request.message and b/examples/SqliteDapperExample/request.message differ diff --git a/examples/SqliteDapperLegacyExample/QuerySql.cs b/examples/SqliteDapperLegacyExample/QuerySql.cs index e754db3c..c3570d44 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 rest of line 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 1e0d6561..4a08cf29 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 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 6aea0a22..7ec8b832 100644 Binary files a/examples/SqliteDapperLegacyExample/request.message and b/examples/SqliteDapperLegacyExample/request.message differ diff --git a/examples/SqliteExample/QuerySql.cs b/examples/SqliteExample/QuerySql.cs index 91559ed0..28dae146 100644 --- a/examples/SqliteExample/QuerySql.cs +++ b/examples/SqliteExample/QuerySql.cs @@ -37,7 +37,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) @@ -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 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); 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 f033a8e1..0ab004eb 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 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 04c9dda8..d7fca134 100644 Binary files a/examples/SqliteExample/request.message and b/examples/SqliteExample/request.message differ diff --git a/examples/SqliteLegacyExample/QuerySql.cs b/examples/SqliteLegacyExample/QuerySql.cs index 628160f0..844da110 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 rest of line 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 8b3c33ea..5649bf25 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 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 fa44c3f3..efdd7241 100644 Binary files a/examples/SqliteLegacyExample/request.message and b/examples/SqliteLegacyExample/request.message differ diff --git a/examples/config/sqlite/authors/query.sql b/examples/config/sqlite/authors/query.sql index 19b241ae..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 +SELECT * FROM authors -- test rest of line comment WHERE id = ? LIMIT 1; -- name: GetAuthorByIdWithMultipleNamedParam :one