diff --git a/.github/workflows/legacy-tests.yml b/.github/workflows/legacy-tests.yml index d0a573f4..132ee38c 100644 --- a/.github/workflows/legacy-tests.yml +++ b/.github/workflows/legacy-tests.yml @@ -51,7 +51,7 @@ jobs: - name: Init PostgresSQL Schema shell: powershell - run: psql -U $Env:POSTGRES_USER -f 'examples/config/postgresql/schema.sql' + run: psql -U $Env:POSTGRES_USER -f 'examples/config/postgresql/types/schema.sql' -f 'examples/config/postgresql/authors/schema.sql' env: PGSERVICE: ${{ steps.postgres.outputs.service-name }} PGPASSWORD: ${{ env.POSTGRES_PASSWORD }} @@ -101,7 +101,7 @@ jobs: $env:Path += ";C:\Program Files\MySQL\MySQL Server 8.0\bin" [Environment]::SetEnvironmentVariable("Path", $env:Path, "Machine") mysql -u root -e "SET GLOBAL local_infile=1; CREATE DATABASE $Env:TESTS_DB;" - mysql -u root $Env:TESTS_DB --execute="source examples/config/mysql/schema.sql" + mysql -u root $Env:TESTS_DB --execute="source examples/config/mysql/types/schema.sql; source examples/config/mysql/authors/schema.sql;" - name: Run Tests shell: powershell diff --git a/CodeGenerator/CodeGenerator.cs b/CodeGenerator/CodeGenerator.cs index 6c74c030..d9b8c664 100644 --- a/CodeGenerator/CodeGenerator.cs +++ b/CodeGenerator/CodeGenerator.cs @@ -9,21 +9,13 @@ using System.Text; using System.Text.Json; using System.Threading.Tasks; -using Enum = Plugin.Enum; namespace SqlcGenCsharp; public class CodeGenerator { - private readonly HashSet _excludedSchemas = - [ - "pg_catalog", - "information_schema" - ]; - private Options? _options; - private Dictionary>? _tables; - private Dictionary>? _enums; + private Catalog? _catalog; private List? _queries; private DbDriver? _dbDriver; private QueriesGen? _queriesGen; @@ -37,16 +29,10 @@ private Options Options set => _options = value; } - private Dictionary> Tables + private Catalog Catalog { - get => _tables!; - set => _tables = value; - } - - private Dictionary> Enums - { - get => _enums!; - set => _enums = value; + get => _catalog!; + set => _catalog = value; } private List Queries @@ -89,79 +75,29 @@ private void InitGenerators(GenerateRequest generateRequest) { var outputDirectory = generateRequest.Settings.Codegen.Out; var projectName = new DirectoryInfo(outputDirectory).Name; - Options = new Options(generateRequest); + Options = new(generateRequest); if (Options.DebugRequest) return; Queries = generateRequest.Queries.ToList(); - Tables = ConstructTablesLookup(generateRequest.Catalog); - Enums = ConstructEnumsLookup(generateRequest.Catalog); - var namespaceName = Options.NamespaceName == string.Empty ? projectName : Options.NamespaceName; - DbDriver = InstantiateDriver(generateRequest.Catalog.DefaultSchema); + Catalog = generateRequest.Catalog; + DbDriver = InstantiateDriver(); // initialize file generators - CsprojGen = new CsprojGen(outputDirectory, projectName, namespaceName, Options); - QueriesGen = new QueriesGen(DbDriver, namespaceName); - ModelsGen = new ModelsGen(DbDriver, namespaceName); - UtilsGen = new UtilsGen(DbDriver, namespaceName); - } - - private Dictionary> ConstructTablesLookup(Catalog catalog) - { - return catalog.Schemas - .Where(s => !_excludedSchemas.Contains(s.Name)) - .ToDictionary( - s => s.Name == catalog.DefaultSchema ? string.Empty : s.Name, - s => s.Tables.ToDictionary(t => t.Rel.Name, t => t)); - } - - /// - /// Enums in the request exist only in the default schema (in mysql), this remaps enums to their original schema. - /// - /// - /// - private Dictionary> ConstructEnumsLookup(Catalog catalog) - { - var defaultSchemaCatalog = catalog.Schemas.First(s => s.Name == catalog.DefaultSchema); - var schemaEnumTuples = defaultSchemaCatalog.Enums - .Select(e => new - { - EnumItem = e, - Schema = FindEnumSchema(e) - }); - var schemaToEnums = schemaEnumTuples - .GroupBy(x => x.Schema) - .ToDictionary( - group => group.Key, - group => group.ToDictionary( - x => x.EnumItem.Name, - x => x.EnumItem) - ); - return schemaToEnums; - } - - private string FindEnumSchema(Enum e) - { - foreach (var schemaTables in Tables) - { - foreach (var table in schemaTables.Value) - { - var isEnumColumn = table.Value.Columns.Any(c => c.Type.Name == e.Name); - if (isEnumColumn) - return schemaTables.Key; - } - } - throw new InvalidDataException($"No enum {e.Name} schema found."); + CsprojGen = new(outputDirectory, projectName, namespaceName, Options); + QueriesGen = new(DbDriver, namespaceName); + ModelsGen = new(DbDriver, namespaceName); + UtilsGen = new(DbDriver, namespaceName); } - private DbDriver InstantiateDriver(string defaultSchema) + private DbDriver InstantiateDriver() { return Options.DriverName switch { - DriverName.MySqlConnector => new MySqlConnectorDriver(Options, defaultSchema, Tables, Enums, Queries), - DriverName.Npgsql => new NpgsqlDriver(Options, defaultSchema, Tables, Enums, Queries), - DriverName.Sqlite => new SqliteDriver(Options, defaultSchema, Tables, Enums, Queries), + DriverName.MySqlConnector => new MySqlConnectorDriver(Options, Catalog, Queries), + DriverName.Npgsql => new NpgsqlDriver(Options, Catalog, Queries), + DriverName.Sqlite => new SqliteDriver(Options, Catalog, Queries), _ => throw new ArgumentException($"unknown driver: {Options.DriverName}") }; } @@ -182,7 +118,7 @@ public Task Generate(GenerateRequest generateRequest) var files = GetFileQueries() .Select(fq => QueriesGen.GenerateFile(fq.Value, fq.Key)) .AddRangeExcludeNulls([ - ModelsGen.GenerateFile(Tables, Enums), + ModelsGen.GenerateFile(DbDriver.Tables, DbDriver.Enums), UtilsGen.GenerateFile() ]) .AddRangeIf([CsprojGen.GenerateFile()], Options.GenerateCsproj); @@ -218,12 +154,12 @@ private static Plugin.File RequestToJsonFile(GenerateRequest request) { var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithIndentation()); request.PluginOptions = GetOptionsWithoutDebugRequest(request); - return new Plugin.File { Name = "request.json", Contents = ByteString.CopyFromUtf8(formatter.Format(request)) }; + return new() { Name = "request.json", Contents = ByteString.CopyFromUtf8(formatter.Format(request)) }; } private static Plugin.File RequestToProtobufFile(GenerateRequest request) { request.PluginOptions = GetOptionsWithoutDebugRequest(request); - return new Plugin.File { Name = "request.message", Contents = request.ToByteString() }; + return new() { Name = "request.message", Contents = request.ToByteString() }; } } \ No newline at end of file diff --git a/CodeGenerator/Generators/EnumsGen.cs b/CodeGenerator/Generators/EnumsGen.cs index f4649b85..3e06aa32 100644 --- a/CodeGenerator/Generators/EnumsGen.cs +++ b/CodeGenerator/Generators/EnumsGen.cs @@ -31,15 +31,28 @@ public static class {{name}}Extensions .Select(v => $"[\"{v}\"] = {name}.{v.ToPascalCase()}") .JoinByComma()}} }; + + private static readonly Dictionary<{{name}}, string> EnumToString = new Dictionary<{{name}}, string>() + { + [{{name}}.Invalid] = string.Empty, + {{possibleValues + .Select(v => $"[{name}.{v.ToPascalCase()}] = \"{v}\"") + .JoinByComma()}} + }; public static {{name}} To{{name}}(this string me) { return StringToEnum[me]; } - public static {{name}}[] To{{name}}Arr(this string me) + public static string Stringify(this {{name}} me) + { + return EnumToString[me]; + } + + public static HashSet<{{name}}> To{{name}}Set(this string me) { - return me.Split(',').ToList().Select(v => StringToEnum[v]).ToArray(); + return new HashSet<{{name}}>(me.Split(',').ToList().Select(v => StringToEnum[v])); } } """)!; diff --git a/CodeGenerator/Generators/ModelsGen.cs b/CodeGenerator/Generators/ModelsGen.cs index 549738ab..f536bd10 100644 --- a/CodeGenerator/Generators/ModelsGen.cs +++ b/CodeGenerator/Generators/ModelsGen.cs @@ -2,7 +2,6 @@ using Plugin; using SqlcGenCsharp.Drivers; using System.Collections.Generic; -using System.Collections.Immutable; using System.Linq; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; @@ -17,7 +16,6 @@ internal class ModelsGen(DbDriver dbDriver, string namespaceName) private DataClassesGen DataClassesGen { get; } = new(dbDriver); - private EnumsGen EnumsGen { get; } = new(dbDriver); public File GenerateFile( @@ -59,8 +57,12 @@ private MemberDeclarationSyntax[] GenerateEnums(Dictionary { - var enumName = e.Value.Name.ToModelName(s.Key, dbDriver.DefaultSchema); - return EnumsGen.Generate(enumName, e.Value.Vals); + if (dbDriver is EnumDbDriver enumDbDriver) + { + var enumName = enumDbDriver.EnumToModelName(s.Key, e.Value); + return EnumsGen.Generate(enumName, e.Value.Vals); + } + return []; }); }).ToArray(); } diff --git a/CodeGenerator/Generators/QueriesGen.cs b/CodeGenerator/Generators/QueriesGen.cs index b19841e6..35988432 100644 --- a/CodeGenerator/Generators/QueriesGen.cs +++ b/CodeGenerator/Generators/QueriesGen.cs @@ -4,12 +4,13 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.RegularExpressions; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; namespace SqlcGenCsharp.Generators; -internal class QueriesGen(DbDriver dbDriver, string namespaceName) +internal partial class QueriesGen(DbDriver dbDriver, string namespaceName) { private static readonly string[] ResharperDisables = [ @@ -132,16 +133,22 @@ private IEnumerable GetMembersForSingleQuery(Query quer private MemberDeclarationSyntax? GetQueryTextConstant(Query query) { - var transformQueryText = dbDriver.TransformQueryText(query); - if (transformQueryText == string.Empty) + var transformedQueryText = dbDriver.TransformQueryText(query); + if (transformedQueryText == string.Empty) return null; + + var singleLineQueryText = LongWhitespaceRegex().Replace(transformedQueryText, " "); return ParseMemberDeclaration( $""" - private const string {ClassMember.Sql.Name(query.Name)} = "{transformQueryText}"; + private const string {ClassMember.Sql.Name(query.Name)} = "{singleLineQueryText}"; """)! .AppendNewLine(); } + + [GeneratedRegex(@"\s{1,}")] + private static partial Regex LongWhitespaceRegex(); + private MemberDeclarationSyntax AddMethodDeclaration(Query query) { var queryTextConstant = ClassMember.Sql.Name(query.Name); diff --git a/CodegenTests/CodegenSchemaTests.cs b/CodegenTests/CodegenSchemaTests.cs index 7184843e..57254c05 100644 --- a/CodegenTests/CodegenSchemaTests.cs +++ b/CodegenTests/CodegenSchemaTests.cs @@ -47,8 +47,8 @@ public void TestSchemaScopedEnum() var expected = new HashSet { "DummySchemaDummyTable", - "DummySchemaDummyTableDummyColumn", - "DummySchemaDummyTableDummyColumnExtensions" + "DummyTableDummyColumn", + "DummyTableDummyColumnExtensions" }; var actual = GetMemberNames(modelsCode); Assert.That(actual.IsSupersetOf(expected)); diff --git a/CodegenTests/CodegenTypeOverrideTests.cs b/CodegenTests/CodegenTypeOverrideTests.cs index afe70395..9fd2ff65 100644 --- a/CodegenTests/CodegenTypeOverrideTests.cs +++ b/CodegenTests/CodegenTypeOverrideTests.cs @@ -2,7 +2,6 @@ using Plugin; using SqlcGenCsharp; using System.Text; -using System.Xml; namespace CodegenTests; diff --git a/Drivers/DbDriver.cs b/Drivers/DbDriver.cs index 1225266d..1b95baa3 100644 --- a/Drivers/DbDriver.cs +++ b/Drivers/DbDriver.cs @@ -55,11 +55,9 @@ public abstract class DbDriver "NpgsqlCidr", ]; + protected abstract Dictionary ColumnMappings { get; } - public abstract Dictionary ColumnMappings { get; } - - protected const string JsonElementTypeHandler = - """ + protected const string JsonElementTypeHandler = """ private class JsonElementTypeHandler : SqlMapper.TypeHandler { public override JsonElement Parse(object value) @@ -84,33 +82,62 @@ public static string TransformQueryForSliceArgs(string originalSql, int sliceSiz } """; + public readonly string TransactionConnectionNullExcetionThrow = $""" + if (this.{Variable.Transaction.AsPropertyName()}?.Connection == null || this.{Variable.Transaction.AsPropertyName()}?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + """; + protected DbDriver( Options options, - string defaultSchema, - Dictionary> tables, - Dictionary> enums, + Catalog catalog, IList queries) { Options = options; - DefaultSchema = defaultSchema; - Tables = tables; - Enums = enums; + DefaultSchema = catalog.DefaultSchema; + Tables = ConstructTablesLookup(catalog); Queries = queries; + Enums = ConstructEnumsLookup(catalog); foreach (var schemaEnums in Enums) - { foreach (var e in schemaEnums.Value) - { NullableTypes.Add(e.Key.ToModelName(schemaEnums.Key, DefaultSchema)); - } - } - if (!Options.DotnetFramework.IsDotnetCore()) return; + if (!Options.DotnetFramework.IsDotnetCore()) + return; foreach (var t in NullableTypesInDotnetCore) - { NullableTypes.Add(t); - } + } + + private static readonly HashSet _excludedSchemas = + [ + "pg_catalog", + "information_schema" + ]; + + private static Dictionary> ConstructTablesLookup(Catalog catalog) + { + return catalog.Schemas + .Where(s => !_excludedSchemas.Contains(s.Name)) + .ToDictionary( + s => s.Name == catalog.DefaultSchema ? string.Empty : s.Name, + s => s.Tables.ToDictionary(t => t.Rel.Name, t => t) + ); + } + + private static Dictionary> ConstructEnumsLookup(Catalog catalog) + { + return catalog + .Schemas + .SelectMany(s => s.Enums.Select(e => new { EnumItem = e, Schema = s.Name })) + .GroupBy(x => x.Schema == catalog.DefaultSchema ? string.Empty : x.Schema) + .ToDictionary( + group => group.Key, + group => group.ToDictionary( + x => x.EnumItem.Name, + x => x.EnumItem + ) + ); } public virtual ISet GetUsingDirectivesForQueries() @@ -200,6 +227,46 @@ public static void ConfigureSqlMapper() """)!]; } + public abstract string TransformQueryText(Query query); + + public abstract ConnectionGenCommands EstablishConnection(Query query); + + public abstract string CreateSqlCommand(string sqlTextConstant); + + /* Since there is no indication of the primary key column in SQLC protobuf (assuming it is a single column), + this method uses a few heuristics to assess the data type of the id column + */ + public string GetIdColumnType(Query query) + { + var tableColumns = Tables[query.InsertIntoTable.Schema][query.InsertIntoTable.Name].Columns; + var idColumn = tableColumns.First(c => c.Name.Equals("id", StringComparison.OrdinalIgnoreCase)); + if (idColumn is not null) + return GetCsharpType(idColumn, query); + + idColumn = tableColumns.First(c => c.Name.Contains("id", StringComparison.CurrentCultureIgnoreCase)); + return GetCsharpType(idColumn ?? tableColumns[0], query); + } + + public virtual string[] GetLastIdStatement(Query query) + { + var idColumnType = GetIdColumnType(query); + var convertFunc = ColumnMappings[idColumnType].ConvertFunc ?? + throw new InvalidOperationException($"ConvertFunc is missing for id column type {idColumnType}"); + var convertFuncCall = convertFunc(Variable.Result.AsVarName()); + return + [ + $"var {Variable.Result.AsVarName()} = await {Variable.Command.AsVarName()}.ExecuteScalarAsync();", + $"return {convertFuncCall};" + ]; + } + + public Column GetColumnFromParam(Parameter queryParam, Query query) + { + if (string.IsNullOrEmpty(queryParam.Column.Name)) + queryParam.Column.Name = $"{GetCsharpType(queryParam.Column, query).Replace("[]", "Arr")}_{queryParam.Number}"; + return queryParam.Column; + } + protected bool TypeExistsInQueries(string csharpType) { return Queries.Any(q => TypeExistsInQuery(csharpType, q)); @@ -213,30 +280,64 @@ protected bool TypeExistsInQuery(string csharpType, Query query) .Any(p => csharpType == GetCsharpTypeWithoutNullableSuffix(p.Column, query)); } - public string AddNullableSuffixIfNeeded(string csharpType, bool notNull) + protected bool SliceQueryExists() { - if (notNull) - return csharpType; - return IsTypeNullable(csharpType) ? $"{csharpType}?" : csharpType; + return Queries.Any(q => q.Params.Any(p => p.Column.IsSqlcSlice)); + } + + protected bool CopyFromQueryExists() + { + return Queries.Any(q => q.Cmd is ":copyfrom"); + } + + private OverrideOption? FindOverrideForQueryColumn(Query? query, Column column) + { + if (query is null) + return null; + return Options.Overrides.FirstOrDefault(o => + o.Column == $"{query.Name}:{column.Name}" || o.Column == $"*:{column.Name}"); + } + + // If the column data type is overridden, we need to check for nulls in generated code + public bool IsColumnNotNull(Column column, Query? query) + { + if (FindOverrideForQueryColumn(query, column) is { CsharpType: var csharpType }) + return csharpType.NotNull; + return column.NotNull; } + /* Data type methods */ public string GetCsharpType(Column column, Query? query) { var csharpType = GetCsharpTypeWithoutNullableSuffix(column, query); return AddNullableSuffixIfNeeded(csharpType, IsColumnNotNull(column, query)); } - public string GetColumnSchema(Column column) + public string AddNullableSuffixIfNeeded(string csharpType, bool notNull) + { + if (notNull) + return csharpType; + return IsTypeNullable(csharpType) ? $"{csharpType}?" : csharpType; + } + + protected string? GetColumnDbTypeOverride(Column column) { - return column.Table.Schema == DefaultSchema ? string.Empty : column.Table.Schema; + var columnType = column.Type.Name.ToLower(); + foreach (var columnMapping in ColumnMappings.Values) + { + if (columnMapping.DbTypes.TryGetValue(columnType, out var dbTypeOverride)) + return dbTypeOverride.NpgsqlTypeOverride; + } + throw new NotSupportedException($"Column {column.Name} has unsupported column type: {column.Type.Name}"); } - public virtual string GetEnumTypeAsCsharpType(Column column, Plugin.Enum enumType) + public bool IsTypeNullable(string csharpType) { - return column.Type.Name.ToModelName(GetColumnSchema(column), DefaultSchema); + if (NullableTypes.Contains(csharpType.Replace("?", ""))) return true; + return Options.DotnetFramework.IsDotnetCore(); // non-primitives in .Net Core are inherently nullable } - public string GetCsharpTypeWithoutNullableSuffix(Column column, Query? query) + protected virtual string GetCsharpTypeWithoutNullableSuffix(Column column, Query? query) { if (column.EmbedTable != null) return column.EmbedTable.Name.ToModelName(column.EmbedTable.Schema, DefaultSchema); @@ -244,9 +345,6 @@ public string GetCsharpTypeWithoutNullableSuffix(Column column, Query? query) if (string.IsNullOrEmpty(column.Type.Name)) return "object"; - if (GetEnumType(column) is { } enumType) - return GetEnumTypeAsCsharpType(column, enumType); - if (FindOverrideForQueryColumn(query, column) is { CsharpType: var csharpType }) return csharpType.Type; @@ -256,18 +354,7 @@ public string GetCsharpTypeWithoutNullableSuffix(Column column, Query? query) if (column.IsArray || column.IsSqlcSlice) return $"{columnMapping.Key}[]"; return columnMapping.Key; } - - throw new NotSupportedException($"Column {column.Name} has unsupported column type: {column.Type.Name}"); - } - - public Plugin.Enum? GetEnumType(Column column) - { - if (column.Table is null) - return null; - var schemaName = GetColumnSchema(column); - if (!Enums.TryGetValue(schemaName, value: out var enumsInSchema)) - return null; - return enumsInSchema.GetValueOrDefault(column.Type.Name); + throw new NotSupportedException($"Column {column.Name} has unsupported column type: {column.Type.Name} in {GetType().Name}"); } private static bool DoesColumnMappingApply(ColumnMapping columnMapping, Column column) @@ -280,6 +367,18 @@ private static bool DoesColumnMappingApply(ColumnMapping columnMapping, Column c return typeInfo.Length.Value == column.Length; } + public virtual Func? GetWriterFn(Column column, Query query) + { + var csharpType = GetCsharpTypeWithoutNullableSuffix(column, query); + var writerFn = ColumnMappings.GetValueOrDefault(csharpType)?.WriterFn; + if (writerFn is not null) + return writerFn; + + static string DefaultWriterFn(string el, bool notNull, bool isDapper) => notNull ? el : $"{el} ?? (object)DBNull.Value"; + return Options.UseDapper ? null : DefaultWriterFn; + } + + /* Column reader methods */ private string GetColumnReader(CsharpTypeOption csharpTypeOption, int ordinal) { if (ColumnMappings.TryGetValue(csharpTypeOption.Type, out var value)) @@ -287,21 +386,8 @@ private string GetColumnReader(CsharpTypeOption csharpTypeOption, int ordinal) throw new NotSupportedException($"Could not find column mapping for type override: {csharpTypeOption.Type}"); } - private string GetEnumReader(Column column, int ordinal, Plugin.Enum enumType) - { - var enumName = column.Type.Name.ToModelName(column.Table.Schema, DefaultSchema); - var fullEnumType = GetEnumTypeAsCsharpType(column, enumType); - var readStmt = $"{Variable.Reader.AsVarName()}.GetString({ordinal})"; - if (fullEnumType.EndsWith("[]")) - return $"{readStmt}.To{enumName}Arr()"; - return $"{readStmt}.To{enumName}()"; - } - - public string GetColumnReader(Column column, int ordinal, Query? query) + public virtual string GetColumnReader(Column column, int ordinal, Query? query) { - if (GetEnumType(column) is { } enumType) - return GetEnumReader(column, ordinal, enumType); - if (FindOverrideForQueryColumn(query, column) is { CsharpType: var csharpType }) return GetColumnReader(csharpType, ordinal); @@ -312,97 +398,6 @@ public string GetColumnReader(Column column, int ordinal, Query? query) return columnMapping.ReaderArrayFn?.Invoke(ordinal) ?? throw new InvalidOperationException("ReaderArrayFn is null"); return columnMapping.ReaderFn(ordinal); } - throw new NotSupportedException($"Column {column.Name} has unsupported column type: {column.Type.Name}"); - } - - protected string? GetColumnDbTypeOverride(Column column) - { - var columnType = column.Type.Name.ToLower(); - foreach (var columnMapping in ColumnMappings.Values) - { - if (columnMapping.DbTypes.TryGetValue(columnType, out var dbTypeOverride)) - return dbTypeOverride.NpgsqlTypeOverride; - } - throw new NotSupportedException($"Column {column.Name} has unsupported column type: {column.Type.Name}"); - } - - public abstract string TransformQueryText(Query query); - - public abstract ConnectionGenCommands EstablishConnection(Query query); - - public abstract string CreateSqlCommand(string sqlTextConstant); - - public bool IsTypeNullable(string csharpType) - { - if (NullableTypes.Contains(csharpType.Replace("?", ""))) return true; - return Options.DotnetFramework.IsDotnetCore(); // non-primitives in .Net Core are inherently nullable - } - - /// - /// Since there is no indication of the primary key column in SQLC protobuf (assuming it is a single column), - /// this method uses a few heuristics to assess the data type of the id column - /// - /// - /// The data type of the id column - public string GetIdColumnType(Query query) - { - var tableColumns = Tables[query.InsertIntoTable.Schema][query.InsertIntoTable.Name].Columns; - var idColumn = tableColumns.First(c => c.Name.Equals("id", StringComparison.OrdinalIgnoreCase)); - if (idColumn is not null) - return GetCsharpType(idColumn, query); - - idColumn = tableColumns.First(c => c.Name.Contains("id", StringComparison.CurrentCultureIgnoreCase)); - return GetCsharpType(idColumn ?? tableColumns[0], query); - } - - public virtual string[] GetLastIdStatement(Query query) - { - var idColumnType = GetIdColumnType(query); - var convertFunc = ColumnMappings[idColumnType].ConvertFunc ?? - throw new InvalidOperationException($"ConvertFunc is missing for id column type {idColumnType}"); - var convertFuncCall = convertFunc(Variable.Result.AsVarName()); - return - [ - $"var {Variable.Result.AsVarName()} = await {Variable.Command.AsVarName()}.ExecuteScalarAsync();", - $"return {convertFuncCall};" - ]; - } - - public Column GetColumnFromParam(Parameter queryParam, Query query) - { - if (string.IsNullOrEmpty(queryParam.Column.Name)) - queryParam.Column.Name = $"{GetCsharpType(queryParam.Column, query).Replace("[]", "Arr")}_{queryParam.Number}"; - return queryParam.Column; - } - - protected bool SliceQueryExists() - { - return Queries.Any(q => q.Params.Any(p => p.Column.IsSqlcSlice)); - } - - protected bool CopyFromQueryExists() - { - return Queries.Any(q => q.Cmd is ":copyfrom"); - } - - public OverrideOption? FindOverrideForQueryColumn(Query? query, Column column) - { - if (query is null) - return null; - return Options.Overrides.FirstOrDefault(o => - o.Column == $"{query.Name}:{column.Name}" || o.Column == $"*:{column.Name}"); - } - - /// - /// If the column data type is overridden, we need to check for nulls in generated code - /// - /// - /// - /// Adjusted not null value - public bool IsColumnNotNull(Column column, Query? query) - { - if (FindOverrideForQueryColumn(query, column) is { CsharpType: var csharpType }) - return csharpType.NotNull; - return column.NotNull; + throw new NotSupportedException($"column {column.Name} has unsupported column type: {column.Type.Name} in {GetType().Name}"); } } \ No newline at end of file diff --git a/Drivers/EnumDbDriver.cs b/Drivers/EnumDbDriver.cs new file mode 100644 index 00000000..ef857c91 --- /dev/null +++ b/Drivers/EnumDbDriver.cs @@ -0,0 +1,31 @@ +using Plugin; +using SqlcGenCsharp; +using SqlcGenCsharp.Drivers; +using System.Collections.Generic; + +public abstract class EnumDbDriver(Options options, Catalog catalog, IList queries) : DbDriver(options, catalog, queries) +{ + protected abstract Enum? GetEnumType(Column column); + + protected abstract string EnumToCsharpDataType(Column column); + + public abstract string EnumToModelName(string schemaName, Enum enumType); + + protected abstract string EnumToModelName(Column column); + + protected abstract string GetEnumReader(Column column, int ordinal); + + public override string GetColumnReader(Column column, int ordinal, Query? query) + { + if (GetEnumType(column) is not null) + return GetEnumReader(column, ordinal); + return base.GetColumnReader(column, ordinal, query); + } + + protected override string GetCsharpTypeWithoutNullableSuffix(Column column, Query? query) + { + if (GetEnumType(column) is not null) + return EnumToCsharpDataType(column); + return base.GetCsharpTypeWithoutNullableSuffix(column, query); + } +} \ No newline at end of file diff --git a/Drivers/Generators/CommonGen.cs b/Drivers/Generators/CommonGen.cs index 4a4a8892..6a1bc25f 100644 --- a/Drivers/Generators/CommonGen.cs +++ b/Drivers/Generators/CommonGen.cs @@ -1,5 +1,4 @@ using Plugin; -using System; using System.Collections.Generic; using System.Linq; @@ -14,28 +13,6 @@ public static string GetMethodParameterList(string argInterface, IEnumerable? GetWriterFn(Column column, Query query) - { - var csharpType = dbDriver.GetCsharpTypeWithoutNullableSuffix(column, query); - var writerFn = dbDriver.ColumnMappings.GetValueOrDefault(csharpType)?.WriterFn; - if (writerFn is not null) - return writerFn; - - if (dbDriver.GetEnumType(column) is { } enumType) - if (dbDriver.GetEnumTypeAsCsharpType(column, enumType).EndsWith("[]")) - return (el, notNull, isDapper) => - { - var stringJoinStmt = $"string.Join(\",\", {el})"; - var nullValue = isDapper ? "null" : "(object)DBNull.Value"; - return notNull - ? stringJoinStmt - : $"{el} != null ? {stringJoinStmt} : {nullValue}"; - }; - - string DefaultWriterFn(string el, bool notNull, bool isDapper) => notNull ? el : $"{el} ?? (object)DBNull.Value"; - return dbDriver.Options.UseDapper ? null : DefaultWriterFn; - } - // TODO: extract AddWithValue statement generation to a method + possible override for Npgsql for type override public string AddParametersToCommand(Query query) { @@ -50,7 +27,7 @@ public string AddParametersToCommand(Query query) """; var notNull = dbDriver.IsColumnNotNull(p.Column, query); - var writerFn = GetWriterFn(p.Column, query); + var writerFn = dbDriver.GetWriterFn(p.Column, query); var paramToWrite = writerFn is null ? param : writerFn(param, notNull, dbDriver.Options.UseDapper); var addParamToCommand = $"""{commandVar}.Parameters.AddWithValue("@{p.Column.Name}", {paramToWrite});"""; return addParamToCommand; @@ -79,7 +56,7 @@ public string ConstructDapperParamsDict(Query query) param += "?.ToEnumString()"; var notNull = dbDriver.IsColumnNotNull(p.Column, query); - var writerFn = GetWriterFn(p.Column, query); + var writerFn = dbDriver.GetWriterFn(p.Column, query); var paramToWrite = writerFn is null ? $"{argsVar}.{param}" : writerFn($"{argsVar}.{param}", notNull, dbDriver.Options.UseDapper); var addParamToDict = $"{queryParamsVar}.Add(\"{p.Column.Name}\", {paramToWrite});"; return addParamToDict; diff --git a/Drivers/Generators/ExecDeclareGen.cs b/Drivers/Generators/ExecDeclareGen.cs index d4e7cf13..2470457d 100644 --- a/Drivers/Generators/ExecDeclareGen.cs +++ b/Drivers/Generators/ExecDeclareGen.cs @@ -49,9 +49,7 @@ private string GetDapperNoTxBody(string sqlVar, Query query) var dapperArgs = query.Params.Any() ? $", {Variable.QueryParams.AsVarName()}" : string.Empty; return $$""" using ({{establishConnection}}) - { await {{Variable.Connection.AsVarName()}}.ExecuteAsync({{sqlVar}}{{dapperArgs}}); - } return; """; } @@ -61,11 +59,7 @@ private string GetDapperWithTxBody(string sqlVar, Query query) var transactionProperty = Variable.Transaction.AsPropertyName(); var dapperArgs = query.Params.Any() ? $", {Variable.QueryParams.AsVarName()}" : string.Empty; return $$""" - if (this.{{transactionProperty}}?.Connection == null || this.{{transactionProperty}}?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + {{dbDriver.TransactionConnectionNullExcetionThrow}} await this.{{transactionProperty}}.Connection.ExecuteAsync( {{sqlVar}}{{dapperArgs}}, transaction: this.{{transactionProperty}}); @@ -98,11 +92,7 @@ private string GetDriverWithTxBody(string sqlVar, Query query) var commandParameters = CommonGen.AddParametersToCommand(query); return $$""" - if (this.{{transactionProperty}}?.Connection == null || this.{{transactionProperty}}?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + {{dbDriver.TransactionConnectionNullExcetionThrow}} using (var {{commandVar}} = this.{{transactionProperty}}.Connection.CreateCommand()) { {{commandVar}}.CommandText = {{sqlVar}}; diff --git a/Drivers/Generators/ExecLastIdDeclareGen.cs b/Drivers/Generators/ExecLastIdDeclareGen.cs index f5e8beda..48c9a231 100644 --- a/Drivers/Generators/ExecLastIdDeclareGen.cs +++ b/Drivers/Generators/ExecLastIdDeclareGen.cs @@ -49,9 +49,7 @@ private string GetDapperNoTxBody(string sqlVar, Query query) var dapperArgs = query.Params.Any() ? $", {Variable.QueryParams.AsVarName()}" : string.Empty; return $$""" using ({{establishConnection}}) - { return await {{Variable.Connection.AsVarName()}}.QuerySingleAsync<{{dbDriver.GetIdColumnType(query)}}>({{sqlVar}}{{dapperArgs}}); - } """; } @@ -60,11 +58,7 @@ private string GetDapperWithTxBody(string sqlVar, Query query) var transactionProperty = Variable.Transaction.AsPropertyName(); var dapperArgs = query.Params.Any() ? $", {Variable.QueryParams.AsVarName()}" : string.Empty; return $$""" - if (this.{{transactionProperty}}?.Connection == null || this.{{transactionProperty}}?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + {{dbDriver.TransactionConnectionNullExcetionThrow}} return await this.{{transactionProperty}}.Connection.QuerySingleAsync<{{dbDriver.GetIdColumnType(query)}}>({{sqlVar}}{{dapperArgs}}, transaction: this.{{transactionProperty}}); """; } @@ -96,11 +90,7 @@ private string GetDriverWithTxBody(string sqlVar, Query query) var returnLastId = ((IExecLastId)dbDriver).GetLastIdStatement(query).JoinByNewLine(); return $$""" - if (this.{{transactionProperty}}?.Connection == null || this.{{transactionProperty}}?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + {{dbDriver.TransactionConnectionNullExcetionThrow}} using (var {{commandVar}} = this.{{transactionProperty}}.Connection.CreateCommand()) { {{commandVar}}.CommandText = {{sqlVar}}; diff --git a/Drivers/Generators/ExecRowsDeclareGen.cs b/Drivers/Generators/ExecRowsDeclareGen.cs index fde479c9..7acdc8c4 100644 --- a/Drivers/Generators/ExecRowsDeclareGen.cs +++ b/Drivers/Generators/ExecRowsDeclareGen.cs @@ -49,9 +49,7 @@ private string GetDapperNoTxBody(string sqlVar, Query query) var dapperArgs = query.Params.Any() ? $", {Variable.QueryParams.AsVarName()}" : string.Empty; return $$""" using ({{establishConnection}}) - { return await {{Variable.Connection.AsVarName()}}.ExecuteAsync({{sqlVar}}{{dapperArgs}}); - } """; } @@ -60,11 +58,7 @@ private string GetDapperWithTxBody(string sqlVar, Query query) var transactionProperty = Variable.Transaction.AsPropertyName(); var dapperArgs = query.Params.Any() ? $", {Variable.QueryParams.AsVarName()}" : string.Empty; return $$""" - if (this.{{transactionProperty}}?.Connection == null || this.{{transactionProperty}}?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + {{dbDriver.TransactionConnectionNullExcetionThrow}} return await this.{{transactionProperty}}.Connection.ExecuteAsync( {{sqlVar}}{{dapperArgs}}, transaction: this.{{transactionProperty}}); @@ -96,11 +90,7 @@ private string GetDriverWithTxBody(string sqlVar, Query query) var commandParameters = CommonGen.AddParametersToCommand(query); return $$""" - if (this.{{transactionProperty}}?.Connection == null || this.{{transactionProperty}}?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + {{dbDriver.TransactionConnectionNullExcetionThrow}} using (var {{commandVar}} = this.{{transactionProperty}}.Connection.CreateCommand()) { {{commandVar}}.CommandText = {{sqlVar}}; diff --git a/Drivers/Generators/ManyDeclareGen.cs b/Drivers/Generators/ManyDeclareGen.cs index 73945fe5..73a13547 100644 --- a/Drivers/Generators/ManyDeclareGen.cs +++ b/Drivers/Generators/ManyDeclareGen.cs @@ -68,9 +68,7 @@ private string GetDapperWithTxBody(string sqlVar, string returnInterface, Query var returnType = dbDriver.AddNullableSuffixIfNeeded(returnInterface, true); return $$""" - if (this.{{transactionProperty}}?.Connection == null || this.{{transactionProperty}}?.Connection.State != System.Data.ConnectionState.Open) - throw new InvalidOperationException("Transaction is provided, but its connection is null."); - + {{dbDriver.TransactionConnectionNullExcetionThrow}} return (await this.{{transactionProperty}}.Connection.QueryAsync<{{returnType}}>( {{sqlVar}}{{dapperArgs}}, transaction: this.{{transactionProperty}})).AsList(); @@ -124,9 +122,7 @@ private string GetDriverWithTxBody(string sqlVar, string returnInterface, Query """; return $$""" - if (this.{{transactionProperty}}?.Connection == null || this.{{transactionProperty}}?.Connection.State != System.Data.ConnectionState.Open) - throw new InvalidOperationException("Transaction is provided, but its connection is null."); - + {{dbDriver.TransactionConnectionNullExcetionThrow}} using (var {{commandVar}} = this.{{transactionProperty}}.Connection.CreateCommand()) { {{commandVar}}.CommandText = {{sqlVar}}; diff --git a/Drivers/Generators/OneDeclareGen.cs b/Drivers/Generators/OneDeclareGen.cs index 0e43dd2f..c35d4d52 100644 --- a/Drivers/Generators/OneDeclareGen.cs +++ b/Drivers/Generators/OneDeclareGen.cs @@ -68,11 +68,7 @@ private string GetDapperWithTxBody(string sqlVar, string returnInterface, Query var returnType = dbDriver.AddNullableSuffixIfNeeded(returnInterface, false); return $$""" - if (this.{{transactionProperty}}?.Connection == null || this.{{transactionProperty}}?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + {{dbDriver.TransactionConnectionNullExcetionThrow}} return await this.{{transactionProperty}}.Connection.QueryFirstOrDefaultAsync<{{returnType}}>( {{sqlVar}}{{dapperArgs}}, transaction: this.{{transactionProperty}}); @@ -118,11 +114,7 @@ private string GetDriverWithTxBody(string sqlVar, string returnInterface, Query var returnDataclass = CommonGen.InstantiateDataclass(query.Columns.ToArray(), returnInterface, query); return $$""" - if (this.{{transactionProperty}}?.Connection == null || this.{{transactionProperty}}?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + {{dbDriver.TransactionConnectionNullExcetionThrow}} using (var {{commandVar}} = this.{{transactionProperty}}.Connection.CreateCommand()) { {{commandVar}}.CommandText = {{sqlVar}}; diff --git a/Drivers/MySqlConnectorDriver.cs b/Drivers/MySqlConnectorDriver.cs index 4d9afabf..f43f2574 100644 --- a/Drivers/MySqlConnectorDriver.cs +++ b/Drivers/MySqlConnectorDriver.cs @@ -6,24 +6,18 @@ using System.Linq; using System.Text.RegularExpressions; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; -using OneDeclareGen = SqlcGenCsharp.Drivers.Generators.OneDeclareGen; +using Enum = Plugin.Enum; namespace SqlcGenCsharp.Drivers; -public partial class MySqlConnectorDriver( +public sealed partial class MySqlConnectorDriver( Options options, - string defaultSchema, - Dictionary> tables, - Dictionary> enums, + Catalog catalog, IList queries) : - DbDriver(options, defaultSchema, tables, enums, queries), IOne, IMany, IExec, IExecRows, IExecLastId, ICopyFrom + EnumDbDriver(options, catalog, queries), + IOne, IMany, IExec, IExecRows, IExecLastId, ICopyFrom { - public const string NullToStringCsvConverter = "NullToStringCsvConverter"; - public const string BoolToBitCsvConverter = "BoolToBitCsvConverter"; - public const string ByteCsvConverter = "ByteCsvConverter"; - public const string ByteArrayCsvConverter = "ByteArrayCsvConverter"; - - public override Dictionary ColumnMappings { get; } = + protected override Dictionary ColumnMappings { get; } = new() { /* Numeric data types */ @@ -106,7 +100,6 @@ public partial class MySqlConnectorDriver( { "longtext", new() }, { "mediumtext", new() }, { "text", new() }, - { "time", new() }, { "tinytext", new() }, { "varchar", new() }, { "var_string", new() }, @@ -122,7 +115,14 @@ public partial class MySqlConnectorDriver( { "datetime", new() }, { "timestamp", new() } }, - ordinal => $"reader.GetDateTime({ordinal})" + readerFn: ordinal => $"reader.GetDateTime({ordinal})" + ), + ["TimeSpan"] = new( + new() + { + { "time", new() } + }, + readerFn: ordinal => $"reader.GetFieldValue({ordinal})" ), /* Unstructured data types */ @@ -156,23 +156,37 @@ public partial class MySqlConnectorDriver( public override string TransactionClassName => "MySqlTransaction"; - private readonly Func _setTypeHandlerFunc = x => - $$""" - private class {{x}}TypeHandler : SqlMapper.TypeHandler<{{x}}[]> - { - public override {{x}}[] Parse(object value) - { - if (value is string s) - return s.To{{x}}Arr(); - throw new DataException($"Cannot convert {value?.GetType()} to {{x}}[]"); - } - - public override void SetValue(IDbDataParameter parameter, {{x}}[] value) - { - parameter.Value = string.Join(",", value); - } - } - """; + public MemberDeclarationSyntax OneDeclare(string queryTextConstant, string argInterface, + string returnInterface, Query query) + { + return new OneDeclareGen(this).Generate(queryTextConstant, argInterface, returnInterface, query); + } + + public MemberDeclarationSyntax ExecDeclare(string queryTextConstant, string argInterface, Query query) + { + return new ExecDeclareGen(this).Generate(queryTextConstant, argInterface, query); + } + + public MemberDeclarationSyntax ManyDeclare(string queryTextConstant, string argInterface, + string returnInterface, Query query) + { + return new ManyDeclareGen(this).Generate(queryTextConstant, argInterface, returnInterface, query); + } + + public MemberDeclarationSyntax ExecRowsDeclare(string queryTextConstant, string argInterface, Query query) + { + return new ExecRowsDeclareGen(this).Generate(queryTextConstant, argInterface, query); + } + + public MemberDeclarationSyntax ExecLastIdDeclare(string queryTextConstant, string argInterface, Query query) + { + return new ExecLastIdDeclareGen(this).Generate(queryTextConstant, argInterface, query); + } + + public MemberDeclarationSyntax CopyFromDeclare(string queryTextConstant, string argInterface, Query query) + { + return new CopyFromDeclareGen(this).Generate(queryTextConstant, argInterface, query); + } public override ISet GetUsingDirectivesForQueries() { @@ -219,24 +233,23 @@ public override ISet GetUsingDirectivesForUtils() "CsvHelper.Configuration" ], CopyFromQueryExists() + ) + .AddRangeExcludeNulls( + [ + "System.Collections.Generic" + ] ); } - private bool IsSetType(Column column) - { - var enumType = GetEnumType(column); - return enumType is not null && IsEnumOfTypeSet(column, enumType); - } - protected override ISet GetConfigureSqlMappings() { var setSqlMappings = Queries .SelectMany(q => q.Columns) - .Where(IsSetType) + .Where(IsSetDataType) .Select(c => { - var enumName = c.Type.Name.ToModelName(GetColumnSchema(c), DefaultSchema); - return $"SqlMapper.AddTypeHandler(typeof({enumName}[]), new {enumName}TypeHandler());"; + var enumName = EnumToModelName(c); + return $"SqlMapper.AddTypeHandler(typeof(HashSet<{enumName}>), new {enumName}TypeHandler());"; }) .Distinct(); @@ -247,14 +260,32 @@ protected override ISet GetConfigureSqlMappings() private MemberDeclarationSyntax[] GetSetTypeHandlers() { + var setTypeHandlerFunc = (string x) => + $$""" + private class {{x}}TypeHandler : SqlMapper.TypeHandler> + { + public override HashSet<{{x}}> Parse(object value) + { + if (value is string s) + return s.To{{x}}Set(); + throw new DataException($"Cannot convert {value?.GetType()} to HashSet<{{x}}>"); + } + + public override void SetValue(IDbDataParameter parameter, HashSet<{{x}}> value) + { + parameter.Value = string.Join(",", value); + } + } + """; + return Queries .SelectMany(q => q.Columns) .Where(c => { var enumType = GetEnumType(c); - return enumType is not null && IsEnumOfTypeSet(c, enumType); + return enumType is not null && IsSetDataType(c, enumType); }) - .Select(c => _setTypeHandlerFunc(c.Type.Name.ToModelName(GetColumnSchema(c), DefaultSchema))) + .Select(c => setTypeHandlerFunc(EnumToModelName(c))) .Distinct() .Select(m => ParseMemberDeclaration(m)!) .ToArray(); @@ -276,9 +307,9 @@ public override MemberDeclarationSyntax[] GetMemberDeclarationsForUtils() continue; foreach (var p in query.Params) { - if (!IsSetType(p.Column)) + if (!IsSetDataType(p.Column)) continue; - var enumName = p.Column.Type.Name.ToModelName(GetColumnSchema(p.Column), DefaultSchema); + var enumName = EnumToModelName(p.Column); memberDeclarations = memberDeclarations.AddRangeExcludeNulls([ParseMemberDeclaration(SetCsvConverterFunc(enumName))!]); } } @@ -359,8 +390,8 @@ public class {{x}}CsvConverter : DefaultTypeConverter { if (value == null) return @"\N"; - if (value is {{x}}[] arrVal) - return string.Join(",", arrVal); + if (value is HashSet<{{x}}> setVal) + return string.Join(",", setVal); return base.ConvertToString(value, row, memberMapData); } } @@ -369,7 +400,7 @@ public class {{x}}CsvConverter : DefaultTypeConverter public override ConnectionGenCommands EstablishConnection(Query query) { - return new ConnectionGenCommands( + return new( $"var {Variable.Connection.AsVarName()} = new MySqlConnection({Variable.ConnectionString.AsPropertyName()})", $"await {Variable.Connection.AsVarName()}.OpenAsync()" ); @@ -398,22 +429,6 @@ public override string TransformQueryText(Query query) [GeneratedRegex(@"\?")] private static partial Regex QueryParamRegex(); - public MemberDeclarationSyntax OneDeclare(string queryTextConstant, string argInterface, - string returnInterface, Query query) - { - return new OneDeclareGen(this).Generate(queryTextConstant, argInterface, returnInterface, query); - } - - public MemberDeclarationSyntax ExecDeclare(string queryTextConstant, string argInterface, Query query) - { - return new ExecDeclareGen(this).Generate(queryTextConstant, argInterface, query); - } - - public MemberDeclarationSyntax ExecLastIdDeclare(string queryTextConstant, string argInterface, Query query) - { - return new ExecLastIdDeclareGen(this).Generate(queryTextConstant, argInterface, query); - } - public override string[] GetLastIdStatement(Query query) { return @@ -423,20 +438,11 @@ public override string[] GetLastIdStatement(Query query) ]; } - public MemberDeclarationSyntax ManyDeclare(string queryTextConstant, string argInterface, string returnInterface, Query query) - { - return new ManyDeclareGen(this).Generate(queryTextConstant, argInterface, returnInterface, query); - } - - public MemberDeclarationSyntax ExecRowsDeclare(string queryTextConstant, string argInterface, Query query) - { - return new ExecRowsDeclareGen(this).Generate(queryTextConstant, argInterface, query); - } - - public MemberDeclarationSyntax CopyFromDeclare(string queryTextConstant, string argInterface, Query query) - { - return new CopyFromDeclareGen(this).Generate(queryTextConstant, argInterface, query); - } + /* :copyfrom methods */ + public const string NullToStringCsvConverter = "NullToStringCsvConverter"; + private const string BoolToBitCsvConverter = "BoolToBitCsvConverter"; + private const string ByteCsvConverter = "ByteCsvConverter"; + private const string ByteArrayCsvConverter = "ByteArrayCsvConverter"; public string GetCopyFromImpl(Query query, string queryTextConstant) { @@ -466,8 +472,7 @@ public string GetCopyFromImpl(Query query, string queryTextConstant) var {{optionsVar}} = new TypeConverterOptions { Formats = new[] { supportedDateTimeFormat } }; {{csvWriterVar}}.Context.TypeConverterOptionsCache.AddOptions({{optionsVar}}); {{csvWriterVar}}.Context.TypeConverterOptionsCache.AddOptions({{optionsVar}}); - {{GetBoolAndByteConverters(query).JoinByNewLine()}} - {{GetCsvNullConverters(query).JoinByNewLine()}} + {{GetCsvConverters(query).JoinByNewLine()}} await {{csvWriterVar}}.WriteRecordsAsync({{Variable.Args.AsVarName()}}); } @@ -492,33 +497,14 @@ public string GetCopyFromImpl(Query query, string queryTextConstant) """; } - private readonly ISet BoolAndByteTypes = new HashSet + private readonly ISet _boolAndByteTypes = new HashSet { "bool", "byte", "byte[]" }; - private ISet GetCsvNullConverters(Query query) - { - var nullConverterFn = Variable.NullConverterFn.AsVarName(); - var converters = new HashSet(); - foreach (var p in query.Params) - { - var csharpType = GetCsharpTypeWithoutNullableSuffix(p.Column, query); - if ( - !BoolAndByteTypes.Contains(csharpType) && - !IsSetType(p.Column) && - TypeExistsInQuery(csharpType, query)) - { - var nullableCsharpType = AddNullableSuffixIfNeeded(csharpType, false); - converters.Add($"{Variable.CsvWriter.AsVarName()}.Context.TypeConverterCache.AddConverter<{nullableCsharpType}>({nullConverterFn});"); - } - } - return converters; - } - - private ISet GetBoolAndByteConverters(Query query) + private ISet GetCsvConverters(Query query) { var csvWriterVar = Variable.CsvWriter.AsVarName(); return new HashSet() @@ -543,7 +529,27 @@ private ISet GetBoolAndByteConverters(Query query) ], TypeExistsInQuery("byte[]", query) ) - .AddRangeExcludeNulls(GetSetConverters(query)); + .AddRangeExcludeNulls(GetSetConverters(query)) + .AddRangeExcludeNulls(GetCsvNullConverters(query)); + } + + private ISet GetCsvNullConverters(Query query) + { + var nullConverterFn = Variable.NullConverterFn.AsVarName(); + var converters = new HashSet(); + foreach (var p in query.Params) + { + var csharpType = GetCsharpTypeWithoutNullableSuffix(p.Column, query); + if ( + !_boolAndByteTypes.Contains(csharpType) && + !IsSetDataType(p.Column) && + TypeExistsInQuery(csharpType, query)) + { + var nullableCsharpType = AddNullableSuffixIfNeeded(csharpType, false); + converters.Add($"{Variable.CsvWriter.AsVarName()}.Context.TypeConverterCache.AddConverter<{nullableCsharpType}>({nullConverterFn});"); + } + } + return converters; } private ISet GetSetConverters(Query query) @@ -551,25 +557,79 @@ private ISet GetSetConverters(Query query) var converters = new HashSet(); foreach (var p in query.Params) { - if (!IsSetType(p.Column)) + if (!IsSetDataType(p.Column)) continue; - var enumName = p.Column.Type.Name.ToModelName(GetColumnSchema(p.Column), DefaultSchema); + var enumName = EnumToModelName(p.Column); var csvWriterVar = Variable.CsvWriter.AsVarName(); - converters.Add($"{csvWriterVar}.Context.TypeConverterCache.AddConverter<{AddNullableSuffixIfNeeded($"{enumName}[]", true)}>(new Utils.{enumName}CsvConverter());"); - converters.Add($"{csvWriterVar}.Context.TypeConverterCache.AddConverter<{AddNullableSuffixIfNeeded($"{enumName}[]", false)}>(new Utils.{enumName}CsvConverter());"); + converters.Add($"{csvWriterVar}.Context.TypeConverterCache.AddConverter<{AddNullableSuffixIfNeeded($"HashSet<{enumName}>", true)}>(new Utils.{enumName}CsvConverter());"); + converters.Add($"{csvWriterVar}.Context.TypeConverterCache.AddConverter<{AddNullableSuffixIfNeeded($"HashSet<{enumName}>", false)}>(new Utils.{enumName}CsvConverter());"); } return converters; } - private static bool IsEnumOfTypeSet(Column column, Plugin.Enum enumType) + /* Enum methods */ + private static bool IsSetDataType(Column column, Enum enumType) { return column.Length > enumType.Vals.Select(v => v.Length).Sum(); } - public override string GetEnumTypeAsCsharpType(Column column, Plugin.Enum enumType) + private bool IsSetDataType(Column column) + { + var enumType = GetEnumType(column); + return enumType is not null && IsSetDataType(column, enumType); + } + + public override Func? GetWriterFn(Column column, Query query) + { + var csharpType = GetCsharpTypeWithoutNullableSuffix(column, query); + var writerFn = ColumnMappings.GetValueOrDefault(csharpType)?.WriterFn; + if (writerFn is not null) + return writerFn; + + if (GetEnumType(column) is { } enumType && IsSetDataType(column, enumType)) + return (el, notNull, isDapper) => + { + var stringJoinStmt = $"string.Join(\",\", {el})"; + var nullValue = isDapper ? "null" : "(object)DBNull.Value"; + return notNull + ? stringJoinStmt + : $"{el} != null ? {stringJoinStmt} : {nullValue}"; + }; + + static string DefaultWriterFn(string el, bool notNull, bool isDapper) => notNull ? el : $"{el} ?? (object)DBNull.Value"; + return Options.UseDapper ? null : DefaultWriterFn; + } + + protected override string GetEnumReader(Column column, int ordinal) + { + var enumName = EnumToModelName(column); + var readStmt = $"{Variable.Reader.AsVarName()}.GetString({ordinal})"; + return IsSetDataType(column) + ? $"{readStmt}.To{enumName}Set()" + : $"{readStmt}.To{enumName}()"; + } + + protected override Enum? GetEnumType(Column column) + { + if (!Enums.TryGetValue(string.Empty, value: out var enumsInSchema)) + return null; + return enumsInSchema.GetValueOrDefault(column.Type.Name); + } + + protected override string EnumToCsharpDataType(Column column) + { + var enumName = EnumToModelName(column); + return IsSetDataType(column) ? $"HashSet<{enumName}>" : enumName; + } + + public override string EnumToModelName(string _, Enum enumType) + { + return enumType.Name.ToPascalCase(); + } + + protected override string EnumToModelName(Column column) { - var enumName = column.Type.Name.ToModelName(GetColumnSchema(column), DefaultSchema); - return IsEnumOfTypeSet(column, enumType) ? $"{enumName}[]" : enumName; + return column.Type.Name.ToPascalCase(); } } \ No newline at end of file diff --git a/Drivers/NpgsqlDriver.cs b/Drivers/NpgsqlDriver.cs index a707ac46..7ca821f5 100644 --- a/Drivers/NpgsqlDriver.cs +++ b/Drivers/NpgsqlDriver.cs @@ -1,22 +1,22 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Plugin; using SqlcGenCsharp.Drivers.Generators; +using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; +using Enum = Plugin.Enum; namespace SqlcGenCsharp.Drivers; -public class NpgsqlDriver : DbDriver, IOne, IMany, IExec, IExecRows, IExecLastId, ICopyFrom +public sealed class NpgsqlDriver : EnumDbDriver, IOne, IMany, IExec, IExecRows, IExecLastId, ICopyFrom { public NpgsqlDriver( Options options, - string defaultSchema, - Dictionary> tables, - Dictionary> enums, + Catalog catalog, IList queries) : - base(options, defaultSchema, tables, enums, queries) + base(options, catalog, queries) { foreach (var columnMapping in ColumnMappings.Values) { @@ -26,12 +26,9 @@ public NpgsqlDriver( columnMapping.DbTypes.Add(dbTypeToAdd, dbType.Value); } } - CommonGen = new CommonGen(this); } - private CommonGen CommonGen { get; } - - public sealed override Dictionary ColumnMappings { get; } = + protected override Dictionary ColumnMappings { get; } = new() { /* Numeric data types */ @@ -79,7 +76,8 @@ public NpgsqlDriver( ["float"] = new( new() { - { "float4", new() } + { "float4", new() }, + { "real", new() } }, readerFn: ordinal => $"reader.GetFloat({ordinal})", readerArrayFn: ordinal => $"reader.GetFieldValue({ordinal})" @@ -194,7 +192,7 @@ public NpgsqlDriver( readerFn: ordinal => $"reader.GetFieldValue({ordinal})", readerArrayFn: ordinal => $"reader.GetFieldValue({ordinal})", usingDirective: "NpgsqlTypes", - sqlMapper: "RegisterNpgsqlTypeHandler();" + sqlMapper: "SqlMapper.AddTypeHandler(typeof(NpgsqlPoint), new NpgsqlTypeHandler());" ), ["NpgsqlLine"] = new( new() @@ -204,7 +202,7 @@ public NpgsqlDriver( readerFn: ordinal => $"reader.GetFieldValue({ordinal})", readerArrayFn: ordinal => $"reader.GetFieldValue({ordinal})", usingDirective: "NpgsqlTypes", - sqlMapper: "RegisterNpgsqlTypeHandler();" + sqlMapper: "SqlMapper.AddTypeHandler(typeof(NpgsqlLine), new NpgsqlTypeHandler());" ), ["NpgsqlLSeg"] = new( new() @@ -214,7 +212,7 @@ public NpgsqlDriver( readerFn: ordinal => $"reader.GetFieldValue({ordinal})", readerArrayFn: ordinal => $"reader.GetFieldValue({ordinal})", usingDirective: "NpgsqlTypes", - sqlMapper: "RegisterNpgsqlTypeHandler();" + sqlMapper: "SqlMapper.AddTypeHandler(typeof(NpgsqlLSeg), new NpgsqlTypeHandler());" ), ["NpgsqlBox"] = new( new() @@ -224,7 +222,7 @@ public NpgsqlDriver( readerFn: ordinal => $"reader.GetFieldValue({ordinal})", readerArrayFn: ordinal => $"reader.GetFieldValue({ordinal})", usingDirective: "NpgsqlTypes", - sqlMapper: "RegisterNpgsqlTypeHandler();" + sqlMapper: "SqlMapper.AddTypeHandler(typeof(NpgsqlBox), new NpgsqlTypeHandler());" ), ["NpgsqlPath"] = new( new() @@ -234,7 +232,7 @@ public NpgsqlDriver( readerFn: ordinal => $"reader.GetFieldValue({ordinal})", readerArrayFn: ordinal => $"reader.GetFieldValue({ordinal})", usingDirective: "NpgsqlTypes", - sqlMapper: "RegisterNpgsqlTypeHandler();" + sqlMapper: "SqlMapper.AddTypeHandler(typeof(NpgsqlPath), new NpgsqlTypeHandler());" ), ["NpgsqlPolygon"] = new( new() @@ -244,7 +242,7 @@ public NpgsqlDriver( readerFn: ordinal => $"reader.GetFieldValue({ordinal})", readerArrayFn: ordinal => $"reader.GetFieldValue({ordinal})", usingDirective: "NpgsqlTypes", - sqlMapper: "RegisterNpgsqlTypeHandler();" + sqlMapper: "SqlMapper.AddTypeHandler(typeof(NpgsqlPolygon), new NpgsqlTypeHandler());" ), ["NpgsqlCircle"] = new( new() @@ -254,7 +252,7 @@ public NpgsqlDriver( readerFn: ordinal => $"reader.GetFieldValue({ordinal})", readerArrayFn: ordinal => $"reader.GetFieldValue({ordinal})", usingDirective: "NpgsqlTypes", - sqlMapper: "RegisterNpgsqlTypeHandler();" + sqlMapper: "SqlMapper.AddTypeHandler(typeof(NpgsqlCircle), new NpgsqlTypeHandler());" ), /* Network data types */ @@ -266,7 +264,7 @@ public NpgsqlDriver( readerFn: ordinal => $"reader.GetFieldValue({ordinal})", readerArrayFn: ordinal => $"reader.GetFieldValue({ordinal})", usingDirective: "NpgsqlTypes", - sqlMapper: "RegisterNpgsqlTypeHandler();" + sqlMapper: "SqlMapper.AddTypeHandler(typeof(NpgsqlCidr), new NpgsqlTypeHandler());" ), ["IPAddress"] = new( new() @@ -276,7 +274,7 @@ public NpgsqlDriver( readerFn: ordinal => $"reader.GetFieldValue({ordinal})", readerArrayFn: ordinal => $"reader.GetFieldValue({ordinal})", usingDirective: "System.Net", - sqlMapper: "RegisterNpgsqlTypeHandler();" + sqlMapper: "SqlMapper.AddTypeHandler(typeof(IPAddress), new NpgsqlTypeHandler());" ), ["PhysicalAddress"] = new( new() @@ -286,7 +284,29 @@ public NpgsqlDriver( readerFn: ordinal => $"reader.GetFieldValue({ordinal})", readerArrayFn: ordinal => $"reader.GetFieldValue({ordinal})", usingDirective: "System.Net.NetworkInformation", - sqlMapper: "RegisterNpgsqlTypeHandler();" + sqlMapper: "SqlMapper.AddTypeHandler(typeof(PhysicalAddress), new NpgsqlTypeHandler());" + ), + + /* Full-text search data types */ + ["NpgsqlTsQuery"] = new( + new() + { + { "tsquery", new() } + }, + readerFn: ordinal => $"reader.GetFieldValue({ordinal})", + readerArrayFn: ordinal => $"reader.GetFieldValue({ordinal})", + usingDirective: "NpgsqlTypes", + sqlMapper: "SqlMapper.AddTypeHandler(typeof(NpgsqlTsQuery), new NpgsqlTypeHandler());" + ), + ["NpgsqlTsVector"] = new( + new() + { + { "tsvector", new() } + }, + readerFn: ordinal => $"reader.GetFieldValue({ordinal})", + readerArrayFn: ordinal => $"reader.GetFieldValue({ordinal})", + usingDirective: "NpgsqlTypes", + sqlMapper: "SqlMapper.AddTypeHandler(typeof(NpgsqlTsVector), new NpgsqlTypeHandler());" ), /* Other data types */ @@ -325,7 +345,7 @@ public NpgsqlDriver( public override string TransactionClassName => "NpgsqlTransaction"; - protected const string XmlDocumentTypeHandler = + private const string XmlDocumentTypeHandler = """ private class XmlDocumentTypeHandler : SqlMapper.TypeHandler { @@ -347,6 +367,38 @@ public override void SetValue(IDbDataParameter parameter, XmlDocument value) } """; + public MemberDeclarationSyntax OneDeclare(string queryTextConstant, string argInterface, + string returnInterface, Query query) + { + return new OneDeclareGen(this).Generate(queryTextConstant, argInterface, returnInterface, query); + } + + public MemberDeclarationSyntax ExecDeclare(string queryTextConstant, string argInterface, Query query) + { + return new ExecDeclareGen(this).Generate(queryTextConstant, argInterface, query); + } + + public MemberDeclarationSyntax ManyDeclare(string queryTextConstant, string argInterface, + string returnInterface, Query query) + { + return new ManyDeclareGen(this).Generate(queryTextConstant, argInterface, returnInterface, query); + } + + public MemberDeclarationSyntax ExecRowsDeclare(string queryTextConstant, string argInterface, Query query) + { + return new ExecRowsDeclareGen(this).Generate(queryTextConstant, argInterface, query); + } + + public MemberDeclarationSyntax ExecLastIdDeclare(string queryTextConstant, string argInterface, Query query) + { + return new ExecLastIdDeclareGen(this).Generate(queryTextConstant, argInterface, query); + } + + public MemberDeclarationSyntax CopyFromDeclare(string queryTextConstant, string argInterface, Query query) + { + return new CopyFromDeclareGen(this).Generate(queryTextConstant, argInterface, query); + } + public override ISet GetUsingDirectivesForQueries() { return base.GetUsingDirectivesForQueries().AddRangeExcludeNulls( @@ -360,7 +412,8 @@ public override ISet GetUsingDirectivesForModels() { return base.GetUsingDirectivesForModels().AddRangeExcludeNulls( [ - "System" + "System", + "System.Collections.Generic" ]); } @@ -405,13 +458,7 @@ public override void SetValue(IDbDataParameter parameter, T{{optionalDotnetCoreN parameter.Value = value; } } - """)!, - ParseMemberDeclaration($$""" - private static void RegisterNpgsqlTypeHandler(){{optionalDotnetCoreSuffix}} - { - SqlMapper.AddTypeHandler(typeof(T), new NpgsqlTypeHandler()); - } - """)!, + """)! ]; } @@ -421,6 +468,7 @@ public override ConnectionGenCommands EstablishConnection(Query query) var connectionVar = Variable.Connection.AsVarName(); var embedTableExists = query.Columns.Any(c => c.EmbedTable is not null); var useOpenConnection = query.Cmd == ":copyfrom" || (Options.UseDapper && !embedTableExists); + var optionalNotNullVerify = Options.DotnetFramework.IsDotnetCore() ? "!" : string.Empty; return useOpenConnection ? new ConnectionGenCommands( @@ -428,7 +476,7 @@ public override ConnectionGenCommands EstablishConnection(Query query) string.Empty ) : new ConnectionGenCommands( - $"var {connectionVar} = NpgsqlDataSource.Create({connectionStringVar})", + $"var {connectionVar} = NpgsqlDataSource.Create({connectionStringVar}{optionalNotNullVerify})", string.Empty ); } @@ -460,38 +508,6 @@ string GetCopyCommand() } } - public MemberDeclarationSyntax OneDeclare(string queryTextConstant, string argInterface, - string returnInterface, Query query) - { - return new OneDeclareGen(this).Generate(queryTextConstant, argInterface, returnInterface, query); - } - - public MemberDeclarationSyntax ExecDeclare(string queryTextConstant, string argInterface, Query query) - { - return new ExecDeclareGen(this).Generate(queryTextConstant, argInterface, query); - } - - public MemberDeclarationSyntax ManyDeclare(string queryTextConstant, string argInterface, - string returnInterface, Query query) - { - return new ManyDeclareGen(this).Generate(queryTextConstant, argInterface, returnInterface, query); - } - - public MemberDeclarationSyntax ExecRowsDeclare(string queryTextConstant, string argInterface, Query query) - { - return new ExecRowsDeclareGen(this).Generate(queryTextConstant, argInterface, query); - } - - public MemberDeclarationSyntax ExecLastIdDeclare(string queryTextConstant, string argInterface, Query query) - { - return new ExecLastIdDeclareGen(this).Generate(queryTextConstant, argInterface, query); - } - - public MemberDeclarationSyntax CopyFromDeclare(string queryTextConstant, string argInterface, Query query) - { - return new CopyFromDeclareGen(this).Generate(queryTextConstant, argInterface, query); - } - public string GetCopyFromImpl(Query query, string queryTextConstant) { var (establishConnection, connectionOpen) = EstablishConnection(query); @@ -522,7 +538,7 @@ string AddRowsToCopyCommand() { var typeOverride = GetColumnDbTypeOverride(p.Column); var param = $"{rowVar}.{p.Column.Name.ToPascalCase()}"; - var writerFn = CommonGen.GetWriterFn(p.Column, query); + var writerFn = GetWriterFn(p.Column, query); var paramToWrite = writerFn is null ? param : writerFn(param, p.Column.NotNull, false); var partialStmt = $"await {writerVar}.WriteAsync({paramToWrite}"; return typeOverride is null @@ -539,4 +555,72 @@ string AddRowsToCopyCommand() """; } } + + public override Func? GetWriterFn(Column column, Query query) + { + var csharpType = GetCsharpTypeWithoutNullableSuffix(column, query); + var writerFn = ColumnMappings.GetValueOrDefault(csharpType)?.WriterFn; + if (writerFn is not null) + return writerFn; + + if (GetEnumType(column) is not null) + { + return (el, notNull, isDapper) => + { + var enumToStringStmt = $"{el}.Value.Stringify()"; + var nullValue = isDapper ? "null" : "(object)DBNull.Value"; + return notNull + ? enumToStringStmt + : $"{el} != null ? {enumToStringStmt} : {nullValue}"; + }; + } + + static string DefaultWriterFn(string el, bool notNull, bool isDapper) => notNull ? el : $"{el} ?? (object)DBNull.Value"; + return Options.UseDapper ? null : DefaultWriterFn; + } + + private static (string, string) GetEnumSchemaAndName(Column column) + { + var schemaName = column.Type.Schema; + var enumName = column.Type.Name; + if (schemaName == string.Empty && enumName.Contains('.')) + { + var schemaAndEnum = enumName.Split('.'); + schemaName = schemaAndEnum[0]; + enumName = schemaAndEnum[1]; + } + return (schemaName, enumName); + } + + protected override string GetEnumReader(Column column, int ordinal) + { + var enumName = EnumToModelName(column); + var readStmt = $"{Variable.Reader.AsVarName()}.GetString({ordinal})"; + return $"{readStmt}.To{enumName}()"; + } + + protected override Enum? GetEnumType(Column column) + { + var (schemaName, enumName) = GetEnumSchemaAndName(column); + if (!Enums.TryGetValue(schemaName, value: out var enumsInSchema)) + return null; + return enumsInSchema.GetValueOrDefault(enumName); + } + + protected override string EnumToCsharpDataType(Column column) + { + var (schemaName, enumName) = GetEnumSchemaAndName(column); + return $"{schemaName}.{enumName}".ToPascalCase(); + } + + public override string EnumToModelName(string schemaName, Enum enumType) + { + return $"{schemaName}.{enumType.Name}".ToPascalCase(); + } + + protected override string EnumToModelName(Column column) + { + var (schemaName, enumName) = GetEnumSchemaAndName(column); + return $"{schemaName}.{enumName}".ToPascalCase(); + } } \ No newline at end of file diff --git a/Drivers/QueryAnnotations.cs b/Drivers/QueryAnnotations.cs index 4bd347ee..8975a544 100644 --- a/Drivers/QueryAnnotations.cs +++ b/Drivers/QueryAnnotations.cs @@ -15,7 +15,6 @@ public interface IExec { MemberDeclarationSyntax ExecDeclare(string queryTextConstant, string argInterface, Query query); } - public interface IExecRows { MemberDeclarationSyntax ExecRowsDeclare(string queryTextConstant, string argInterface, Query query); diff --git a/Drivers/SqliteDriver.cs b/Drivers/SqliteDriver.cs index d8bbeacc..9997a8e1 100644 --- a/Drivers/SqliteDriver.cs +++ b/Drivers/SqliteDriver.cs @@ -1,7 +1,6 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Plugin; using SqlcGenCsharp.Drivers.Generators; -using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; @@ -9,15 +8,13 @@ namespace SqlcGenCsharp.Drivers; -public partial class SqliteDriver( +public sealed partial class SqliteDriver( Options options, - string defaultSchema, - Dictionary> tables, - Dictionary> enums, + Catalog catalog, IList queries) : - DbDriver(options, defaultSchema, tables, enums, queries), IOne, IMany, IExec, IExecRows, IExecLastId, ICopyFrom + DbDriver(options, catalog, queries), IOne, IMany, IExec, IExecRows, IExecLastId, ICopyFrom { - public override Dictionary ColumnMappings { get; } = + protected override Dictionary ColumnMappings { get; } = new() { ["byte[]"] = new( @@ -82,81 +79,28 @@ public override ISet GetUsingDirectivesForUtils() ); } - public override MemberDeclarationSyntax[] GetMemberDeclarationsForUtils() - { - var memberDeclarations = base - .GetMemberDeclarationsForUtils() - .AddRangeIf([ParseMemberDeclaration(TransformQueryForSliceArgsImpl)!], SliceQueryExists()); - - if (!CopyFromQueryExists()) - return memberDeclarations.ToArray(); - - return memberDeclarations - .Append(ParseMemberDeclaration(""" - private static readonly Regex ValuesRegex = new Regex(@"VALUES\s*\((?[^)]*)\)", RegexOptions.IgnoreCase); - """)!) - .Append(ParseMemberDeclaration(""" - public static string TransformQueryForSqliteBatch(string originalSql, int cntRecords) - { - var match = ValuesRegex.Match(originalSql); - if (!match.Success) - throw new ArgumentException("The query does not contain a valid VALUES clause."); - - var valuesParams = match.Groups["params"].Value - .Split(',') - .Select(p => p.Trim()) - .ToList(); - var batchRows = Enumerable.Range(0, cntRecords) - .Select(i => "(" + string.Join(", ", valuesParams.Select(p => $"{p}{i}")) + ")"); - - var batchValuesClause = "VALUES " + string.Join(",\n", batchRows); - return ValuesRegex.Replace(originalSql, batchValuesClause); - } - """)!) - .ToArray(); - } - - public override ConnectionGenCommands EstablishConnection(Query query) - { - return new ConnectionGenCommands( - $"var {Variable.Connection.AsVarName()} = new SqliteConnection({Variable.ConnectionString.AsPropertyName()})", - $"await {Variable.Connection.AsVarName()}.OpenAsync()" - ); - } - - public override string CreateSqlCommand(string sqlTextConstant) - { - return $"var {Variable.Command.AsVarName()} = new SqliteCommand({sqlTextConstant}, {Variable.Connection.AsVarName()})"; - } - - public override string TransformQueryText(Query query) - { - // Regex to detect numbered parameters like ?1, ?2 - var areArgumentsNumbered = new Regex(@"\?\d+\b").IsMatch(query.Text); - var queryText = query.Text; + private const string ValuesRegex = """ + private static readonly Regex ValuesRegex = new Regex(@"VALUES\s*\((?[^)]*)\)", RegexOptions.IgnoreCase); + """; - if (areArgumentsNumbered) + private const string TransformQueryForBatch = """ + public static string TransformQueryForSqliteBatch(string originalSql, int cntRecords) { - // For numbered parameters, we replace all occurrences of each parameter number. - foreach (var p in query.Params) - { - var column = GetColumnFromParam(p, query); - var regex = new Regex($@"\?{p.Number}\b"); - queryText = regex.Replace(queryText, $"@{column.Name}"); - } - } - else - { - // For positional '?' parameters, we must replace them one by one in order. - var regex = new Regex(@"\?"); - foreach (var p in query.Params) - { - var column = GetColumnFromParam(p, query); - queryText = regex.Replace(queryText, $"@{column.Name}", 1); - } + var match = ValuesRegex.Match(originalSql); + if (!match.Success) + throw new ArgumentException("The query does not contain a valid VALUES clause."); + + var valuesParams = match.Groups["params"].Value + .Split(',') + .Select(p => p.Trim()) + .ToList(); + var batchRows = Enumerable.Range(0, cntRecords) + .Select(i => "(" + string.Join(", ", valuesParams.Select(p => $"{p}{i}")) + ")"); + + var batchValuesClause = "VALUES " + string.Join(",\n", batchRows); + return ValuesRegex.Replace(originalSql, batchValuesClause); } - return queryText; - } + """; public MemberDeclarationSyntax OneDeclare(string queryTextConstant, string argInterface, string returnInterface, Query query) @@ -190,6 +134,57 @@ public MemberDeclarationSyntax CopyFromDeclare(string queryTextConstant, string return new CopyFromDeclareGen(this).Generate(queryTextConstant, argInterface, query); } + public override MemberDeclarationSyntax[] GetMemberDeclarationsForUtils() + { + return base + .GetMemberDeclarationsForUtils() + .AddRangeIf([ + ParseMemberDeclaration(TransformQueryForSliceArgsImpl)! + ], SliceQueryExists()) + .AddRangeIf([ + ParseMemberDeclaration(ValuesRegex)!, + ParseMemberDeclaration(TransformQueryForBatch)! + ], CopyFromQueryExists()) + .ToArray(); + } + + public override ConnectionGenCommands EstablishConnection(Query query) + { + return new( + $"var {Variable.Connection.AsVarName()} = new SqliteConnection({Variable.ConnectionString.AsPropertyName()})", + $"await {Variable.Connection.AsVarName()}.OpenAsync()" + ); + } + + public override string CreateSqlCommand(string sqlTextConstant) + { + return $"var {Variable.Command.AsVarName()} = new SqliteCommand({sqlTextConstant}, {Variable.Connection.AsVarName()})"; + } + + public override string TransformQueryText(Query query) + { + var queryText = query.Text; + var areArgumentsNumbered = NumberedArgumentsRegex().IsMatch(queryText); + + foreach (var p in query.Params) + { + var column = GetColumnFromParam(p, query); + queryText = areArgumentsNumbered + // For numbered parameters, we replace all occurrences of each parameter number. + ? new Regex($@"\?{p.Number}\b").Replace(queryText, $"@{column.Name}") + // For positional '?' parameters, we must replace them one by one in order. + : QueryParamRegex().Replace(queryText, $"@{column.Name}", 1); + } + return queryText; + } + + // Regex to detect numbered parameters like ?1, ?2 + [GeneratedRegex(@"\?\d+\b")] + private static partial Regex NumberedArgumentsRegex(); + + [GeneratedRegex(@"\?")] + private static partial Regex QueryParamRegex(); + public string GetCopyFromImpl(Query query, string queryTextConstant) { var sqlTextVar = Variable.TransformedSql.AsVarName(); @@ -222,7 +217,7 @@ string AddParametersToCommand() var nullParamCast = p.Column.NotNull ? string.Empty : " ?? (object)DBNull.Value"; var addParamToCommand = $$""" {{commandVar}}.Parameters.AddWithValue($"@{{p.Column.Name}}{i}", {{argsVar}}[i].{{param}}{{nullParamCast}}); - """; + """; return addParamToCommand; }).JoinByNewLine(); diff --git a/Extensions/StringExtensions.cs b/Extensions/StringExtensions.cs index 4594c8f9..40ea9425 100644 --- a/Extensions/StringExtensions.cs +++ b/Extensions/StringExtensions.cs @@ -1,32 +1,42 @@ +using System.Globalization; +using System.Text; using System.Text.RegularExpressions; namespace SqlcGenCsharp; public static partial class StringExtensions { + [GeneratedRegex(@"[A-Za-z0-9]+")] + private static partial Regex WordRegex(); + + [GeneratedRegex(@"[^A-Za-z0-9]+")] + private static partial Regex NoWordRegex(); + public static string ToPascalCase(this string value) { - var invalidCharsRgx = InvalidCharsRegex(); - var whiteSpace = WhiteSpaceRegex(); - var startsWithLowerCaseChar = StartsWithLowerCaseCharRegex(); - var firstCharFollowedByUpperCasesOnly = FirstCharFollowedByUpperCasesOnlyRegex(); - var lowerCaseNextToNumber = LowerCaseNextToNumberRegex(); - var upperCaseInside = UpperCaseInsideRegex(); - - // replace white spaces with undescore, then replace all invalid chars with empty string - var pascalCase = invalidCharsRgx.Replace(whiteSpace.Replace(value, "_"), string.Empty) - // split by underscores - .Split(["_"], StringSplitOptions.RemoveEmptyEntries) - // set first letter to uppercase - .Select(w => startsWithLowerCaseChar.Replace(w, m => m.Value.ToUpper())) - // replace second and all following upper case letters to lower if there is no next lower (ABC -> Abc) - .Select(w => firstCharFollowedByUpperCasesOnly.Replace(w, m => m.Value.ToLower())) - // set upper case the first lower case following a number (Ab9cd -> Ab9Cd) - .Select(w => lowerCaseNextToNumber.Replace(w, m => m.Value.ToUpper())) - // lower second and next upper case letters except the last if it follows by any lower (ABcDEf -> AbcDef) - .Select(w => upperCaseInside.Replace(w, m => m.Value.ToLower())); - - return string.Concat(pascalCase); + if (string.IsNullOrWhiteSpace(value)) + return string.Empty; + string cleaned = NoWordRegex().Replace(value, " "); + + var sb = new StringBuilder(); + foreach (Match match in WordRegex().Matches(cleaned)) + { + var word = match.Value; + if (word.Length == 0) + continue; + + if (word.Length == 1) + { + sb.Append(CultureInfo.InvariantCulture.TextInfo.ToUpper(word)); + continue; + } + + sb.Append(char.ToUpperInvariant(word[0])); + if (word.Length > 1) + sb.Append(word[1..]); + } + + return sb.ToString(); } public static string ToCamelCase(this string value) @@ -45,17 +55,4 @@ public static string AppendSemicolonUnlessEmpty(this string input) { return input == string.Empty ? "" : $"{input};"; } - - [GeneratedRegex("[^_a-zA-Z0-9]")] - private static partial Regex InvalidCharsRegex(); - [GeneratedRegex(@"(?<=\s)")] - private static partial Regex WhiteSpaceRegex(); - [GeneratedRegex("^[a-z]")] - private static partial Regex StartsWithLowerCaseCharRegex(); - [GeneratedRegex("(?<=[A-Z])[A-Z0-9]+$")] - private static partial Regex FirstCharFollowedByUpperCasesOnlyRegex(); - [GeneratedRegex("(?<=[0-9])[a-z]")] - private static partial Regex LowerCaseNextToNumberRegex(); - [GeneratedRegex("(?<=[A-Z])[A-Z]+?((?=[A-Z][a-z])|(?=[0-9]))")] - private static partial Regex UpperCaseInsideRegex(); } \ No newline at end of file diff --git a/RequestRunner/App.cs b/RequestRunner/App.cs index 169ab65b..4caf0b3d 100644 --- a/RequestRunner/App.cs +++ b/RequestRunner/App.cs @@ -10,7 +10,10 @@ public static class App public static async Task Main(string[] requestFiles) { foreach (var requestFile in requestFiles) + { await ProcessRequestFile(requestFile); + break; + } } private static async Task ProcessRequestFile(string requestFile) diff --git a/docs/04_Postgres.md b/docs/04_Postgres.md index 2f980017..fa0389a4 100644 --- a/docs/04_Postgres.md +++ b/docs/04_Postgres.md @@ -46,7 +46,7 @@ we consider support for the different data types separately for batch inserts an | varchar, character varying | ✅ | ✅ | | text | ✅ | ✅ | | bytea | ✅ | ✅ | -| 2-dimensional arrays (e.g text[],int[]) | ✅ | ⌠| +| 2-dimensional arrays (e.g text[],int[]) | ✅ | ✅ | | money | ✅ | ✅ | | point | ✅ | ✅ | | line | ✅ | ✅ | @@ -58,19 +58,33 @@ we consider support for the different data types separately for batch inserts an | cidr | ✅ | ✅ | | inet | ✅ | ✅ | | macaddr | ✅ | ✅ | -| macaddr8 | ✅ | ⌠| -| tsvector | ⌠| ⌠| -| tsquery | ⌠| ⌠| +| macaddr8 | ✅ | âš ï¸ | +| tsvector | ✅ | ⌠| +| tsquery | ✅ | ⌠| | uuid | ✅ | ✅ | -| json | ✅ | ⌠| -| jsonb | ✅ | ⌠| -| jsonpath | ✅ | ⌠| -| xml | ✅ | ⌠| -| enum | ⌠| ⌠| +| json | ✅ | âš ï¸ | +| jsonb | ✅ | âš ï¸ | +| jsonpath | ✅ | âš ï¸ | +| xml | ✅ | âš ï¸ | +| enum | ✅ | âš ï¸ | *** `time with time zone` is not useful and not recommended to use by Postgres themselves - see [here](https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-DATETIME) - so we decided not to implement support for it. +*** Some data types require conversion in the INSERT statement, and SQLC disallows argument conversion in queries with `:copyfrom` annotation, +which are used for batch inserts. These are the data types that require this conversion: +1. `macaddr8` +2. `json` +3. `jsonb` +4. `jsonpath` +5. `xml` +6. `enum` + +An example of this conversion: +```sql +INSERT INTO tab1 (json_field) VALUES (sqlc.narg('json_field')::json); +``` + diff --git a/docs/ExamplesDocGen/Program.cs b/docs/ExamplesDocGen/Program.cs index ce94ec83..2538b48d 100644 --- a/docs/ExamplesDocGen/Program.cs +++ b/docs/ExamplesDocGen/Program.cs @@ -26,11 +26,10 @@ public static void Main() private static string ParseConfigNode(YamlNode node) { var item = (YamlMappingNode)node; - var queryFiles = item["queries"].ToString(); var codegenArray = (YamlSequenceNode)item["codegen"]; - var firstCodegenObj = (YamlMappingNode)codegenArray.Children[0]; + var codegenObj = (YamlMappingNode)codegenArray.Children[0]; - var outputDirectory = firstCodegenObj["out"].ToString(); + var outputDirectory = codegenObj["out"].ToString(); var projectName = outputDirectory.Replace("examples/", ""); var testProject = projectName.Contains("Legacy") ? "EndToEndTestsLegacy" : "EndToEndTests"; var testClassName = projectName.Replace("Example", "Tester"); @@ -38,7 +37,7 @@ private static string ParseConfigNode(YamlNode node) testClassName = testClassName.Replace("Legacy", ""); var yamlStream = new YamlStream(); - var yamlDocument = new YamlDocument(firstCodegenObj["options"]); + var yamlDocument = new YamlDocument(codegenObj["options"]); yamlStream.Documents.Add(yamlDocument); using var optionsWriter = new StringWriter(); yamlStream.Save(optionsWriter, false); @@ -49,7 +48,7 @@ private static string ParseConfigNode(YamlNode node) {projectName.Replace("Example", "")} ## Engine `{item["engine"]}`: [{projectName}]({outputDirectory}) - ### [Schema]({item["schema"]}) | [Queries]({queryFiles}) | [End2End Test](end2end/{testProject}/{testClassName}.cs) + ### [Schema]({item["schema"][0]}) | [Queries]({item["queries"][0]}) | [End2End Test](end2end/{testProject}/{testClassName}.cs) ### Config ```yaml {optionsStr}``` diff --git a/end2end/EndToEndCommon/EndToEndCommon.cs b/end2end/EndToEndCommon/EndToEndCommon.cs index d926542e..d2866625 100644 --- a/end2end/EndToEndCommon/EndToEndCommon.cs +++ b/end2end/EndToEndCommon/EndToEndCommon.cs @@ -9,7 +9,10 @@ namespace EndToEndTests public static class EndToEndCommon { private const string EnvFile = ".env"; - private const string SchemaFile = "sqlite.schema.sql"; + private static readonly string[] SchemaFiles = new string[] { + "authors.sqlite.schema.sql", + "types.sqlite.schema.sql" + }; public const string PostgresConnectionStringEnv = "POSTGRES_CONNECTION_STRING"; public const string MySqlConnectionStringEnv = "MYSQL_CONNECTION_STRING"; @@ -20,8 +23,7 @@ public static void SetUp() if (File.Exists(EnvFile)) DotEnv.Load(options: new DotEnvOptions(envFilePaths: new[] { EnvFile })); RemoveExistingSqliteDb(); - if (File.Exists(SchemaFile)) - InitSqliteDb(); + InitSqliteDb(); } public static void TearDown() @@ -49,15 +51,21 @@ private static void RemoveExistingSqliteDb() } private static void InitSqliteDb() { - var schemaSql = File.ReadAllText(SchemaFile); var connectionString = Environment.GetEnvironmentVariable(EndToEndCommon.SqliteConnectionStringEnv); using (var connection = new SqliteConnection(connectionString)) { connection.Open(); - using (var command = connection.CreateCommand()) + foreach (var schemaFile in SchemaFiles) { - command.CommandText = schemaSql; - command.ExecuteNonQuery(); + if (!File.Exists(schemaFile)) + continue; + + var schemaSql = File.ReadAllText(schemaFile); + using (var command = connection.CreateCommand()) + { + command.CommandText = schemaSql; + command.ExecuteNonQuery(); + } } } } diff --git a/end2end/EndToEndCommon/EndToEndCommon.csproj b/end2end/EndToEndCommon/EndToEndCommon.csproj index 1883febe..e254c45c 100644 --- a/end2end/EndToEndCommon/EndToEndCommon.csproj +++ b/end2end/EndToEndCommon/EndToEndCommon.csproj @@ -5,16 +5,6 @@ EndToEndTests - - - Always - - - Always - sqlite.schema.sql - - - diff --git a/end2end/EndToEndScaffold/Config.cs b/end2end/EndToEndScaffold/Config.cs index 9fcca5fb..f87f7d72 100644 --- a/end2end/EndToEndScaffold/Config.cs +++ b/end2end/EndToEndScaffold/Config.cs @@ -35,58 +35,174 @@ public enum KnownTestType SqliteTransactionRollback, // Postgres + PostgresTransaction, + PostgresTransactionRollback, + ArrayAsParam, + MultipleArraysAsParams, + PostgresDataTypesOverride, + PostgresInvalidJson, + PostgresInvalidXml, + + // Data types PostgresStringDataTypes, PostgresIntegerDataTypes, PostgresFloatingPointDataTypes, PostgresDateTimeDataTypes, PostgresArrayDataTypes, - PostgresDataTypesOverride, PostgresGuidDataTypes, + PostgresFullTextSearchDataTypes, + PostgresNetworkDataTypes, + PostgresGeoDataTypes, + PostgresJsonDataTypes, + PostgresXmlDataTypes, + PostgresEnumDataType, + // :copyfrom (Batch) PostgresStringCopyFrom, - PostgresTransaction, - PostgresTransactionRollback, PostgresIntegerCopyFrom, PostgresFloatingPointCopyFrom, PostgresDateTimeCopyFrom, PostgresGuidCopyFrom, PostgresNetworkCopyFrom, PostgresArrayCopyFrom, - PostgresGeoDataTypes, PostgresGeoCopyFrom, - PostgresNetworkDataTypes, - PostgresJsonDataTypes, - PostgresInvalidJson, - PostgresXmlDataTypes, - - ArrayAsParam, - MultipleArraysAsParams, // MySql - MySqlStringDataTypes, - MySqlIntegerDataTypes, MySqlTransaction, MySqlTransactionRollback, + MySqlDataTypesOverride, + MySqlScopedSchemaEnum, + MySqlInvalidJson, + + // Data types + MySqlStringDataTypes, + MySqlIntegerDataTypes, MySqlFloatingPointDataTypes, MySqlDateTimeDataTypes, MySqlBinaryDataTypes, MySqlEnumDataType, - MySqlDataTypesOverride, - MySqlScopedSchemaEnum, MySqlJsonDataTypes, - MySqlJsonCopyFrom, - MySqlInvalidJson, + // :copyfrom (Batch) MySqlStringCopyFrom, MySqlIntegerCopyFrom, MySqlFloatingPointCopyFrom, MySqlDateTimeCopyFrom, MySqlBinaryCopyFrom, - MySqlEnumCopyFrom + MySqlEnumCopyFrom, + MySqlJsonCopyFrom } internal static class Config { + private static readonly SortedSet _mysqlTestTypes = [ + KnownTestType.MySqlTransaction, + KnownTestType.MySqlTransactionRollback, + KnownTestType.MySqlDataTypesOverride, + KnownTestType.MySqlScopedSchemaEnum, + KnownTestType.MySqlInvalidJson, + + // query annotations + KnownTestType.One, + KnownTestType.Many, + KnownTestType.Exec, + KnownTestType.ExecRows, + KnownTestType.ExecLastId, + + // macros + KnownTestType.JoinEmbed, + KnownTestType.SelfJoinEmbed, + KnownTestType.Slice, + KnownTestType.MultipleSlices, + KnownTestType.NargNull, + KnownTestType.NargNotNull, + + // Data types + KnownTestType.MySqlStringDataTypes, + KnownTestType.MySqlIntegerDataTypes, + KnownTestType.MySqlFloatingPointDataTypes, + KnownTestType.MySqlDateTimeDataTypes, + KnownTestType.MySqlBinaryDataTypes, + KnownTestType.MySqlEnumDataType, + KnownTestType.MySqlJsonDataTypes, + + // :copyfrom (Batch) + KnownTestType.MySqlJsonCopyFrom, + KnownTestType.MySqlStringCopyFrom, + KnownTestType.MySqlIntegerCopyFrom, + KnownTestType.MySqlFloatingPointCopyFrom, + KnownTestType.MySqlDateTimeCopyFrom, + KnownTestType.MySqlBinaryCopyFrom, + KnownTestType.MySqlEnumCopyFrom + ]; + + private static readonly SortedSet _postgresTestTypes = [ + KnownTestType.PostgresTransaction, + KnownTestType.PostgresTransactionRollback, + KnownTestType.ArrayAsParam, + KnownTestType.MultipleArraysAsParams, + KnownTestType.PostgresInvalidJson, + KnownTestType.PostgresInvalidXml, + + // query annotations + KnownTestType.One, + KnownTestType.Many, + KnownTestType.Exec, + KnownTestType.ExecRows, + KnownTestType.ExecLastId, + + // macros + KnownTestType.JoinEmbed, + KnownTestType.SelfJoinEmbed, + KnownTestType.NargNull, + KnownTestType.NargNotNull, + + // Data types + KnownTestType.PostgresStringDataTypes, + KnownTestType.PostgresIntegerDataTypes, + KnownTestType.PostgresFloatingPointDataTypes, + KnownTestType.PostgresDateTimeDataTypes, + KnownTestType.PostgresGuidDataTypes, + KnownTestType.PostgresArrayDataTypes, + KnownTestType.PostgresGeoDataTypes, + KnownTestType.PostgresDataTypesOverride, + KnownTestType.PostgresJsonDataTypes, + KnownTestType.PostgresNetworkDataTypes, + KnownTestType.PostgresXmlDataTypes, + KnownTestType.PostgresEnumDataType, + KnownTestType.PostgresFullTextSearchDataTypes, + + // :copyfrom (Batch) + KnownTestType.PostgresGeoCopyFrom, + KnownTestType.PostgresStringCopyFrom, + KnownTestType.PostgresIntegerCopyFrom, + KnownTestType.PostgresFloatingPointCopyFrom, + KnownTestType.PostgresDateTimeCopyFrom, + KnownTestType.PostgresGuidCopyFrom, + KnownTestType.PostgresArrayCopyFrom, + KnownTestType.PostgresNetworkCopyFrom + ]; + + private static readonly SortedSet _sqliteTestTypes = [ + KnownTestType.One, + KnownTestType.Many, + KnownTestType.Exec, + KnownTestType.ExecRows, + KnownTestType.ExecLastId, + KnownTestType.JoinEmbed, + KnownTestType.SelfJoinEmbed, + KnownTestType.Slice, + KnownTestType.MultipleSlices, + KnownTestType.NargNull, + KnownTestType.NargNotNull, + KnownTestType.SqliteTransaction, + KnownTestType.SqliteTransactionRollback, + KnownTestType.SqliteDataTypes, + KnownTestType.SqliteCopyFrom, + KnownTestType.SqliteDataTypesOverride, + KnownTestType.SqliteMultipleNamedParam + ]; + public static Dictionary FilesToGenerate { get; } = new() { @@ -95,125 +211,23 @@ internal static class Config { TestNamespace = "MySqlConnectorExampleGen", LegacyTestNamespace = "MySqlConnectorLegacyExampleGen", - TestTypes = [ - KnownTestType.One, - KnownTestType.Many, - KnownTestType.Exec, - KnownTestType.ExecRows, - KnownTestType.ExecLastId, - KnownTestType.JoinEmbed, - KnownTestType.SelfJoinEmbed, - KnownTestType.Slice, - KnownTestType.MultipleSlices, - KnownTestType.NargNull, - KnownTestType.NargNotNull, - - KnownTestType.MySqlStringDataTypes, - KnownTestType.MySqlIntegerDataTypes, - KnownTestType.MySqlTransaction, - KnownTestType.MySqlTransactionRollback, - KnownTestType.MySqlFloatingPointDataTypes, - KnownTestType.MySqlDateTimeDataTypes, - KnownTestType.MySqlBinaryDataTypes, - KnownTestType.MySqlEnumDataType, - KnownTestType.MySqlScopedSchemaEnum, - KnownTestType.MySqlJsonDataTypes, - KnownTestType.MySqlInvalidJson, - KnownTestType.MySqlJsonCopyFrom, - KnownTestType.MySqlDataTypesOverride, - - KnownTestType.MySqlStringCopyFrom, - KnownTestType.MySqlIntegerCopyFrom, - KnownTestType.MySqlFloatingPointCopyFrom, - KnownTestType.MySqlDateTimeCopyFrom, - KnownTestType.MySqlBinaryCopyFrom, - KnownTestType.MySqlEnumCopyFrom - ] + TestTypes = _mysqlTestTypes } }, { "MySqlConnectorDapperTester", new ClassGenConfig - { - TestNamespace = "MySqlConnectorDapperExampleGen", - LegacyTestNamespace = "MySqlConnectorDapperLegacyExampleGen", - TestTypes = [ - KnownTestType.One, - KnownTestType.Many, - KnownTestType.Exec, - KnownTestType.ExecRows, - KnownTestType.ExecLastId, - KnownTestType.JoinEmbed, - KnownTestType.SelfJoinEmbed, - KnownTestType.Slice, - KnownTestType.MultipleSlices, - KnownTestType.NargNull, - KnownTestType.NargNotNull, - - KnownTestType.MySqlStringDataTypes, - KnownTestType.MySqlIntegerDataTypes, - KnownTestType.MySqlTransaction, - KnownTestType.MySqlTransactionRollback, - KnownTestType.MySqlFloatingPointDataTypes, - KnownTestType.MySqlDateTimeDataTypes, - KnownTestType.MySqlBinaryDataTypes, - KnownTestType.MySqlEnumDataType, - KnownTestType.MySqlScopedSchemaEnum, - KnownTestType.MySqlJsonDataTypes, - KnownTestType.MySqlInvalidJson, - KnownTestType.MySqlJsonCopyFrom, - KnownTestType.MySqlDataTypesOverride, - - KnownTestType.MySqlStringCopyFrom, - KnownTestType.MySqlIntegerCopyFrom, - KnownTestType.MySqlFloatingPointCopyFrom, - KnownTestType.MySqlDateTimeCopyFrom, - KnownTestType.MySqlBinaryCopyFrom, - KnownTestType.MySqlEnumCopyFrom - ] - } + { + TestNamespace = "MySqlConnectorDapperExampleGen", + LegacyTestNamespace = "MySqlConnectorDapperLegacyExampleGen", + TestTypes = _mysqlTestTypes + } }, { "NpgsqlTester", new ClassGenConfig { TestNamespace = "NpgsqlExampleGen", LegacyTestNamespace = "NpgsqlLegacyExampleGen", - TestTypes = [ - KnownTestType.One, - KnownTestType.Many, - KnownTestType.Exec, - KnownTestType.ExecRows, - KnownTestType.ExecLastId, - KnownTestType.JoinEmbed, - KnownTestType.SelfJoinEmbed, - KnownTestType.ArrayAsParam, - KnownTestType.MultipleArraysAsParams, - KnownTestType.NargNull, - KnownTestType.NargNotNull, - - KnownTestType.PostgresTransaction, - KnownTestType.PostgresTransactionRollback, - KnownTestType.PostgresStringDataTypes, - KnownTestType.PostgresIntegerDataTypes, - KnownTestType.PostgresFloatingPointDataTypes, - KnownTestType.PostgresDateTimeDataTypes, - KnownTestType.PostgresGuidDataTypes, - KnownTestType.PostgresArrayDataTypes, - KnownTestType.PostgresGeoDataTypes, - KnownTestType.PostgresGeoCopyFrom, - KnownTestType.PostgresDataTypesOverride, - KnownTestType.PostgresJsonDataTypes, - KnownTestType.PostgresInvalidJson, - KnownTestType.PostgresNetworkDataTypes, - KnownTestType.PostgresXmlDataTypes, - - KnownTestType.PostgresStringCopyFrom, - KnownTestType.PostgresIntegerCopyFrom, - KnownTestType.PostgresFloatingPointCopyFrom, - KnownTestType.PostgresDateTimeCopyFrom, - KnownTestType.PostgresGuidCopyFrom, - KnownTestType.PostgresArrayCopyFrom, - KnownTestType.PostgresNetworkCopyFrom, - ] + TestTypes = _postgresTestTypes } }, { @@ -221,43 +235,7 @@ internal static class Config { TestNamespace = "NpgsqlDapperExampleGen", LegacyTestNamespace = "NpgsqlDapperLegacyExampleGen", - TestTypes = [ - KnownTestType.One, - KnownTestType.Many, - KnownTestType.Exec, - KnownTestType.ExecRows, - KnownTestType.ExecLastId, - KnownTestType.JoinEmbed, - KnownTestType.SelfJoinEmbed, - KnownTestType.ArrayAsParam, - KnownTestType.MultipleArraysAsParams, - KnownTestType.NargNull, - KnownTestType.NargNotNull, - KnownTestType.PostgresTransaction, - KnownTestType.PostgresTransactionRollback, - - KnownTestType.PostgresStringDataTypes, - KnownTestType.PostgresIntegerDataTypes, - KnownTestType.PostgresFloatingPointDataTypes, - KnownTestType.PostgresDateTimeDataTypes, - KnownTestType.PostgresGuidDataTypes, - KnownTestType.PostgresArrayDataTypes, - KnownTestType.PostgresGeoDataTypes, - KnownTestType.PostgresGeoCopyFrom, - KnownTestType.PostgresDataTypesOverride, - KnownTestType.PostgresJsonDataTypes, - KnownTestType.PostgresInvalidJson, - KnownTestType.PostgresNetworkDataTypes, - KnownTestType.PostgresXmlDataTypes, - - KnownTestType.PostgresStringCopyFrom, - KnownTestType.PostgresIntegerCopyFrom, - KnownTestType.PostgresFloatingPointCopyFrom, - KnownTestType.PostgresDateTimeCopyFrom, - KnownTestType.PostgresGuidCopyFrom, - KnownTestType.PostgresArrayCopyFrom, - KnownTestType.PostgresNetworkCopyFrom - ] + TestTypes = _postgresTestTypes } }, { @@ -265,25 +243,7 @@ internal static class Config { TestNamespace = "SqliteExampleGen", LegacyTestNamespace = "SqliteLegacyExampleGen", - TestTypes = [ - KnownTestType.One, - KnownTestType.Many, - KnownTestType.Exec, - KnownTestType.ExecRows, - KnownTestType.ExecLastId, - KnownTestType.JoinEmbed, - KnownTestType.SelfJoinEmbed, - KnownTestType.Slice, - KnownTestType.MultipleSlices, - KnownTestType.NargNull, - KnownTestType.NargNotNull, - KnownTestType.SqliteTransaction, - KnownTestType.SqliteTransactionRollback, - KnownTestType.SqliteDataTypes, - KnownTestType.SqliteCopyFrom, - KnownTestType.SqliteDataTypesOverride, - KnownTestType.SqliteMultipleNamedParam - ] + TestTypes = _sqliteTestTypes } }, { @@ -291,25 +251,7 @@ internal static class Config { TestNamespace = "SqliteDapperExampleGen", LegacyTestNamespace = "SqliteDapperLegacyExampleGen", - TestTypes = [ - KnownTestType.One, - KnownTestType.Many, - KnownTestType.Exec, - KnownTestType.ExecRows, - KnownTestType.ExecLastId, - KnownTestType.JoinEmbed, - KnownTestType.SelfJoinEmbed, - KnownTestType.Slice, - KnownTestType.MultipleSlices, - KnownTestType.NargNull, - KnownTestType.NargNotNull, - KnownTestType.SqliteTransaction, - KnownTestType.SqliteTransactionRollback, - KnownTestType.SqliteDataTypes, - KnownTestType.SqliteCopyFrom, - KnownTestType.SqliteDataTypesOverride, - KnownTestType.SqliteMultipleNamedParam - ] + TestTypes = _sqliteTestTypes } }, }; diff --git a/end2end/EndToEndScaffold/Templates/AnnotationTests.cs b/end2end/EndToEndScaffold/Templates/AnnotationTests.cs index 4bebe4e8..7d73f5d6 100644 --- a/end2end/EndToEndScaffold/Templates/AnnotationTests.cs +++ b/end2end/EndToEndScaffold/Templates/AnnotationTests.cs @@ -26,14 +26,14 @@ public async Task TestOne() { Name = {{Consts.BojackAuthor}} }); - Assert.That(SingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}})); - } + AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - private static bool SingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) - { - return x.Id.Equals(y.Id) && - x.Name.Equals(y.Name) && - x.Bio.Equals(y.Bio); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } """ }, @@ -66,21 +66,19 @@ public async Task TestMany() Offset = 0 }); AssertSequenceEquals(expected, actual); - } - private static void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) - { - Assert.That(x.Id, Is.EqualTo(y.Id)); - Assert.That(x.Name, Is.EqualTo(y.Name)); - Assert.That(x.Bio, Is.EqualTo(y.Bio)); - } + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } - private static void AssertSequenceEquals(List x, List y) - { - Assert.That(x.Count, Is.EqualTo(y.Count)); - for (int i = 0; i < x.Count; i++) + void AssertSequenceEquals(List x, List y) { - AssertSingularEquals(x[i], y[i]); + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); } } """ @@ -139,6 +137,20 @@ public async Task TestExecRows() Offset = 0 }); AssertSequenceEquals(expected, actual); + + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } """, }, @@ -159,14 +171,14 @@ public async Task TestExecLastId() { Id = id1 }); - Assert.That(SingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}})); - } + AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - private static bool SingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) - { - return x.Id.Equals(y.Id) && - x.Name.Equals(y.Name) && - x.Bio.Equals(y.Bio); + void AssertSingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } """ }, diff --git a/end2end/EndToEndScaffold/Templates/MacroTests.cs b/end2end/EndToEndScaffold/Templates/MacroTests.cs index 436d1a87..7ec53980 100644 --- a/end2end/EndToEndScaffold/Templates/MacroTests.cs +++ b/end2end/EndToEndScaffold/Templates/MacroTests.cs @@ -31,20 +31,21 @@ public async Task TestNargNull() }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs()); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Id).ToList(); - y = y.OrderBy(o => o.Id).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } - private static bool SingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSequenceEquals(expected, actual); + + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } + + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } """ }, @@ -68,7 +69,21 @@ public async Task TestNargNotNull() }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs { NamePattern = "Bojack%" }); - Assert.That(SequenceEquals(expected, actual)); + AssertSequenceEquals(expected, actual); + + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } + + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } """ }, @@ -116,37 +131,24 @@ public async Task TestJoinEmbed() } }; var actual = await QuerySql.ListAllAuthorsBooks(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) - { - return - SingularEquals(x.Author{{Consts.UnknownRecordValuePlaceholder}}, y.Author{{Consts.UnknownRecordValuePlaceholder}}) && - SingularEquals(x.Book{{Consts.UnknownRecordValuePlaceholder}}, y.Book{{Consts.UnknownRecordValuePlaceholder}}); - } + AssertSequenceEquals(expected, actual); - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Author{{Consts.UnknownRecordValuePlaceholder}}.Name + o.Book{{Consts.UnknownRecordValuePlaceholder}}.Name).ToList(); - y = y.OrderBy(o => o.Author{{Consts.UnknownRecordValuePlaceholder}}.Name + o.Book{{Consts.UnknownRecordValuePlaceholder}}.Name).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } - - private static bool SingularEquals(Author x, Author y) - { - return x.Id.Equals(y.Id) && - x.Name.Equals(y.Name) && - x.Bio.Equals(y.Bio); - } + void AssertSingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) + { + Assert.That(x.Author{{Consts.UnknownRecordValuePlaceholder}}.Id, Is.EqualTo(y.Author{{Consts.UnknownRecordValuePlaceholder}}.Id)); + Assert.That(x.Author{{Consts.UnknownRecordValuePlaceholder}}.Name, Is.EqualTo(y.Author{{Consts.UnknownRecordValuePlaceholder}}.Name)); + Assert.That(x.Author{{Consts.UnknownRecordValuePlaceholder}}.Bio, Is.EqualTo(y.Author{{Consts.UnknownRecordValuePlaceholder}}.Bio)); + Assert.That(x.Book{{Consts.UnknownRecordValuePlaceholder}}.Id, Is.EqualTo(y.Book{{Consts.UnknownRecordValuePlaceholder}}.Id)); + Assert.That(x.Book{{Consts.UnknownRecordValuePlaceholder}}.AuthorId, Is.EqualTo(y.Book{{Consts.UnknownRecordValuePlaceholder}}.AuthorId)); + Assert.That(x.Book{{Consts.UnknownRecordValuePlaceholder}}.Name, Is.EqualTo(y.Book{{Consts.UnknownRecordValuePlaceholder}}.Name)); + } - private static bool SingularEquals(Book x, Book y) - { - return x.Id.Equals(y.Id) && - x.AuthorId.Equals(y.AuthorId) && - x.Name.Equals(y.Name); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } """ }, @@ -177,21 +179,24 @@ public async Task TestSelfJoinEmbed() } }; var actual = await QuerySql.GetDuplicateAuthors(); - Assert.That(SequenceEquals(expected, actual)); - } + AssertSequenceEquals(expected, actual); - private static bool SingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) - { - return - SingularEquals(x.Author{{Consts.UnknownRecordValuePlaceholder}}, y.Author{{Consts.UnknownRecordValuePlaceholder}}) && - SingularEquals(x.Author2{{Consts.UnknownRecordValuePlaceholder}}, y.Author2{{Consts.UnknownRecordValuePlaceholder}}); - } + void AssertSingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) + { + Assert.That(x.Author{{Consts.UnknownRecordValuePlaceholder}}.Id, Is.EqualTo(y.Author{{Consts.UnknownRecordValuePlaceholder}}.Id)); + Assert.That(x.Author{{Consts.UnknownRecordValuePlaceholder}}.Name, Is.EqualTo(y.Author{{Consts.UnknownRecordValuePlaceholder}}.Name)); + Assert.That(x.Author{{Consts.UnknownRecordValuePlaceholder}}.Bio, Is.EqualTo(y.Author{{Consts.UnknownRecordValuePlaceholder}}.Bio)); + Assert.That(x.Author2{{Consts.UnknownRecordValuePlaceholder}}.Id, Is.EqualTo(y.Author2{{Consts.UnknownRecordValuePlaceholder}}.Id)); + Assert.That(x.Author2{{Consts.UnknownRecordValuePlaceholder}}.Name, Is.EqualTo(y.Author2{{Consts.UnknownRecordValuePlaceholder}}.Name)); + Assert.That(x.Author2{{Consts.UnknownRecordValuePlaceholder}}.Bio, Is.EqualTo(y.Author2{{Consts.UnknownRecordValuePlaceholder}}.Bio)); + } - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } """ }, @@ -224,22 +229,24 @@ public async Task TestPartialEmbed() { Name = {{Consts.BojackBookTitle}} }); - Assert.That(SequenceEquals(expected, actual)); - } + AssertSequenceEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - private static bool SingularEquals(QuerySql.GetAuthorsByBookNameRow x, QuerySql.GetAuthorsByBookNameRow y) - { - return x.Id.Equals(y.Id) && - x.Name.Equals(y.Name) && - x.Bio.Equals(y.Bio) && - SingularEquals(x.Book, y.Book); - } + void AssertSingularEquals(QuerySql.GetAuthorsByBookNameRow x, QuerySql.GetAuthorsByBookNameRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + Assert.That(x.Book{{Consts.UnknownRecordValuePlaceholder}}.Id, Is.EqualTo(y.Book{{Consts.UnknownRecordValuePlaceholder}}.Id)); + Assert.That(x.Book{{Consts.UnknownRecordValuePlaceholder}}.AuthorId, Is.EqualTo(y.Book{{Consts.UnknownRecordValuePlaceholder}}.AuthorId)); + Assert.That(x.Book{{Consts.UnknownRecordValuePlaceholder}}.Name, Is.EqualTo(y.Book{{Consts.UnknownRecordValuePlaceholder}}.Name)); + } - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } """ }, diff --git a/end2end/EndToEndScaffold/Templates/MySqlTests.cs b/end2end/EndToEndScaffold/Templates/MySqlTests.cs index 76dbcf15..d5745d34 100644 --- a/end2end/EndToEndScaffold/Templates/MySqlTests.cs +++ b/end2end/EndToEndScaffold/Templates/MySqlTests.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Text.Json; namespace EndToEndScaffold.Templates; @@ -23,7 +22,7 @@ public async Task TestMySqlStringTypes( string cText, string cLongtext) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs + await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CChar = cChar, CNchar = cNchar, @@ -35,7 +34,7 @@ await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs CLongtext = cLongtext }); - var expected = new QuerySql.GetMysqlTypesRow + var expected = new QuerySql.GetMysqlStringTypesRow { CChar = cChar, CNchar = cNchar, @@ -46,16 +45,20 @@ await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs CText = cText, CLongtext = cLongtext }; - var actual = await QuerySql.GetMysqlTypes(); - - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CChar, Is.EqualTo(expected.CChar)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CNchar, Is.EqualTo(expected.CNchar)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CNationalChar, Is.EqualTo(expected.CNationalChar)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CVarchar, Is.EqualTo(expected.CVarchar)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CTinytext, Is.EqualTo(expected.CTinytext)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CMediumtext, Is.EqualTo(expected.CMediumtext)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CText, Is.EqualTo(expected.CText)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CLongtext, Is.EqualTo(expected.CLongtext)); + var actual = await QuerySql.GetMysqlStringTypes(); + AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); + + void AssertSingularEquals(QuerySql.GetMysqlStringTypesRow x, QuerySql.GetMysqlStringTypesRow y) + { + Assert.That(x.CChar, Is.EqualTo(y.CChar)); + Assert.That(x.CNchar, Is.EqualTo(y.CNchar)); + Assert.That(x.CNationalChar, Is.EqualTo(y.CNationalChar)); + Assert.That(x.CVarchar, Is.EqualTo(y.CVarchar)); + Assert.That(x.CTinytext, Is.EqualTo(y.CTinytext)); + Assert.That(x.CMediumtext, Is.EqualTo(y.CMediumtext)); + Assert.That(x.CText, Is.EqualTo(y.CText)); + Assert.That(x.CLongtext, Is.EqualTo(y.CLongtext)); + } } """ }, @@ -76,7 +79,7 @@ public async Task TestMySqlIntegerTypes( int? cInteger, long? cBigint) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs + await QuerySql.InsertMysqlNumericTypes(new QuerySql.InsertMysqlNumericTypesArgs { CBool = cBool, CBoolean = cBoolean, @@ -88,7 +91,7 @@ await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs CBigint = cBigint }); - var expected = new QuerySql.GetMysqlTypesRow + var expected = new QuerySql.GetMysqlNumericTypesRow { CBool = cBool, CBoolean = cBoolean, @@ -99,16 +102,20 @@ await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs CInteger = cInteger, CBigint = cBigint }; - var actual = await QuerySql.GetMysqlTypes(); - - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CBool, Is.EqualTo(expected.CBool)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CBoolean, Is.EqualTo(expected.CBoolean)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CTinyint, Is.EqualTo(expected.CTinyint)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CSmallint, Is.EqualTo(expected.CSmallint)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CMediumint, Is.EqualTo(expected.CMediumint)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CInt, Is.EqualTo(expected.CInt)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CInteger, Is.EqualTo(expected.CInteger)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CBigint, Is.EqualTo(expected.CBigint)); + var actual = await QuerySql.GetMysqlNumericTypes(); + AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); + + void AssertSingularEquals(QuerySql.GetMysqlNumericTypesRow x, QuerySql.GetMysqlNumericTypesRow y) + { + Assert.That(x.CBool, Is.EqualTo(y.CBool)); + Assert.That(x.CBoolean, Is.EqualTo(y.CBoolean)); + Assert.That(x.CTinyint, Is.EqualTo(y.CTinyint)); + Assert.That(x.CSmallint, Is.EqualTo(y.CSmallint)); + Assert.That(x.CMediumint, Is.EqualTo(y.CMediumint)); + Assert.That(x.CInt, Is.EqualTo(y.CInt)); + Assert.That(x.CInteger, Is.EqualTo(y.CInteger)); + Assert.That(x.CBigint, Is.EqualTo(y.CBigint)); + } } """ }, @@ -127,7 +134,7 @@ public async Task TestMySqlFloatingPointTypes( double? cDouble, double? cDoublePrecision) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs + await QuerySql.InsertMysqlNumericTypes(new QuerySql.InsertMysqlNumericTypesArgs { CFloat = cFloat, CNumeric = cNumeric, @@ -138,7 +145,7 @@ await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs CDoublePrecision = cDoublePrecision }); - var expected = new QuerySql.GetMysqlTypesRow + var expected = new QuerySql.GetMysqlNumericTypesRow { CFloat = cFloat, CNumeric = cNumeric, @@ -148,15 +155,19 @@ await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs CDouble = cDouble, CDoublePrecision = cDoublePrecision }; - var actual = await QuerySql.GetMysqlTypes(); - - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CFloat, Is.EqualTo(expected.CFloat)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CNumeric, Is.EqualTo(expected.CNumeric)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CDecimal, Is.EqualTo(expected.CDecimal)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CDec, Is.EqualTo(expected.CDec)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CFixed, Is.EqualTo(expected.CFixed)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CDouble, Is.EqualTo(expected.CDouble)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CDoublePrecision, Is.EqualTo(expected.CDoublePrecision)); + var actual = await QuerySql.GetMysqlNumericTypes(); + AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); + + void AssertSingularEquals(QuerySql.GetMysqlNumericTypesRow x, QuerySql.GetMysqlNumericTypesRow y) + { + Assert.That(x.CFloat, Is.EqualTo(y.CFloat)); + Assert.That(x.CNumeric, Is.EqualTo(y.CNumeric)); + Assert.That(x.CDecimal, Is.EqualTo(y.CDecimal)); + Assert.That(x.CDec, Is.EqualTo(y.CDec)); + Assert.That(x.CFixed, Is.EqualTo(y.CFixed)); + Assert.That(x.CDouble, Is.EqualTo(y.CDouble)); + Assert.That(x.CDoublePrecision, Is.EqualTo(y.CDoublePrecision)); + } } """ }, @@ -164,31 +175,43 @@ await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { Impl = $$""" [Test] - [TestCase(1999, "2000-1-30", "1983-11-3 02:01:22")] - [TestCase(null, null, "1970-1-1 00:00:01")] + [TestCase(1999, "2000-1-30", "1983-11-3 02:01:22", "2010-1-30 08:11:00", "02:01:22")] + [TestCase(null, null, null, null, null)] public async Task TestMySqlDateTimeTypes( short? cYear, DateTime? cDate, - DateTime? cTimestamp) + DateTime? cDatetime, + DateTime? cTimestamp, + TimeSpan? cTime) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs + await QuerySql.InsertMysqlDatetimeTypes(new QuerySql.InsertMysqlDatetimeTypesArgs { CYear = cYear, CDate = cDate, - CTimestamp = cTimestamp + CDatetime = cDatetime, + CTimestamp = cTimestamp, + CTime = cTime }); - var expected = new QuerySql.GetMysqlTypesRow + var expected = new QuerySql.GetMysqlDatetimeTypesRow { CYear = cYear, CDate = cDate, - CTimestamp = cTimestamp + CDatetime = cDatetime, + CTimestamp = cTimestamp, + CTime = cTime }; - var actual = await QuerySql.GetMysqlTypes(); + var actual = await QuerySql.GetMysqlDatetimeTypes(); + AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CYear, Is.EqualTo(expected.CYear)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CDate, Is.EqualTo(expected.CDate)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CTimestamp, Is.EqualTo(expected.CTimestamp)); + void AssertSingularEquals(QuerySql.GetMysqlDatetimeTypesRow x, QuerySql.GetMysqlDatetimeTypesRow y) + { + Assert.That(x.CYear, Is.EqualTo(y.CYear)); + Assert.That(x.CDate, Is.EqualTo(y.CDate)); + Assert.That(x.CDatetime, Is.EqualTo(y.CDatetime)); + Assert.That(x.CTimestamp, Is.EqualTo(y.CTimestamp)); + Assert.That(x.CTime, Is.EqualTo(y.CTime)); + } } """ }, @@ -208,7 +231,7 @@ public async Task TestMySqlBinaryTypes( byte[] cMediumblob, byte[] cLongblob) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs + await QuerySql.InsertMysqlBinaryTypes(new QuerySql.InsertMysqlBinaryTypesArgs { CBit = cBit, CBinary = cBinary, @@ -219,7 +242,7 @@ await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs CLongblob = cLongblob }); - var expected = new QuerySql.GetMysqlTypesRow + var expected = new QuerySql.GetMysqlBinaryTypesRow { CBit = cBit, CBinary = cBinary, @@ -230,10 +253,10 @@ await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs CLongblob = cLongblob }; - var actual = await QuerySql.GetMysqlTypes(); + var actual = await QuerySql.GetMysqlBinaryTypes(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow y) + void AssertSingularEquals(QuerySql.GetMysqlBinaryTypesRow x, QuerySql.GetMysqlBinaryTypesRow y) { Assert.That(x.CBit, Is.EqualTo(y.CBit)); Assert.That(x.CBinary, Is.EqualTo(y.CBinary)); @@ -246,38 +269,6 @@ void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow } """ }, - [KnownTestType.MySqlEnumDataType] = new TestImpl - { - Impl = $$""" - [Test] - [TestCase(MysqlTypesCEnum.Medium, new[] { MysqlTypesCSet.Tea, MysqlTypesCSet.Coffee })] - [TestCase(null, null)] - public async Task TestMySqlStringTypes( - MysqlTypesCEnum? cEnum, - MysqlTypesCSet[] cSet) - { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs - { - CEnum = cEnum, - CSet = cSet - }); - - var expected = new QuerySql.GetMysqlTypesRow - { - CEnum = cEnum, - CSet = cSet - }; - var actual = await QuerySql.GetMysqlTypes(); - AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - - void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow y) - { - Assert.That(x.CEnum, Is.EqualTo(y.CEnum)); - Assert.That(x.CSet, Is.EqualTo(y.CSet)); - } - } - """ - }, [KnownTestType.MySqlStringCopyFrom] = new TestImpl { Impl = $$""" @@ -296,7 +287,7 @@ public async Task TestStringCopyFrom( string cLongtext) { var batchArgs = Enumerable.Range(0, batchSize) - .Select(_ => new QuerySql.InsertMysqlTypesBatchArgs + .Select(_ => new QuerySql.InsertMysqlStringTypesBatchArgs { CChar = cChar, CNchar = cNchar, @@ -308,8 +299,8 @@ public async Task TestStringCopyFrom( CLongtext = cLongtext }) .ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + await QuerySql.InsertMysqlStringTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlStringTypesCntRow { Cnt = batchSize, CChar = cChar, @@ -322,10 +313,10 @@ public async Task TestStringCopyFrom( CLongtext = cLongtext }; - var actual = await QuerySql.GetMysqlTypesCnt(); + var actual = await QuerySql.GetMysqlStringTypesCnt(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypesCntRow y) + void AssertSingularEquals(QuerySql.GetMysqlStringTypesCntRow x, QuerySql.GetMysqlStringTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CChar, Is.EqualTo(y.CChar)); @@ -358,7 +349,7 @@ public async Task TestIntegerCopyFrom( long? cBigint) { var batchArgs = Enumerable.Range(0, batchSize) - .Select(_ => new QuerySql.InsertMysqlTypesBatchArgs + .Select(_ => new QuerySql.InsertMysqlNumericTypesBatchArgs { CBool = cBool, CBoolean = cBoolean, @@ -370,8 +361,8 @@ public async Task TestIntegerCopyFrom( CBigint = cBigint }) .ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + await QuerySql.InsertMysqlNumericTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlNumericTypesCntRow { Cnt = batchSize, CBool = cBool, @@ -384,10 +375,10 @@ public async Task TestIntegerCopyFrom( CBigint = cBigint }; - var actual = await QuerySql.GetMysqlTypesCnt(); + var actual = await QuerySql.GetMysqlNumericTypesCnt(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypesCntRow y) + void AssertSingularEquals(QuerySql.GetMysqlNumericTypesCntRow x, QuerySql.GetMysqlNumericTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CBool, Is.EqualTo(y.CBool)); @@ -419,7 +410,7 @@ public async Task TestFloatingPointCopyFrom( double? cDoublePrecision) { var batchArgs = Enumerable.Range(0, batchSize) - .Select(_ => new QuerySql.InsertMysqlTypesBatchArgs + .Select(_ => new QuerySql.InsertMysqlNumericTypesBatchArgs { CFloat = cFloat, CNumeric = cNumeric, @@ -430,8 +421,8 @@ public async Task TestFloatingPointCopyFrom( CDoublePrecision = cDoublePrecision }) .ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + await QuerySql.InsertMysqlNumericTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlNumericTypesCntRow { Cnt = batchSize, CFloat = cFloat, @@ -442,15 +433,20 @@ public async Task TestFloatingPointCopyFrom( CDouble = cDouble, CDoublePrecision = cDoublePrecision }; - var actual = await QuerySql.GetMysqlTypesCnt(); + var actual = await QuerySql.GetMysqlNumericTypesCnt(); + AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CFloat, Is.EqualTo(expected.CFloat)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CNumeric, Is.EqualTo(expected.CNumeric)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CDecimal, Is.EqualTo(expected.CDecimal)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CDec, Is.EqualTo(expected.CDec)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CFixed, Is.EqualTo(expected.CFixed)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CDouble, Is.EqualTo(expected.CDouble)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CDoublePrecision, Is.EqualTo(expected.CDoublePrecision)); + void AssertSingularEquals(QuerySql.GetMysqlNumericTypesCntRow x, QuerySql.GetMysqlNumericTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CFloat, Is.EqualTo(y.CFloat)); + Assert.That(x.CNumeric, Is.EqualTo(y.CNumeric)); + Assert.That(x.CDecimal, Is.EqualTo(y.CDecimal)); + Assert.That(x.CDec, Is.EqualTo(y.CDec)); + Assert.That(x.CFixed, Is.EqualTo(y.CFixed)); + Assert.That(x.CDouble, Is.EqualTo(y.CDouble)); + Assert.That(x.CDoublePrecision, Is.EqualTo(y.CDoublePrecision)); + } } """ }, @@ -458,40 +454,48 @@ public async Task TestFloatingPointCopyFrom( { Impl = $$""" [Test] - [TestCase(100, 1993, "2000-1-30", "1983-11-3 02:01:22", "2010-1-30 08:11:00")] - [TestCase(10, null, null, null, null)] + [TestCase(100, 1993, "2000-1-30", "1983-11-3 02:01:22", "2010-1-30 08:11:00", "02:01:22")] + [TestCase(10, null, null, null, null, null)] public async Task TestDateTimeCopyFrom( int batchSize, short? cYear, DateTime? cDate, DateTime? cDatetime, - DateTime? cTimestamp) + DateTime? cTimestamp, + TimeSpan? cTime) { var batchArgs = Enumerable.Range(0, batchSize) - .Select(_ => new QuerySql.InsertMysqlTypesBatchArgs + .Select(_ => new QuerySql.InsertMysqlDatetimeTypesBatchArgs { CYear = cYear, CDate = cDate, CDatetime = cDatetime, - CTimestamp = cTimestamp + CTimestamp = cTimestamp, + CTime = cTime }) .ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + await QuerySql.InsertMysqlDatetimeTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlDatetimeTypesCntRow { Cnt = batchSize, CYear = cYear, CDate = cDate, CDatetime = cDatetime, - CTimestamp = cTimestamp + CTimestamp = cTimestamp, + CTime = cTime }; - var actual = await QuerySql.GetMysqlTypesCnt(); + var actual = await QuerySql.GetMysqlDatetimeTypesCnt(); + AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.Cnt, Is.EqualTo(expected.Cnt)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CYear, Is.EqualTo(expected.CYear)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CDate, Is.EqualTo(expected.CDate)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CDatetime, Is.EqualTo(expected.CDatetime)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CTimestamp, Is.EqualTo(expected.CTimestamp)); + void AssertSingularEquals(QuerySql.GetMysqlDatetimeTypesCntRow x, QuerySql.GetMysqlDatetimeTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CYear, Is.EqualTo(y.CYear)); + Assert.That(x.CDate, Is.EqualTo(y.CDate)); + Assert.That(x.CDatetime, Is.EqualTo(y.CDatetime)); + Assert.That(x.CTimestamp, Is.EqualTo(y.CTimestamp)); + Assert.That(x.CTime, Is.EqualTo(y.CTime)); + } } """ }, @@ -513,7 +517,7 @@ public async Task TestBinaryCopyFrom( byte[] cLongblob) { var batchArgs = Enumerable.Range(0, batchSize) - .Select(_ => new QuerySql.InsertMysqlTypesBatchArgs + .Select(_ => new QuerySql.InsertMysqlBinaryTypesBatchArgs { CBit = cBit, CBinary = cBinary, @@ -524,8 +528,8 @@ public async Task TestBinaryCopyFrom( CLongblob = cLongblob }) .ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + await QuerySql.InsertMysqlBinaryTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlBinaryTypesCntRow { Cnt = batchSize, CBit = cBit, @@ -536,16 +540,20 @@ public async Task TestBinaryCopyFrom( CMediumblob = cMediumblob, CLongblob = cLongblob }; - var actual = await QuerySql.GetMysqlTypesCnt(); + var actual = await QuerySql.GetMysqlBinaryTypesCnt(); + AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.Cnt, Is.EqualTo(expected.Cnt)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CBit, Is.EqualTo(expected.CBit)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CBinary, Is.EqualTo(expected.CBinary)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CVarbinary, Is.EqualTo(expected.CVarbinary)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CTinyblob, Is.EqualTo(expected.CTinyblob)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CBlob, Is.EqualTo(expected.CBlob)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CMediumblob, Is.EqualTo(expected.CMediumblob)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CLongblob, Is.EqualTo(expected.CLongblob)); + void AssertSingularEquals(QuerySql.GetMysqlBinaryTypesCntRow x, QuerySql.GetMysqlBinaryTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CBit, Is.EqualTo(y.CBit)); + Assert.That(x.CBinary, Is.EqualTo(y.CBinary)); + Assert.That(x.CVarbinary, Is.EqualTo(y.CVarbinary)); + Assert.That(x.CTinyblob, Is.EqualTo(y.CTinyblob)); + Assert.That(x.CBlob, Is.EqualTo(y.CBlob)); + Assert.That(x.CMediumblob, Is.EqualTo(y.CMediumblob)); + Assert.That(x.CLongblob, Is.EqualTo(y.CLongblob)); + } } """ }, @@ -562,8 +570,8 @@ public async Task TestMySqlTransaction() var querySqlWithTx = QuerySql.WithTransaction(transaction); await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = {{Consts.BojackId}}, Name = {{Consts.BojackAuthor}}, Bio = {{Consts.BojackTheme}} }); - var actualNull = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = {{Consts.BojackAuthor}} }); - Assert.That(actualNull == null, "there is author"); // This is correct for nullable types + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = {{Consts.BojackAuthor}} }); + ClassicAssert.IsNull(actual); await transaction.CommitAsync(); @@ -573,8 +581,15 @@ public async Task TestMySqlTransaction() Name = {{Consts.BojackAuthor}}, Bio = {{Consts.BojackTheme}} }; - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = {{Consts.BojackAuthor}} }); - Assert.That(SingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}})); // Apply placeholder here + actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = {{Consts.BojackAuthor}} }); + AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); + + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } """ }, @@ -594,40 +609,103 @@ public async Task TestMySqlTransactionRollback() await transaction.RollbackAsync(); var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = {{Consts.BojackAuthor}} }); - Assert.That(actual == null, "author should not exist after rollback"); + ClassicAssert.IsNull(actual); + } + """ + }, + [KnownTestType.MySqlEnumDataType] = new TestImpl + { + Impl = $$""" + private static IEnumerable MySqlEnumTypesTestCases + { + get + { + yield return new TestCaseData( + MysqlStringTypesCEnum.Medium, + new HashSet { MysqlStringTypesCSet.Tea, MysqlStringTypesCSet.Coffee } + ).SetName("Valid Enum values"); + + yield return new TestCaseData( + null, + null + ).SetName("Enum with null values"); + } + } + + [Test] + [TestCaseSource(nameof(MySqlEnumTypesTestCases))] + public async Task TestMySqlStringTypes( + MysqlStringTypesCEnum? cEnum, + HashSet cSet) + { + await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs + { + CEnum = cEnum, + CSet = cSet + }); + + var expected = new QuerySql.GetMysqlStringTypesRow + { + CEnum = cEnum, + CSet = cSet + }; + var actual = await QuerySql.GetMysqlStringTypes(); + AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); + + void AssertSingularEquals(QuerySql.GetMysqlStringTypesRow x, QuerySql.GetMysqlStringTypesRow y) + { + Assert.That(x.CEnum, Is.EqualTo(y.CEnum)); + Assert.That(x.CSet, Is.EqualTo(y.CSet)); + } } """ }, [KnownTestType.MySqlEnumCopyFrom] = new TestImpl { Impl = $$""" + private static IEnumerable MySqlEnumCopyFromTestCases + { + get + { + yield return new TestCaseData( + 100, + MysqlStringTypesCEnum.Big, + new HashSet { MysqlStringTypesCSet.Tea, MysqlStringTypesCSet.Coffee } + ).SetName("Valid Enum values"); + + yield return new TestCaseData( + 10, + null, + null + ).SetName("Enum with null values"); + } + } + [Test] - [TestCase(100, MysqlTypesCEnum.Big, new[] { MysqlTypesCSet.Tea, MysqlTypesCSet.Coffee })] - [TestCase(500, MysqlTypesCEnum.Small, new[] { MysqlTypesCSet.Milk })] - [TestCase(10, null, null)] + [TestCaseSource(nameof(MySqlEnumCopyFromTestCases))] public async Task TestCopyFrom( int batchSize, - MysqlTypesCEnum? cEnum, - MysqlTypesCSet[] cSet) + MysqlStringTypesCEnum? cEnum, + HashSet cSet) { var batchArgs = Enumerable.Range(0, batchSize) - .Select(_ => new QuerySql.InsertMysqlTypesBatchArgs + .Select(_ => new QuerySql.InsertMysqlStringTypesBatchArgs { CEnum = cEnum, CSet = cSet }) .ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + await QuerySql.InsertMysqlStringTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlStringTypesCntRow { Cnt = batchSize, CEnum = cEnum, CSet = cSet }; - var actual = await QuerySql.GetMysqlTypesCnt(); + var actual = await QuerySql.GetMysqlStringTypesCnt(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypesCntRow y) + void AssertSingularEquals(QuerySql.GetMysqlStringTypesCntRow x, QuerySql.GetMysqlStringTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CEnum, Is.EqualTo(y.CEnum)); @@ -646,30 +724,30 @@ await this.QuerySql.CreateExtendedBio(new QuerySql.CreateExtendedBioArgs { AuthorName = {{Consts.BojackAuthor}}, Name = {{Consts.BojackBookTitle}}, - BioType = ExtendedBiosBioType.Memoir, - AuthorType = new ExtendedBiosAuthorType[] { ExtendedBiosAuthorType.Author, ExtendedBiosAuthorType.Translator } + BioType = BiosBioType.Memoir, + AuthorType = new HashSet { BiosAuthorType.Author, BiosAuthorType.Translator } }); var expected = new QuerySql.GetFirstExtendedBioByTypeRow { AuthorName = {{Consts.BojackAuthor}}, Name = {{Consts.BojackBookTitle}}, - BioType = ExtendedBiosBioType.Memoir, - AuthorType = new ExtendedBiosAuthorType[] { ExtendedBiosAuthorType.Author, ExtendedBiosAuthorType.Translator } + BioType = BiosBioType.Memoir, + AuthorType = new HashSet { BiosAuthorType.Author, BiosAuthorType.Translator } }; var actual = await this.QuerySql.GetFirstExtendedBioByType(new QuerySql.GetFirstExtendedBioByTypeArgs { - BioType = ExtendedBiosBioType.Memoir + BioType = BiosBioType.Memoir }); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - } - private void AssertSingularEquals(QuerySql.GetFirstExtendedBioByTypeRow x, QuerySql.GetFirstExtendedBioByTypeRow y) - { - Assert.That(x.AuthorName, Is.EqualTo(y.AuthorName)); - Assert.That(x.Name, Is.EqualTo(y.Name)); - Assert.That(x.BioType, Is.EqualTo(y.BioType)); - Assert.That(x.AuthorType, Is.EqualTo(y.AuthorType)); + void AssertSingularEquals(QuerySql.GetFirstExtendedBioByTypeRow x, QuerySql.GetFirstExtendedBioByTypeRow y) + { + Assert.That(x.AuthorName, Is.EqualTo(y.AuthorName)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.BioType, Is.EqualTo(y.BioType)); + Assert.That(x.AuthorType, Is.EqualTo(y.AuthorType)); + } } """ }, @@ -686,20 +764,20 @@ public async Task TestMySqlJsonDataType( if (cJson != null) cParsedJson = JsonDocument.Parse(cJson).RootElement; - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs + await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CJson = cParsedJson, CJsonStringOverride = cJson }); - var expected = new QuerySql.GetMysqlTypesRow + var expected = new QuerySql.GetMysqlStringTypesRow { CJson = cParsedJson, CJsonStringOverride = cJson }; - var actual = await QuerySql.GetMysqlTypes(); + var actual = await QuerySql.GetMysqlStringTypes(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow y) + void AssertSingularEquals(QuerySql.GetMysqlStringTypesRow x, QuerySql.GetMysqlStringTypesRow y) { Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); if (x.CJson.HasValue) @@ -716,7 +794,7 @@ void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow public void TestMySqlInvalidJson() { Assert.ThrowsAsync(async () => await - QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs + QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CJsonStringOverride = "SOME INVALID JSON" })); @@ -738,22 +816,22 @@ public async Task TestJsonCopyFrom( cParsedJson = JsonDocument.Parse(cJson).RootElement; var batchArgs = Enumerable.Range(0, batchSize) - .Select(_ => new QuerySql.InsertMysqlTypesBatchArgs + .Select(_ => new QuerySql.InsertMysqlStringTypesBatchArgs { CJson = cParsedJson }) .ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + await QuerySql.InsertMysqlStringTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlStringTypesCntRow { Cnt = batchSize, CJson = cParsedJson }; - var actual = await QuerySql.GetMysqlTypesCnt(); + var actual = await QuerySql.GetMysqlStringTypesCnt(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypesCntRow y) + void AssertSingularEquals(QuerySql.GetMysqlStringTypesCntRow x, QuerySql.GetMysqlStringTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); @@ -774,12 +852,19 @@ public async Task TestMySqlDataTypesOverride( string cVarchar, DateTime cTimestamp) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs + await QuerySql.InsertMysqlNumericTypes(new QuerySql.InsertMysqlNumericTypesArgs + { + CInt = cInt + }); + await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs + { + CVarchar = cVarchar + }); + await QuerySql.InsertMysqlDatetimeTypes(new QuerySql.InsertMysqlDatetimeTypesArgs { - CInt = cInt, - CVarchar = cVarchar, CTimestamp = cTimestamp }); + var expected = new QuerySql.GetMysqlFunctionsRow { MaxInt = cInt, @@ -789,13 +874,13 @@ await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs var actual = await QuerySql.GetMysqlFunctions(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - } - private static void AssertSingularEquals(QuerySql.GetMysqlFunctionsRow expected, QuerySql.GetMysqlFunctionsRow actual) - { - Assert.That(actual.MaxInt, Is.EqualTo(expected.MaxInt)); - Assert.That(actual.MaxVarchar, Is.EqualTo(expected.MaxVarchar)); - Assert.That(actual.MaxTimestamp, Is.EqualTo(expected.MaxTimestamp)); + void AssertSingularEquals(QuerySql.GetMysqlFunctionsRow x, QuerySql.GetMysqlFunctionsRow y) + { + Assert.That(x.MaxInt, Is.EqualTo(y.MaxInt)); + Assert.That(x.MaxVarchar, Is.EqualTo(y.MaxVarchar)); + Assert.That(x.MaxTimestamp, Is.EqualTo(y.MaxTimestamp)); + } } """ } diff --git a/end2end/EndToEndScaffold/Templates/PostgresTests.cs b/end2end/EndToEndScaffold/Templates/PostgresTests.cs index 52cbc6c3..1ed3c7dd 100644 --- a/end2end/EndToEndScaffold/Templates/PostgresTests.cs +++ b/end2end/EndToEndScaffold/Templates/PostgresTests.cs @@ -19,7 +19,7 @@ public async Task TestPostgresStringTypes( string cBpchar, string cText) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs + await QuerySql.InsertPostgresStringTypes(new QuerySql.InsertPostgresStringTypesArgs { CChar = cChar, CVarchar = cVarchar, @@ -28,7 +28,7 @@ await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs CText = cText, }); - var expected = new QuerySql.GetPostgresTypesRow + var expected = new QuerySql.GetPostgresStringTypesRow { CChar = cChar, CVarchar = cVarchar, @@ -37,10 +37,10 @@ await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs CText = cText, }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresStringTypes(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresStringTypesRow x, QuerySql.GetPostgresStringTypesRow y) { Assert.That(x.CChar, Is.EqualTo(y.CChar)); Assert.That(x.CVarchar, Is.EqualTo(y.CVarchar)); @@ -63,7 +63,7 @@ public async Task TestPostgresIntegerTypes( int cInteger, long cBigint) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs + await QuerySql.InsertPostgresNumericTypes(new QuerySql.InsertPostgresNumericTypesArgs { CBoolean = cBoolean, CSmallint = cSmallint, @@ -71,19 +71,23 @@ await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs CBigint = cBigint }); - var expected = new QuerySql.GetPostgresTypesRow + var expected = new QuerySql.GetPostgresNumericTypesRow { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresNumericTypes(); + AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CBoolean, Is.EqualTo(expected.CBoolean)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CSmallint, Is.EqualTo(expected.CSmallint)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CInteger, Is.EqualTo(expected.CInteger)); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CBigint, Is.EqualTo(expected.CBigint)); + void AssertSingularEquals(QuerySql.GetPostgresNumericTypesRow x, QuerySql.GetPostgresNumericTypesRow y) + { + Assert.That(x.CBoolean, Is.EqualTo(y.CBoolean)); + Assert.That(x.CSmallint, Is.EqualTo(y.CSmallint)); + Assert.That(x.CInteger, Is.EqualTo(y.CInteger)); + Assert.That(x.CBigint, Is.EqualTo(y.CBigint)); + } } """ }, @@ -100,7 +104,7 @@ public async Task TestPostgresFloatingPointTypes( double? cDoublePrecision, decimal? cMoney) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs + await QuerySql.InsertPostgresNumericTypes(new QuerySql.InsertPostgresNumericTypesArgs { CReal = cReal, CNumeric = cNumeric, @@ -109,7 +113,7 @@ await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs CMoney = cMoney }); - var expected = new QuerySql.GetPostgresTypesRow + var expected = new QuerySql.GetPostgresNumericTypesRow { CReal = cReal, CNumeric = cNumeric, @@ -117,10 +121,10 @@ await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs CDoublePrecision = cDoublePrecision, CMoney = cMoney }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresNumericTypes(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresNumericTypesRow x, QuerySql.GetPostgresNumericTypesRow y) { Assert.That(x.CReal, Is.EqualTo(y.CReal)); Assert.That(x.CNumeric, Is.EqualTo(y.CNumeric)); @@ -144,7 +148,7 @@ public async Task TestPostgresDateTimeTypes( DateTime? cTimestampWithTz, TimeSpan? cInterval) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs + await QuerySql.InsertPostgresDateTimeTypes(new QuerySql.InsertPostgresDateTimeTypesArgs { CDate = cDate, CTime = cTime, @@ -153,7 +157,7 @@ await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs CInterval = cInterval }); - var expected = new QuerySql.GetPostgresTypesRow + var expected = new QuerySql.GetPostgresDateTimeTypesRow { CDate = cDate, CTime = cTime, @@ -161,10 +165,10 @@ await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs CTimestampWithTz = cTimestampWithTz, CInterval = cInterval }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresDateTimeTypes(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresDateTimeTypesRow x, QuerySql.GetPostgresDateTimeTypesRow y) { Assert.That(x.CDate, Is.EqualTo(y.CDate)); Assert.That(x.CTime, Is.EqualTo(y.CTime)); @@ -277,7 +281,7 @@ public async Task TestStringCopyFrom( string cText) { var batchArgs = Enumerable.Range(0, batchSize) - .Select(_ => new QuerySql.InsertPostgresTypesBatchArgs + .Select(_ => new QuerySql.InsertPostgresStringTypesBatchArgs { CChar = cChar, CVarchar = cVarchar, @@ -286,8 +290,8 @@ public async Task TestStringCopyFrom( CText = cText }) .ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + await QuerySql.InsertPostgresStringTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresStringTypesCntRow { Cnt = batchSize, CChar = cChar, @@ -296,10 +300,10 @@ public async Task TestStringCopyFrom( CBpchar = cBpchar, CText = cText }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresStringTypesCnt(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresStringTypesCntRow x, QuerySql.GetPostgresStringTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CChar, Is.EqualTo(y.CChar)); @@ -325,7 +329,7 @@ public async Task TestIntegerCopyFrom( long? cBigint) { var batchArgs = Enumerable.Range(0, batchSize) - .Select(_ => new QuerySql.InsertPostgresTypesBatchArgs + .Select(_ => new QuerySql.InsertPostgresNumericTypesBatchArgs { CBoolean = cBoolean, CSmallint = cSmallint, @@ -333,8 +337,8 @@ public async Task TestIntegerCopyFrom( CBigint = cBigint }) .ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + await QuerySql.InsertPostgresNumericTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresNumericTypesCntRow { Cnt = batchSize, CBoolean = cBoolean, @@ -342,10 +346,10 @@ public async Task TestIntegerCopyFrom( CInteger = cInteger, CBigint = cBigint }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresNumericTypesCnt(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresNumericTypesCntRow x, QuerySql.GetPostgresNumericTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CBoolean, Is.EqualTo(y.CBoolean)); @@ -371,7 +375,7 @@ public async Task TestFloatingPointCopyFrom( decimal? cMoney) { var batchArgs = Enumerable.Range(0, batchSize) - .Select(_ => new QuerySql.InsertPostgresTypesBatchArgs + .Select(_ => new QuerySql.InsertPostgresNumericTypesBatchArgs { CReal = cReal, CDecimal = cDecimal, @@ -380,8 +384,8 @@ public async Task TestFloatingPointCopyFrom( CMoney = cMoney }) .ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + await QuerySql.InsertPostgresNumericTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresNumericTypesCntRow { Cnt = batchSize, CReal = cReal, @@ -390,10 +394,10 @@ public async Task TestFloatingPointCopyFrom( CDoublePrecision = cDoublePrecision, CMoney = cMoney }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresNumericTypesCnt(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresNumericTypesCntRow x, QuerySql.GetPostgresNumericTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CReal, Is.EqualTo(y.CReal)); @@ -424,7 +428,7 @@ public async Task TestDateTimeCopyFrom( cTimestampWithTzAsUtc = DateTime.SpecifyKind(cTimestampWithTz.Value, DateTimeKind.Utc); var batchArgs = Enumerable.Range(0, batchSize) - .Select(_ => new QuerySql.InsertPostgresTypesBatchArgs + .Select(_ => new QuerySql.InsertPostgresDateTimeTypesBatchArgs { CDate = cDate, CTime = cTime, @@ -433,8 +437,8 @@ public async Task TestDateTimeCopyFrom( CInterval = cInterval }) .ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + await QuerySql.InsertPostgresDateTimeTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresDateTimeTypesCntRow { Cnt = batchSize, CDate = cDate, @@ -443,10 +447,10 @@ public async Task TestDateTimeCopyFrom( CTimestampWithTz = cTimestampWithTz, CInterval = cInterval }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresDateTimeTypesCnt(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresDateTimeTypesCntRow x, QuerySql.GetPostgresDateTimeTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CDate, Is.EqualTo(y.CDate)); @@ -472,7 +476,7 @@ public async Task TestPostgresJsonDataTypes( if (cJson != null) cParsedJson = JsonDocument.Parse(cJson).RootElement; - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs + await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CJson = cParsedJson, CJsonb = cParsedJson, @@ -480,7 +484,7 @@ await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs CJsonpath = cJsonpath }); - var expected = new QuerySql.GetPostgresTypesRow + var expected = new QuerySql.GetPostgresSpecialTypesRow { CJson = cParsedJson, CJsonb = cParsedJson, @@ -488,10 +492,10 @@ await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs CJsonpath = cJsonpath }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresSpecialTypes(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPostgresSpecialTypesRow y) { Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); if (x.CJson.HasValue) @@ -512,13 +516,13 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTy public void TestPostgresInvalidJson() { Assert.ThrowsAsync(async () => await - QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs + QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CJsonStringOverride = "SOME INVALID JSON" })); Assert.ThrowsAsync(async () => await - QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs + QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CJsonpath = "SOME INVALID JSONPATH" })); @@ -556,7 +560,7 @@ public async Task TestPostgresNetworkDataTypes( PhysicalAddress cMacaddr, string cMacaddr8) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs + await QuerySql.InsertPostgresNetworkTypes(new QuerySql.InsertPostgresNetworkTypesArgs { CCidr = cCidr, CInet = cInet, @@ -564,7 +568,7 @@ await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs CMacaddr8 = cMacaddr8 }); - var expected = new QuerySql.GetPostgresTypesRow + var expected = new QuerySql.GetPostgresNetworkTypesRow { CCidr = cCidr, CInet = cInet, @@ -572,10 +576,10 @@ await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs CMacaddr8 = cMacaddr8 }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresNetworkTypes(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresNetworkTypesRow x, QuerySql.GetPostgresNetworkTypesRow y) { Assert.That(x.CCidr, Is.EqualTo(y.CCidr)); Assert.That(x.CInet, Is.EqualTo(y.CInet)); @@ -588,25 +592,74 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTy [KnownTestType.PostgresArrayCopyFrom] = new TestImpl { Impl = $$""" + private static IEnumerable PostgresArrayCopyFromTestCases + { + get + { + yield return new TestCaseData( + 100, + new byte[] { 0x53, 0x56 }, + new bool[] { true, false }, + new string[] { "Sister Ray", "Venus in Furs" }, + new int[] { 1, 2 }, + new decimal[] { 132.13m, 23.22m }, + new DateTime[] { new DateTime(1984, 8, 26), new DateTime(2000, 1, 2) } + ).SetName("Valid Array Copy From"); + + yield return new TestCaseData( + 10, + new byte[] { }, + new bool[] { }, + new string[] { }, + new int[] { }, + new decimal[] { }, + new DateTime[] { } + ).SetName("Empty Array Copy From"); + + yield return new TestCaseData( + 10, + null, + null, + null, + null, + null, + null + ).SetName("Null Array Copy From"); + } + } + [Test] - [TestCase(100, new byte[] { 0x53, 0x56 })] - [TestCase(10, new byte[] { })] - [TestCase(10, null)] + [TestCaseSource(nameof(PostgresArrayCopyFromTestCases))] public async Task TestArrayCopyFrom( int batchSize, - byte[] cBytea) + byte[] cBytea, + bool[] cBooleanArray, + string[] cTextArray, + int[] cIntegerArray, + decimal[] cDecimalArray, + DateTime[] cTimestampArray) { var batchArgs = Enumerable.Range(0, batchSize) .Select(_ => new QuerySql.InsertPostgresArrayTypesBatchArgs { - CBytea = cBytea + CBytea = cBytea, + CBooleanArray = cBooleanArray, + CTextArray = cTextArray, + CIntegerArray = cIntegerArray, + CDecimalArray = cDecimalArray, + CTimestampArray = cTimestampArray }) .ToList(); await QuerySql.InsertPostgresArrayTypesBatch(batchArgs); var expected = new QuerySql.GetPostgresArrayTypesCntRow { Cnt = batchSize, - CBytea = cBytea + CBytea = cBytea, + CBooleanArray = cBooleanArray, + CTextArray = cTextArray, + CIntegerArray = cIntegerArray, + CDecimalArray = cDecimalArray, + CTimestampArray = cTimestampArray }; var actual = await QuerySql.GetPostgresArrayTypesCnt(); @@ -615,6 +668,12 @@ public async Task TestArrayCopyFrom( void AssertSingularEquals(QuerySql.GetPostgresArrayTypesCntRow x, QuerySql.GetPostgresArrayTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CBytea, Is.EqualTo(y.CBytea)); + Assert.That(x.CBooleanArray, Is.EqualTo(y.CBooleanArray)); + Assert.That(x.CTextArray, Is.EqualTo(y.CTextArray)); + Assert.That(x.CIntegerArray, Is.EqualTo(y.CIntegerArray)); + Assert.That(x.CDecimalArray, Is.EqualTo(y.CDecimalArray)); + Assert.That(x.CTimestampArray, Is.EqualTo(y.CTimestampArray)); } } """ @@ -809,9 +868,8 @@ public async Task TestPostgresTransaction() var querySqlWithTx = QuerySql.WithTransaction(transaction); await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = {{Consts.BojackId}}, Name = {{Consts.BojackAuthor}}, Bio = {{Consts.BojackTheme}} }); - // The GetAuthor method in NpgsqlExampleGen returns QuerySql.GetAuthorRow? (nullable record struct) - var actualNull = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = {{Consts.BojackAuthor}} }); - Assert.That(actualNull == null, "there is author"); // This is correct for nullable types + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = {{Consts.BojackAuthor}} }); + ClassicAssert.IsNull(actual); await transaction.CommitAsync(); @@ -821,8 +879,15 @@ public async Task TestPostgresTransaction() Name = {{Consts.BojackAuthor}}, Bio = {{Consts.BojackTheme}} }; - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = {{Consts.BojackAuthor}} }); - Assert.That(SingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}})); // Apply placeholder here + actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = {{Consts.BojackAuthor}} }); + AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); + + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } """ }, @@ -842,7 +907,7 @@ public async Task TestPostgresTransactionRollback() await transaction.RollbackAsync(); var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = {{Consts.BojackAuthor}} }); - Assert.That(actual == null, "author should not exist after rollback"); + ClassicAssert.IsNull(actual); } """ }, @@ -857,12 +922,18 @@ public async Task TestPostgresDataTypesOverride( string cVarchar, DateTime cTimestamp) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs + await QuerySql.InsertPostgresNumericTypes(new QuerySql.InsertPostgresNumericTypesArgs + { + CInteger = cInteger + }); + await QuerySql.InsertPostgresDateTimeTypes(new QuerySql.InsertPostgresDateTimeTypesArgs { - CInteger = cInteger, - CVarchar = cVarchar, CTimestamp = cTimestamp }); + await QuerySql.InsertPostgresStringTypes(new QuerySql.InsertPostgresStringTypesArgs + { + CVarchar = cVarchar + }); var expected = new QuerySql.GetPostgresFunctionsRow { @@ -873,13 +944,13 @@ await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs var actual = await QuerySql.GetPostgresFunctions(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - } - private static void AssertSingularEquals(QuerySql.GetPostgresFunctionsRow expected, QuerySql.GetPostgresFunctionsRow actual) - { - Assert.That(actual.MaxInteger, Is.EqualTo(expected.MaxInteger)); - Assert.That(actual.MaxVarchar, Is.EqualTo(expected.MaxVarchar)); - Assert.That(actual.MaxTimestamp, Is.EqualTo(expected.MaxTimestamp)); + void AssertSingularEquals(QuerySql.GetPostgresFunctionsRow x, QuerySql.GetPostgresFunctionsRow y) + { + Assert.That(x.MaxInteger, Is.EqualTo(y.MaxInteger)); + Assert.That(x.MaxVarchar, Is.EqualTo(y.MaxVarchar)); + Assert.That(x.MaxTimestamp, Is.EqualTo(y.MaxTimestamp)); + } } """ }, @@ -899,19 +970,19 @@ private static IEnumerable PostgresGuidDataTypesTestCases [TestCaseSource(nameof(PostgresGuidDataTypesTestCases))] public async Task TestPostgresGuidDataTypes(Guid? cUuid) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs + await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CUuid = cUuid }); - var expected = new QuerySql.GetPostgresTypesRow + var expected = new QuerySql.GetPostgresSpecialTypesRow { CUuid = cUuid }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresSpecialTypes(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPostgresSpecialTypesRow y) { Assert.That(x.CUuid, Is.EqualTo(y.CUuid)); } @@ -935,22 +1006,22 @@ private static IEnumerable PostgresGuidCopyFromTestCases public async Task TestPostgresGuidCopyFrom(int batchSize, Guid? cUuid) { var batchArgs = Enumerable.Range(0, batchSize) - .Select(_ => new QuerySql.InsertPostgresTypesBatchArgs + .Select(_ => new QuerySql.InsertPostgresSpecialTypesBatchArgs { CUuid = cUuid }) .ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); + await QuerySql.InsertPostgresSpecialTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var expected = new QuerySql.GetPostgresSpecialTypesCntRow { Cnt = batchSize, CUuid = cUuid }; - var actual = await QuerySql.GetPostgresTypesCnt(); - Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.Cnt, Is.EqualTo(expected.Cnt)); + var actual = await QuerySql.GetPostgresSpecialTypesCnt(); + AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesCntRow x, QuerySql.GetPostgresSpecialTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CUuid, Is.EqualTo(y.CUuid)); @@ -973,28 +1044,43 @@ public async Task TestPostgresXmlDataTypes(string cXml) parsedXml.LoadXml(cXml); } - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs + await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CXml = parsedXml }); - var expected = new QuerySql.GetPostgresTypesRow + var expected = new QuerySql.GetPostgresSpecialTypesRow { CXml = parsedXml }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresSpecialTypes(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPostgresSpecialTypesRow y) { - if (x.CXml == null && y.CXml == null) - return; - Assert.That(x.CXml.OuterXml, Is.EqualTo(y.CXml.OuterXml)); + Assert.That(x.CXml == null, Is.EqualTo(y.CXml == null)); + if (x.CXml != null) + Assert.That(x.CXml.OuterXml, Is.EqualTo(y.CXml.OuterXml)); } } """ }, + + [KnownTestType.PostgresInvalidXml] = new TestImpl + { + Impl = $$""" + [Test] + public void TestPostgresInvalidXml() + { + Assert.ThrowsAsync(async () => await + QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs + { + CXmlStringOverride = "SOME INVALID XML" + })); + } + """ + }, [KnownTestType.PostgresNetworkCopyFrom] = new TestImpl { Impl = $$""" @@ -1026,26 +1112,26 @@ public async Task TestPostgresNetworkCopyFrom( PhysicalAddress cMacaddr) { var batchArgs = Enumerable.Range(0, batchSize) - .Select(_ => new QuerySql.InsertPostgresTypesBatchArgs + .Select(_ => new QuerySql.InsertPostgresNetworkTypesBatchArgs { CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr }) .ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); + await QuerySql.InsertPostgresNetworkTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var expected = new QuerySql.GetPostgresNetworkTypesCntRow { Cnt = batchSize, CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresNetworkTypesCnt(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresNetworkTypesCntRow x, QuerySql.GetPostgresNetworkTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CCidr, Is.EqualTo(y.CCidr)); @@ -1054,6 +1140,67 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgre } } """ + }, + [KnownTestType.PostgresEnumDataType] = new TestImpl + { + Impl = $$""" + [Test] + [TestCase(CEnum.Medium)] + [TestCase(null)] + public async Task TestPostgresStringTypes(CEnum? cEnum) + { + await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs + { + CEnum = cEnum + }); + + var expected = new QuerySql.GetPostgresSpecialTypesRow + { + CEnum = cEnum + }; + var actual = await QuerySql.GetPostgresSpecialTypes(); + AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); + + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPostgresSpecialTypesRow y) + { + Assert.That(x.CEnum, Is.EqualTo(y.CEnum)); + } + } + """ + }, + [KnownTestType.PostgresFullTextSearchDataTypes] = new TestImpl + { + Impl = $$""" + [Test] + [Obsolete] // due to NpgsqlTsVector.Parse usage + public async Task TestPostgresFullTextSearchDataTypes() + { + await QuerySql.InsertPostgresStringTypes(new QuerySql.InsertPostgresStringTypesArgs + { + CText = "Hello world" + }); + + var actual = await QuerySql.GetPostgresStringTypesTextSearch( + new QuerySql.GetPostgresStringTypesTextSearchArgs { ToTsquery = "Hello" }); + + var expected = new QuerySql.GetPostgresStringTypesTextSearchRow + { + CText = "Hello world", + Query = new NpgsqlTsQueryLexeme("hello"), + Tsv = NpgsqlTsVector.Parse("hello:1 world:2"), + Rnk = 0.07f + }; + AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); + + void AssertSingularEquals(QuerySql.GetPostgresStringTypesTextSearchRow x, QuerySql.GetPostgresStringTypesTextSearchRow y) + { + Assert.That(y.CText, Is.EqualTo(x.CText)); + Assert.That(y.Query.ToString(), Is.EqualTo(x.Query.ToString())); + Assert.That(y.Tsv.ToString(), Is.EqualTo(x.Tsv.ToString())); + Assert.That(y.Rnk, Is.AtMost(x.Rnk)); + } + } + """ } }; } \ No newline at end of file diff --git a/end2end/EndToEndScaffold/Templates/SqliteTests.cs b/end2end/EndToEndScaffold/Templates/SqliteTests.cs index deddb5aa..ae627b5e 100644 --- a/end2end/EndToEndScaffold/Templates/SqliteTests.cs +++ b/end2end/EndToEndScaffold/Templates/SqliteTests.cs @@ -36,14 +36,14 @@ await QuerySql.InsertSqliteTypes(new QuerySql.InsertSqliteTypesArgs }; var actual = await QuerySql.GetSqliteTypes(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - } - private static void AssertSingularEquals(QuerySql.GetSqliteTypesRow expected, QuerySql.GetSqliteTypesRow actual) - { - Assert.That(actual.CInteger, Is.EqualTo(expected.CInteger)); - Assert.That(actual.CReal, Is.EqualTo(expected.CReal)); - Assert.That(actual.CText, Is.EqualTo(expected.CText)); - Assert.That(actual.CBlob, Is.EqualTo(expected.CBlob)); + void AssertSingularEquals(QuerySql.GetSqliteTypesRow x, QuerySql.GetSqliteTypesRow y) + { + Assert.That(x.CInteger, Is.EqualTo(y.CInteger)); + Assert.That(x.CReal, Is.EqualTo(y.CReal)); + Assert.That(x.CText, Is.EqualTo(y.CText)); + Assert.That(x.CBlob, Is.EqualTo(y.CBlob)); + } } """ }, @@ -78,14 +78,14 @@ public async Task TestCopyFrom( }; var actual = await QuerySql.GetSqliteTypesCnt(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - } - - private static void AssertSingularEquals(QuerySql.GetSqliteTypesCntRow expected, QuerySql.GetSqliteTypesCntRow actual) - { - Assert.That(actual.Cnt, Is.EqualTo(expected.Cnt)); - Assert.That(actual.CInteger, Is.EqualTo(expected.CInteger)); - Assert.That(actual.CReal, Is.EqualTo(expected.CReal)); - Assert.That(actual.CText, Is.EqualTo(expected.CText)); + + void AssertSingularEquals(QuerySql.GetSqliteTypesCntRow x, QuerySql.GetSqliteTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CInteger, Is.EqualTo(y.CInteger)); + Assert.That(x.CReal, Is.EqualTo(y.CReal)); + Assert.That(x.CText, Is.EqualTo(y.CText)); + } } """ }, @@ -102,9 +102,8 @@ public async Task TestSqliteTransaction() var querySqlWithTx = QuerySql.WithTransaction(transaction); await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = {{Consts.BojackId}}, Name = {{Consts.BojackAuthor}}, Bio = {{Consts.BojackTheme}} }); - // The GetAuthor method in SqliteExampleGen returns QuerySql.GetAuthorRow? (nullable record struct/class) - var actualNull = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = {{Consts.BojackAuthor}} }); - Assert.That(actualNull == null, "there is author"); // This is correct for nullable types + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = {{Consts.BojackAuthor}} }); + ClassicAssert.IsNull(actual); transaction.Commit(); @@ -114,8 +113,15 @@ public async Task TestSqliteTransaction() Name = {{Consts.BojackAuthor}}, Bio = {{Consts.BojackTheme}} }; - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = {{Consts.BojackAuthor}} }); - Assert.That(SingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}})); // Apply placeholder here + actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = {{Consts.BojackAuthor}} }); + AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); + + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } """ }, @@ -135,7 +141,7 @@ public async Task TestSqliteTransactionRollback() transaction.Rollback(); var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = {{Consts.BojackAuthor}} }); - Assert.That(actual == null, "author should not exist after rollback"); + ClassicAssert.IsNull(actual); } """ }, @@ -165,13 +171,13 @@ await QuerySql.InsertSqliteTypes(new QuerySql.InsertSqliteTypesArgs }; var actual = await QuerySql.GetSqliteFunctions(); AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - } - private static void AssertSingularEquals(QuerySql.GetSqliteFunctionsRow expected, QuerySql.GetSqliteFunctionsRow actual) - { - Assert.That(actual.MaxInteger, Is.EqualTo(expected.MaxInteger)); - Assert.That(actual.MaxReal, Is.EqualTo(expected.MaxReal)); - Assert.That(actual.MaxText, Is.EqualTo(expected.MaxText)); + void AssertSingularEquals(QuerySql.GetSqliteFunctionsRow x, QuerySql.GetSqliteFunctionsRow y) + { + Assert.That(x.MaxInteger, Is.EqualTo(y.MaxInteger)); + Assert.That(x.MaxReal, Is.EqualTo(y.MaxReal)); + Assert.That(x.MaxText, Is.EqualTo(y.MaxText)); + } } """ }, @@ -193,12 +199,14 @@ public async Task TestGetAuthorByIdWithMultipleNamedParam() IdArg = {{Consts.BojackId}}, Take = 1 }); - Assert.That(SingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}})); - } + AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}}); - private static bool SingularEquals(QuerySql.GetAuthorByIdWithMultipleNamedParamRow x, QuerySql.GetAuthorByIdWithMultipleNamedParamRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + void AssertSingularEquals(QuerySql.GetAuthorByIdWithMultipleNamedParamRow x, QuerySql.GetAuthorByIdWithMultipleNamedParamRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } """ } diff --git a/end2end/EndToEndTests/EndToEndTests.csproj b/end2end/EndToEndTests/EndToEndTests.csproj index babe0a3c..a8a8e10f 100644 --- a/end2end/EndToEndTests/EndToEndTests.csproj +++ b/end2end/EndToEndTests/EndToEndTests.csproj @@ -10,9 +10,13 @@ Always - + Always - sqlite.schema.sql + authors.sqlite.schema.sql + + + Always + types.sqlite.schema.sql diff --git a/end2end/EndToEndTests/MySqlConnectorDapperTester.cs b/end2end/EndToEndTests/MySqlConnectorDapperTester.cs index 278c8568..6abddaf9 100644 --- a/end2end/EndToEndTests/MySqlConnectorDapperTester.cs +++ b/end2end/EndToEndTests/MySqlConnectorDapperTester.cs @@ -14,7 +14,10 @@ public partial class MySqlConnectorDapperTester public async Task EmptyTestsTable() { await QuerySql.DeleteAllAuthors(); - await QuerySql.TruncateMysqlTypes(); await QuerySql.TruncateExtendedBios(); + await QuerySql.TruncateMysqlNumericTypes(); + await QuerySql.TruncateMysqlStringTypes(); + await QuerySql.TruncateMysqlDatetimeTypes(); + await QuerySql.TruncateMysqlBinaryTypes(); } } \ No newline at end of file diff --git a/end2end/EndToEndTests/MySqlConnectorDapperTester.generated.cs b/end2end/EndToEndTests/MySqlConnectorDapperTester.generated.cs index bbd69996..50f7a0c3 100644 --- a/end2end/EndToEndTests/MySqlConnectorDapperTester.generated.cs +++ b/end2end/EndToEndTests/MySqlConnectorDapperTester.generated.cs @@ -24,12 +24,13 @@ public async Task TestOne() Bio = "Back in the 90s he was in a very famous TV show" }; var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -54,21 +55,18 @@ public async Task TestMany() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) - { - Assert.That(x.Id, Is.EqualTo(y.Id)); - Assert.That(x.Name, Is.EqualTo(y.Name)); - Assert.That(x.Bio, Is.EqualTo(y.Bio)); - } + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } - private static void AssertSequenceEquals(List x, List y) - { - Assert.That(x.Count, Is.EqualTo(y.Count)); - for (int i = 0; i < x.Count; i++) + void AssertSequenceEquals(List x, List y) { - AssertSingularEquals(x[i], y[i]); + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); } } @@ -106,6 +104,19 @@ public async Task TestExecRows() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -119,12 +130,13 @@ public async Task TestExecLastId() Bio = "Quote that everyone always attribute to Einstein" }; var actual = await QuerySql.GetAuthorById(new QuerySql.GetAuthorByIdArgs { Id = id1 }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -151,19 +163,23 @@ public async Task TestSelfJoinEmbed() } }; var actual = await QuerySql.GetDuplicateAuthors(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) - { - return SingularEquals(x.Author, y.Author) && SingularEquals(x.Author2, y.Author2); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) + { + Assert.That(x.Author.Id, Is.EqualTo(y.Author.Id)); + Assert.That(x.Author.Name, Is.EqualTo(y.Author.Name)); + Assert.That(x.Author.Bio, Is.EqualTo(y.Author.Bio)); + Assert.That(x.Author2.Id, Is.EqualTo(y.Author2.Id)); + Assert.That(x.Author2.Name, Is.EqualTo(y.Author2.Name)); + Assert.That(x.Author2.Bio, Is.EqualTo(y.Author2.Bio)); + } - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -207,31 +223,23 @@ public async Task TestJoinEmbed() } }; var actual = await QuerySql.ListAllAuthorsBooks(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) - { - return SingularEquals(x.Author, y.Author) && SingularEquals(x.Book, y.Book); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Author.Name + o.Book.Name).ToList(); - y = y.OrderBy(o => o.Author.Name + o.Book.Name).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } - - private static bool SingularEquals(Author x, Author y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) + { + Assert.That(x.Author.Id, Is.EqualTo(y.Author.Id)); + Assert.That(x.Author.Name, Is.EqualTo(y.Author.Name)); + Assert.That(x.Author.Bio, Is.EqualTo(y.Author.Bio)); + Assert.That(x.Book.Id, Is.EqualTo(y.Book.Id)); + Assert.That(x.Book.AuthorId, Is.EqualTo(y.Book.AuthorId)); + Assert.That(x.Book.Name, Is.EqualTo(y.Book.Name)); + } - private static bool SingularEquals(Book x, Book y) - { - return x.Id.Equals(y.Id) && x.AuthorId.Equals(y.AuthorId) && x.Name.Equals(y.Name); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -273,21 +281,20 @@ public async Task TestNargNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs()); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Id).ToList(); - y = y.OrderBy(o => o.Id).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } - private static bool SingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -305,7 +312,116 @@ public async Task TestNargNotNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs { NamePattern = "Bojack%" }); - Assert.That(SequenceEquals(expected, actual)); + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } + + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + } + + [Test] + public async Task TestMySqlTransaction() + { + var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)); + await connection.OpenAsync(); + var transaction = connection.BeginTransaction(); + var querySqlWithTx = QuerySql.WithTransaction(transaction); + await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + ClassicAssert.IsNull(actual); + await transaction.CommitAsync(); + var expected = new QuerySql.GetAuthorRow + { + Id = 1111, + Name = "Bojack Horseman", + Bio = "Back in the 90s he was in a very famous TV show" + }; + actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + } + + [Test] + public async Task TestMySqlTransactionRollback() + { + var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)); + await connection.OpenAsync(); + var transaction = connection.BeginTransaction(); + var querySqlWithTx = QuerySql.WithTransaction(transaction); + await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + await transaction.RollbackAsync(); + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + ClassicAssert.IsNull(actual); + } + + [Test] + [TestCase(-54355, "Scream of the Butterfly", "2025-06-29 12:00:00")] + [TestCase(null, null, "1971-01-01 00:00:00")] + public async Task TestMySqlDataTypesOverride(int? cInt, string cVarchar, DateTime cTimestamp) + { + await QuerySql.InsertMysqlNumericTypes(new QuerySql.InsertMysqlNumericTypesArgs { CInt = cInt }); + await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CVarchar = cVarchar }); + await QuerySql.InsertMysqlDatetimeTypes(new QuerySql.InsertMysqlDatetimeTypesArgs { CTimestamp = cTimestamp }); + var expected = new QuerySql.GetMysqlFunctionsRow + { + MaxInt = cInt, + MaxVarchar = cVarchar, + MaxTimestamp = cTimestamp + }; + var actual = await QuerySql.GetMysqlFunctions(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlFunctionsRow x, QuerySql.GetMysqlFunctionsRow y) + { + Assert.That(x.MaxInt, Is.EqualTo(y.MaxInt)); + Assert.That(x.MaxVarchar, Is.EqualTo(y.MaxVarchar)); + Assert.That(x.MaxTimestamp, Is.EqualTo(y.MaxTimestamp)); + } + } + + [Test] + public async Task TestMySqlScopedSchemaEnum() + { + await this.QuerySql.CreateExtendedBio(new QuerySql.CreateExtendedBioArgs { AuthorName = "Bojack Horseman", Name = "One Trick Pony", BioType = BiosBioType.Memoir, AuthorType = new HashSet { BiosAuthorType.Author, BiosAuthorType.Translator } }); + var expected = new QuerySql.GetFirstExtendedBioByTypeRow + { + AuthorName = "Bojack Horseman", + Name = "One Trick Pony", + BioType = BiosBioType.Memoir, + AuthorType = new HashSet + { + BiosAuthorType.Author, + BiosAuthorType.Translator + } + }; + var actual = await this.QuerySql.GetFirstExtendedBioByType(new QuerySql.GetFirstExtendedBioByTypeArgs { BioType = BiosBioType.Memoir }); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetFirstExtendedBioByTypeRow x, QuerySql.GetFirstExtendedBioByTypeRow y) + { + Assert.That(x.AuthorName, Is.EqualTo(y.AuthorName)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.BioType, Is.EqualTo(y.BioType)); + Assert.That(x.AuthorType, Is.EqualTo(y.AuthorType)); + } + } + + [Test] + public void TestMySqlInvalidJson() + { + Assert.ThrowsAsync(async () => await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CJsonStringOverride = "SOME INVALID JSON" })); } [Test] @@ -313,8 +429,8 @@ public async Task TestNargNotNull() [TestCase(null, null, null, null, null, null, null, null)] public async Task TestMySqlStringTypes(string cChar, string cNchar, string cNationalChar, string cVarchar, string cTinytext, string cMediumtext, string cText, string cLongtext) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CChar = cChar, CNchar = cNchar, CNationalChar = cNationalChar, CVarchar = cVarchar, CTinytext = cTinytext, CMediumtext = cMediumtext, CText = cText, CLongtext = cLongtext }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CChar = cChar, CNchar = cNchar, CNationalChar = cNationalChar, CVarchar = cVarchar, CTinytext = cTinytext, CMediumtext = cMediumtext, CText = cText, CLongtext = cLongtext }); + var expected = new QuerySql.GetMysqlStringTypesRow { CChar = cChar, CNchar = cNchar, @@ -325,15 +441,19 @@ public async Task TestMySqlStringTypes(string cChar, string cNchar, string cNati CText = cText, CLongtext = cLongtext }; - var actual = await QuerySql.GetMysqlTypes(); - Assert.That(actual.CChar, Is.EqualTo(expected.CChar)); - Assert.That(actual.CNchar, Is.EqualTo(expected.CNchar)); - Assert.That(actual.CNationalChar, Is.EqualTo(expected.CNationalChar)); - Assert.That(actual.CVarchar, Is.EqualTo(expected.CVarchar)); - Assert.That(actual.CTinytext, Is.EqualTo(expected.CTinytext)); - Assert.That(actual.CMediumtext, Is.EqualTo(expected.CMediumtext)); - Assert.That(actual.CText, Is.EqualTo(expected.CText)); - Assert.That(actual.CLongtext, Is.EqualTo(expected.CLongtext)); + var actual = await QuerySql.GetMysqlStringTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlStringTypesRow x, QuerySql.GetMysqlStringTypesRow y) + { + Assert.That(x.CChar, Is.EqualTo(y.CChar)); + Assert.That(x.CNchar, Is.EqualTo(y.CNchar)); + Assert.That(x.CNationalChar, Is.EqualTo(y.CNationalChar)); + Assert.That(x.CVarchar, Is.EqualTo(y.CVarchar)); + Assert.That(x.CTinytext, Is.EqualTo(y.CTinytext)); + Assert.That(x.CMediumtext, Is.EqualTo(y.CMediumtext)); + Assert.That(x.CText, Is.EqualTo(y.CText)); + Assert.That(x.CLongtext, Is.EqualTo(y.CLongtext)); + } } [Test] @@ -341,8 +461,8 @@ public async Task TestMySqlStringTypes(string cChar, string cNchar, string cNati [TestCase(null, null, null, null, null, null, null, null, null)] public async Task TestMySqlIntegerTypes(bool? cBool, bool? cBoolean, short? cTinyint, short? cYear, short? cSmallint, int? cMediumint, int? cInt, int? cInteger, long? cBigint) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CBool = cBool, CBoolean = cBoolean, CTinyint = cTinyint, CSmallint = cSmallint, CMediumint = cMediumint, CInt = cInt, CInteger = cInteger, CBigint = cBigint }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlNumericTypes(new QuerySql.InsertMysqlNumericTypesArgs { CBool = cBool, CBoolean = cBoolean, CTinyint = cTinyint, CSmallint = cSmallint, CMediumint = cMediumint, CInt = cInt, CInteger = cInteger, CBigint = cBigint }); + var expected = new QuerySql.GetMysqlNumericTypesRow { CBool = cBool, CBoolean = cBoolean, @@ -353,49 +473,19 @@ public async Task TestMySqlIntegerTypes(bool? cBool, bool? cBoolean, short? cTin CInteger = cInteger, CBigint = cBigint }; - var actual = await QuerySql.GetMysqlTypes(); - Assert.That(actual.CBool, Is.EqualTo(expected.CBool)); - Assert.That(actual.CBoolean, Is.EqualTo(expected.CBoolean)); - Assert.That(actual.CTinyint, Is.EqualTo(expected.CTinyint)); - Assert.That(actual.CSmallint, Is.EqualTo(expected.CSmallint)); - Assert.That(actual.CMediumint, Is.EqualTo(expected.CMediumint)); - Assert.That(actual.CInt, Is.EqualTo(expected.CInt)); - Assert.That(actual.CInteger, Is.EqualTo(expected.CInteger)); - Assert.That(actual.CBigint, Is.EqualTo(expected.CBigint)); - } - - [Test] - public async Task TestMySqlTransaction() - { - var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)); - await connection.OpenAsync(); - var transaction = connection.BeginTransaction(); - var querySqlWithTx = QuerySql.WithTransaction(transaction); - await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - var actualNull = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actualNull == null, "there is author"); // This is correct for nullable types - await transaction.CommitAsync(); - var expected = new QuerySql.GetAuthorRow + var actual = await QuerySql.GetMysqlNumericTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlNumericTypesRow x, QuerySql.GetMysqlNumericTypesRow y) { - Id = 1111, - Name = "Bojack Horseman", - Bio = "Back in the 90s he was in a very famous TV show" - }; - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual)); // Apply placeholder here - } - - [Test] - public async Task TestMySqlTransactionRollback() - { - var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)); - await connection.OpenAsync(); - var transaction = connection.BeginTransaction(); - var querySqlWithTx = QuerySql.WithTransaction(transaction); - await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - await transaction.RollbackAsync(); - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actual == null, "author should not exist after rollback"); + Assert.That(x.CBool, Is.EqualTo(y.CBool)); + Assert.That(x.CBoolean, Is.EqualTo(y.CBoolean)); + Assert.That(x.CTinyint, Is.EqualTo(y.CTinyint)); + Assert.That(x.CSmallint, Is.EqualTo(y.CSmallint)); + Assert.That(x.CMediumint, Is.EqualTo(y.CMediumint)); + Assert.That(x.CInt, Is.EqualTo(y.CInt)); + Assert.That(x.CInteger, Is.EqualTo(y.CInteger)); + Assert.That(x.CBigint, Is.EqualTo(y.CBigint)); + } } [Test] @@ -403,8 +493,8 @@ public async Task TestMySqlTransactionRollback() [TestCase(null, null, null, null, null, null, null)] public async Task TestMySqlFloatingPointTypes(float? cFloat, decimal? cNumeric, decimal? cDecimal, decimal? cDec, decimal? cFixed, double? cDouble, double? cDoublePrecision) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CFloat = cFloat, CNumeric = cNumeric, CDecimal = cDecimal, CDec = cDec, CFixed = cFixed, CDouble = cDouble, CDoublePrecision = cDoublePrecision }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlNumericTypes(new QuerySql.InsertMysqlNumericTypesArgs { CFloat = cFloat, CNumeric = cNumeric, CDecimal = cDecimal, CDec = cDec, CFixed = cFixed, CDouble = cDouble, CDoublePrecision = cDoublePrecision }); + var expected = new QuerySql.GetMysqlNumericTypesRow { CFloat = cFloat, CNumeric = cNumeric, @@ -414,32 +504,44 @@ public async Task TestMySqlFloatingPointTypes(float? cFloat, decimal? cNumeric, CDouble = cDouble, CDoublePrecision = cDoublePrecision }; - var actual = await QuerySql.GetMysqlTypes(); - Assert.That(actual.CFloat, Is.EqualTo(expected.CFloat)); - Assert.That(actual.CNumeric, Is.EqualTo(expected.CNumeric)); - Assert.That(actual.CDecimal, Is.EqualTo(expected.CDecimal)); - Assert.That(actual.CDec, Is.EqualTo(expected.CDec)); - Assert.That(actual.CFixed, Is.EqualTo(expected.CFixed)); - Assert.That(actual.CDouble, Is.EqualTo(expected.CDouble)); - Assert.That(actual.CDoublePrecision, Is.EqualTo(expected.CDoublePrecision)); + var actual = await QuerySql.GetMysqlNumericTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlNumericTypesRow x, QuerySql.GetMysqlNumericTypesRow y) + { + Assert.That(x.CFloat, Is.EqualTo(y.CFloat)); + Assert.That(x.CNumeric, Is.EqualTo(y.CNumeric)); + Assert.That(x.CDecimal, Is.EqualTo(y.CDecimal)); + Assert.That(x.CDec, Is.EqualTo(y.CDec)); + Assert.That(x.CFixed, Is.EqualTo(y.CFixed)); + Assert.That(x.CDouble, Is.EqualTo(y.CDouble)); + Assert.That(x.CDoublePrecision, Is.EqualTo(y.CDoublePrecision)); + } } [Test] - [TestCase(1999, "2000-1-30", "1983-11-3 02:01:22")] - [TestCase(null, null, "1970-1-1 00:00:01")] - public async Task TestMySqlDateTimeTypes(short? cYear, DateTime? cDate, DateTime? cTimestamp) + [TestCase(1999, "2000-1-30", "1983-11-3 02:01:22", "2010-1-30 08:11:00", "02:01:22")] + [TestCase(null, null, null, null, null)] + public async Task TestMySqlDateTimeTypes(short? cYear, DateTime? cDate, DateTime? cDatetime, DateTime? cTimestamp, TimeSpan? cTime) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CYear = cYear, CDate = cDate, CTimestamp = cTimestamp }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlDatetimeTypes(new QuerySql.InsertMysqlDatetimeTypesArgs { CYear = cYear, CDate = cDate, CDatetime = cDatetime, CTimestamp = cTimestamp, CTime = cTime }); + var expected = new QuerySql.GetMysqlDatetimeTypesRow { CYear = cYear, CDate = cDate, - CTimestamp = cTimestamp + CDatetime = cDatetime, + CTimestamp = cTimestamp, + CTime = cTime }; - var actual = await QuerySql.GetMysqlTypes(); - Assert.That(actual.CYear, Is.EqualTo(expected.CYear)); - Assert.That(actual.CDate, Is.EqualTo(expected.CDate)); - Assert.That(actual.CTimestamp, Is.EqualTo(expected.CTimestamp)); + var actual = await QuerySql.GetMysqlDatetimeTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlDatetimeTypesRow x, QuerySql.GetMysqlDatetimeTypesRow y) + { + Assert.That(x.CYear, Is.EqualTo(y.CYear)); + Assert.That(x.CDate, Is.EqualTo(y.CDate)); + Assert.That(x.CDatetime, Is.EqualTo(y.CDatetime)); + Assert.That(x.CTimestamp, Is.EqualTo(y.CTimestamp)); + Assert.That(x.CTime, Is.EqualTo(y.CTime)); + } } [Test] @@ -448,8 +550,8 @@ public async Task TestMySqlDateTimeTypes(short? cYear, DateTime? cDate, DateTime [TestCase(null, null, null, null, null, null, null)] public async Task TestMySqlBinaryTypes(byte? cBit, byte[] cBinary, byte[] cVarbinary, byte[] cTinyblob, byte[] cBlob, byte[] cMediumblob, byte[] cLongblob) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CBit = cBit, CBinary = cBinary, CVarbinary = cVarbinary, CTinyblob = cTinyblob, CBlob = cBlob, CMediumblob = cMediumblob, CLongblob = cLongblob }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlBinaryTypes(new QuerySql.InsertMysqlBinaryTypesArgs { CBit = cBit, CBinary = cBinary, CVarbinary = cVarbinary, CTinyblob = cTinyblob, CBlob = cBlob, CMediumblob = cMediumblob, CLongblob = cLongblob }); + var expected = new QuerySql.GetMysqlBinaryTypesRow { CBit = cBit, CBinary = cBinary, @@ -459,9 +561,9 @@ public async Task TestMySqlBinaryTypes(byte? cBit, byte[] cBinary, byte[] cVarbi CMediumblob = cMediumblob, CLongblob = cLongblob }; - var actual = await QuerySql.GetMysqlTypes(); + var actual = await QuerySql.GetMysqlBinaryTypes(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow y) + void AssertSingularEquals(QuerySql.GetMysqlBinaryTypesRow x, QuerySql.GetMysqlBinaryTypesRow y) { Assert.That(x.CBit, Is.EqualTo(y.CBit)); Assert.That(x.CBinary, Is.EqualTo(y.CBinary)); @@ -473,74 +575,32 @@ void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow } } - [Test] - [TestCase(MysqlTypesCEnum.Medium, new[] { MysqlTypesCSet.Tea, MysqlTypesCSet.Coffee })] - [TestCase(null, null)] - public async Task TestMySqlStringTypes(MysqlTypesCEnum? cEnum, MysqlTypesCSet[] cSet) + private static IEnumerable MySqlEnumTypesTestCases { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CEnum = cEnum, CSet = cSet }); - var expected = new QuerySql.GetMysqlTypesRow - { - CEnum = cEnum, - CSet = cSet - }; - var actual = await QuerySql.GetMysqlTypes(); - AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow y) + get { - Assert.That(x.CEnum, Is.EqualTo(y.CEnum)); - Assert.That(x.CSet, Is.EqualTo(y.CSet)); + yield return new TestCaseData(MysqlStringTypesCEnum.Medium, new HashSet { MysqlStringTypesCSet.Tea, MysqlStringTypesCSet.Coffee }).SetName("Valid Enum values"); + yield return new TestCaseData(null, null).SetName("Enum with null values"); } } [Test] - [TestCase(-54355, "Scream of the Butterfly", "2025-06-29 12:00:00")] - [TestCase(null, null, "1971-01-01 00:00:00")] - public async Task TestMySqlDataTypesOverride(int? cInt, string cVarchar, DateTime cTimestamp) + [TestCaseSource(nameof(MySqlEnumTypesTestCases))] + public async Task TestMySqlStringTypes(MysqlStringTypesCEnum? cEnum, HashSet cSet) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CInt = cInt, CVarchar = cVarchar, CTimestamp = cTimestamp }); - var expected = new QuerySql.GetMysqlFunctionsRow + await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CEnum = cEnum, CSet = cSet }); + var expected = new QuerySql.GetMysqlStringTypesRow { - MaxInt = cInt, - MaxVarchar = cVarchar, - MaxTimestamp = cTimestamp + CEnum = cEnum, + CSet = cSet }; - var actual = await QuerySql.GetMysqlFunctions(); + var actual = await QuerySql.GetMysqlStringTypes(); AssertSingularEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.GetMysqlFunctionsRow expected, QuerySql.GetMysqlFunctionsRow actual) - { - Assert.That(actual.MaxInt, Is.EqualTo(expected.MaxInt)); - Assert.That(actual.MaxVarchar, Is.EqualTo(expected.MaxVarchar)); - Assert.That(actual.MaxTimestamp, Is.EqualTo(expected.MaxTimestamp)); - } - - [Test] - public async Task TestMySqlScopedSchemaEnum() - { - await this.QuerySql.CreateExtendedBio(new QuerySql.CreateExtendedBioArgs { AuthorName = "Bojack Horseman", Name = "One Trick Pony", BioType = ExtendedBiosBioType.Memoir, AuthorType = new ExtendedBiosAuthorType[] { ExtendedBiosAuthorType.Author, ExtendedBiosAuthorType.Translator } }); - var expected = new QuerySql.GetFirstExtendedBioByTypeRow + void AssertSingularEquals(QuerySql.GetMysqlStringTypesRow x, QuerySql.GetMysqlStringTypesRow y) { - AuthorName = "Bojack Horseman", - Name = "One Trick Pony", - BioType = ExtendedBiosBioType.Memoir, - AuthorType = new ExtendedBiosAuthorType[] - { - ExtendedBiosAuthorType.Author, - ExtendedBiosAuthorType.Translator - } - }; - var actual = await this.QuerySql.GetFirstExtendedBioByType(new QuerySql.GetFirstExtendedBioByTypeArgs { BioType = ExtendedBiosBioType.Memoir }); - AssertSingularEquals(expected, actual); - } - - private void AssertSingularEquals(QuerySql.GetFirstExtendedBioByTypeRow x, QuerySql.GetFirstExtendedBioByTypeRow y) - { - Assert.That(x.AuthorName, Is.EqualTo(y.AuthorName)); - Assert.That(x.Name, Is.EqualTo(y.Name)); - Assert.That(x.BioType, Is.EqualTo(y.BioType)); - Assert.That(x.AuthorType, Is.EqualTo(y.AuthorType)); + Assert.That(x.CEnum, Is.EqualTo(y.CEnum)); + Assert.That(x.CSet, Is.EqualTo(y.CSet)); + } } [Test] @@ -551,15 +611,15 @@ public async Task TestMySqlJsonDataType(string cJson) JsonElement? cParsedJson = null; if (cJson != null) cParsedJson = JsonDocument.Parse(cJson).RootElement; - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CJson = cParsedJson, CJsonStringOverride = cJson }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CJson = cParsedJson, CJsonStringOverride = cJson }); + var expected = new QuerySql.GetMysqlStringTypesRow { CJson = cParsedJson, CJsonStringOverride = cJson }; - var actual = await QuerySql.GetMysqlTypes(); + var actual = await QuerySql.GetMysqlStringTypes(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow y) + void AssertSingularEquals(QuerySql.GetMysqlStringTypesRow x, QuerySql.GetMysqlStringTypesRow y) { Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); if (x.CJson.HasValue) @@ -568,46 +628,14 @@ void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow } } - [Test] - [TestCase(100, "{\"name\": \"Swordfishtrombones\", \"year\": 1983}")] - [TestCase(10, null)] - public async Task TestJsonCopyFrom(int batchSize, string cJson) - { - JsonElement? cParsedJson = null; - if (cJson != null) - cParsedJson = JsonDocument.Parse(cJson).RootElement; - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CJson = cParsedJson }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow - { - Cnt = batchSize, - CJson = cParsedJson - }; - var actual = await QuerySql.GetMysqlTypesCnt(); - AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypesCntRow y) - { - Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); - Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); - if (x.CJson.HasValue) - Assert.That(x.CJson.Value.GetRawText(), Is.EqualTo(y.CJson.Value.GetRawText())); - } - } - - [Test] - public void TestMySqlInvalidJson() - { - Assert.ThrowsAsync(async () => await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CJsonStringOverride = "SOME INVALID JSON" })); - } - [Test] [TestCase(100, "D", "\u4321", "\u2345", "Parasite", "Clockwork Orange", "Dr. Strangelove", "Interview with a Vampire", "Memento")] [TestCase(10, null, null, null, null, null, null, null, null)] public async Task TestStringCopyFrom(int batchSize, string cChar, string cNchar, string cNationalChar, string cVarchar, string cTinytext, string cMediumtext, string cText, string cLongtext) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CChar = cChar, CNchar = cNchar, CNationalChar = cNationalChar, CVarchar = cVarchar, CTinytext = cTinytext, CMediumtext = cMediumtext, CText = cText, CLongtext = cLongtext }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlStringTypesBatchArgs { CChar = cChar, CNchar = cNchar, CNationalChar = cNationalChar, CVarchar = cVarchar, CTinytext = cTinytext, CMediumtext = cMediumtext, CText = cText, CLongtext = cLongtext }).ToList(); + await QuerySql.InsertMysqlStringTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlStringTypesCntRow { Cnt = batchSize, CChar = cChar, @@ -619,9 +647,9 @@ public async Task TestStringCopyFrom(int batchSize, string cChar, string cNchar, CText = cText, CLongtext = cLongtext }; - var actual = await QuerySql.GetMysqlTypesCnt(); + var actual = await QuerySql.GetMysqlStringTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypesCntRow y) + void AssertSingularEquals(QuerySql.GetMysqlStringTypesCntRow x, QuerySql.GetMysqlStringTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CChar, Is.EqualTo(y.CChar)); @@ -640,9 +668,9 @@ void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypes [TestCase(10, null, null, null, null, null, null, null, null)] public async Task TestIntegerCopyFrom(int batchSize, bool? cBool, bool? cBoolean, short? cTinyint, short? cSmallint, int? cMediumint, int? cInt, int? cInteger, long? cBigint) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CBool = cBool, CBoolean = cBoolean, CTinyint = cTinyint, CSmallint = cSmallint, CMediumint = cMediumint, CInt = cInt, CInteger = cInteger, CBigint = cBigint }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlNumericTypesBatchArgs { CBool = cBool, CBoolean = cBoolean, CTinyint = cTinyint, CSmallint = cSmallint, CMediumint = cMediumint, CInt = cInt, CInteger = cInteger, CBigint = cBigint }).ToList(); + await QuerySql.InsertMysqlNumericTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlNumericTypesCntRow { Cnt = batchSize, CBool = cBool, @@ -654,9 +682,9 @@ public async Task TestIntegerCopyFrom(int batchSize, bool? cBool, bool? cBoolean CInteger = cInteger, CBigint = cBigint }; - var actual = await QuerySql.GetMysqlTypesCnt(); + var actual = await QuerySql.GetMysqlNumericTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypesCntRow y) + void AssertSingularEquals(QuerySql.GetMysqlNumericTypesCntRow x, QuerySql.GetMysqlNumericTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CBool, Is.EqualTo(y.CBool)); @@ -675,9 +703,9 @@ void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypes [TestCase(10, null, null, null, null, null, null, null)] public async Task TestFloatingPointCopyFrom(int batchSize, float? cFloat, decimal? cNumeric, decimal? cDecimal, decimal? cDec, decimal? cFixed, double? cDouble, double? cDoublePrecision) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CFloat = cFloat, CNumeric = cNumeric, CDecimal = cDecimal, CDec = cDec, CFixed = cFixed, CDouble = cDouble, CDoublePrecision = cDoublePrecision }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlNumericTypesBatchArgs { CFloat = cFloat, CNumeric = cNumeric, CDecimal = cDecimal, CDec = cDec, CFixed = cFixed, CDouble = cDouble, CDoublePrecision = cDoublePrecision }).ToList(); + await QuerySql.InsertMysqlNumericTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlNumericTypesCntRow { Cnt = batchSize, CFloat = cFloat, @@ -688,37 +716,48 @@ public async Task TestFloatingPointCopyFrom(int batchSize, float? cFloat, decima CDouble = cDouble, CDoublePrecision = cDoublePrecision }; - var actual = await QuerySql.GetMysqlTypesCnt(); - Assert.That(actual.CFloat, Is.EqualTo(expected.CFloat)); - Assert.That(actual.CNumeric, Is.EqualTo(expected.CNumeric)); - Assert.That(actual.CDecimal, Is.EqualTo(expected.CDecimal)); - Assert.That(actual.CDec, Is.EqualTo(expected.CDec)); - Assert.That(actual.CFixed, Is.EqualTo(expected.CFixed)); - Assert.That(actual.CDouble, Is.EqualTo(expected.CDouble)); - Assert.That(actual.CDoublePrecision, Is.EqualTo(expected.CDoublePrecision)); + var actual = await QuerySql.GetMysqlNumericTypesCnt(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlNumericTypesCntRow x, QuerySql.GetMysqlNumericTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CFloat, Is.EqualTo(y.CFloat)); + Assert.That(x.CNumeric, Is.EqualTo(y.CNumeric)); + Assert.That(x.CDecimal, Is.EqualTo(y.CDecimal)); + Assert.That(x.CDec, Is.EqualTo(y.CDec)); + Assert.That(x.CFixed, Is.EqualTo(y.CFixed)); + Assert.That(x.CDouble, Is.EqualTo(y.CDouble)); + Assert.That(x.CDoublePrecision, Is.EqualTo(y.CDoublePrecision)); + } } [Test] - [TestCase(100, 1993, "2000-1-30", "1983-11-3 02:01:22", "2010-1-30 08:11:00")] - [TestCase(10, null, null, null, null)] - public async Task TestDateTimeCopyFrom(int batchSize, short? cYear, DateTime? cDate, DateTime? cDatetime, DateTime? cTimestamp) + [TestCase(100, 1993, "2000-1-30", "1983-11-3 02:01:22", "2010-1-30 08:11:00", "02:01:22")] + [TestCase(10, null, null, null, null, null)] + public async Task TestDateTimeCopyFrom(int batchSize, short? cYear, DateTime? cDate, DateTime? cDatetime, DateTime? cTimestamp, TimeSpan? cTime) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CYear = cYear, CDate = cDate, CDatetime = cDatetime, CTimestamp = cTimestamp }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlDatetimeTypesBatchArgs { CYear = cYear, CDate = cDate, CDatetime = cDatetime, CTimestamp = cTimestamp, CTime = cTime }).ToList(); + await QuerySql.InsertMysqlDatetimeTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlDatetimeTypesCntRow { Cnt = batchSize, CYear = cYear, CDate = cDate, CDatetime = cDatetime, - CTimestamp = cTimestamp + CTimestamp = cTimestamp, + CTime = cTime }; - var actual = await QuerySql.GetMysqlTypesCnt(); - Assert.That(actual.Cnt, Is.EqualTo(expected.Cnt)); - Assert.That(actual.CYear, Is.EqualTo(expected.CYear)); - Assert.That(actual.CDate, Is.EqualTo(expected.CDate)); - Assert.That(actual.CDatetime, Is.EqualTo(expected.CDatetime)); - Assert.That(actual.CTimestamp, Is.EqualTo(expected.CTimestamp)); + var actual = await QuerySql.GetMysqlDatetimeTypesCnt(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlDatetimeTypesCntRow x, QuerySql.GetMysqlDatetimeTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CYear, Is.EqualTo(y.CYear)); + Assert.That(x.CDate, Is.EqualTo(y.CDate)); + Assert.That(x.CDatetime, Is.EqualTo(y.CDatetime)); + Assert.That(x.CTimestamp, Is.EqualTo(y.CTimestamp)); + Assert.That(x.CTime, Is.EqualTo(y.CTime)); + } } [Test] @@ -727,9 +766,9 @@ public async Task TestDateTimeCopyFrom(int batchSize, short? cYear, DateTime? cD [TestCase(10, null, null, null, null, null, null, null)] public async Task TestBinaryCopyFrom(int batchSize, byte? cBit, byte[] cBinary, byte[] cVarbinary, byte[] cTinyblob, byte[] cBlob, byte[] cMediumblob, byte[] cLongblob) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CBit = cBit, CBinary = cBinary, CVarbinary = cVarbinary, CTinyblob = cTinyblob, CBlob = cBlob, CMediumblob = cMediumblob, CLongblob = cLongblob }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlBinaryTypesBatchArgs { CBit = cBit, CBinary = cBinary, CVarbinary = cVarbinary, CTinyblob = cTinyblob, CBlob = cBlob, CMediumblob = cMediumblob, CLongblob = cLongblob }).ToList(); + await QuerySql.InsertMysqlBinaryTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlBinaryTypesCntRow { Cnt = batchSize, CBit = cBit, @@ -740,39 +779,76 @@ public async Task TestBinaryCopyFrom(int batchSize, byte? cBit, byte[] cBinary, CMediumblob = cMediumblob, CLongblob = cLongblob }; - var actual = await QuerySql.GetMysqlTypesCnt(); - Assert.That(actual.Cnt, Is.EqualTo(expected.Cnt)); - Assert.That(actual.CBit, Is.EqualTo(expected.CBit)); - Assert.That(actual.CBinary, Is.EqualTo(expected.CBinary)); - Assert.That(actual.CVarbinary, Is.EqualTo(expected.CVarbinary)); - Assert.That(actual.CTinyblob, Is.EqualTo(expected.CTinyblob)); - Assert.That(actual.CBlob, Is.EqualTo(expected.CBlob)); - Assert.That(actual.CMediumblob, Is.EqualTo(expected.CMediumblob)); - Assert.That(actual.CLongblob, Is.EqualTo(expected.CLongblob)); + var actual = await QuerySql.GetMysqlBinaryTypesCnt(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlBinaryTypesCntRow x, QuerySql.GetMysqlBinaryTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CBit, Is.EqualTo(y.CBit)); + Assert.That(x.CBinary, Is.EqualTo(y.CBinary)); + Assert.That(x.CVarbinary, Is.EqualTo(y.CVarbinary)); + Assert.That(x.CTinyblob, Is.EqualTo(y.CTinyblob)); + Assert.That(x.CBlob, Is.EqualTo(y.CBlob)); + Assert.That(x.CMediumblob, Is.EqualTo(y.CMediumblob)); + Assert.That(x.CLongblob, Is.EqualTo(y.CLongblob)); + } + } + + private static IEnumerable MySqlEnumCopyFromTestCases + { + get + { + yield return new TestCaseData(100, MysqlStringTypesCEnum.Big, new HashSet { MysqlStringTypesCSet.Tea, MysqlStringTypesCSet.Coffee }).SetName("Valid Enum values"); + yield return new TestCaseData(10, null, null).SetName("Enum with null values"); + } } [Test] - [TestCase(100, MysqlTypesCEnum.Big, new[] { MysqlTypesCSet.Tea, MysqlTypesCSet.Coffee })] - [TestCase(500, MysqlTypesCEnum.Small, new[] { MysqlTypesCSet.Milk })] - [TestCase(10, null, null)] - public async Task TestCopyFrom(int batchSize, MysqlTypesCEnum? cEnum, MysqlTypesCSet[] cSet) + [TestCaseSource(nameof(MySqlEnumCopyFromTestCases))] + public async Task TestCopyFrom(int batchSize, MysqlStringTypesCEnum? cEnum, HashSet cSet) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CEnum = cEnum, CSet = cSet }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlStringTypesBatchArgs { CEnum = cEnum, CSet = cSet }).ToList(); + await QuerySql.InsertMysqlStringTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlStringTypesCntRow { Cnt = batchSize, CEnum = cEnum, CSet = cSet }; - var actual = await QuerySql.GetMysqlTypesCnt(); + var actual = await QuerySql.GetMysqlStringTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypesCntRow y) + void AssertSingularEquals(QuerySql.GetMysqlStringTypesCntRow x, QuerySql.GetMysqlStringTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CEnum, Is.EqualTo(y.CEnum)); Assert.That(x.CSet, Is.EqualTo(y.CSet)); } } + + [Test] + [TestCase(100, "{\"name\": \"Swordfishtrombones\", \"year\": 1983}")] + [TestCase(10, null)] + public async Task TestJsonCopyFrom(int batchSize, string cJson) + { + JsonElement? cParsedJson = null; + if (cJson != null) + cParsedJson = JsonDocument.Parse(cJson).RootElement; + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlStringTypesBatchArgs { CJson = cParsedJson }).ToList(); + await QuerySql.InsertMysqlStringTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlStringTypesCntRow + { + Cnt = batchSize, + CJson = cParsedJson + }; + var actual = await QuerySql.GetMysqlStringTypesCnt(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlStringTypesCntRow x, QuerySql.GetMysqlStringTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); + if (x.CJson.HasValue) + Assert.That(x.CJson.Value.GetRawText(), Is.EqualTo(y.CJson.Value.GetRawText())); + } + } } } diff --git a/end2end/EndToEndTests/MySqlConnectorTester.cs b/end2end/EndToEndTests/MySqlConnectorTester.cs index 3a9c01c2..dfa6f154 100644 --- a/end2end/EndToEndTests/MySqlConnectorTester.cs +++ b/end2end/EndToEndTests/MySqlConnectorTester.cs @@ -14,7 +14,10 @@ public partial class MySqlConnectorTester public async Task EmptyTestsTable() { await QuerySql.DeleteAllAuthors(); - await QuerySql.TruncateMysqlTypes(); await QuerySql.TruncateExtendedBios(); + await QuerySql.TruncateMysqlNumericTypes(); + await QuerySql.TruncateMysqlStringTypes(); + await QuerySql.TruncateMysqlDatetimeTypes(); + await QuerySql.TruncateMysqlBinaryTypes(); } } \ No newline at end of file diff --git a/end2end/EndToEndTests/MySqlConnectorTester.generated.cs b/end2end/EndToEndTests/MySqlConnectorTester.generated.cs index 97605d41..d51787d7 100644 --- a/end2end/EndToEndTests/MySqlConnectorTester.generated.cs +++ b/end2end/EndToEndTests/MySqlConnectorTester.generated.cs @@ -24,12 +24,13 @@ public async Task TestOne() Bio = "Back in the 90s he was in a very famous TV show" }; var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual.Value)); - } - - private static bool SingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -54,21 +55,18 @@ public async Task TestMany() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) - { - Assert.That(x.Id, Is.EqualTo(y.Id)); - Assert.That(x.Name, Is.EqualTo(y.Name)); - Assert.That(x.Bio, Is.EqualTo(y.Bio)); - } + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } - private static void AssertSequenceEquals(List x, List y) - { - Assert.That(x.Count, Is.EqualTo(y.Count)); - for (int i = 0; i < x.Count; i++) + void AssertSequenceEquals(List x, List y) { - AssertSingularEquals(x[i], y[i]); + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); } } @@ -106,6 +104,19 @@ public async Task TestExecRows() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -119,12 +130,13 @@ public async Task TestExecLastId() Bio = "Quote that everyone always attribute to Einstein" }; var actual = await QuerySql.GetAuthorById(new QuerySql.GetAuthorByIdArgs { Id = id1 }); - Assert.That(SingularEquals(expected, actual.Value)); - } - - private static bool SingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -151,19 +163,23 @@ public async Task TestSelfJoinEmbed() } }; var actual = await QuerySql.GetDuplicateAuthors(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) - { - return SingularEquals(x.Author.Value, y.Author.Value) && SingularEquals(x.Author2.Value, y.Author2.Value); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) + { + Assert.That(x.Author.Value.Id, Is.EqualTo(y.Author.Value.Id)); + Assert.That(x.Author.Value.Name, Is.EqualTo(y.Author.Value.Name)); + Assert.That(x.Author.Value.Bio, Is.EqualTo(y.Author.Value.Bio)); + Assert.That(x.Author2.Value.Id, Is.EqualTo(y.Author2.Value.Id)); + Assert.That(x.Author2.Value.Name, Is.EqualTo(y.Author2.Value.Name)); + Assert.That(x.Author2.Value.Bio, Is.EqualTo(y.Author2.Value.Bio)); + } - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -207,31 +223,23 @@ public async Task TestJoinEmbed() } }; var actual = await QuerySql.ListAllAuthorsBooks(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) - { - return SingularEquals(x.Author.Value, y.Author.Value) && SingularEquals(x.Book.Value, y.Book.Value); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Author.Value.Name + o.Book.Value.Name).ToList(); - y = y.OrderBy(o => o.Author.Value.Name + o.Book.Value.Name).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } - - private static bool SingularEquals(Author x, Author y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) + { + Assert.That(x.Author.Value.Id, Is.EqualTo(y.Author.Value.Id)); + Assert.That(x.Author.Value.Name, Is.EqualTo(y.Author.Value.Name)); + Assert.That(x.Author.Value.Bio, Is.EqualTo(y.Author.Value.Bio)); + Assert.That(x.Book.Value.Id, Is.EqualTo(y.Book.Value.Id)); + Assert.That(x.Book.Value.AuthorId, Is.EqualTo(y.Book.Value.AuthorId)); + Assert.That(x.Book.Value.Name, Is.EqualTo(y.Book.Value.Name)); + } - private static bool SingularEquals(Book x, Book y) - { - return x.Id.Equals(y.Id) && x.AuthorId.Equals(y.AuthorId) && x.Name.Equals(y.Name); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -273,21 +281,20 @@ public async Task TestNargNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs()); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Id).ToList(); - y = y.OrderBy(o => o.Id).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } - private static bool SingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -305,7 +312,116 @@ public async Task TestNargNotNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs { NamePattern = "Bojack%" }); - Assert.That(SequenceEquals(expected, actual)); + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } + + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + } + + [Test] + public async Task TestMySqlTransaction() + { + var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)); + await connection.OpenAsync(); + var transaction = connection.BeginTransaction(); + var querySqlWithTx = QuerySql.WithTransaction(transaction); + await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + ClassicAssert.IsNull(actual); + await transaction.CommitAsync(); + var expected = new QuerySql.GetAuthorRow + { + Id = 1111, + Name = "Bojack Horseman", + Bio = "Back in the 90s he was in a very famous TV show" + }; + actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + } + + [Test] + public async Task TestMySqlTransactionRollback() + { + var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)); + await connection.OpenAsync(); + var transaction = connection.BeginTransaction(); + var querySqlWithTx = QuerySql.WithTransaction(transaction); + await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + await transaction.RollbackAsync(); + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + ClassicAssert.IsNull(actual); + } + + [Test] + [TestCase(-54355, "Scream of the Butterfly", "2025-06-29 12:00:00")] + [TestCase(null, null, "1971-01-01 00:00:00")] + public async Task TestMySqlDataTypesOverride(int? cInt, string cVarchar, DateTime cTimestamp) + { + await QuerySql.InsertMysqlNumericTypes(new QuerySql.InsertMysqlNumericTypesArgs { CInt = cInt }); + await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CVarchar = cVarchar }); + await QuerySql.InsertMysqlDatetimeTypes(new QuerySql.InsertMysqlDatetimeTypesArgs { CTimestamp = cTimestamp }); + var expected = new QuerySql.GetMysqlFunctionsRow + { + MaxInt = cInt, + MaxVarchar = cVarchar, + MaxTimestamp = cTimestamp + }; + var actual = await QuerySql.GetMysqlFunctions(); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetMysqlFunctionsRow x, QuerySql.GetMysqlFunctionsRow y) + { + Assert.That(x.MaxInt, Is.EqualTo(y.MaxInt)); + Assert.That(x.MaxVarchar, Is.EqualTo(y.MaxVarchar)); + Assert.That(x.MaxTimestamp, Is.EqualTo(y.MaxTimestamp)); + } + } + + [Test] + public async Task TestMySqlScopedSchemaEnum() + { + await this.QuerySql.CreateExtendedBio(new QuerySql.CreateExtendedBioArgs { AuthorName = "Bojack Horseman", Name = "One Trick Pony", BioType = BiosBioType.Memoir, AuthorType = new HashSet { BiosAuthorType.Author, BiosAuthorType.Translator } }); + var expected = new QuerySql.GetFirstExtendedBioByTypeRow + { + AuthorName = "Bojack Horseman", + Name = "One Trick Pony", + BioType = BiosBioType.Memoir, + AuthorType = new HashSet + { + BiosAuthorType.Author, + BiosAuthorType.Translator + } + }; + var actual = await this.QuerySql.GetFirstExtendedBioByType(new QuerySql.GetFirstExtendedBioByTypeArgs { BioType = BiosBioType.Memoir }); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetFirstExtendedBioByTypeRow x, QuerySql.GetFirstExtendedBioByTypeRow y) + { + Assert.That(x.AuthorName, Is.EqualTo(y.AuthorName)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.BioType, Is.EqualTo(y.BioType)); + Assert.That(x.AuthorType, Is.EqualTo(y.AuthorType)); + } + } + + [Test] + public void TestMySqlInvalidJson() + { + Assert.ThrowsAsync(async () => await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CJsonStringOverride = "SOME INVALID JSON" })); } [Test] @@ -313,8 +429,8 @@ public async Task TestNargNotNull() [TestCase(null, null, null, null, null, null, null, null)] public async Task TestMySqlStringTypes(string cChar, string cNchar, string cNationalChar, string cVarchar, string cTinytext, string cMediumtext, string cText, string cLongtext) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CChar = cChar, CNchar = cNchar, CNationalChar = cNationalChar, CVarchar = cVarchar, CTinytext = cTinytext, CMediumtext = cMediumtext, CText = cText, CLongtext = cLongtext }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CChar = cChar, CNchar = cNchar, CNationalChar = cNationalChar, CVarchar = cVarchar, CTinytext = cTinytext, CMediumtext = cMediumtext, CText = cText, CLongtext = cLongtext }); + var expected = new QuerySql.GetMysqlStringTypesRow { CChar = cChar, CNchar = cNchar, @@ -325,15 +441,19 @@ public async Task TestMySqlStringTypes(string cChar, string cNchar, string cNati CText = cText, CLongtext = cLongtext }; - var actual = await QuerySql.GetMysqlTypes(); - Assert.That(actual.Value.CChar, Is.EqualTo(expected.CChar)); - Assert.That(actual.Value.CNchar, Is.EqualTo(expected.CNchar)); - Assert.That(actual.Value.CNationalChar, Is.EqualTo(expected.CNationalChar)); - Assert.That(actual.Value.CVarchar, Is.EqualTo(expected.CVarchar)); - Assert.That(actual.Value.CTinytext, Is.EqualTo(expected.CTinytext)); - Assert.That(actual.Value.CMediumtext, Is.EqualTo(expected.CMediumtext)); - Assert.That(actual.Value.CText, Is.EqualTo(expected.CText)); - Assert.That(actual.Value.CLongtext, Is.EqualTo(expected.CLongtext)); + var actual = await QuerySql.GetMysqlStringTypes(); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetMysqlStringTypesRow x, QuerySql.GetMysqlStringTypesRow y) + { + Assert.That(x.CChar, Is.EqualTo(y.CChar)); + Assert.That(x.CNchar, Is.EqualTo(y.CNchar)); + Assert.That(x.CNationalChar, Is.EqualTo(y.CNationalChar)); + Assert.That(x.CVarchar, Is.EqualTo(y.CVarchar)); + Assert.That(x.CTinytext, Is.EqualTo(y.CTinytext)); + Assert.That(x.CMediumtext, Is.EqualTo(y.CMediumtext)); + Assert.That(x.CText, Is.EqualTo(y.CText)); + Assert.That(x.CLongtext, Is.EqualTo(y.CLongtext)); + } } [Test] @@ -341,8 +461,8 @@ public async Task TestMySqlStringTypes(string cChar, string cNchar, string cNati [TestCase(null, null, null, null, null, null, null, null, null)] public async Task TestMySqlIntegerTypes(bool? cBool, bool? cBoolean, short? cTinyint, short? cYear, short? cSmallint, int? cMediumint, int? cInt, int? cInteger, long? cBigint) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CBool = cBool, CBoolean = cBoolean, CTinyint = cTinyint, CSmallint = cSmallint, CMediumint = cMediumint, CInt = cInt, CInteger = cInteger, CBigint = cBigint }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlNumericTypes(new QuerySql.InsertMysqlNumericTypesArgs { CBool = cBool, CBoolean = cBoolean, CTinyint = cTinyint, CSmallint = cSmallint, CMediumint = cMediumint, CInt = cInt, CInteger = cInteger, CBigint = cBigint }); + var expected = new QuerySql.GetMysqlNumericTypesRow { CBool = cBool, CBoolean = cBoolean, @@ -353,49 +473,19 @@ public async Task TestMySqlIntegerTypes(bool? cBool, bool? cBoolean, short? cTin CInteger = cInteger, CBigint = cBigint }; - var actual = await QuerySql.GetMysqlTypes(); - Assert.That(actual.Value.CBool, Is.EqualTo(expected.CBool)); - Assert.That(actual.Value.CBoolean, Is.EqualTo(expected.CBoolean)); - Assert.That(actual.Value.CTinyint, Is.EqualTo(expected.CTinyint)); - Assert.That(actual.Value.CSmallint, Is.EqualTo(expected.CSmallint)); - Assert.That(actual.Value.CMediumint, Is.EqualTo(expected.CMediumint)); - Assert.That(actual.Value.CInt, Is.EqualTo(expected.CInt)); - Assert.That(actual.Value.CInteger, Is.EqualTo(expected.CInteger)); - Assert.That(actual.Value.CBigint, Is.EqualTo(expected.CBigint)); - } - - [Test] - public async Task TestMySqlTransaction() - { - var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)); - await connection.OpenAsync(); - var transaction = connection.BeginTransaction(); - var querySqlWithTx = QuerySql.WithTransaction(transaction); - await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - var actualNull = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actualNull == null, "there is author"); // This is correct for nullable types - await transaction.CommitAsync(); - var expected = new QuerySql.GetAuthorRow + var actual = await QuerySql.GetMysqlNumericTypes(); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetMysqlNumericTypesRow x, QuerySql.GetMysqlNumericTypesRow y) { - Id = 1111, - Name = "Bojack Horseman", - Bio = "Back in the 90s he was in a very famous TV show" - }; - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual.Value)); // Apply placeholder here - } - - [Test] - public async Task TestMySqlTransactionRollback() - { - var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)); - await connection.OpenAsync(); - var transaction = connection.BeginTransaction(); - var querySqlWithTx = QuerySql.WithTransaction(transaction); - await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - await transaction.RollbackAsync(); - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actual == null, "author should not exist after rollback"); + Assert.That(x.CBool, Is.EqualTo(y.CBool)); + Assert.That(x.CBoolean, Is.EqualTo(y.CBoolean)); + Assert.That(x.CTinyint, Is.EqualTo(y.CTinyint)); + Assert.That(x.CSmallint, Is.EqualTo(y.CSmallint)); + Assert.That(x.CMediumint, Is.EqualTo(y.CMediumint)); + Assert.That(x.CInt, Is.EqualTo(y.CInt)); + Assert.That(x.CInteger, Is.EqualTo(y.CInteger)); + Assert.That(x.CBigint, Is.EqualTo(y.CBigint)); + } } [Test] @@ -403,8 +493,8 @@ public async Task TestMySqlTransactionRollback() [TestCase(null, null, null, null, null, null, null)] public async Task TestMySqlFloatingPointTypes(float? cFloat, decimal? cNumeric, decimal? cDecimal, decimal? cDec, decimal? cFixed, double? cDouble, double? cDoublePrecision) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CFloat = cFloat, CNumeric = cNumeric, CDecimal = cDecimal, CDec = cDec, CFixed = cFixed, CDouble = cDouble, CDoublePrecision = cDoublePrecision }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlNumericTypes(new QuerySql.InsertMysqlNumericTypesArgs { CFloat = cFloat, CNumeric = cNumeric, CDecimal = cDecimal, CDec = cDec, CFixed = cFixed, CDouble = cDouble, CDoublePrecision = cDoublePrecision }); + var expected = new QuerySql.GetMysqlNumericTypesRow { CFloat = cFloat, CNumeric = cNumeric, @@ -414,32 +504,44 @@ public async Task TestMySqlFloatingPointTypes(float? cFloat, decimal? cNumeric, CDouble = cDouble, CDoublePrecision = cDoublePrecision }; - var actual = await QuerySql.GetMysqlTypes(); - Assert.That(actual.Value.CFloat, Is.EqualTo(expected.CFloat)); - Assert.That(actual.Value.CNumeric, Is.EqualTo(expected.CNumeric)); - Assert.That(actual.Value.CDecimal, Is.EqualTo(expected.CDecimal)); - Assert.That(actual.Value.CDec, Is.EqualTo(expected.CDec)); - Assert.That(actual.Value.CFixed, Is.EqualTo(expected.CFixed)); - Assert.That(actual.Value.CDouble, Is.EqualTo(expected.CDouble)); - Assert.That(actual.Value.CDoublePrecision, Is.EqualTo(expected.CDoublePrecision)); + var actual = await QuerySql.GetMysqlNumericTypes(); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetMysqlNumericTypesRow x, QuerySql.GetMysqlNumericTypesRow y) + { + Assert.That(x.CFloat, Is.EqualTo(y.CFloat)); + Assert.That(x.CNumeric, Is.EqualTo(y.CNumeric)); + Assert.That(x.CDecimal, Is.EqualTo(y.CDecimal)); + Assert.That(x.CDec, Is.EqualTo(y.CDec)); + Assert.That(x.CFixed, Is.EqualTo(y.CFixed)); + Assert.That(x.CDouble, Is.EqualTo(y.CDouble)); + Assert.That(x.CDoublePrecision, Is.EqualTo(y.CDoublePrecision)); + } } [Test] - [TestCase(1999, "2000-1-30", "1983-11-3 02:01:22")] - [TestCase(null, null, "1970-1-1 00:00:01")] - public async Task TestMySqlDateTimeTypes(short? cYear, DateTime? cDate, DateTime? cTimestamp) + [TestCase(1999, "2000-1-30", "1983-11-3 02:01:22", "2010-1-30 08:11:00", "02:01:22")] + [TestCase(null, null, null, null, null)] + public async Task TestMySqlDateTimeTypes(short? cYear, DateTime? cDate, DateTime? cDatetime, DateTime? cTimestamp, TimeSpan? cTime) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CYear = cYear, CDate = cDate, CTimestamp = cTimestamp }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlDatetimeTypes(new QuerySql.InsertMysqlDatetimeTypesArgs { CYear = cYear, CDate = cDate, CDatetime = cDatetime, CTimestamp = cTimestamp, CTime = cTime }); + var expected = new QuerySql.GetMysqlDatetimeTypesRow { CYear = cYear, CDate = cDate, - CTimestamp = cTimestamp + CDatetime = cDatetime, + CTimestamp = cTimestamp, + CTime = cTime }; - var actual = await QuerySql.GetMysqlTypes(); - Assert.That(actual.Value.CYear, Is.EqualTo(expected.CYear)); - Assert.That(actual.Value.CDate, Is.EqualTo(expected.CDate)); - Assert.That(actual.Value.CTimestamp, Is.EqualTo(expected.CTimestamp)); + var actual = await QuerySql.GetMysqlDatetimeTypes(); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetMysqlDatetimeTypesRow x, QuerySql.GetMysqlDatetimeTypesRow y) + { + Assert.That(x.CYear, Is.EqualTo(y.CYear)); + Assert.That(x.CDate, Is.EqualTo(y.CDate)); + Assert.That(x.CDatetime, Is.EqualTo(y.CDatetime)); + Assert.That(x.CTimestamp, Is.EqualTo(y.CTimestamp)); + Assert.That(x.CTime, Is.EqualTo(y.CTime)); + } } [Test] @@ -448,8 +550,8 @@ public async Task TestMySqlDateTimeTypes(short? cYear, DateTime? cDate, DateTime [TestCase(null, null, null, null, null, null, null)] public async Task TestMySqlBinaryTypes(byte? cBit, byte[] cBinary, byte[] cVarbinary, byte[] cTinyblob, byte[] cBlob, byte[] cMediumblob, byte[] cLongblob) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CBit = cBit, CBinary = cBinary, CVarbinary = cVarbinary, CTinyblob = cTinyblob, CBlob = cBlob, CMediumblob = cMediumblob, CLongblob = cLongblob }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlBinaryTypes(new QuerySql.InsertMysqlBinaryTypesArgs { CBit = cBit, CBinary = cBinary, CVarbinary = cVarbinary, CTinyblob = cTinyblob, CBlob = cBlob, CMediumblob = cMediumblob, CLongblob = cLongblob }); + var expected = new QuerySql.GetMysqlBinaryTypesRow { CBit = cBit, CBinary = cBinary, @@ -459,9 +561,9 @@ public async Task TestMySqlBinaryTypes(byte? cBit, byte[] cBinary, byte[] cVarbi CMediumblob = cMediumblob, CLongblob = cLongblob }; - var actual = await QuerySql.GetMysqlTypes(); + var actual = await QuerySql.GetMysqlBinaryTypes(); AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow y) + void AssertSingularEquals(QuerySql.GetMysqlBinaryTypesRow x, QuerySql.GetMysqlBinaryTypesRow y) { Assert.That(x.CBit, Is.EqualTo(y.CBit)); Assert.That(x.CBinary, Is.EqualTo(y.CBinary)); @@ -473,74 +575,32 @@ void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow } } - [Test] - [TestCase(MysqlTypesCEnum.Medium, new[] { MysqlTypesCSet.Tea, MysqlTypesCSet.Coffee })] - [TestCase(null, null)] - public async Task TestMySqlStringTypes(MysqlTypesCEnum? cEnum, MysqlTypesCSet[] cSet) + private static IEnumerable MySqlEnumTypesTestCases { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CEnum = cEnum, CSet = cSet }); - var expected = new QuerySql.GetMysqlTypesRow - { - CEnum = cEnum, - CSet = cSet - }; - var actual = await QuerySql.GetMysqlTypes(); - AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow y) + get { - Assert.That(x.CEnum, Is.EqualTo(y.CEnum)); - Assert.That(x.CSet, Is.EqualTo(y.CSet)); + yield return new TestCaseData(MysqlStringTypesCEnum.Medium, new HashSet { MysqlStringTypesCSet.Tea, MysqlStringTypesCSet.Coffee }).SetName("Valid Enum values"); + yield return new TestCaseData(null, null).SetName("Enum with null values"); } } [Test] - [TestCase(-54355, "Scream of the Butterfly", "2025-06-29 12:00:00")] - [TestCase(null, null, "1971-01-01 00:00:00")] - public async Task TestMySqlDataTypesOverride(int? cInt, string cVarchar, DateTime cTimestamp) + [TestCaseSource(nameof(MySqlEnumTypesTestCases))] + public async Task TestMySqlStringTypes(MysqlStringTypesCEnum? cEnum, HashSet cSet) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CInt = cInt, CVarchar = cVarchar, CTimestamp = cTimestamp }); - var expected = new QuerySql.GetMysqlFunctionsRow + await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CEnum = cEnum, CSet = cSet }); + var expected = new QuerySql.GetMysqlStringTypesRow { - MaxInt = cInt, - MaxVarchar = cVarchar, - MaxTimestamp = cTimestamp + CEnum = cEnum, + CSet = cSet }; - var actual = await QuerySql.GetMysqlFunctions(); + var actual = await QuerySql.GetMysqlStringTypes(); AssertSingularEquals(expected, actual.Value); - } - - private static void AssertSingularEquals(QuerySql.GetMysqlFunctionsRow expected, QuerySql.GetMysqlFunctionsRow actual) - { - Assert.That(actual.MaxInt, Is.EqualTo(expected.MaxInt)); - Assert.That(actual.MaxVarchar, Is.EqualTo(expected.MaxVarchar)); - Assert.That(actual.MaxTimestamp, Is.EqualTo(expected.MaxTimestamp)); - } - - [Test] - public async Task TestMySqlScopedSchemaEnum() - { - await this.QuerySql.CreateExtendedBio(new QuerySql.CreateExtendedBioArgs { AuthorName = "Bojack Horseman", Name = "One Trick Pony", BioType = ExtendedBiosBioType.Memoir, AuthorType = new ExtendedBiosAuthorType[] { ExtendedBiosAuthorType.Author, ExtendedBiosAuthorType.Translator } }); - var expected = new QuerySql.GetFirstExtendedBioByTypeRow + void AssertSingularEquals(QuerySql.GetMysqlStringTypesRow x, QuerySql.GetMysqlStringTypesRow y) { - AuthorName = "Bojack Horseman", - Name = "One Trick Pony", - BioType = ExtendedBiosBioType.Memoir, - AuthorType = new ExtendedBiosAuthorType[] - { - ExtendedBiosAuthorType.Author, - ExtendedBiosAuthorType.Translator - } - }; - var actual = await this.QuerySql.GetFirstExtendedBioByType(new QuerySql.GetFirstExtendedBioByTypeArgs { BioType = ExtendedBiosBioType.Memoir }); - AssertSingularEquals(expected, actual.Value); - } - - private void AssertSingularEquals(QuerySql.GetFirstExtendedBioByTypeRow x, QuerySql.GetFirstExtendedBioByTypeRow y) - { - Assert.That(x.AuthorName, Is.EqualTo(y.AuthorName)); - Assert.That(x.Name, Is.EqualTo(y.Name)); - Assert.That(x.BioType, Is.EqualTo(y.BioType)); - Assert.That(x.AuthorType, Is.EqualTo(y.AuthorType)); + Assert.That(x.CEnum, Is.EqualTo(y.CEnum)); + Assert.That(x.CSet, Is.EqualTo(y.CSet)); + } } [Test] @@ -551,15 +611,15 @@ public async Task TestMySqlJsonDataType(string cJson) JsonElement? cParsedJson = null; if (cJson != null) cParsedJson = JsonDocument.Parse(cJson).RootElement; - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CJson = cParsedJson, CJsonStringOverride = cJson }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CJson = cParsedJson, CJsonStringOverride = cJson }); + var expected = new QuerySql.GetMysqlStringTypesRow { CJson = cParsedJson, CJsonStringOverride = cJson }; - var actual = await QuerySql.GetMysqlTypes(); + var actual = await QuerySql.GetMysqlStringTypes(); AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow y) + void AssertSingularEquals(QuerySql.GetMysqlStringTypesRow x, QuerySql.GetMysqlStringTypesRow y) { Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); if (x.CJson.HasValue) @@ -568,46 +628,14 @@ void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow } } - [Test] - [TestCase(100, "{\"name\": \"Swordfishtrombones\", \"year\": 1983}")] - [TestCase(10, null)] - public async Task TestJsonCopyFrom(int batchSize, string cJson) - { - JsonElement? cParsedJson = null; - if (cJson != null) - cParsedJson = JsonDocument.Parse(cJson).RootElement; - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CJson = cParsedJson }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow - { - Cnt = batchSize, - CJson = cParsedJson - }; - var actual = await QuerySql.GetMysqlTypesCnt(); - AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypesCntRow y) - { - Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); - Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); - if (x.CJson.HasValue) - Assert.That(x.CJson.Value.GetRawText(), Is.EqualTo(y.CJson.Value.GetRawText())); - } - } - - [Test] - public void TestMySqlInvalidJson() - { - Assert.ThrowsAsync(async () => await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CJsonStringOverride = "SOME INVALID JSON" })); - } - [Test] [TestCase(100, "D", "\u4321", "\u2345", "Parasite", "Clockwork Orange", "Dr. Strangelove", "Interview with a Vampire", "Memento")] [TestCase(10, null, null, null, null, null, null, null, null)] public async Task TestStringCopyFrom(int batchSize, string cChar, string cNchar, string cNationalChar, string cVarchar, string cTinytext, string cMediumtext, string cText, string cLongtext) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CChar = cChar, CNchar = cNchar, CNationalChar = cNationalChar, CVarchar = cVarchar, CTinytext = cTinytext, CMediumtext = cMediumtext, CText = cText, CLongtext = cLongtext }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlStringTypesBatchArgs { CChar = cChar, CNchar = cNchar, CNationalChar = cNationalChar, CVarchar = cVarchar, CTinytext = cTinytext, CMediumtext = cMediumtext, CText = cText, CLongtext = cLongtext }).ToList(); + await QuerySql.InsertMysqlStringTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlStringTypesCntRow { Cnt = batchSize, CChar = cChar, @@ -619,9 +647,9 @@ public async Task TestStringCopyFrom(int batchSize, string cChar, string cNchar, CText = cText, CLongtext = cLongtext }; - var actual = await QuerySql.GetMysqlTypesCnt(); + var actual = await QuerySql.GetMysqlStringTypesCnt(); AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypesCntRow y) + void AssertSingularEquals(QuerySql.GetMysqlStringTypesCntRow x, QuerySql.GetMysqlStringTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CChar, Is.EqualTo(y.CChar)); @@ -640,9 +668,9 @@ void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypes [TestCase(10, null, null, null, null, null, null, null, null)] public async Task TestIntegerCopyFrom(int batchSize, bool? cBool, bool? cBoolean, short? cTinyint, short? cSmallint, int? cMediumint, int? cInt, int? cInteger, long? cBigint) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CBool = cBool, CBoolean = cBoolean, CTinyint = cTinyint, CSmallint = cSmallint, CMediumint = cMediumint, CInt = cInt, CInteger = cInteger, CBigint = cBigint }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlNumericTypesBatchArgs { CBool = cBool, CBoolean = cBoolean, CTinyint = cTinyint, CSmallint = cSmallint, CMediumint = cMediumint, CInt = cInt, CInteger = cInteger, CBigint = cBigint }).ToList(); + await QuerySql.InsertMysqlNumericTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlNumericTypesCntRow { Cnt = batchSize, CBool = cBool, @@ -654,9 +682,9 @@ public async Task TestIntegerCopyFrom(int batchSize, bool? cBool, bool? cBoolean CInteger = cInteger, CBigint = cBigint }; - var actual = await QuerySql.GetMysqlTypesCnt(); + var actual = await QuerySql.GetMysqlNumericTypesCnt(); AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypesCntRow y) + void AssertSingularEquals(QuerySql.GetMysqlNumericTypesCntRow x, QuerySql.GetMysqlNumericTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CBool, Is.EqualTo(y.CBool)); @@ -675,9 +703,9 @@ void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypes [TestCase(10, null, null, null, null, null, null, null)] public async Task TestFloatingPointCopyFrom(int batchSize, float? cFloat, decimal? cNumeric, decimal? cDecimal, decimal? cDec, decimal? cFixed, double? cDouble, double? cDoublePrecision) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CFloat = cFloat, CNumeric = cNumeric, CDecimal = cDecimal, CDec = cDec, CFixed = cFixed, CDouble = cDouble, CDoublePrecision = cDoublePrecision }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlNumericTypesBatchArgs { CFloat = cFloat, CNumeric = cNumeric, CDecimal = cDecimal, CDec = cDec, CFixed = cFixed, CDouble = cDouble, CDoublePrecision = cDoublePrecision }).ToList(); + await QuerySql.InsertMysqlNumericTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlNumericTypesCntRow { Cnt = batchSize, CFloat = cFloat, @@ -688,37 +716,48 @@ public async Task TestFloatingPointCopyFrom(int batchSize, float? cFloat, decima CDouble = cDouble, CDoublePrecision = cDoublePrecision }; - var actual = await QuerySql.GetMysqlTypesCnt(); - Assert.That(actual.Value.CFloat, Is.EqualTo(expected.CFloat)); - Assert.That(actual.Value.CNumeric, Is.EqualTo(expected.CNumeric)); - Assert.That(actual.Value.CDecimal, Is.EqualTo(expected.CDecimal)); - Assert.That(actual.Value.CDec, Is.EqualTo(expected.CDec)); - Assert.That(actual.Value.CFixed, Is.EqualTo(expected.CFixed)); - Assert.That(actual.Value.CDouble, Is.EqualTo(expected.CDouble)); - Assert.That(actual.Value.CDoublePrecision, Is.EqualTo(expected.CDoublePrecision)); + var actual = await QuerySql.GetMysqlNumericTypesCnt(); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetMysqlNumericTypesCntRow x, QuerySql.GetMysqlNumericTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CFloat, Is.EqualTo(y.CFloat)); + Assert.That(x.CNumeric, Is.EqualTo(y.CNumeric)); + Assert.That(x.CDecimal, Is.EqualTo(y.CDecimal)); + Assert.That(x.CDec, Is.EqualTo(y.CDec)); + Assert.That(x.CFixed, Is.EqualTo(y.CFixed)); + Assert.That(x.CDouble, Is.EqualTo(y.CDouble)); + Assert.That(x.CDoublePrecision, Is.EqualTo(y.CDoublePrecision)); + } } [Test] - [TestCase(100, 1993, "2000-1-30", "1983-11-3 02:01:22", "2010-1-30 08:11:00")] - [TestCase(10, null, null, null, null)] - public async Task TestDateTimeCopyFrom(int batchSize, short? cYear, DateTime? cDate, DateTime? cDatetime, DateTime? cTimestamp) + [TestCase(100, 1993, "2000-1-30", "1983-11-3 02:01:22", "2010-1-30 08:11:00", "02:01:22")] + [TestCase(10, null, null, null, null, null)] + public async Task TestDateTimeCopyFrom(int batchSize, short? cYear, DateTime? cDate, DateTime? cDatetime, DateTime? cTimestamp, TimeSpan? cTime) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CYear = cYear, CDate = cDate, CDatetime = cDatetime, CTimestamp = cTimestamp }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlDatetimeTypesBatchArgs { CYear = cYear, CDate = cDate, CDatetime = cDatetime, CTimestamp = cTimestamp, CTime = cTime }).ToList(); + await QuerySql.InsertMysqlDatetimeTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlDatetimeTypesCntRow { Cnt = batchSize, CYear = cYear, CDate = cDate, CDatetime = cDatetime, - CTimestamp = cTimestamp + CTimestamp = cTimestamp, + CTime = cTime }; - var actual = await QuerySql.GetMysqlTypesCnt(); - Assert.That(actual.Value.Cnt, Is.EqualTo(expected.Cnt)); - Assert.That(actual.Value.CYear, Is.EqualTo(expected.CYear)); - Assert.That(actual.Value.CDate, Is.EqualTo(expected.CDate)); - Assert.That(actual.Value.CDatetime, Is.EqualTo(expected.CDatetime)); - Assert.That(actual.Value.CTimestamp, Is.EqualTo(expected.CTimestamp)); + var actual = await QuerySql.GetMysqlDatetimeTypesCnt(); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetMysqlDatetimeTypesCntRow x, QuerySql.GetMysqlDatetimeTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CYear, Is.EqualTo(y.CYear)); + Assert.That(x.CDate, Is.EqualTo(y.CDate)); + Assert.That(x.CDatetime, Is.EqualTo(y.CDatetime)); + Assert.That(x.CTimestamp, Is.EqualTo(y.CTimestamp)); + Assert.That(x.CTime, Is.EqualTo(y.CTime)); + } } [Test] @@ -727,9 +766,9 @@ public async Task TestDateTimeCopyFrom(int batchSize, short? cYear, DateTime? cD [TestCase(10, null, null, null, null, null, null, null)] public async Task TestBinaryCopyFrom(int batchSize, byte? cBit, byte[] cBinary, byte[] cVarbinary, byte[] cTinyblob, byte[] cBlob, byte[] cMediumblob, byte[] cLongblob) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CBit = cBit, CBinary = cBinary, CVarbinary = cVarbinary, CTinyblob = cTinyblob, CBlob = cBlob, CMediumblob = cMediumblob, CLongblob = cLongblob }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlBinaryTypesBatchArgs { CBit = cBit, CBinary = cBinary, CVarbinary = cVarbinary, CTinyblob = cTinyblob, CBlob = cBlob, CMediumblob = cMediumblob, CLongblob = cLongblob }).ToList(); + await QuerySql.InsertMysqlBinaryTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlBinaryTypesCntRow { Cnt = batchSize, CBit = cBit, @@ -740,39 +779,76 @@ public async Task TestBinaryCopyFrom(int batchSize, byte? cBit, byte[] cBinary, CMediumblob = cMediumblob, CLongblob = cLongblob }; - var actual = await QuerySql.GetMysqlTypesCnt(); - Assert.That(actual.Value.Cnt, Is.EqualTo(expected.Cnt)); - Assert.That(actual.Value.CBit, Is.EqualTo(expected.CBit)); - Assert.That(actual.Value.CBinary, Is.EqualTo(expected.CBinary)); - Assert.That(actual.Value.CVarbinary, Is.EqualTo(expected.CVarbinary)); - Assert.That(actual.Value.CTinyblob, Is.EqualTo(expected.CTinyblob)); - Assert.That(actual.Value.CBlob, Is.EqualTo(expected.CBlob)); - Assert.That(actual.Value.CMediumblob, Is.EqualTo(expected.CMediumblob)); - Assert.That(actual.Value.CLongblob, Is.EqualTo(expected.CLongblob)); + var actual = await QuerySql.GetMysqlBinaryTypesCnt(); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetMysqlBinaryTypesCntRow x, QuerySql.GetMysqlBinaryTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CBit, Is.EqualTo(y.CBit)); + Assert.That(x.CBinary, Is.EqualTo(y.CBinary)); + Assert.That(x.CVarbinary, Is.EqualTo(y.CVarbinary)); + Assert.That(x.CTinyblob, Is.EqualTo(y.CTinyblob)); + Assert.That(x.CBlob, Is.EqualTo(y.CBlob)); + Assert.That(x.CMediumblob, Is.EqualTo(y.CMediumblob)); + Assert.That(x.CLongblob, Is.EqualTo(y.CLongblob)); + } + } + + private static IEnumerable MySqlEnumCopyFromTestCases + { + get + { + yield return new TestCaseData(100, MysqlStringTypesCEnum.Big, new HashSet { MysqlStringTypesCSet.Tea, MysqlStringTypesCSet.Coffee }).SetName("Valid Enum values"); + yield return new TestCaseData(10, null, null).SetName("Enum with null values"); + } } [Test] - [TestCase(100, MysqlTypesCEnum.Big, new[] { MysqlTypesCSet.Tea, MysqlTypesCSet.Coffee })] - [TestCase(500, MysqlTypesCEnum.Small, new[] { MysqlTypesCSet.Milk })] - [TestCase(10, null, null)] - public async Task TestCopyFrom(int batchSize, MysqlTypesCEnum? cEnum, MysqlTypesCSet[] cSet) + [TestCaseSource(nameof(MySqlEnumCopyFromTestCases))] + public async Task TestCopyFrom(int batchSize, MysqlStringTypesCEnum? cEnum, HashSet cSet) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CEnum = cEnum, CSet = cSet }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlStringTypesBatchArgs { CEnum = cEnum, CSet = cSet }).ToList(); + await QuerySql.InsertMysqlStringTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlStringTypesCntRow { Cnt = batchSize, CEnum = cEnum, CSet = cSet }; - var actual = await QuerySql.GetMysqlTypesCnt(); + var actual = await QuerySql.GetMysqlStringTypesCnt(); AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypesCntRow y) + void AssertSingularEquals(QuerySql.GetMysqlStringTypesCntRow x, QuerySql.GetMysqlStringTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CEnum, Is.EqualTo(y.CEnum)); Assert.That(x.CSet, Is.EqualTo(y.CSet)); } } + + [Test] + [TestCase(100, "{\"name\": \"Swordfishtrombones\", \"year\": 1983}")] + [TestCase(10, null)] + public async Task TestJsonCopyFrom(int batchSize, string cJson) + { + JsonElement? cParsedJson = null; + if (cJson != null) + cParsedJson = JsonDocument.Parse(cJson).RootElement; + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlStringTypesBatchArgs { CJson = cParsedJson }).ToList(); + await QuerySql.InsertMysqlStringTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlStringTypesCntRow + { + Cnt = batchSize, + CJson = cParsedJson + }; + var actual = await QuerySql.GetMysqlStringTypesCnt(); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetMysqlStringTypesCntRow x, QuerySql.GetMysqlStringTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); + if (x.CJson.HasValue) + Assert.That(x.CJson.Value.GetRawText(), Is.EqualTo(y.CJson.Value.GetRawText())); + } + } } } diff --git a/end2end/EndToEndTests/NpgsqlDapperTester.cs b/end2end/EndToEndTests/NpgsqlDapperTester.cs index 425855b6..6668dea5 100644 --- a/end2end/EndToEndTests/NpgsqlDapperTester.cs +++ b/end2end/EndToEndTests/NpgsqlDapperTester.cs @@ -14,8 +14,12 @@ public partial class NpgsqlDapperTester public async Task EmptyTestsTable() { await QuerySql.TruncateAuthors(); - await QuerySql.TruncatePostgresTypes(); + await QuerySql.TruncatePostgresNumericTypes(); + await QuerySql.TruncatePostgresStringTypes(); + await QuerySql.TruncatePostgresDateTimeTypes(); await QuerySql.TruncatePostgresGeoTypes(); + await QuerySql.TruncatePostgresNetworkTypes(); await QuerySql.TruncatePostgresArrayTypes(); + await QuerySql.TruncatePostgresSpecialTypes(); } } \ No newline at end of file diff --git a/end2end/EndToEndTests/NpgsqlDapperTester.generated.cs b/end2end/EndToEndTests/NpgsqlDapperTester.generated.cs index 7acfb102..d46e473f 100644 --- a/end2end/EndToEndTests/NpgsqlDapperTester.generated.cs +++ b/end2end/EndToEndTests/NpgsqlDapperTester.generated.cs @@ -28,12 +28,13 @@ public async Task TestOne() Bio = "Back in the 90s he was in a very famous TV show" }; var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -58,21 +59,18 @@ public async Task TestMany() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) - { - Assert.That(x.Id, Is.EqualTo(y.Id)); - Assert.That(x.Name, Is.EqualTo(y.Name)); - Assert.That(x.Bio, Is.EqualTo(y.Bio)); - } + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } - private static void AssertSequenceEquals(List x, List y) - { - Assert.That(x.Count, Is.EqualTo(y.Count)); - for (int i = 0; i < x.Count; i++) + void AssertSequenceEquals(List x, List y) { - AssertSingularEquals(x[i], y[i]); + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); } } @@ -110,6 +108,19 @@ public async Task TestExecRows() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -123,12 +134,13 @@ public async Task TestExecLastId() Bio = "Quote that everyone always attribute to Einstein" }; var actual = await QuerySql.GetAuthorById(new QuerySql.GetAuthorByIdArgs { Id = id1 }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -155,19 +167,23 @@ public async Task TestSelfJoinEmbed() } }; var actual = await QuerySql.GetDuplicateAuthors(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) - { - return SingularEquals(x.Author, y.Author) && SingularEquals(x.Author2, y.Author2); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) + { + Assert.That(x.Author.Id, Is.EqualTo(y.Author.Id)); + Assert.That(x.Author.Name, Is.EqualTo(y.Author.Name)); + Assert.That(x.Author.Bio, Is.EqualTo(y.Author.Bio)); + Assert.That(x.Author2.Id, Is.EqualTo(y.Author2.Id)); + Assert.That(x.Author2.Name, Is.EqualTo(y.Author2.Name)); + Assert.That(x.Author2.Bio, Is.EqualTo(y.Author2.Bio)); + } - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -211,31 +227,23 @@ public async Task TestJoinEmbed() } }; var actual = await QuerySql.ListAllAuthorsBooks(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) - { - return SingularEquals(x.Author, y.Author) && SingularEquals(x.Book, y.Book); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Author.Name + o.Book.Name).ToList(); - y = y.OrderBy(o => o.Author.Name + o.Book.Name).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } - - private static bool SingularEquals(Author x, Author y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) + { + Assert.That(x.Author.Id, Is.EqualTo(y.Author.Id)); + Assert.That(x.Author.Name, Is.EqualTo(y.Author.Name)); + Assert.That(x.Author.Bio, Is.EqualTo(y.Author.Bio)); + Assert.That(x.Book.Id, Is.EqualTo(y.Book.Id)); + Assert.That(x.Book.AuthorId, Is.EqualTo(y.Book.AuthorId)); + Assert.That(x.Book.Name, Is.EqualTo(y.Book.Name)); + } - private static bool SingularEquals(Book x, Book y) - { - return x.Id.Equals(y.Id) && x.AuthorId.Equals(y.AuthorId) && x.Name.Equals(y.Name); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -259,21 +267,20 @@ public async Task TestNargNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs()); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Id).ToList(); - y = y.OrderBy(o => o.Id).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } - private static bool SingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -291,7 +298,116 @@ public async Task TestNargNotNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs { NamePattern = "Bojack%" }); - Assert.That(SequenceEquals(expected, actual)); + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } + + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + } + + [Test] + public async Task TestPostgresTransaction() + { + var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv)); + await connection.OpenAsync(); + var transaction = connection.BeginTransaction(); + var querySqlWithTx = QuerySql.WithTransaction(transaction); + await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + ClassicAssert.IsNull(actual); + await transaction.CommitAsync(); + var expected = new QuerySql.GetAuthorRow + { + Id = 1111, + Name = "Bojack Horseman", + Bio = "Back in the 90s he was in a very famous TV show" + }; + actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + } + + [Test] + public async Task TestPostgresTransactionRollback() + { + var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv)); + await connection.OpenAsync(); + var transaction = connection.BeginTransaction(); + var sqlQueryWithTx = QuerySql.WithTransaction(transaction); + await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + await transaction.RollbackAsync(); + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + ClassicAssert.IsNull(actual); + } + + [Test] + public async Task TestArray() + { + var id1 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Quote that everyone always attribute to Einstein" }); + var bojackId = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + var actual = await QuerySql.GetAuthorsByIds(new QuerySql.GetAuthorsByIdsArgs { LongArr1 = new[] { id1, bojackId } }); + ClassicAssert.AreEqual(2, actual.Count); + } + + [Test] + public async Task TestMultipleArrays() + { + var id1 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Quote that everyone always attribute to Einstein" }); + var id2 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Only 2 things are infinite, the universe and human stupidity" }); + var bojackId = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + var actual = await QuerySql.GetAuthorsByIdsAndNames(new QuerySql.GetAuthorsByIdsAndNamesArgs { LongArr1 = new[] { id1, bojackId }, StringArr2 = new[] { "Albert Einstein" } }); + ClassicAssert.AreEqual(1, actual.Count); + } + + [Test] + [TestCase(-54355, "White Light from the Mouth of Infinity", "2022-10-2 15:44:01+09:00")] + [TestCase(null, null, "1970-01-01 00:00:00")] + public async Task TestPostgresDataTypesOverride(int? cInteger, string cVarchar, DateTime cTimestamp) + { + await QuerySql.InsertPostgresNumericTypes(new QuerySql.InsertPostgresNumericTypesArgs { CInteger = cInteger }); + await QuerySql.InsertPostgresDateTimeTypes(new QuerySql.InsertPostgresDateTimeTypesArgs { CTimestamp = cTimestamp }); + await QuerySql.InsertPostgresStringTypes(new QuerySql.InsertPostgresStringTypesArgs { CVarchar = cVarchar }); + var expected = new QuerySql.GetPostgresFunctionsRow + { + MaxInteger = cInteger, + MaxVarchar = cVarchar, + MaxTimestamp = cTimestamp + }; + var actual = await QuerySql.GetPostgresFunctions(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresFunctionsRow x, QuerySql.GetPostgresFunctionsRow y) + { + Assert.That(x.MaxInteger, Is.EqualTo(y.MaxInteger)); + Assert.That(x.MaxVarchar, Is.EqualTo(y.MaxVarchar)); + Assert.That(x.MaxTimestamp, Is.EqualTo(y.MaxTimestamp)); + } + } + + [Test] + public void TestPostgresInvalidJson() + { + Assert.ThrowsAsync(async () => await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CJsonStringOverride = "SOME INVALID JSON" })); + Assert.ThrowsAsync(async () => await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CJsonpath = "SOME INVALID JSONPATH" })); + } + + [Test] + public void TestPostgresInvalidXml() + { + Assert.ThrowsAsync(async () => await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CXmlStringOverride = "SOME INVALID XML" })); } [Test] @@ -299,8 +415,8 @@ public async Task TestNargNotNull() [TestCase(null, null, null, null, null)] public async Task TestPostgresStringTypes(string cChar, string cVarchar, string cCharacterVarying, string cBpchar, string cText) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CBpchar = cBpchar, CText = cText, }); - var expected = new QuerySql.GetPostgresTypesRow + await QuerySql.InsertPostgresStringTypes(new QuerySql.InsertPostgresStringTypesArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CBpchar = cBpchar, CText = cText, }); + var expected = new QuerySql.GetPostgresStringTypesRow { CChar = cChar, CVarchar = cVarchar, @@ -308,9 +424,9 @@ public async Task TestPostgresStringTypes(string cChar, string cVarchar, string CBpchar = cBpchar, CText = cText, }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresStringTypes(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresStringTypesRow x, QuerySql.GetPostgresStringTypesRow y) { Assert.That(x.CChar, Is.EqualTo(y.CChar)); Assert.That(x.CVarchar, Is.EqualTo(y.CVarchar)); @@ -325,19 +441,23 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTy [TestCase(null, null, null, null)] public async Task TestPostgresIntegerTypes(bool cBoolean, short cSmallint, int cInteger, long cBigint) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }); - var expected = new QuerySql.GetPostgresTypesRow + await QuerySql.InsertPostgresNumericTypes(new QuerySql.InsertPostgresNumericTypesArgs { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }); + var expected = new QuerySql.GetPostgresNumericTypesRow { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }; - var actual = await QuerySql.GetPostgresTypes(); - Assert.That(actual.CBoolean, Is.EqualTo(expected.CBoolean)); - Assert.That(actual.CSmallint, Is.EqualTo(expected.CSmallint)); - Assert.That(actual.CInteger, Is.EqualTo(expected.CInteger)); - Assert.That(actual.CBigint, Is.EqualTo(expected.CBigint)); + var actual = await QuerySql.GetPostgresNumericTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresNumericTypesRow x, QuerySql.GetPostgresNumericTypesRow y) + { + Assert.That(x.CBoolean, Is.EqualTo(y.CBoolean)); + Assert.That(x.CSmallint, Is.EqualTo(y.CSmallint)); + Assert.That(x.CInteger, Is.EqualTo(y.CInteger)); + Assert.That(x.CBigint, Is.EqualTo(y.CBigint)); + } } [Test] @@ -345,8 +465,8 @@ public async Task TestPostgresIntegerTypes(bool cBoolean, short cSmallint, int c [TestCase(null, null, null, null, null)] public async Task TestPostgresFloatingPointTypes(float? cReal, decimal? cNumeric, decimal? cDecimal, double? cDoublePrecision, decimal? cMoney) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CReal = cReal, CNumeric = cNumeric, CDecimal = cDecimal, CDoublePrecision = cDoublePrecision, CMoney = cMoney }); - var expected = new QuerySql.GetPostgresTypesRow + await QuerySql.InsertPostgresNumericTypes(new QuerySql.InsertPostgresNumericTypesArgs { CReal = cReal, CNumeric = cNumeric, CDecimal = cDecimal, CDoublePrecision = cDoublePrecision, CMoney = cMoney }); + var expected = new QuerySql.GetPostgresNumericTypesRow { CReal = cReal, CNumeric = cNumeric, @@ -354,9 +474,9 @@ public async Task TestPostgresFloatingPointTypes(float? cReal, decimal? cNumeric CDoublePrecision = cDoublePrecision, CMoney = cMoney }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresNumericTypes(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresNumericTypesRow x, QuerySql.GetPostgresNumericTypesRow y) { Assert.That(x.CReal, Is.EqualTo(y.CReal)); Assert.That(x.CNumeric, Is.EqualTo(y.CNumeric)); @@ -371,8 +491,8 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTy [TestCase(null, null, null, null, null)] public async Task TestPostgresDateTimeTypes(DateTime? cDate, TimeSpan? cTime, DateTime? cTimestamp, DateTime? cTimestampWithTz, TimeSpan? cInterval) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CDate = cDate, CTime = cTime, CTimestamp = cTimestamp, CTimestampWithTz = cTimestampWithTz, CInterval = cInterval }); - var expected = new QuerySql.GetPostgresTypesRow + await QuerySql.InsertPostgresDateTimeTypes(new QuerySql.InsertPostgresDateTimeTypesArgs { CDate = cDate, CTime = cTime, CTimestamp = cTimestamp, CTimestampWithTz = cTimestampWithTz, CInterval = cInterval }); + var expected = new QuerySql.GetPostgresDateTimeTypesRow { CDate = cDate, CTime = cTime, @@ -380,9 +500,9 @@ public async Task TestPostgresDateTimeTypes(DateTime? cDate, TimeSpan? cTime, Da CTimestampWithTz = cTimestampWithTz, CInterval = cInterval }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresDateTimeTypes(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresDateTimeTypesRow x, QuerySql.GetPostgresDateTimeTypesRow y) { Assert.That(x.CDate, Is.EqualTo(y.CDate)); Assert.That(x.CTime, Is.EqualTo(y.CTime)); @@ -431,52 +551,198 @@ void AssertSingularEquals(QuerySql.GetPostgresArrayTypesRow x, QuerySql.GetPostg } } + private static IEnumerable PostgresGuidDataTypesTestCases + { + get + { + yield return new TestCaseData(Guid.NewGuid()).SetName("Valid Guid"); + yield return new TestCaseData(null).SetName("Null Guid"); + } + } + [Test] - [TestCase(-54355, "White Light from the Mouth of Infinity", "2022-10-2 15:44:01+09:00")] - [TestCase(null, null, "1970-01-01 00:00:00")] - public async Task TestPostgresDataTypesOverride(int? cInteger, string cVarchar, DateTime cTimestamp) + [TestCaseSource(nameof(PostgresGuidDataTypesTestCases))] + public async Task TestPostgresGuidDataTypes(Guid? cUuid) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CInteger = cInteger, CVarchar = cVarchar, CTimestamp = cTimestamp }); - var expected = new QuerySql.GetPostgresFunctionsRow + await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CUuid = cUuid }); + var expected = new QuerySql.GetPostgresSpecialTypesRow { - MaxInteger = cInteger, - MaxVarchar = cVarchar, - MaxTimestamp = cTimestamp + CUuid = cUuid }; - var actual = await QuerySql.GetPostgresFunctions(); + var actual = await QuerySql.GetPostgresSpecialTypes(); AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPostgresSpecialTypesRow y) + { + Assert.That(x.CUuid, Is.EqualTo(y.CUuid)); + } } - private static void AssertSingularEquals(QuerySql.GetPostgresFunctionsRow expected, QuerySql.GetPostgresFunctionsRow actual) + [Test] + [Obsolete] // due to NpgsqlTsVector.Parse usage + public async Task TestPostgresFullTextSearchDataTypes() { - Assert.That(actual.MaxInteger, Is.EqualTo(expected.MaxInteger)); - Assert.That(actual.MaxVarchar, Is.EqualTo(expected.MaxVarchar)); - Assert.That(actual.MaxTimestamp, Is.EqualTo(expected.MaxTimestamp)); + await QuerySql.InsertPostgresStringTypes(new QuerySql.InsertPostgresStringTypesArgs { CText = "Hello world" }); + var actual = await QuerySql.GetPostgresStringTypesTextSearch(new QuerySql.GetPostgresStringTypesTextSearchArgs { ToTsquery = "Hello" }); + var expected = new QuerySql.GetPostgresStringTypesTextSearchRow + { + CText = "Hello world", + Query = new NpgsqlTsQueryLexeme("hello"), + Tsv = NpgsqlTsVector.Parse("hello:1 world:2"), + Rnk = 0.07f + }; + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresStringTypesTextSearchRow x, QuerySql.GetPostgresStringTypesTextSearchRow y) + { + Assert.That(y.CText, Is.EqualTo(x.CText)); + Assert.That(y.Query.ToString(), Is.EqualTo(x.Query.ToString())); + Assert.That(y.Tsv.ToString(), Is.EqualTo(x.Tsv.ToString())); + Assert.That(y.Rnk, Is.AtMost(x.Rnk)); + } } - private static IEnumerable PostgresGuidDataTypesTestCases + private static IEnumerable PostgresNetworkDataTypesTestCases { get { - yield return new TestCaseData(Guid.NewGuid()).SetName("Valid Guid"); - yield return new TestCaseData(null).SetName("Null Guid"); + yield return new TestCaseData(new NpgsqlCidr("192.168.1.0/24"), new IPAddress(new byte[] { 192, 168, 1, 1 }), new PhysicalAddress(new byte[] { 0x00, 0x1A, 0x2B, 0x3C, 0x4D, 0x5E }), "00:1a:2b:ff:fe:3c:4d:5e").SetName("Valid Network Data Types"); + yield return new TestCaseData(null, null, null, null).SetName("Null Network Data Types"); } } [Test] - [TestCaseSource(nameof(PostgresGuidDataTypesTestCases))] - public async Task TestPostgresGuidDataTypes(Guid? cUuid) + [TestCaseSource(nameof(PostgresNetworkDataTypesTestCases))] + public async Task TestPostgresNetworkDataTypes(NpgsqlCidr? cCidr, IPAddress cInet, PhysicalAddress cMacaddr, string cMacaddr8) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CUuid = cUuid }); - var expected = new QuerySql.GetPostgresTypesRow + await QuerySql.InsertPostgresNetworkTypes(new QuerySql.InsertPostgresNetworkTypesArgs { CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr, CMacaddr8 = cMacaddr8 }); + var expected = new QuerySql.GetPostgresNetworkTypesRow { - CUuid = cUuid + CCidr = cCidr, + CInet = cInet, + CMacaddr = cMacaddr, + CMacaddr8 = cMacaddr8 }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresNetworkTypes(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresNetworkTypesRow x, QuerySql.GetPostgresNetworkTypesRow y) { - Assert.That(x.CUuid, Is.EqualTo(y.CUuid)); + Assert.That(x.CCidr, Is.EqualTo(y.CCidr)); + Assert.That(x.CInet, Is.EqualTo(y.CInet)); + Assert.That(x.CMacaddr, Is.EqualTo(y.CMacaddr)); + Assert.That(x.CMacaddr8, Is.EqualTo(y.CMacaddr8)); + } + } + + private static IEnumerable PostgresGeoTypesTestCases + { + get + { + yield return new TestCaseData(new NpgsqlPoint(1, 2), new NpgsqlLine(3, 4, 5), new NpgsqlLSeg(1, 2, 3, 4), new NpgsqlBox(1, 2, 3, 4), new NpgsqlPath(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlPolygon(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlCircle(1, 2, 3)).SetName("Valid Geo Types"); + yield return new TestCaseData(null, null, null, null, null, null, null).SetName("Null Geo Types"); + } + } + + [Test] + [TestCaseSource(nameof(PostgresGeoTypesTestCases))] + public async Task TestPostgresGeoTypes(NpgsqlPoint? cPoint, NpgsqlLine? cLine, NpgsqlLSeg? cLSeg, NpgsqlBox? cBox, NpgsqlPath? cPath, NpgsqlPolygon? cPolygon, NpgsqlCircle? cCircle) + { + await QuerySql.InsertPostgresGeoTypes(new QuerySql.InsertPostgresGeoTypesArgs { CPoint = cPoint, CLine = cLine, CLseg = cLSeg, CBox = cBox, CPath = cPath, CPolygon = cPolygon, CCircle = cCircle }); + var expected = new QuerySql.GetPostgresGeoTypesRow + { + CPoint = cPoint, + CLine = cLine, + CLseg = cLSeg, + CBox = cBox, + CPath = cPath, + CPolygon = cPolygon, + CCircle = cCircle + }; + var actual = await QuerySql.GetPostgresGeoTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresGeoTypesRow x, QuerySql.GetPostgresGeoTypesRow y) + { + Assert.That(x.CPoint, Is.EqualTo(y.CPoint)); + Assert.That(x.CLine, Is.EqualTo(y.CLine)); + Assert.That(x.CLseg, Is.EqualTo(y.CLseg)); + Assert.That(x.CBox, Is.EqualTo(y.CBox)); + Assert.That(x.CPath, Is.EqualTo(y.CPath)); + Assert.That(x.CPolygon, Is.EqualTo(y.CPolygon)); + Assert.That(x.CCircle, Is.EqualTo(y.CCircle)); + } + } + + [Test] + [TestCase("{\"name\": \"Swordfishtrombones\", \"year\": 1983}", "$.\"name\"")] + [TestCase(null, null)] + public async Task TestPostgresJsonDataTypes(string cJson, string cJsonpath) + { + JsonElement? cParsedJson = null; + if (cJson != null) + cParsedJson = JsonDocument.Parse(cJson).RootElement; + await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CJson = cParsedJson, CJsonb = cParsedJson, CJsonStringOverride = cJson, CJsonpath = cJsonpath }); + var expected = new QuerySql.GetPostgresSpecialTypesRow + { + CJson = cParsedJson, + CJsonb = cParsedJson, + CJsonStringOverride = cJson, + CJsonpath = cJsonpath + }; + var actual = await QuerySql.GetPostgresSpecialTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPostgresSpecialTypesRow y) + { + Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); + if (x.CJson.HasValue) + Assert.That(x.CJson.Value.GetRawText(), Is.EqualTo(y.CJson.Value.GetRawText())); + Assert.That(x.CJsonb.HasValue, Is.EqualTo(y.CJsonb.HasValue)); + if (x.CJsonb.HasValue) + Assert.That(x.CJsonb.Value.GetRawText(), Is.EqualTo(y.CJsonb.Value.GetRawText())); + Assert.That(x.CJsonStringOverride, Is.EqualTo(y.CJsonStringOverride)); + Assert.That(x.CJsonpath, Is.EqualTo(y.CJsonpath)); + } + } + + [Test] + [TestCase("Good morning xml, the world says hello")] + [TestCase(null)] + public async Task TestPostgresXmlDataTypes(string cXml) + { + XmlDocument parsedXml = null; + if (cXml != null) + { + parsedXml = new XmlDocument(); + parsedXml.LoadXml(cXml); + } + + await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CXml = parsedXml }); + var expected = new QuerySql.GetPostgresSpecialTypesRow + { + CXml = parsedXml + }; + var actual = await QuerySql.GetPostgresSpecialTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPostgresSpecialTypesRow y) + { + Assert.That(x.CXml == null, Is.EqualTo(y.CXml == null)); + if (x.CXml != null) + Assert.That(x.CXml.OuterXml, Is.EqualTo(y.CXml.OuterXml)); + } + } + + [Test] + [TestCase(CEnum.Medium)] + [TestCase(null)] + public async Task TestPostgresStringTypes(CEnum? cEnum) + { + await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CEnum = cEnum }); + var expected = new QuerySql.GetPostgresSpecialTypesRow + { + CEnum = cEnum + }; + var actual = await QuerySql.GetPostgresSpecialTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPostgresSpecialTypesRow y) + { + Assert.That(x.CEnum, Is.EqualTo(y.CEnum)); } } @@ -485,9 +751,9 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTy [TestCase(10, null, null, null, null, null)] public async Task TestStringCopyFrom(int batchSize, string cChar, string cVarchar, string cCharacterVarying, string cBpchar, string cText) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CBpchar = cBpchar, CText = cText }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresStringTypesBatchArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CBpchar = cBpchar, CText = cText }).ToList(); + await QuerySql.InsertPostgresStringTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresStringTypesCntRow { Cnt = batchSize, CChar = cChar, @@ -496,9 +762,9 @@ public async Task TestStringCopyFrom(int batchSize, string cChar, string cVarcha CBpchar = cBpchar, CText = cText }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresStringTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresStringTypesCntRow x, QuerySql.GetPostgresStringTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CChar, Is.EqualTo(y.CChar)); @@ -509,49 +775,14 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgre } } - [Test] - public async Task TestPostgresTransaction() - { - var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv)); - await connection.OpenAsync(); - var transaction = connection.BeginTransaction(); - var querySqlWithTx = QuerySql.WithTransaction(transaction); - await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - // The GetAuthor method in NpgsqlExampleGen returns QuerySql.GetAuthorRow? (nullable record struct) - var actualNull = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actualNull == null, "there is author"); // This is correct for nullable types - await transaction.CommitAsync(); - var expected = new QuerySql.GetAuthorRow - { - Id = 1111, - Name = "Bojack Horseman", - Bio = "Back in the 90s he was in a very famous TV show" - }; - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual)); // Apply placeholder here - } - - [Test] - public async Task TestPostgresTransactionRollback() - { - var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv)); - await connection.OpenAsync(); - var transaction = connection.BeginTransaction(); - var sqlQueryWithTx = QuerySql.WithTransaction(transaction); - await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - await transaction.RollbackAsync(); - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actual == null, "author should not exist after rollback"); - } - [Test] [TestCase(100, true, 3, 453, -1445214231L)] [TestCase(10, null, null, null, null)] public async Task TestIntegerCopyFrom(int batchSize, bool? cBoolean, short? cSmallint, int? cInteger, long? cBigint) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresNumericTypesBatchArgs { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }).ToList(); + await QuerySql.InsertPostgresNumericTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresNumericTypesCntRow { Cnt = batchSize, CBoolean = cBoolean, @@ -559,9 +790,9 @@ public async Task TestIntegerCopyFrom(int batchSize, bool? cBoolean, short? cSma CInteger = cInteger, CBigint = cBigint }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresNumericTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresNumericTypesCntRow x, QuerySql.GetPostgresNumericTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CBoolean, Is.EqualTo(y.CBoolean)); @@ -576,9 +807,9 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgre [TestCase(10, null, null, null, null, null)] public async Task TestFloatingPointCopyFrom(int batchSize, float? cReal, decimal? cDecimal, decimal? cNumeric, double? cDoublePrecision, decimal? cMoney) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CReal = cReal, CDecimal = cDecimal, CNumeric = cNumeric, CDoublePrecision = cDoublePrecision, CMoney = cMoney }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresNumericTypesBatchArgs { CReal = cReal, CDecimal = cDecimal, CNumeric = cNumeric, CDoublePrecision = cDoublePrecision, CMoney = cMoney }).ToList(); + await QuerySql.InsertPostgresNumericTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresNumericTypesCntRow { Cnt = batchSize, CReal = cReal, @@ -587,9 +818,9 @@ public async Task TestFloatingPointCopyFrom(int batchSize, float? cReal, decimal CDoublePrecision = cDoublePrecision, CMoney = cMoney }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresNumericTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresNumericTypesCntRow x, QuerySql.GetPostgresNumericTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CReal, Is.EqualTo(y.CReal)); @@ -608,9 +839,9 @@ public async Task TestDateTimeCopyFrom(int batchSize, DateTime? cDate, TimeSpan? DateTime? cTimestampWithTzAsUtc = null; if (cTimestampWithTz != null) cTimestampWithTzAsUtc = DateTime.SpecifyKind(cTimestampWithTz.Value, DateTimeKind.Utc); - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CDate = cDate, CTime = cTime, CTimestamp = cTimestamp, CTimestampWithTz = cTimestampWithTzAsUtc, CInterval = cInterval }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresDateTimeTypesBatchArgs { CDate = cDate, CTime = cTime, CTimestamp = cTimestamp, CTimestampWithTz = cTimestampWithTzAsUtc, CInterval = cInterval }).ToList(); + await QuerySql.InsertPostgresDateTimeTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresDateTimeTypesCntRow { Cnt = batchSize, CDate = cDate, @@ -619,9 +850,9 @@ public async Task TestDateTimeCopyFrom(int batchSize, DateTime? cDate, TimeSpan? CTimestampWithTz = cTimestampWithTz, CInterval = cInterval }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresDateTimeTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresDateTimeTypesCntRow x, QuerySql.GetPostgresDateTimeTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CDate, Is.EqualTo(y.CDate)); @@ -645,16 +876,16 @@ private static IEnumerable PostgresGuidCopyFromTestCases [TestCaseSource(nameof(PostgresGuidCopyFromTestCases))] public async Task TestPostgresGuidCopyFrom(int batchSize, Guid? cUuid) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CUuid = cUuid }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresSpecialTypesBatchArgs { CUuid = cUuid }).ToList(); + await QuerySql.InsertPostgresSpecialTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresSpecialTypesCntRow { Cnt = batchSize, CUuid = cUuid }; - var actual = await QuerySql.GetPostgresTypesCnt(); - Assert.That(actual.Cnt, Is.EqualTo(expected.Cnt)); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + var actual = await QuerySql.GetPostgresSpecialTypesCnt(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesCntRow x, QuerySql.GetPostgresSpecialTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CUuid, Is.EqualTo(y.CUuid)); @@ -674,18 +905,18 @@ private static IEnumerable PostgresNetworkCopyFromTestCases [TestCaseSource(nameof(PostgresNetworkCopyFromTestCases))] public async Task TestPostgresNetworkCopyFrom(int batchSize, NpgsqlCidr? cCidr, IPAddress cInet, PhysicalAddress cMacaddr) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresNetworkTypesBatchArgs { CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr }).ToList(); + await QuerySql.InsertPostgresNetworkTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresNetworkTypesCntRow { Cnt = batchSize, CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresNetworkTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresNetworkTypesCntRow x, QuerySql.GetPostgresNetworkTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CCidr, Is.EqualTo(y.CCidr)); @@ -694,62 +925,43 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgre } } - [Test] - [TestCase(100, new byte[] { 0x53, 0x56 })] - [TestCase(10, new byte[] { })] - [TestCase(10, null)] - public async Task TestArrayCopyFrom(int batchSize, byte[] cBytea) - { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresArrayTypesBatchArgs { CBytea = cBytea }).ToList(); - await QuerySql.InsertPostgresArrayTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresArrayTypesCntRow - { - Cnt = batchSize, - CBytea = cBytea - }; - var actual = await QuerySql.GetPostgresArrayTypesCnt(); - AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresArrayTypesCntRow x, QuerySql.GetPostgresArrayTypesCntRow y) - { - Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); - } - } - - private static IEnumerable PostgresGeoTypesTestCases + private static IEnumerable PostgresArrayCopyFromTestCases { get { - yield return new TestCaseData(new NpgsqlPoint(1, 2), new NpgsqlLine(3, 4, 5), new NpgsqlLSeg(1, 2, 3, 4), new NpgsqlBox(1, 2, 3, 4), new NpgsqlPath(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlPolygon(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlCircle(1, 2, 3)).SetName("Valid Geo Types"); - yield return new TestCaseData(null, null, null, null, null, null, null).SetName("Null Geo Types"); + yield return new TestCaseData(100, new byte[] { 0x53, 0x56 }, new bool[] { true, false }, new string[] { "Sister Ray", "Venus in Furs" }, new int[] { 1, 2 }, new decimal[] { 132.13m, 23.22m }, new DateTime[] { new DateTime(1984, 8, 26), new DateTime(2000, 1, 2) }).SetName("Valid Array Copy From"); + yield return new TestCaseData(10, new byte[] { }, new bool[] { }, new string[] { }, new int[] { }, new decimal[] { }, new DateTime[] { }).SetName("Empty Array Copy From"); + yield return new TestCaseData(10, null, null, null, null, null, null).SetName("Null Array Copy From"); } } [Test] - [TestCaseSource(nameof(PostgresGeoTypesTestCases))] - public async Task TestPostgresGeoTypes(NpgsqlPoint? cPoint, NpgsqlLine? cLine, NpgsqlLSeg? cLSeg, NpgsqlBox? cBox, NpgsqlPath? cPath, NpgsqlPolygon? cPolygon, NpgsqlCircle? cCircle) + [TestCaseSource(nameof(PostgresArrayCopyFromTestCases))] + public async Task TestArrayCopyFrom(int batchSize, byte[] cBytea, bool[] cBooleanArray, string[] cTextArray, int[] cIntegerArray, decimal[] cDecimalArray, DateTime[] cTimestampArray) { - await QuerySql.InsertPostgresGeoTypes(new QuerySql.InsertPostgresGeoTypesArgs { CPoint = cPoint, CLine = cLine, CLseg = cLSeg, CBox = cBox, CPath = cPath, CPolygon = cPolygon, CCircle = cCircle }); - var expected = new QuerySql.GetPostgresGeoTypesRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresArrayTypesBatchArgs { CBytea = cBytea, CBooleanArray = cBooleanArray, CTextArray = cTextArray, CIntegerArray = cIntegerArray, CDecimalArray = cDecimalArray, CTimestampArray = cTimestampArray }).ToList(); + await QuerySql.InsertPostgresArrayTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresArrayTypesCntRow { - CPoint = cPoint, - CLine = cLine, - CLseg = cLSeg, - CBox = cBox, - CPath = cPath, - CPolygon = cPolygon, - CCircle = cCircle + Cnt = batchSize, + CBytea = cBytea, + CBooleanArray = cBooleanArray, + CTextArray = cTextArray, + CIntegerArray = cIntegerArray, + CDecimalArray = cDecimalArray, + CTimestampArray = cTimestampArray }; - var actual = await QuerySql.GetPostgresGeoTypes(); + var actual = await QuerySql.GetPostgresArrayTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresGeoTypesRow x, QuerySql.GetPostgresGeoTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresArrayTypesCntRow x, QuerySql.GetPostgresArrayTypesCntRow y) { - Assert.That(x.CPoint, Is.EqualTo(y.CPoint)); - Assert.That(x.CLine, Is.EqualTo(y.CLine)); - Assert.That(x.CLseg, Is.EqualTo(y.CLseg)); - Assert.That(x.CBox, Is.EqualTo(y.CBox)); - Assert.That(x.CPath, Is.EqualTo(y.CPath)); - Assert.That(x.CPolygon, Is.EqualTo(y.CPolygon)); - Assert.That(x.CCircle, Is.EqualTo(y.CCircle)); + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CBytea, Is.EqualTo(y.CBytea)); + Assert.That(x.CBooleanArray, Is.EqualTo(y.CBooleanArray)); + Assert.That(x.CTextArray, Is.EqualTo(y.CTextArray)); + Assert.That(x.CIntegerArray, Is.EqualTo(y.CIntegerArray)); + Assert.That(x.CDecimalArray, Is.EqualTo(y.CDecimalArray)); + Assert.That(x.CTimestampArray, Is.EqualTo(y.CTimestampArray)); } } @@ -791,121 +1003,5 @@ void AssertSingularEquals(QuerySql.GetPostgresGeoTypesRow x, QuerySql.GetPostgre Assert.That(x.CCircle, Is.EqualTo(y.CCircle)); } } - - private static IEnumerable PostgresNetworkDataTypesTestCases - { - get - { - yield return new TestCaseData(new NpgsqlCidr("192.168.1.0/24"), new IPAddress(new byte[] { 192, 168, 1, 1 }), new PhysicalAddress(new byte[] { 0x00, 0x1A, 0x2B, 0x3C, 0x4D, 0x5E }), "00:1a:2b:ff:fe:3c:4d:5e").SetName("Valid Network Data Types"); - yield return new TestCaseData(null, null, null, null).SetName("Null Network Data Types"); - } - } - - [Test] - [TestCaseSource(nameof(PostgresNetworkDataTypesTestCases))] - public async Task TestPostgresNetworkDataTypes(NpgsqlCidr? cCidr, IPAddress cInet, PhysicalAddress cMacaddr, string cMacaddr8) - { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr, CMacaddr8 = cMacaddr8 }); - var expected = new QuerySql.GetPostgresTypesRow - { - CCidr = cCidr, - CInet = cInet, - CMacaddr = cMacaddr, - CMacaddr8 = cMacaddr8 - }; - var actual = await QuerySql.GetPostgresTypes(); - AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) - { - Assert.That(x.CCidr, Is.EqualTo(y.CCidr)); - Assert.That(x.CInet, Is.EqualTo(y.CInet)); - Assert.That(x.CMacaddr, Is.EqualTo(y.CMacaddr)); - Assert.That(x.CMacaddr8, Is.EqualTo(y.CMacaddr8)); - } - } - - [Test] - [TestCase("{\"name\": \"Swordfishtrombones\", \"year\": 1983}", "$.\"name\"")] - [TestCase(null, null)] - public async Task TestPostgresJsonDataTypes(string cJson, string cJsonpath) - { - JsonElement? cParsedJson = null; - if (cJson != null) - cParsedJson = JsonDocument.Parse(cJson).RootElement; - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CJson = cParsedJson, CJsonb = cParsedJson, CJsonStringOverride = cJson, CJsonpath = cJsonpath }); - var expected = new QuerySql.GetPostgresTypesRow - { - CJson = cParsedJson, - CJsonb = cParsedJson, - CJsonStringOverride = cJson, - CJsonpath = cJsonpath - }; - var actual = await QuerySql.GetPostgresTypes(); - AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) - { - Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); - if (x.CJson.HasValue) - Assert.That(x.CJson.Value.GetRawText(), Is.EqualTo(y.CJson.Value.GetRawText())); - Assert.That(x.CJsonb.HasValue, Is.EqualTo(y.CJsonb.HasValue)); - if (x.CJsonb.HasValue) - Assert.That(x.CJsonb.Value.GetRawText(), Is.EqualTo(y.CJsonb.Value.GetRawText())); - Assert.That(x.CJsonStringOverride, Is.EqualTo(y.CJsonStringOverride)); - Assert.That(x.CJsonpath, Is.EqualTo(y.CJsonpath)); - } - } - - [Test] - public void TestPostgresInvalidJson() - { - Assert.ThrowsAsync(async () => await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CJsonStringOverride = "SOME INVALID JSON" })); - Assert.ThrowsAsync(async () => await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CJsonpath = "SOME INVALID JSONPATH" })); - } - - [Test] - [TestCase("Good morning xml, the world says hello")] - [TestCase(null)] - public async Task TestPostgresXmlDataTypes(string cXml) - { - XmlDocument parsedXml = null; - if (cXml != null) - { - parsedXml = new XmlDocument(); - parsedXml.LoadXml(cXml); - } - - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CXml = parsedXml }); - var expected = new QuerySql.GetPostgresTypesRow - { - CXml = parsedXml - }; - var actual = await QuerySql.GetPostgresTypes(); - AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) - { - if (x.CXml == null && y.CXml == null) - return; - Assert.That(x.CXml.OuterXml, Is.EqualTo(y.CXml.OuterXml)); - } - } - - [Test] - public async Task TestArray() - { - var id1 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Quote that everyone always attribute to Einstein" }); - var bojackId = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - var actual = await QuerySql.GetAuthorsByIds(new QuerySql.GetAuthorsByIdsArgs { LongArr1 = new[] { id1, bojackId } }); - ClassicAssert.AreEqual(2, actual.Count); - } - - [Test] - public async Task TestMultipleArrays() - { - var id1 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Quote that everyone always attribute to Einstein" }); - var id2 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Only 2 things are infinite, the universe and human stupidity" }); - var bojackId = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - var actual = await QuerySql.GetAuthorsByIdsAndNames(new QuerySql.GetAuthorsByIdsAndNamesArgs { LongArr1 = new[] { id1, bojackId }, StringArr2 = new[] { "Albert Einstein" } }); - ClassicAssert.AreEqual(1, actual.Count); - } } } diff --git a/end2end/EndToEndTests/NpgsqlTester.cs b/end2end/EndToEndTests/NpgsqlTester.cs index 39093f3e..adddd5ba 100644 --- a/end2end/EndToEndTests/NpgsqlTester.cs +++ b/end2end/EndToEndTests/NpgsqlTester.cs @@ -14,8 +14,12 @@ public partial class NpgsqlTester public async Task EmptyTestsTables() { await QuerySql.TruncateAuthors(); - await QuerySql.TruncatePostgresTypes(); + await QuerySql.TruncatePostgresNumericTypes(); + await QuerySql.TruncatePostgresStringTypes(); + await QuerySql.TruncatePostgresDateTimeTypes(); await QuerySql.TruncatePostgresGeoTypes(); + await QuerySql.TruncatePostgresNetworkTypes(); await QuerySql.TruncatePostgresArrayTypes(); + await QuerySql.TruncatePostgresSpecialTypes(); } } \ No newline at end of file diff --git a/end2end/EndToEndTests/NpgsqlTester.generated.cs b/end2end/EndToEndTests/NpgsqlTester.generated.cs index 0bf4630a..fad87b7a 100644 --- a/end2end/EndToEndTests/NpgsqlTester.generated.cs +++ b/end2end/EndToEndTests/NpgsqlTester.generated.cs @@ -28,12 +28,13 @@ public async Task TestOne() Bio = "Back in the 90s he was in a very famous TV show" }; var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual.Value)); - } - - private static bool SingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -58,21 +59,18 @@ public async Task TestMany() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) - { - Assert.That(x.Id, Is.EqualTo(y.Id)); - Assert.That(x.Name, Is.EqualTo(y.Name)); - Assert.That(x.Bio, Is.EqualTo(y.Bio)); - } + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } - private static void AssertSequenceEquals(List x, List y) - { - Assert.That(x.Count, Is.EqualTo(y.Count)); - for (int i = 0; i < x.Count; i++) + void AssertSequenceEquals(List x, List y) { - AssertSingularEquals(x[i], y[i]); + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); } } @@ -110,6 +108,19 @@ public async Task TestExecRows() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -123,12 +134,13 @@ public async Task TestExecLastId() Bio = "Quote that everyone always attribute to Einstein" }; var actual = await QuerySql.GetAuthorById(new QuerySql.GetAuthorByIdArgs { Id = id1 }); - Assert.That(SingularEquals(expected, actual.Value)); - } - - private static bool SingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -155,19 +167,23 @@ public async Task TestSelfJoinEmbed() } }; var actual = await QuerySql.GetDuplicateAuthors(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) - { - return SingularEquals(x.Author.Value, y.Author.Value) && SingularEquals(x.Author2.Value, y.Author2.Value); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) + { + Assert.That(x.Author.Value.Id, Is.EqualTo(y.Author.Value.Id)); + Assert.That(x.Author.Value.Name, Is.EqualTo(y.Author.Value.Name)); + Assert.That(x.Author.Value.Bio, Is.EqualTo(y.Author.Value.Bio)); + Assert.That(x.Author2.Value.Id, Is.EqualTo(y.Author2.Value.Id)); + Assert.That(x.Author2.Value.Name, Is.EqualTo(y.Author2.Value.Name)); + Assert.That(x.Author2.Value.Bio, Is.EqualTo(y.Author2.Value.Bio)); + } - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -211,31 +227,23 @@ public async Task TestJoinEmbed() } }; var actual = await QuerySql.ListAllAuthorsBooks(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) - { - return SingularEquals(x.Author.Value, y.Author.Value) && SingularEquals(x.Book.Value, y.Book.Value); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Author.Value.Name + o.Book.Value.Name).ToList(); - y = y.OrderBy(o => o.Author.Value.Name + o.Book.Value.Name).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } - - private static bool SingularEquals(Author x, Author y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) + { + Assert.That(x.Author.Value.Id, Is.EqualTo(y.Author.Value.Id)); + Assert.That(x.Author.Value.Name, Is.EqualTo(y.Author.Value.Name)); + Assert.That(x.Author.Value.Bio, Is.EqualTo(y.Author.Value.Bio)); + Assert.That(x.Book.Value.Id, Is.EqualTo(y.Book.Value.Id)); + Assert.That(x.Book.Value.AuthorId, Is.EqualTo(y.Book.Value.AuthorId)); + Assert.That(x.Book.Value.Name, Is.EqualTo(y.Book.Value.Name)); + } - private static bool SingularEquals(Book x, Book y) - { - return x.Id.Equals(y.Id) && x.AuthorId.Equals(y.AuthorId) && x.Name.Equals(y.Name); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -259,21 +267,20 @@ public async Task TestNargNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs()); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Id).ToList(); - y = y.OrderBy(o => o.Id).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } - private static bool SingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -291,7 +298,116 @@ public async Task TestNargNotNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs { NamePattern = "Bojack%" }); - Assert.That(SequenceEquals(expected, actual)); + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } + + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + } + + [Test] + public async Task TestPostgresTransaction() + { + var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv)); + await connection.OpenAsync(); + var transaction = connection.BeginTransaction(); + var querySqlWithTx = QuerySql.WithTransaction(transaction); + await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + ClassicAssert.IsNull(actual); + await transaction.CommitAsync(); + var expected = new QuerySql.GetAuthorRow + { + Id = 1111, + Name = "Bojack Horseman", + Bio = "Back in the 90s he was in a very famous TV show" + }; + actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + } + + [Test] + public async Task TestPostgresTransactionRollback() + { + var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv)); + await connection.OpenAsync(); + var transaction = connection.BeginTransaction(); + var sqlQueryWithTx = QuerySql.WithTransaction(transaction); + await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + await transaction.RollbackAsync(); + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + ClassicAssert.IsNull(actual); + } + + [Test] + public async Task TestArray() + { + var id1 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Quote that everyone always attribute to Einstein" }); + var bojackId = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + var actual = await QuerySql.GetAuthorsByIds(new QuerySql.GetAuthorsByIdsArgs { LongArr1 = new[] { id1, bojackId } }); + ClassicAssert.AreEqual(2, actual.Count); + } + + [Test] + public async Task TestMultipleArrays() + { + var id1 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Quote that everyone always attribute to Einstein" }); + var id2 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Only 2 things are infinite, the universe and human stupidity" }); + var bojackId = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + var actual = await QuerySql.GetAuthorsByIdsAndNames(new QuerySql.GetAuthorsByIdsAndNamesArgs { LongArr1 = new[] { id1, bojackId }, StringArr2 = new[] { "Albert Einstein" } }); + ClassicAssert.AreEqual(1, actual.Count); + } + + [Test] + [TestCase(-54355, "White Light from the Mouth of Infinity", "2022-10-2 15:44:01+09:00")] + [TestCase(null, null, "1970-01-01 00:00:00")] + public async Task TestPostgresDataTypesOverride(int? cInteger, string cVarchar, DateTime cTimestamp) + { + await QuerySql.InsertPostgresNumericTypes(new QuerySql.InsertPostgresNumericTypesArgs { CInteger = cInteger }); + await QuerySql.InsertPostgresDateTimeTypes(new QuerySql.InsertPostgresDateTimeTypesArgs { CTimestamp = cTimestamp }); + await QuerySql.InsertPostgresStringTypes(new QuerySql.InsertPostgresStringTypesArgs { CVarchar = cVarchar }); + var expected = new QuerySql.GetPostgresFunctionsRow + { + MaxInteger = cInteger, + MaxVarchar = cVarchar, + MaxTimestamp = cTimestamp + }; + var actual = await QuerySql.GetPostgresFunctions(); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetPostgresFunctionsRow x, QuerySql.GetPostgresFunctionsRow y) + { + Assert.That(x.MaxInteger, Is.EqualTo(y.MaxInteger)); + Assert.That(x.MaxVarchar, Is.EqualTo(y.MaxVarchar)); + Assert.That(x.MaxTimestamp, Is.EqualTo(y.MaxTimestamp)); + } + } + + [Test] + public void TestPostgresInvalidJson() + { + Assert.ThrowsAsync(async () => await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CJsonStringOverride = "SOME INVALID JSON" })); + Assert.ThrowsAsync(async () => await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CJsonpath = "SOME INVALID JSONPATH" })); + } + + [Test] + public void TestPostgresInvalidXml() + { + Assert.ThrowsAsync(async () => await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CXmlStringOverride = "SOME INVALID XML" })); } [Test] @@ -299,8 +415,8 @@ public async Task TestNargNotNull() [TestCase(null, null, null, null, null)] public async Task TestPostgresStringTypes(string cChar, string cVarchar, string cCharacterVarying, string cBpchar, string cText) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CBpchar = cBpchar, CText = cText, }); - var expected = new QuerySql.GetPostgresTypesRow + await QuerySql.InsertPostgresStringTypes(new QuerySql.InsertPostgresStringTypesArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CBpchar = cBpchar, CText = cText, }); + var expected = new QuerySql.GetPostgresStringTypesRow { CChar = cChar, CVarchar = cVarchar, @@ -308,9 +424,9 @@ public async Task TestPostgresStringTypes(string cChar, string cVarchar, string CBpchar = cBpchar, CText = cText, }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresStringTypes(); AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresStringTypesRow x, QuerySql.GetPostgresStringTypesRow y) { Assert.That(x.CChar, Is.EqualTo(y.CChar)); Assert.That(x.CVarchar, Is.EqualTo(y.CVarchar)); @@ -325,19 +441,23 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTy [TestCase(null, null, null, null)] public async Task TestPostgresIntegerTypes(bool cBoolean, short cSmallint, int cInteger, long cBigint) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }); - var expected = new QuerySql.GetPostgresTypesRow + await QuerySql.InsertPostgresNumericTypes(new QuerySql.InsertPostgresNumericTypesArgs { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }); + var expected = new QuerySql.GetPostgresNumericTypesRow { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }; - var actual = await QuerySql.GetPostgresTypes(); - Assert.That(actual.Value.CBoolean, Is.EqualTo(expected.CBoolean)); - Assert.That(actual.Value.CSmallint, Is.EqualTo(expected.CSmallint)); - Assert.That(actual.Value.CInteger, Is.EqualTo(expected.CInteger)); - Assert.That(actual.Value.CBigint, Is.EqualTo(expected.CBigint)); + var actual = await QuerySql.GetPostgresNumericTypes(); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetPostgresNumericTypesRow x, QuerySql.GetPostgresNumericTypesRow y) + { + Assert.That(x.CBoolean, Is.EqualTo(y.CBoolean)); + Assert.That(x.CSmallint, Is.EqualTo(y.CSmallint)); + Assert.That(x.CInteger, Is.EqualTo(y.CInteger)); + Assert.That(x.CBigint, Is.EqualTo(y.CBigint)); + } } [Test] @@ -345,8 +465,8 @@ public async Task TestPostgresIntegerTypes(bool cBoolean, short cSmallint, int c [TestCase(null, null, null, null, null)] public async Task TestPostgresFloatingPointTypes(float? cReal, decimal? cNumeric, decimal? cDecimal, double? cDoublePrecision, decimal? cMoney) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CReal = cReal, CNumeric = cNumeric, CDecimal = cDecimal, CDoublePrecision = cDoublePrecision, CMoney = cMoney }); - var expected = new QuerySql.GetPostgresTypesRow + await QuerySql.InsertPostgresNumericTypes(new QuerySql.InsertPostgresNumericTypesArgs { CReal = cReal, CNumeric = cNumeric, CDecimal = cDecimal, CDoublePrecision = cDoublePrecision, CMoney = cMoney }); + var expected = new QuerySql.GetPostgresNumericTypesRow { CReal = cReal, CNumeric = cNumeric, @@ -354,9 +474,9 @@ public async Task TestPostgresFloatingPointTypes(float? cReal, decimal? cNumeric CDoublePrecision = cDoublePrecision, CMoney = cMoney }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresNumericTypes(); AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresNumericTypesRow x, QuerySql.GetPostgresNumericTypesRow y) { Assert.That(x.CReal, Is.EqualTo(y.CReal)); Assert.That(x.CNumeric, Is.EqualTo(y.CNumeric)); @@ -371,8 +491,8 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTy [TestCase(null, null, null, null, null)] public async Task TestPostgresDateTimeTypes(DateTime? cDate, TimeSpan? cTime, DateTime? cTimestamp, DateTime? cTimestampWithTz, TimeSpan? cInterval) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CDate = cDate, CTime = cTime, CTimestamp = cTimestamp, CTimestampWithTz = cTimestampWithTz, CInterval = cInterval }); - var expected = new QuerySql.GetPostgresTypesRow + await QuerySql.InsertPostgresDateTimeTypes(new QuerySql.InsertPostgresDateTimeTypesArgs { CDate = cDate, CTime = cTime, CTimestamp = cTimestamp, CTimestampWithTz = cTimestampWithTz, CInterval = cInterval }); + var expected = new QuerySql.GetPostgresDateTimeTypesRow { CDate = cDate, CTime = cTime, @@ -380,9 +500,9 @@ public async Task TestPostgresDateTimeTypes(DateTime? cDate, TimeSpan? cTime, Da CTimestampWithTz = cTimestampWithTz, CInterval = cInterval }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresDateTimeTypes(); AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresDateTimeTypesRow x, QuerySql.GetPostgresDateTimeTypesRow y) { Assert.That(x.CDate, Is.EqualTo(y.CDate)); Assert.That(x.CTime, Is.EqualTo(y.CTime)); @@ -431,52 +551,198 @@ void AssertSingularEquals(QuerySql.GetPostgresArrayTypesRow x, QuerySql.GetPostg } } + private static IEnumerable PostgresGuidDataTypesTestCases + { + get + { + yield return new TestCaseData(Guid.NewGuid()).SetName("Valid Guid"); + yield return new TestCaseData(null).SetName("Null Guid"); + } + } + [Test] - [TestCase(-54355, "White Light from the Mouth of Infinity", "2022-10-2 15:44:01+09:00")] - [TestCase(null, null, "1970-01-01 00:00:00")] - public async Task TestPostgresDataTypesOverride(int? cInteger, string cVarchar, DateTime cTimestamp) + [TestCaseSource(nameof(PostgresGuidDataTypesTestCases))] + public async Task TestPostgresGuidDataTypes(Guid? cUuid) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CInteger = cInteger, CVarchar = cVarchar, CTimestamp = cTimestamp }); - var expected = new QuerySql.GetPostgresFunctionsRow + await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CUuid = cUuid }); + var expected = new QuerySql.GetPostgresSpecialTypesRow { - MaxInteger = cInteger, - MaxVarchar = cVarchar, - MaxTimestamp = cTimestamp + CUuid = cUuid }; - var actual = await QuerySql.GetPostgresFunctions(); + var actual = await QuerySql.GetPostgresSpecialTypes(); AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPostgresSpecialTypesRow y) + { + Assert.That(x.CUuid, Is.EqualTo(y.CUuid)); + } } - private static void AssertSingularEquals(QuerySql.GetPostgresFunctionsRow expected, QuerySql.GetPostgresFunctionsRow actual) + [Test] + [Obsolete] // due to NpgsqlTsVector.Parse usage + public async Task TestPostgresFullTextSearchDataTypes() { - Assert.That(actual.MaxInteger, Is.EqualTo(expected.MaxInteger)); - Assert.That(actual.MaxVarchar, Is.EqualTo(expected.MaxVarchar)); - Assert.That(actual.MaxTimestamp, Is.EqualTo(expected.MaxTimestamp)); + await QuerySql.InsertPostgresStringTypes(new QuerySql.InsertPostgresStringTypesArgs { CText = "Hello world" }); + var actual = await QuerySql.GetPostgresStringTypesTextSearch(new QuerySql.GetPostgresStringTypesTextSearchArgs { ToTsquery = "Hello" }); + var expected = new QuerySql.GetPostgresStringTypesTextSearchRow + { + CText = "Hello world", + Query = new NpgsqlTsQueryLexeme("hello"), + Tsv = NpgsqlTsVector.Parse("hello:1 world:2"), + Rnk = 0.07f + }; + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetPostgresStringTypesTextSearchRow x, QuerySql.GetPostgresStringTypesTextSearchRow y) + { + Assert.That(y.CText, Is.EqualTo(x.CText)); + Assert.That(y.Query.ToString(), Is.EqualTo(x.Query.ToString())); + Assert.That(y.Tsv.ToString(), Is.EqualTo(x.Tsv.ToString())); + Assert.That(y.Rnk, Is.AtMost(x.Rnk)); + } } - private static IEnumerable PostgresGuidDataTypesTestCases + private static IEnumerable PostgresNetworkDataTypesTestCases { get { - yield return new TestCaseData(Guid.NewGuid()).SetName("Valid Guid"); - yield return new TestCaseData(null).SetName("Null Guid"); + yield return new TestCaseData(new NpgsqlCidr("192.168.1.0/24"), new IPAddress(new byte[] { 192, 168, 1, 1 }), new PhysicalAddress(new byte[] { 0x00, 0x1A, 0x2B, 0x3C, 0x4D, 0x5E }), "00:1a:2b:ff:fe:3c:4d:5e").SetName("Valid Network Data Types"); + yield return new TestCaseData(null, null, null, null).SetName("Null Network Data Types"); } } [Test] - [TestCaseSource(nameof(PostgresGuidDataTypesTestCases))] - public async Task TestPostgresGuidDataTypes(Guid? cUuid) + [TestCaseSource(nameof(PostgresNetworkDataTypesTestCases))] + public async Task TestPostgresNetworkDataTypes(NpgsqlCidr? cCidr, IPAddress cInet, PhysicalAddress cMacaddr, string cMacaddr8) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CUuid = cUuid }); - var expected = new QuerySql.GetPostgresTypesRow + await QuerySql.InsertPostgresNetworkTypes(new QuerySql.InsertPostgresNetworkTypesArgs { CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr, CMacaddr8 = cMacaddr8 }); + var expected = new QuerySql.GetPostgresNetworkTypesRow { - CUuid = cUuid + CCidr = cCidr, + CInet = cInet, + CMacaddr = cMacaddr, + CMacaddr8 = cMacaddr8 }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresNetworkTypes(); AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresNetworkTypesRow x, QuerySql.GetPostgresNetworkTypesRow y) { - Assert.That(x.CUuid, Is.EqualTo(y.CUuid)); + Assert.That(x.CCidr, Is.EqualTo(y.CCidr)); + Assert.That(x.CInet, Is.EqualTo(y.CInet)); + Assert.That(x.CMacaddr, Is.EqualTo(y.CMacaddr)); + Assert.That(x.CMacaddr8, Is.EqualTo(y.CMacaddr8)); + } + } + + private static IEnumerable PostgresGeoTypesTestCases + { + get + { + yield return new TestCaseData(new NpgsqlPoint(1, 2), new NpgsqlLine(3, 4, 5), new NpgsqlLSeg(1, 2, 3, 4), new NpgsqlBox(1, 2, 3, 4), new NpgsqlPath(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlPolygon(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlCircle(1, 2, 3)).SetName("Valid Geo Types"); + yield return new TestCaseData(null, null, null, null, null, null, null).SetName("Null Geo Types"); + } + } + + [Test] + [TestCaseSource(nameof(PostgresGeoTypesTestCases))] + public async Task TestPostgresGeoTypes(NpgsqlPoint? cPoint, NpgsqlLine? cLine, NpgsqlLSeg? cLSeg, NpgsqlBox? cBox, NpgsqlPath? cPath, NpgsqlPolygon? cPolygon, NpgsqlCircle? cCircle) + { + await QuerySql.InsertPostgresGeoTypes(new QuerySql.InsertPostgresGeoTypesArgs { CPoint = cPoint, CLine = cLine, CLseg = cLSeg, CBox = cBox, CPath = cPath, CPolygon = cPolygon, CCircle = cCircle }); + var expected = new QuerySql.GetPostgresGeoTypesRow + { + CPoint = cPoint, + CLine = cLine, + CLseg = cLSeg, + CBox = cBox, + CPath = cPath, + CPolygon = cPolygon, + CCircle = cCircle + }; + var actual = await QuerySql.GetPostgresGeoTypes(); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetPostgresGeoTypesRow x, QuerySql.GetPostgresGeoTypesRow y) + { + Assert.That(x.CPoint, Is.EqualTo(y.CPoint)); + Assert.That(x.CLine, Is.EqualTo(y.CLine)); + Assert.That(x.CLseg, Is.EqualTo(y.CLseg)); + Assert.That(x.CBox, Is.EqualTo(y.CBox)); + Assert.That(x.CPath, Is.EqualTo(y.CPath)); + Assert.That(x.CPolygon, Is.EqualTo(y.CPolygon)); + Assert.That(x.CCircle, Is.EqualTo(y.CCircle)); + } + } + + [Test] + [TestCase("{\"name\": \"Swordfishtrombones\", \"year\": 1983}", "$.\"name\"")] + [TestCase(null, null)] + public async Task TestPostgresJsonDataTypes(string cJson, string cJsonpath) + { + JsonElement? cParsedJson = null; + if (cJson != null) + cParsedJson = JsonDocument.Parse(cJson).RootElement; + await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CJson = cParsedJson, CJsonb = cParsedJson, CJsonStringOverride = cJson, CJsonpath = cJsonpath }); + var expected = new QuerySql.GetPostgresSpecialTypesRow + { + CJson = cParsedJson, + CJsonb = cParsedJson, + CJsonStringOverride = cJson, + CJsonpath = cJsonpath + }; + var actual = await QuerySql.GetPostgresSpecialTypes(); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPostgresSpecialTypesRow y) + { + Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); + if (x.CJson.HasValue) + Assert.That(x.CJson.Value.GetRawText(), Is.EqualTo(y.CJson.Value.GetRawText())); + Assert.That(x.CJsonb.HasValue, Is.EqualTo(y.CJsonb.HasValue)); + if (x.CJsonb.HasValue) + Assert.That(x.CJsonb.Value.GetRawText(), Is.EqualTo(y.CJsonb.Value.GetRawText())); + Assert.That(x.CJsonStringOverride, Is.EqualTo(y.CJsonStringOverride)); + Assert.That(x.CJsonpath, Is.EqualTo(y.CJsonpath)); + } + } + + [Test] + [TestCase("Good morning xml, the world says hello")] + [TestCase(null)] + public async Task TestPostgresXmlDataTypes(string cXml) + { + XmlDocument parsedXml = null; + if (cXml != null) + { + parsedXml = new XmlDocument(); + parsedXml.LoadXml(cXml); + } + + await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CXml = parsedXml }); + var expected = new QuerySql.GetPostgresSpecialTypesRow + { + CXml = parsedXml + }; + var actual = await QuerySql.GetPostgresSpecialTypes(); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPostgresSpecialTypesRow y) + { + Assert.That(x.CXml == null, Is.EqualTo(y.CXml == null)); + if (x.CXml != null) + Assert.That(x.CXml.OuterXml, Is.EqualTo(y.CXml.OuterXml)); + } + } + + [Test] + [TestCase(CEnum.Medium)] + [TestCase(null)] + public async Task TestPostgresStringTypes(CEnum? cEnum) + { + await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CEnum = cEnum }); + var expected = new QuerySql.GetPostgresSpecialTypesRow + { + CEnum = cEnum + }; + var actual = await QuerySql.GetPostgresSpecialTypes(); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPostgresSpecialTypesRow y) + { + Assert.That(x.CEnum, Is.EqualTo(y.CEnum)); } } @@ -485,9 +751,9 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTy [TestCase(10, null, null, null, null, null)] public async Task TestStringCopyFrom(int batchSize, string cChar, string cVarchar, string cCharacterVarying, string cBpchar, string cText) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CBpchar = cBpchar, CText = cText }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresStringTypesBatchArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CBpchar = cBpchar, CText = cText }).ToList(); + await QuerySql.InsertPostgresStringTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresStringTypesCntRow { Cnt = batchSize, CChar = cChar, @@ -496,9 +762,9 @@ public async Task TestStringCopyFrom(int batchSize, string cChar, string cVarcha CBpchar = cBpchar, CText = cText }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresStringTypesCnt(); AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresStringTypesCntRow x, QuerySql.GetPostgresStringTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CChar, Is.EqualTo(y.CChar)); @@ -509,49 +775,14 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgre } } - [Test] - public async Task TestPostgresTransaction() - { - var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv)); - await connection.OpenAsync(); - var transaction = connection.BeginTransaction(); - var querySqlWithTx = QuerySql.WithTransaction(transaction); - await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - // The GetAuthor method in NpgsqlExampleGen returns QuerySql.GetAuthorRow? (nullable record struct) - var actualNull = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actualNull == null, "there is author"); // This is correct for nullable types - await transaction.CommitAsync(); - var expected = new QuerySql.GetAuthorRow - { - Id = 1111, - Name = "Bojack Horseman", - Bio = "Back in the 90s he was in a very famous TV show" - }; - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual.Value)); // Apply placeholder here - } - - [Test] - public async Task TestPostgresTransactionRollback() - { - var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv)); - await connection.OpenAsync(); - var transaction = connection.BeginTransaction(); - var sqlQueryWithTx = QuerySql.WithTransaction(transaction); - await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - await transaction.RollbackAsync(); - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actual == null, "author should not exist after rollback"); - } - [Test] [TestCase(100, true, 3, 453, -1445214231L)] [TestCase(10, null, null, null, null)] public async Task TestIntegerCopyFrom(int batchSize, bool? cBoolean, short? cSmallint, int? cInteger, long? cBigint) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresNumericTypesBatchArgs { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }).ToList(); + await QuerySql.InsertPostgresNumericTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresNumericTypesCntRow { Cnt = batchSize, CBoolean = cBoolean, @@ -559,9 +790,9 @@ public async Task TestIntegerCopyFrom(int batchSize, bool? cBoolean, short? cSma CInteger = cInteger, CBigint = cBigint }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresNumericTypesCnt(); AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresNumericTypesCntRow x, QuerySql.GetPostgresNumericTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CBoolean, Is.EqualTo(y.CBoolean)); @@ -576,9 +807,9 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgre [TestCase(10, null, null, null, null, null)] public async Task TestFloatingPointCopyFrom(int batchSize, float? cReal, decimal? cDecimal, decimal? cNumeric, double? cDoublePrecision, decimal? cMoney) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CReal = cReal, CDecimal = cDecimal, CNumeric = cNumeric, CDoublePrecision = cDoublePrecision, CMoney = cMoney }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresNumericTypesBatchArgs { CReal = cReal, CDecimal = cDecimal, CNumeric = cNumeric, CDoublePrecision = cDoublePrecision, CMoney = cMoney }).ToList(); + await QuerySql.InsertPostgresNumericTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresNumericTypesCntRow { Cnt = batchSize, CReal = cReal, @@ -587,9 +818,9 @@ public async Task TestFloatingPointCopyFrom(int batchSize, float? cReal, decimal CDoublePrecision = cDoublePrecision, CMoney = cMoney }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresNumericTypesCnt(); AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresNumericTypesCntRow x, QuerySql.GetPostgresNumericTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CReal, Is.EqualTo(y.CReal)); @@ -608,9 +839,9 @@ public async Task TestDateTimeCopyFrom(int batchSize, DateTime? cDate, TimeSpan? DateTime? cTimestampWithTzAsUtc = null; if (cTimestampWithTz != null) cTimestampWithTzAsUtc = DateTime.SpecifyKind(cTimestampWithTz.Value, DateTimeKind.Utc); - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CDate = cDate, CTime = cTime, CTimestamp = cTimestamp, CTimestampWithTz = cTimestampWithTzAsUtc, CInterval = cInterval }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresDateTimeTypesBatchArgs { CDate = cDate, CTime = cTime, CTimestamp = cTimestamp, CTimestampWithTz = cTimestampWithTzAsUtc, CInterval = cInterval }).ToList(); + await QuerySql.InsertPostgresDateTimeTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresDateTimeTypesCntRow { Cnt = batchSize, CDate = cDate, @@ -619,9 +850,9 @@ public async Task TestDateTimeCopyFrom(int batchSize, DateTime? cDate, TimeSpan? CTimestampWithTz = cTimestampWithTz, CInterval = cInterval }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresDateTimeTypesCnt(); AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresDateTimeTypesCntRow x, QuerySql.GetPostgresDateTimeTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CDate, Is.EqualTo(y.CDate)); @@ -645,16 +876,16 @@ private static IEnumerable PostgresGuidCopyFromTestCases [TestCaseSource(nameof(PostgresGuidCopyFromTestCases))] public async Task TestPostgresGuidCopyFrom(int batchSize, Guid? cUuid) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CUuid = cUuid }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresSpecialTypesBatchArgs { CUuid = cUuid }).ToList(); + await QuerySql.InsertPostgresSpecialTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresSpecialTypesCntRow { Cnt = batchSize, CUuid = cUuid }; - var actual = await QuerySql.GetPostgresTypesCnt(); - Assert.That(actual.Value.Cnt, Is.EqualTo(expected.Cnt)); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + var actual = await QuerySql.GetPostgresSpecialTypesCnt(); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesCntRow x, QuerySql.GetPostgresSpecialTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CUuid, Is.EqualTo(y.CUuid)); @@ -674,18 +905,18 @@ private static IEnumerable PostgresNetworkCopyFromTestCases [TestCaseSource(nameof(PostgresNetworkCopyFromTestCases))] public async Task TestPostgresNetworkCopyFrom(int batchSize, NpgsqlCidr? cCidr, IPAddress cInet, PhysicalAddress cMacaddr) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresNetworkTypesBatchArgs { CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr }).ToList(); + await QuerySql.InsertPostgresNetworkTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresNetworkTypesCntRow { Cnt = batchSize, CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresNetworkTypesCnt(); AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresNetworkTypesCntRow x, QuerySql.GetPostgresNetworkTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CCidr, Is.EqualTo(y.CCidr)); @@ -694,62 +925,43 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgre } } - [Test] - [TestCase(100, new byte[] { 0x53, 0x56 })] - [TestCase(10, new byte[] { })] - [TestCase(10, null)] - public async Task TestArrayCopyFrom(int batchSize, byte[] cBytea) - { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresArrayTypesBatchArgs { CBytea = cBytea }).ToList(); - await QuerySql.InsertPostgresArrayTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresArrayTypesCntRow - { - Cnt = batchSize, - CBytea = cBytea - }; - var actual = await QuerySql.GetPostgresArrayTypesCnt(); - AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetPostgresArrayTypesCntRow x, QuerySql.GetPostgresArrayTypesCntRow y) - { - Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); - } - } - - private static IEnumerable PostgresGeoTypesTestCases + private static IEnumerable PostgresArrayCopyFromTestCases { get { - yield return new TestCaseData(new NpgsqlPoint(1, 2), new NpgsqlLine(3, 4, 5), new NpgsqlLSeg(1, 2, 3, 4), new NpgsqlBox(1, 2, 3, 4), new NpgsqlPath(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlPolygon(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlCircle(1, 2, 3)).SetName("Valid Geo Types"); - yield return new TestCaseData(null, null, null, null, null, null, null).SetName("Null Geo Types"); + yield return new TestCaseData(100, new byte[] { 0x53, 0x56 }, new bool[] { true, false }, new string[] { "Sister Ray", "Venus in Furs" }, new int[] { 1, 2 }, new decimal[] { 132.13m, 23.22m }, new DateTime[] { new DateTime(1984, 8, 26), new DateTime(2000, 1, 2) }).SetName("Valid Array Copy From"); + yield return new TestCaseData(10, new byte[] { }, new bool[] { }, new string[] { }, new int[] { }, new decimal[] { }, new DateTime[] { }).SetName("Empty Array Copy From"); + yield return new TestCaseData(10, null, null, null, null, null, null).SetName("Null Array Copy From"); } } [Test] - [TestCaseSource(nameof(PostgresGeoTypesTestCases))] - public async Task TestPostgresGeoTypes(NpgsqlPoint? cPoint, NpgsqlLine? cLine, NpgsqlLSeg? cLSeg, NpgsqlBox? cBox, NpgsqlPath? cPath, NpgsqlPolygon? cPolygon, NpgsqlCircle? cCircle) + [TestCaseSource(nameof(PostgresArrayCopyFromTestCases))] + public async Task TestArrayCopyFrom(int batchSize, byte[] cBytea, bool[] cBooleanArray, string[] cTextArray, int[] cIntegerArray, decimal[] cDecimalArray, DateTime[] cTimestampArray) { - await QuerySql.InsertPostgresGeoTypes(new QuerySql.InsertPostgresGeoTypesArgs { CPoint = cPoint, CLine = cLine, CLseg = cLSeg, CBox = cBox, CPath = cPath, CPolygon = cPolygon, CCircle = cCircle }); - var expected = new QuerySql.GetPostgresGeoTypesRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresArrayTypesBatchArgs { CBytea = cBytea, CBooleanArray = cBooleanArray, CTextArray = cTextArray, CIntegerArray = cIntegerArray, CDecimalArray = cDecimalArray, CTimestampArray = cTimestampArray }).ToList(); + await QuerySql.InsertPostgresArrayTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresArrayTypesCntRow { - CPoint = cPoint, - CLine = cLine, - CLseg = cLSeg, - CBox = cBox, - CPath = cPath, - CPolygon = cPolygon, - CCircle = cCircle + Cnt = batchSize, + CBytea = cBytea, + CBooleanArray = cBooleanArray, + CTextArray = cTextArray, + CIntegerArray = cIntegerArray, + CDecimalArray = cDecimalArray, + CTimestampArray = cTimestampArray }; - var actual = await QuerySql.GetPostgresGeoTypes(); + var actual = await QuerySql.GetPostgresArrayTypesCnt(); AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetPostgresGeoTypesRow x, QuerySql.GetPostgresGeoTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresArrayTypesCntRow x, QuerySql.GetPostgresArrayTypesCntRow y) { - Assert.That(x.CPoint, Is.EqualTo(y.CPoint)); - Assert.That(x.CLine, Is.EqualTo(y.CLine)); - Assert.That(x.CLseg, Is.EqualTo(y.CLseg)); - Assert.That(x.CBox, Is.EqualTo(y.CBox)); - Assert.That(x.CPath, Is.EqualTo(y.CPath)); - Assert.That(x.CPolygon, Is.EqualTo(y.CPolygon)); - Assert.That(x.CCircle, Is.EqualTo(y.CCircle)); + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CBytea, Is.EqualTo(y.CBytea)); + Assert.That(x.CBooleanArray, Is.EqualTo(y.CBooleanArray)); + Assert.That(x.CTextArray, Is.EqualTo(y.CTextArray)); + Assert.That(x.CIntegerArray, Is.EqualTo(y.CIntegerArray)); + Assert.That(x.CDecimalArray, Is.EqualTo(y.CDecimalArray)); + Assert.That(x.CTimestampArray, Is.EqualTo(y.CTimestampArray)); } } @@ -791,121 +1003,5 @@ void AssertSingularEquals(QuerySql.GetPostgresGeoTypesRow x, QuerySql.GetPostgre Assert.That(x.CCircle, Is.EqualTo(y.CCircle)); } } - - private static IEnumerable PostgresNetworkDataTypesTestCases - { - get - { - yield return new TestCaseData(new NpgsqlCidr("192.168.1.0/24"), new IPAddress(new byte[] { 192, 168, 1, 1 }), new PhysicalAddress(new byte[] { 0x00, 0x1A, 0x2B, 0x3C, 0x4D, 0x5E }), "00:1a:2b:ff:fe:3c:4d:5e").SetName("Valid Network Data Types"); - yield return new TestCaseData(null, null, null, null).SetName("Null Network Data Types"); - } - } - - [Test] - [TestCaseSource(nameof(PostgresNetworkDataTypesTestCases))] - public async Task TestPostgresNetworkDataTypes(NpgsqlCidr? cCidr, IPAddress cInet, PhysicalAddress cMacaddr, string cMacaddr8) - { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr, CMacaddr8 = cMacaddr8 }); - var expected = new QuerySql.GetPostgresTypesRow - { - CCidr = cCidr, - CInet = cInet, - CMacaddr = cMacaddr, - CMacaddr8 = cMacaddr8 - }; - var actual = await QuerySql.GetPostgresTypes(); - AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) - { - Assert.That(x.CCidr, Is.EqualTo(y.CCidr)); - Assert.That(x.CInet, Is.EqualTo(y.CInet)); - Assert.That(x.CMacaddr, Is.EqualTo(y.CMacaddr)); - Assert.That(x.CMacaddr8, Is.EqualTo(y.CMacaddr8)); - } - } - - [Test] - [TestCase("{\"name\": \"Swordfishtrombones\", \"year\": 1983}", "$.\"name\"")] - [TestCase(null, null)] - public async Task TestPostgresJsonDataTypes(string cJson, string cJsonpath) - { - JsonElement? cParsedJson = null; - if (cJson != null) - cParsedJson = JsonDocument.Parse(cJson).RootElement; - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CJson = cParsedJson, CJsonb = cParsedJson, CJsonStringOverride = cJson, CJsonpath = cJsonpath }); - var expected = new QuerySql.GetPostgresTypesRow - { - CJson = cParsedJson, - CJsonb = cParsedJson, - CJsonStringOverride = cJson, - CJsonpath = cJsonpath - }; - var actual = await QuerySql.GetPostgresTypes(); - AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) - { - Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); - if (x.CJson.HasValue) - Assert.That(x.CJson.Value.GetRawText(), Is.EqualTo(y.CJson.Value.GetRawText())); - Assert.That(x.CJsonb.HasValue, Is.EqualTo(y.CJsonb.HasValue)); - if (x.CJsonb.HasValue) - Assert.That(x.CJsonb.Value.GetRawText(), Is.EqualTo(y.CJsonb.Value.GetRawText())); - Assert.That(x.CJsonStringOverride, Is.EqualTo(y.CJsonStringOverride)); - Assert.That(x.CJsonpath, Is.EqualTo(y.CJsonpath)); - } - } - - [Test] - public void TestPostgresInvalidJson() - { - Assert.ThrowsAsync(async () => await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CJsonStringOverride = "SOME INVALID JSON" })); - Assert.ThrowsAsync(async () => await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CJsonpath = "SOME INVALID JSONPATH" })); - } - - [Test] - [TestCase("Good morning xml, the world says hello")] - [TestCase(null)] - public async Task TestPostgresXmlDataTypes(string cXml) - { - XmlDocument parsedXml = null; - if (cXml != null) - { - parsedXml = new XmlDocument(); - parsedXml.LoadXml(cXml); - } - - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CXml = parsedXml }); - var expected = new QuerySql.GetPostgresTypesRow - { - CXml = parsedXml - }; - var actual = await QuerySql.GetPostgresTypes(); - AssertSingularEquals(expected, actual.Value); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) - { - if (x.CXml == null && y.CXml == null) - return; - Assert.That(x.CXml.OuterXml, Is.EqualTo(y.CXml.OuterXml)); - } - } - - [Test] - public async Task TestArray() - { - var id1 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Quote that everyone always attribute to Einstein" }); - var bojackId = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - var actual = await QuerySql.GetAuthorsByIds(new QuerySql.GetAuthorsByIdsArgs { LongArr1 = new[] { id1, bojackId } }); - ClassicAssert.AreEqual(2, actual.Count); - } - - [Test] - public async Task TestMultipleArrays() - { - var id1 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Quote that everyone always attribute to Einstein" }); - var id2 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Only 2 things are infinite, the universe and human stupidity" }); - var bojackId = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - var actual = await QuerySql.GetAuthorsByIdsAndNames(new QuerySql.GetAuthorsByIdsAndNamesArgs { LongArr1 = new[] { id1, bojackId }, StringArr2 = new[] { "Albert Einstein" } }); - ClassicAssert.AreEqual(1, actual.Count); - } } } diff --git a/end2end/EndToEndTests/SqliteDapperTester.generated.cs b/end2end/EndToEndTests/SqliteDapperTester.generated.cs index fd786025..a42aa61b 100644 --- a/end2end/EndToEndTests/SqliteDapperTester.generated.cs +++ b/end2end/EndToEndTests/SqliteDapperTester.generated.cs @@ -23,12 +23,13 @@ public async Task TestOne() Bio = "Back in the 90s he was in a very famous TV show" }; var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -53,21 +54,18 @@ public async Task TestMany() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) - { - Assert.That(x.Id, Is.EqualTo(y.Id)); - Assert.That(x.Name, Is.EqualTo(y.Name)); - Assert.That(x.Bio, Is.EqualTo(y.Bio)); - } + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } - private static void AssertSequenceEquals(List x, List y) - { - Assert.That(x.Count, Is.EqualTo(y.Count)); - for (int i = 0; i < x.Count; i++) + void AssertSequenceEquals(List x, List y) { - AssertSingularEquals(x[i], y[i]); + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); } } @@ -105,6 +103,19 @@ public async Task TestExecRows() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -118,12 +129,13 @@ public async Task TestExecLastId() Bio = "Quote that everyone always attribute to Einstein" }; var actual = await QuerySql.GetAuthorById(new QuerySql.GetAuthorByIdArgs { Id = id1 }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -150,19 +162,23 @@ public async Task TestSelfJoinEmbed() } }; var actual = await QuerySql.GetDuplicateAuthors(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) - { - return SingularEquals(x.Author, y.Author) && SingularEquals(x.Author2, y.Author2); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) + { + Assert.That(x.Author.Id, Is.EqualTo(y.Author.Id)); + Assert.That(x.Author.Name, Is.EqualTo(y.Author.Name)); + Assert.That(x.Author.Bio, Is.EqualTo(y.Author.Bio)); + Assert.That(x.Author2.Id, Is.EqualTo(y.Author2.Id)); + Assert.That(x.Author2.Name, Is.EqualTo(y.Author2.Name)); + Assert.That(x.Author2.Bio, Is.EqualTo(y.Author2.Bio)); + } - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -206,31 +222,23 @@ public async Task TestJoinEmbed() } }; var actual = await QuerySql.ListAllAuthorsBooks(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) - { - return SingularEquals(x.Author, y.Author) && SingularEquals(x.Book, y.Book); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Author.Name + o.Book.Name).ToList(); - y = y.OrderBy(o => o.Author.Name + o.Book.Name).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } - - private static bool SingularEquals(Author x, Author y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) + { + Assert.That(x.Author.Id, Is.EqualTo(y.Author.Id)); + Assert.That(x.Author.Name, Is.EqualTo(y.Author.Name)); + Assert.That(x.Author.Bio, Is.EqualTo(y.Author.Bio)); + Assert.That(x.Book.Id, Is.EqualTo(y.Book.Id)); + Assert.That(x.Book.AuthorId, Is.EqualTo(y.Book.AuthorId)); + Assert.That(x.Book.Name, Is.EqualTo(y.Book.Name)); + } - private static bool SingularEquals(Book x, Book y) - { - return x.Id.Equals(y.Id) && x.AuthorId.Equals(y.AuthorId) && x.Name.Equals(y.Name); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -272,21 +280,20 @@ public async Task TestNargNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs()); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Id).ToList(); - y = y.OrderBy(o => o.Id).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } - private static bool SingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -304,7 +311,20 @@ public async Task TestNargNotNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs { NamePattern = "Bojack%" }); - Assert.That(SequenceEquals(expected, actual)); + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } + + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -323,14 +343,13 @@ public async Task TestSqliteTypes(int? cInteger, decimal? cReal, string cText, b }; var actual = await QuerySql.GetSqliteTypes(); AssertSingularEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.GetSqliteTypesRow expected, QuerySql.GetSqliteTypesRow actual) - { - Assert.That(actual.CInteger, Is.EqualTo(expected.CInteger)); - Assert.That(actual.CReal, Is.EqualTo(expected.CReal)); - Assert.That(actual.CText, Is.EqualTo(expected.CText)); - Assert.That(actual.CBlob, Is.EqualTo(expected.CBlob)); + void AssertSingularEquals(QuerySql.GetSqliteTypesRow x, QuerySql.GetSqliteTypesRow y) + { + Assert.That(x.CInteger, Is.EqualTo(y.CInteger)); + Assert.That(x.CReal, Is.EqualTo(y.CReal)); + Assert.That(x.CText, Is.EqualTo(y.CText)); + Assert.That(x.CBlob, Is.EqualTo(y.CBlob)); + } } [Test] @@ -344,12 +363,13 @@ public async Task TestGetAuthorByIdWithMultipleNamedParam() Bio = "Back in the 90s he was in a very famous TV show" }; var actual = await this.QuerySql.GetAuthorByIdWithMultipleNamedParam(new QuerySql.GetAuthorByIdWithMultipleNamedParamArgs { IdArg = 1111, Take = 1 }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorByIdWithMultipleNamedParamRow x, QuerySql.GetAuthorByIdWithMultipleNamedParamRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorByIdWithMultipleNamedParamRow x, QuerySql.GetAuthorByIdWithMultipleNamedParamRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -366,13 +386,12 @@ public async Task TestSqliteDataTypesOverride(int? cInteger, decimal cReal, stri }; var actual = await QuerySql.GetSqliteFunctions(); AssertSingularEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.GetSqliteFunctionsRow expected, QuerySql.GetSqliteFunctionsRow actual) - { - Assert.That(actual.MaxInteger, Is.EqualTo(expected.MaxInteger)); - Assert.That(actual.MaxReal, Is.EqualTo(expected.MaxReal)); - Assert.That(actual.MaxText, Is.EqualTo(expected.MaxText)); + void AssertSingularEquals(QuerySql.GetSqliteFunctionsRow x, QuerySql.GetSqliteFunctionsRow y) + { + Assert.That(x.MaxInteger, Is.EqualTo(y.MaxInteger)); + Assert.That(x.MaxReal, Is.EqualTo(y.MaxReal)); + Assert.That(x.MaxText, Is.EqualTo(y.MaxText)); + } } [Test] @@ -392,14 +411,13 @@ public async Task TestCopyFrom(int batchSize, int? cInteger, decimal? cReal, str }; var actual = await QuerySql.GetSqliteTypesCnt(); AssertSingularEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.GetSqliteTypesCntRow expected, QuerySql.GetSqliteTypesCntRow actual) - { - Assert.That(actual.Cnt, Is.EqualTo(expected.Cnt)); - Assert.That(actual.CInteger, Is.EqualTo(expected.CInteger)); - Assert.That(actual.CReal, Is.EqualTo(expected.CReal)); - Assert.That(actual.CText, Is.EqualTo(expected.CText)); + void AssertSingularEquals(QuerySql.GetSqliteTypesCntRow x, QuerySql.GetSqliteTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CInteger, Is.EqualTo(y.CInteger)); + Assert.That(x.CReal, Is.EqualTo(y.CReal)); + Assert.That(x.CText, Is.EqualTo(y.CText)); + } } [Test] @@ -410,9 +428,8 @@ public async Task TestSqliteTransaction() var transaction = connection.BeginTransaction(); var querySqlWithTx = QuerySql.WithTransaction(transaction); await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - // The GetAuthor method in SqliteExampleGen returns QuerySql.GetAuthorRow? (nullable record struct/class) - var actualNull = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actualNull == null, "there is author"); // This is correct for nullable types + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + ClassicAssert.IsNull(actual); transaction.Commit(); var expected = new QuerySql.GetAuthorRow { @@ -420,8 +437,14 @@ public async Task TestSqliteTransaction() Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }; - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual)); // Apply placeholder here + actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -434,7 +457,7 @@ public async Task TestSqliteTransactionRollback() await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); transaction.Rollback(); var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actual == null, "author should not exist after rollback"); + ClassicAssert.IsNull(actual); } } } diff --git a/end2end/EndToEndTests/SqliteTester.generated.cs b/end2end/EndToEndTests/SqliteTester.generated.cs index cd1fc078..61f62be7 100644 --- a/end2end/EndToEndTests/SqliteTester.generated.cs +++ b/end2end/EndToEndTests/SqliteTester.generated.cs @@ -23,12 +23,13 @@ public async Task TestOne() Bio = "Back in the 90s he was in a very famous TV show" }; var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual.Value)); - } - - private static bool SingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -53,21 +54,18 @@ public async Task TestMany() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) - { - Assert.That(x.Id, Is.EqualTo(y.Id)); - Assert.That(x.Name, Is.EqualTo(y.Name)); - Assert.That(x.Bio, Is.EqualTo(y.Bio)); - } + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } - private static void AssertSequenceEquals(List x, List y) - { - Assert.That(x.Count, Is.EqualTo(y.Count)); - for (int i = 0; i < x.Count; i++) + void AssertSequenceEquals(List x, List y) { - AssertSingularEquals(x[i], y[i]); + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); } } @@ -105,6 +103,19 @@ public async Task TestExecRows() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -118,12 +129,13 @@ public async Task TestExecLastId() Bio = "Quote that everyone always attribute to Einstein" }; var actual = await QuerySql.GetAuthorById(new QuerySql.GetAuthorByIdArgs { Id = id1 }); - Assert.That(SingularEquals(expected, actual.Value)); - } - - private static bool SingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -150,19 +162,23 @@ public async Task TestSelfJoinEmbed() } }; var actual = await QuerySql.GetDuplicateAuthors(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) - { - return SingularEquals(x.Author.Value, y.Author.Value) && SingularEquals(x.Author2.Value, y.Author2.Value); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) + { + Assert.That(x.Author.Value.Id, Is.EqualTo(y.Author.Value.Id)); + Assert.That(x.Author.Value.Name, Is.EqualTo(y.Author.Value.Name)); + Assert.That(x.Author.Value.Bio, Is.EqualTo(y.Author.Value.Bio)); + Assert.That(x.Author2.Value.Id, Is.EqualTo(y.Author2.Value.Id)); + Assert.That(x.Author2.Value.Name, Is.EqualTo(y.Author2.Value.Name)); + Assert.That(x.Author2.Value.Bio, Is.EqualTo(y.Author2.Value.Bio)); + } - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -206,31 +222,23 @@ public async Task TestJoinEmbed() } }; var actual = await QuerySql.ListAllAuthorsBooks(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) - { - return SingularEquals(x.Author.Value, y.Author.Value) && SingularEquals(x.Book.Value, y.Book.Value); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Author.Value.Name + o.Book.Value.Name).ToList(); - y = y.OrderBy(o => o.Author.Value.Name + o.Book.Value.Name).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } - - private static bool SingularEquals(Author x, Author y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) + { + Assert.That(x.Author.Value.Id, Is.EqualTo(y.Author.Value.Id)); + Assert.That(x.Author.Value.Name, Is.EqualTo(y.Author.Value.Name)); + Assert.That(x.Author.Value.Bio, Is.EqualTo(y.Author.Value.Bio)); + Assert.That(x.Book.Value.Id, Is.EqualTo(y.Book.Value.Id)); + Assert.That(x.Book.Value.AuthorId, Is.EqualTo(y.Book.Value.AuthorId)); + Assert.That(x.Book.Value.Name, Is.EqualTo(y.Book.Value.Name)); + } - private static bool SingularEquals(Book x, Book y) - { - return x.Id.Equals(y.Id) && x.AuthorId.Equals(y.AuthorId) && x.Name.Equals(y.Name); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -272,21 +280,20 @@ public async Task TestNargNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs()); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Id).ToList(); - y = y.OrderBy(o => o.Id).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } - private static bool SingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -304,7 +311,20 @@ public async Task TestNargNotNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs { NamePattern = "Bojack%" }); - Assert.That(SequenceEquals(expected, actual)); + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } + + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -323,14 +343,13 @@ public async Task TestSqliteTypes(int? cInteger, decimal? cReal, string cText, b }; var actual = await QuerySql.GetSqliteTypes(); AssertSingularEquals(expected, actual.Value); - } - - private static void AssertSingularEquals(QuerySql.GetSqliteTypesRow expected, QuerySql.GetSqliteTypesRow actual) - { - Assert.That(actual.CInteger, Is.EqualTo(expected.CInteger)); - Assert.That(actual.CReal, Is.EqualTo(expected.CReal)); - Assert.That(actual.CText, Is.EqualTo(expected.CText)); - Assert.That(actual.CBlob, Is.EqualTo(expected.CBlob)); + void AssertSingularEquals(QuerySql.GetSqliteTypesRow x, QuerySql.GetSqliteTypesRow y) + { + Assert.That(x.CInteger, Is.EqualTo(y.CInteger)); + Assert.That(x.CReal, Is.EqualTo(y.CReal)); + Assert.That(x.CText, Is.EqualTo(y.CText)); + Assert.That(x.CBlob, Is.EqualTo(y.CBlob)); + } } [Test] @@ -344,12 +363,13 @@ public async Task TestGetAuthorByIdWithMultipleNamedParam() Bio = "Back in the 90s he was in a very famous TV show" }; var actual = await this.QuerySql.GetAuthorByIdWithMultipleNamedParam(new QuerySql.GetAuthorByIdWithMultipleNamedParamArgs { IdArg = 1111, Take = 1 }); - Assert.That(SingularEquals(expected, actual.Value)); - } - - private static bool SingularEquals(QuerySql.GetAuthorByIdWithMultipleNamedParamRow x, QuerySql.GetAuthorByIdWithMultipleNamedParamRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetAuthorByIdWithMultipleNamedParamRow x, QuerySql.GetAuthorByIdWithMultipleNamedParamRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -366,13 +386,12 @@ public async Task TestSqliteDataTypesOverride(int? cInteger, decimal cReal, stri }; var actual = await QuerySql.GetSqliteFunctions(); AssertSingularEquals(expected, actual.Value); - } - - private static void AssertSingularEquals(QuerySql.GetSqliteFunctionsRow expected, QuerySql.GetSqliteFunctionsRow actual) - { - Assert.That(actual.MaxInteger, Is.EqualTo(expected.MaxInteger)); - Assert.That(actual.MaxReal, Is.EqualTo(expected.MaxReal)); - Assert.That(actual.MaxText, Is.EqualTo(expected.MaxText)); + void AssertSingularEquals(QuerySql.GetSqliteFunctionsRow x, QuerySql.GetSqliteFunctionsRow y) + { + Assert.That(x.MaxInteger, Is.EqualTo(y.MaxInteger)); + Assert.That(x.MaxReal, Is.EqualTo(y.MaxReal)); + Assert.That(x.MaxText, Is.EqualTo(y.MaxText)); + } } [Test] @@ -392,14 +411,13 @@ public async Task TestCopyFrom(int batchSize, int? cInteger, decimal? cReal, str }; var actual = await QuerySql.GetSqliteTypesCnt(); AssertSingularEquals(expected, actual.Value); - } - - private static void AssertSingularEquals(QuerySql.GetSqliteTypesCntRow expected, QuerySql.GetSqliteTypesCntRow actual) - { - Assert.That(actual.Cnt, Is.EqualTo(expected.Cnt)); - Assert.That(actual.CInteger, Is.EqualTo(expected.CInteger)); - Assert.That(actual.CReal, Is.EqualTo(expected.CReal)); - Assert.That(actual.CText, Is.EqualTo(expected.CText)); + void AssertSingularEquals(QuerySql.GetSqliteTypesCntRow x, QuerySql.GetSqliteTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CInteger, Is.EqualTo(y.CInteger)); + Assert.That(x.CReal, Is.EqualTo(y.CReal)); + Assert.That(x.CText, Is.EqualTo(y.CText)); + } } [Test] @@ -410,9 +428,8 @@ public async Task TestSqliteTransaction() var transaction = connection.BeginTransaction(); var querySqlWithTx = QuerySql.WithTransaction(transaction); await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - // The GetAuthor method in SqliteExampleGen returns QuerySql.GetAuthorRow? (nullable record struct/class) - var actualNull = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actualNull == null, "there is author"); // This is correct for nullable types + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + ClassicAssert.IsNull(actual); transaction.Commit(); var expected = new QuerySql.GetAuthorRow { @@ -420,8 +437,14 @@ public async Task TestSqliteTransaction() Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }; - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual.Value)); // Apply placeholder here + actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + AssertSingularEquals(expected, actual.Value); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -434,7 +457,7 @@ public async Task TestSqliteTransactionRollback() await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); transaction.Rollback(); var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actual == null, "author should not exist after rollback"); + ClassicAssert.IsNull(actual); } } } diff --git a/end2end/EndToEndTestsLegacy/EndToEndTestsLegacy.csproj b/end2end/EndToEndTestsLegacy/EndToEndTestsLegacy.csproj index c8c384b9..c20bbe10 100644 --- a/end2end/EndToEndTestsLegacy/EndToEndTestsLegacy.csproj +++ b/end2end/EndToEndTestsLegacy/EndToEndTestsLegacy.csproj @@ -9,9 +9,13 @@ Always - + Always - sqlite.schema.sql + authors.sqlite.schema.sql + + + Always + types.sqlite.schema.sql diff --git a/end2end/EndToEndTestsLegacy/MySqlConnectorDapperTester.cs b/end2end/EndToEndTestsLegacy/MySqlConnectorDapperTester.cs index 7a369ce6..4df7d463 100644 --- a/end2end/EndToEndTestsLegacy/MySqlConnectorDapperTester.cs +++ b/end2end/EndToEndTestsLegacy/MySqlConnectorDapperTester.cs @@ -14,8 +14,11 @@ public partial class MySqlConnectorDapperTester public async Task EmptyTestsTable() { await QuerySql.DeleteAllAuthors(); - await QuerySql.TruncateMysqlTypes(); await QuerySql.TruncateExtendedBios(); + await QuerySql.TruncateMysqlNumericTypes(); + await QuerySql.TruncateMysqlStringTypes(); + await QuerySql.TruncateMysqlDatetimeTypes(); + await QuerySql.TruncateMysqlBinaryTypes(); } } } \ No newline at end of file diff --git a/end2end/EndToEndTestsLegacy/MySqlConnectorDapperTester.generated.cs b/end2end/EndToEndTestsLegacy/MySqlConnectorDapperTester.generated.cs index 02515ada..b0ad64cd 100644 --- a/end2end/EndToEndTestsLegacy/MySqlConnectorDapperTester.generated.cs +++ b/end2end/EndToEndTestsLegacy/MySqlConnectorDapperTester.generated.cs @@ -24,12 +24,13 @@ public async Task TestOne() Bio = "Back in the 90s he was in a very famous TV show" }; var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -54,21 +55,18 @@ public async Task TestMany() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) - { - Assert.That(x.Id, Is.EqualTo(y.Id)); - Assert.That(x.Name, Is.EqualTo(y.Name)); - Assert.That(x.Bio, Is.EqualTo(y.Bio)); - } + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } - private static void AssertSequenceEquals(List x, List y) - { - Assert.That(x.Count, Is.EqualTo(y.Count)); - for (int i = 0; i < x.Count; i++) + void AssertSequenceEquals(List x, List y) { - AssertSingularEquals(x[i], y[i]); + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); } } @@ -106,6 +104,19 @@ public async Task TestExecRows() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -119,12 +130,13 @@ public async Task TestExecLastId() Bio = "Quote that everyone always attribute to Einstein" }; var actual = await QuerySql.GetAuthorById(new QuerySql.GetAuthorByIdArgs { Id = id1 }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -151,19 +163,23 @@ public async Task TestSelfJoinEmbed() } }; var actual = await QuerySql.GetDuplicateAuthors(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) - { - return SingularEquals(x.Author, y.Author) && SingularEquals(x.Author2, y.Author2); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) + { + Assert.That(x.Author.Id, Is.EqualTo(y.Author.Id)); + Assert.That(x.Author.Name, Is.EqualTo(y.Author.Name)); + Assert.That(x.Author.Bio, Is.EqualTo(y.Author.Bio)); + Assert.That(x.Author2.Id, Is.EqualTo(y.Author2.Id)); + Assert.That(x.Author2.Name, Is.EqualTo(y.Author2.Name)); + Assert.That(x.Author2.Bio, Is.EqualTo(y.Author2.Bio)); + } - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -207,31 +223,23 @@ public async Task TestJoinEmbed() } }; var actual = await QuerySql.ListAllAuthorsBooks(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) - { - return SingularEquals(x.Author, y.Author) && SingularEquals(x.Book, y.Book); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Author.Name + o.Book.Name).ToList(); - y = y.OrderBy(o => o.Author.Name + o.Book.Name).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } - - private static bool SingularEquals(Author x, Author y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) + { + Assert.That(x.Author.Id, Is.EqualTo(y.Author.Id)); + Assert.That(x.Author.Name, Is.EqualTo(y.Author.Name)); + Assert.That(x.Author.Bio, Is.EqualTo(y.Author.Bio)); + Assert.That(x.Book.Id, Is.EqualTo(y.Book.Id)); + Assert.That(x.Book.AuthorId, Is.EqualTo(y.Book.AuthorId)); + Assert.That(x.Book.Name, Is.EqualTo(y.Book.Name)); + } - private static bool SingularEquals(Book x, Book y) - { - return x.Id.Equals(y.Id) && x.AuthorId.Equals(y.AuthorId) && x.Name.Equals(y.Name); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -273,21 +281,20 @@ public async Task TestNargNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs()); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Id).ToList(); - y = y.OrderBy(o => o.Id).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } - private static bool SingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -305,7 +312,116 @@ public async Task TestNargNotNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs { NamePattern = "Bojack%" }); - Assert.That(SequenceEquals(expected, actual)); + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } + + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + } + + [Test] + public async Task TestMySqlTransaction() + { + var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)); + await connection.OpenAsync(); + var transaction = connection.BeginTransaction(); + var querySqlWithTx = QuerySql.WithTransaction(transaction); + await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + ClassicAssert.IsNull(actual); + await transaction.CommitAsync(); + var expected = new QuerySql.GetAuthorRow + { + Id = 1111, + Name = "Bojack Horseman", + Bio = "Back in the 90s he was in a very famous TV show" + }; + actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + } + + [Test] + public async Task TestMySqlTransactionRollback() + { + var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)); + await connection.OpenAsync(); + var transaction = connection.BeginTransaction(); + var querySqlWithTx = QuerySql.WithTransaction(transaction); + await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + await transaction.RollbackAsync(); + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + ClassicAssert.IsNull(actual); + } + + [Test] + [TestCase(-54355, "Scream of the Butterfly", "2025-06-29 12:00:00")] + [TestCase(null, null, "1971-01-01 00:00:00")] + public async Task TestMySqlDataTypesOverride(int? cInt, string cVarchar, DateTime cTimestamp) + { + await QuerySql.InsertMysqlNumericTypes(new QuerySql.InsertMysqlNumericTypesArgs { CInt = cInt }); + await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CVarchar = cVarchar }); + await QuerySql.InsertMysqlDatetimeTypes(new QuerySql.InsertMysqlDatetimeTypesArgs { CTimestamp = cTimestamp }); + var expected = new QuerySql.GetMysqlFunctionsRow + { + MaxInt = cInt, + MaxVarchar = cVarchar, + MaxTimestamp = cTimestamp + }; + var actual = await QuerySql.GetMysqlFunctions(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlFunctionsRow x, QuerySql.GetMysqlFunctionsRow y) + { + Assert.That(x.MaxInt, Is.EqualTo(y.MaxInt)); + Assert.That(x.MaxVarchar, Is.EqualTo(y.MaxVarchar)); + Assert.That(x.MaxTimestamp, Is.EqualTo(y.MaxTimestamp)); + } + } + + [Test] + public async Task TestMySqlScopedSchemaEnum() + { + await this.QuerySql.CreateExtendedBio(new QuerySql.CreateExtendedBioArgs { AuthorName = "Bojack Horseman", Name = "One Trick Pony", BioType = BiosBioType.Memoir, AuthorType = new HashSet { BiosAuthorType.Author, BiosAuthorType.Translator } }); + var expected = new QuerySql.GetFirstExtendedBioByTypeRow + { + AuthorName = "Bojack Horseman", + Name = "One Trick Pony", + BioType = BiosBioType.Memoir, + AuthorType = new HashSet + { + BiosAuthorType.Author, + BiosAuthorType.Translator + } + }; + var actual = await this.QuerySql.GetFirstExtendedBioByType(new QuerySql.GetFirstExtendedBioByTypeArgs { BioType = BiosBioType.Memoir }); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetFirstExtendedBioByTypeRow x, QuerySql.GetFirstExtendedBioByTypeRow y) + { + Assert.That(x.AuthorName, Is.EqualTo(y.AuthorName)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.BioType, Is.EqualTo(y.BioType)); + Assert.That(x.AuthorType, Is.EqualTo(y.AuthorType)); + } + } + + [Test] + public void TestMySqlInvalidJson() + { + Assert.ThrowsAsync(async () => await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CJsonStringOverride = "SOME INVALID JSON" })); } [Test] @@ -313,8 +429,8 @@ public async Task TestNargNotNull() [TestCase(null, null, null, null, null, null, null, null)] public async Task TestMySqlStringTypes(string cChar, string cNchar, string cNationalChar, string cVarchar, string cTinytext, string cMediumtext, string cText, string cLongtext) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CChar = cChar, CNchar = cNchar, CNationalChar = cNationalChar, CVarchar = cVarchar, CTinytext = cTinytext, CMediumtext = cMediumtext, CText = cText, CLongtext = cLongtext }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CChar = cChar, CNchar = cNchar, CNationalChar = cNationalChar, CVarchar = cVarchar, CTinytext = cTinytext, CMediumtext = cMediumtext, CText = cText, CLongtext = cLongtext }); + var expected = new QuerySql.GetMysqlStringTypesRow { CChar = cChar, CNchar = cNchar, @@ -325,15 +441,19 @@ public async Task TestMySqlStringTypes(string cChar, string cNchar, string cNati CText = cText, CLongtext = cLongtext }; - var actual = await QuerySql.GetMysqlTypes(); - Assert.That(actual.CChar, Is.EqualTo(expected.CChar)); - Assert.That(actual.CNchar, Is.EqualTo(expected.CNchar)); - Assert.That(actual.CNationalChar, Is.EqualTo(expected.CNationalChar)); - Assert.That(actual.CVarchar, Is.EqualTo(expected.CVarchar)); - Assert.That(actual.CTinytext, Is.EqualTo(expected.CTinytext)); - Assert.That(actual.CMediumtext, Is.EqualTo(expected.CMediumtext)); - Assert.That(actual.CText, Is.EqualTo(expected.CText)); - Assert.That(actual.CLongtext, Is.EqualTo(expected.CLongtext)); + var actual = await QuerySql.GetMysqlStringTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlStringTypesRow x, QuerySql.GetMysqlStringTypesRow y) + { + Assert.That(x.CChar, Is.EqualTo(y.CChar)); + Assert.That(x.CNchar, Is.EqualTo(y.CNchar)); + Assert.That(x.CNationalChar, Is.EqualTo(y.CNationalChar)); + Assert.That(x.CVarchar, Is.EqualTo(y.CVarchar)); + Assert.That(x.CTinytext, Is.EqualTo(y.CTinytext)); + Assert.That(x.CMediumtext, Is.EqualTo(y.CMediumtext)); + Assert.That(x.CText, Is.EqualTo(y.CText)); + Assert.That(x.CLongtext, Is.EqualTo(y.CLongtext)); + } } [Test] @@ -341,8 +461,8 @@ public async Task TestMySqlStringTypes(string cChar, string cNchar, string cNati [TestCase(null, null, null, null, null, null, null, null, null)] public async Task TestMySqlIntegerTypes(bool? cBool, bool? cBoolean, short? cTinyint, short? cYear, short? cSmallint, int? cMediumint, int? cInt, int? cInteger, long? cBigint) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CBool = cBool, CBoolean = cBoolean, CTinyint = cTinyint, CSmallint = cSmallint, CMediumint = cMediumint, CInt = cInt, CInteger = cInteger, CBigint = cBigint }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlNumericTypes(new QuerySql.InsertMysqlNumericTypesArgs { CBool = cBool, CBoolean = cBoolean, CTinyint = cTinyint, CSmallint = cSmallint, CMediumint = cMediumint, CInt = cInt, CInteger = cInteger, CBigint = cBigint }); + var expected = new QuerySql.GetMysqlNumericTypesRow { CBool = cBool, CBoolean = cBoolean, @@ -353,49 +473,19 @@ public async Task TestMySqlIntegerTypes(bool? cBool, bool? cBoolean, short? cTin CInteger = cInteger, CBigint = cBigint }; - var actual = await QuerySql.GetMysqlTypes(); - Assert.That(actual.CBool, Is.EqualTo(expected.CBool)); - Assert.That(actual.CBoolean, Is.EqualTo(expected.CBoolean)); - Assert.That(actual.CTinyint, Is.EqualTo(expected.CTinyint)); - Assert.That(actual.CSmallint, Is.EqualTo(expected.CSmallint)); - Assert.That(actual.CMediumint, Is.EqualTo(expected.CMediumint)); - Assert.That(actual.CInt, Is.EqualTo(expected.CInt)); - Assert.That(actual.CInteger, Is.EqualTo(expected.CInteger)); - Assert.That(actual.CBigint, Is.EqualTo(expected.CBigint)); - } - - [Test] - public async Task TestMySqlTransaction() - { - var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)); - await connection.OpenAsync(); - var transaction = connection.BeginTransaction(); - var querySqlWithTx = QuerySql.WithTransaction(transaction); - await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - var actualNull = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actualNull == null, "there is author"); // This is correct for nullable types - await transaction.CommitAsync(); - var expected = new QuerySql.GetAuthorRow + var actual = await QuerySql.GetMysqlNumericTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlNumericTypesRow x, QuerySql.GetMysqlNumericTypesRow y) { - Id = 1111, - Name = "Bojack Horseman", - Bio = "Back in the 90s he was in a very famous TV show" - }; - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual)); // Apply placeholder here - } - - [Test] - public async Task TestMySqlTransactionRollback() - { - var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)); - await connection.OpenAsync(); - var transaction = connection.BeginTransaction(); - var querySqlWithTx = QuerySql.WithTransaction(transaction); - await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - await transaction.RollbackAsync(); - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actual == null, "author should not exist after rollback"); + Assert.That(x.CBool, Is.EqualTo(y.CBool)); + Assert.That(x.CBoolean, Is.EqualTo(y.CBoolean)); + Assert.That(x.CTinyint, Is.EqualTo(y.CTinyint)); + Assert.That(x.CSmallint, Is.EqualTo(y.CSmallint)); + Assert.That(x.CMediumint, Is.EqualTo(y.CMediumint)); + Assert.That(x.CInt, Is.EqualTo(y.CInt)); + Assert.That(x.CInteger, Is.EqualTo(y.CInteger)); + Assert.That(x.CBigint, Is.EqualTo(y.CBigint)); + } } [Test] @@ -403,8 +493,8 @@ public async Task TestMySqlTransactionRollback() [TestCase(null, null, null, null, null, null, null)] public async Task TestMySqlFloatingPointTypes(float? cFloat, decimal? cNumeric, decimal? cDecimal, decimal? cDec, decimal? cFixed, double? cDouble, double? cDoublePrecision) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CFloat = cFloat, CNumeric = cNumeric, CDecimal = cDecimal, CDec = cDec, CFixed = cFixed, CDouble = cDouble, CDoublePrecision = cDoublePrecision }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlNumericTypes(new QuerySql.InsertMysqlNumericTypesArgs { CFloat = cFloat, CNumeric = cNumeric, CDecimal = cDecimal, CDec = cDec, CFixed = cFixed, CDouble = cDouble, CDoublePrecision = cDoublePrecision }); + var expected = new QuerySql.GetMysqlNumericTypesRow { CFloat = cFloat, CNumeric = cNumeric, @@ -414,32 +504,44 @@ public async Task TestMySqlFloatingPointTypes(float? cFloat, decimal? cNumeric, CDouble = cDouble, CDoublePrecision = cDoublePrecision }; - var actual = await QuerySql.GetMysqlTypes(); - Assert.That(actual.CFloat, Is.EqualTo(expected.CFloat)); - Assert.That(actual.CNumeric, Is.EqualTo(expected.CNumeric)); - Assert.That(actual.CDecimal, Is.EqualTo(expected.CDecimal)); - Assert.That(actual.CDec, Is.EqualTo(expected.CDec)); - Assert.That(actual.CFixed, Is.EqualTo(expected.CFixed)); - Assert.That(actual.CDouble, Is.EqualTo(expected.CDouble)); - Assert.That(actual.CDoublePrecision, Is.EqualTo(expected.CDoublePrecision)); + var actual = await QuerySql.GetMysqlNumericTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlNumericTypesRow x, QuerySql.GetMysqlNumericTypesRow y) + { + Assert.That(x.CFloat, Is.EqualTo(y.CFloat)); + Assert.That(x.CNumeric, Is.EqualTo(y.CNumeric)); + Assert.That(x.CDecimal, Is.EqualTo(y.CDecimal)); + Assert.That(x.CDec, Is.EqualTo(y.CDec)); + Assert.That(x.CFixed, Is.EqualTo(y.CFixed)); + Assert.That(x.CDouble, Is.EqualTo(y.CDouble)); + Assert.That(x.CDoublePrecision, Is.EqualTo(y.CDoublePrecision)); + } } [Test] - [TestCase(1999, "2000-1-30", "1983-11-3 02:01:22")] - [TestCase(null, null, "1970-1-1 00:00:01")] - public async Task TestMySqlDateTimeTypes(short? cYear, DateTime? cDate, DateTime? cTimestamp) + [TestCase(1999, "2000-1-30", "1983-11-3 02:01:22", "2010-1-30 08:11:00", "02:01:22")] + [TestCase(null, null, null, null, null)] + public async Task TestMySqlDateTimeTypes(short? cYear, DateTime? cDate, DateTime? cDatetime, DateTime? cTimestamp, TimeSpan? cTime) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CYear = cYear, CDate = cDate, CTimestamp = cTimestamp }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlDatetimeTypes(new QuerySql.InsertMysqlDatetimeTypesArgs { CYear = cYear, CDate = cDate, CDatetime = cDatetime, CTimestamp = cTimestamp, CTime = cTime }); + var expected = new QuerySql.GetMysqlDatetimeTypesRow { CYear = cYear, CDate = cDate, - CTimestamp = cTimestamp + CDatetime = cDatetime, + CTimestamp = cTimestamp, + CTime = cTime }; - var actual = await QuerySql.GetMysqlTypes(); - Assert.That(actual.CYear, Is.EqualTo(expected.CYear)); - Assert.That(actual.CDate, Is.EqualTo(expected.CDate)); - Assert.That(actual.CTimestamp, Is.EqualTo(expected.CTimestamp)); + var actual = await QuerySql.GetMysqlDatetimeTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlDatetimeTypesRow x, QuerySql.GetMysqlDatetimeTypesRow y) + { + Assert.That(x.CYear, Is.EqualTo(y.CYear)); + Assert.That(x.CDate, Is.EqualTo(y.CDate)); + Assert.That(x.CDatetime, Is.EqualTo(y.CDatetime)); + Assert.That(x.CTimestamp, Is.EqualTo(y.CTimestamp)); + Assert.That(x.CTime, Is.EqualTo(y.CTime)); + } } [Test] @@ -448,8 +550,8 @@ public async Task TestMySqlDateTimeTypes(short? cYear, DateTime? cDate, DateTime [TestCase(null, null, null, null, null, null, null)] public async Task TestMySqlBinaryTypes(byte? cBit, byte[] cBinary, byte[] cVarbinary, byte[] cTinyblob, byte[] cBlob, byte[] cMediumblob, byte[] cLongblob) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CBit = cBit, CBinary = cBinary, CVarbinary = cVarbinary, CTinyblob = cTinyblob, CBlob = cBlob, CMediumblob = cMediumblob, CLongblob = cLongblob }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlBinaryTypes(new QuerySql.InsertMysqlBinaryTypesArgs { CBit = cBit, CBinary = cBinary, CVarbinary = cVarbinary, CTinyblob = cTinyblob, CBlob = cBlob, CMediumblob = cMediumblob, CLongblob = cLongblob }); + var expected = new QuerySql.GetMysqlBinaryTypesRow { CBit = cBit, CBinary = cBinary, @@ -459,9 +561,9 @@ public async Task TestMySqlBinaryTypes(byte? cBit, byte[] cBinary, byte[] cVarbi CMediumblob = cMediumblob, CLongblob = cLongblob }; - var actual = await QuerySql.GetMysqlTypes(); + var actual = await QuerySql.GetMysqlBinaryTypes(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow y) + void AssertSingularEquals(QuerySql.GetMysqlBinaryTypesRow x, QuerySql.GetMysqlBinaryTypesRow y) { Assert.That(x.CBit, Is.EqualTo(y.CBit)); Assert.That(x.CBinary, Is.EqualTo(y.CBinary)); @@ -473,74 +575,32 @@ void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow } } - [Test] - [TestCase(MysqlTypesCEnum.Medium, new[] { MysqlTypesCSet.Tea, MysqlTypesCSet.Coffee })] - [TestCase(null, null)] - public async Task TestMySqlStringTypes(MysqlTypesCEnum? cEnum, MysqlTypesCSet[] cSet) + private static IEnumerable MySqlEnumTypesTestCases { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CEnum = cEnum, CSet = cSet }); - var expected = new QuerySql.GetMysqlTypesRow - { - CEnum = cEnum, - CSet = cSet - }; - var actual = await QuerySql.GetMysqlTypes(); - AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow y) + get { - Assert.That(x.CEnum, Is.EqualTo(y.CEnum)); - Assert.That(x.CSet, Is.EqualTo(y.CSet)); + yield return new TestCaseData(MysqlStringTypesCEnum.Medium, new HashSet { MysqlStringTypesCSet.Tea, MysqlStringTypesCSet.Coffee }).SetName("Valid Enum values"); + yield return new TestCaseData(null, null).SetName("Enum with null values"); } } [Test] - [TestCase(-54355, "Scream of the Butterfly", "2025-06-29 12:00:00")] - [TestCase(null, null, "1971-01-01 00:00:00")] - public async Task TestMySqlDataTypesOverride(int? cInt, string cVarchar, DateTime cTimestamp) + [TestCaseSource(nameof(MySqlEnumTypesTestCases))] + public async Task TestMySqlStringTypes(MysqlStringTypesCEnum? cEnum, HashSet cSet) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CInt = cInt, CVarchar = cVarchar, CTimestamp = cTimestamp }); - var expected = new QuerySql.GetMysqlFunctionsRow + await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CEnum = cEnum, CSet = cSet }); + var expected = new QuerySql.GetMysqlStringTypesRow { - MaxInt = cInt, - MaxVarchar = cVarchar, - MaxTimestamp = cTimestamp + CEnum = cEnum, + CSet = cSet }; - var actual = await QuerySql.GetMysqlFunctions(); + var actual = await QuerySql.GetMysqlStringTypes(); AssertSingularEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.GetMysqlFunctionsRow expected, QuerySql.GetMysqlFunctionsRow actual) - { - Assert.That(actual.MaxInt, Is.EqualTo(expected.MaxInt)); - Assert.That(actual.MaxVarchar, Is.EqualTo(expected.MaxVarchar)); - Assert.That(actual.MaxTimestamp, Is.EqualTo(expected.MaxTimestamp)); - } - - [Test] - public async Task TestMySqlScopedSchemaEnum() - { - await this.QuerySql.CreateExtendedBio(new QuerySql.CreateExtendedBioArgs { AuthorName = "Bojack Horseman", Name = "One Trick Pony", BioType = ExtendedBiosBioType.Memoir, AuthorType = new ExtendedBiosAuthorType[] { ExtendedBiosAuthorType.Author, ExtendedBiosAuthorType.Translator } }); - var expected = new QuerySql.GetFirstExtendedBioByTypeRow + void AssertSingularEquals(QuerySql.GetMysqlStringTypesRow x, QuerySql.GetMysqlStringTypesRow y) { - AuthorName = "Bojack Horseman", - Name = "One Trick Pony", - BioType = ExtendedBiosBioType.Memoir, - AuthorType = new ExtendedBiosAuthorType[] - { - ExtendedBiosAuthorType.Author, - ExtendedBiosAuthorType.Translator - } - }; - var actual = await this.QuerySql.GetFirstExtendedBioByType(new QuerySql.GetFirstExtendedBioByTypeArgs { BioType = ExtendedBiosBioType.Memoir }); - AssertSingularEquals(expected, actual); - } - - private void AssertSingularEquals(QuerySql.GetFirstExtendedBioByTypeRow x, QuerySql.GetFirstExtendedBioByTypeRow y) - { - Assert.That(x.AuthorName, Is.EqualTo(y.AuthorName)); - Assert.That(x.Name, Is.EqualTo(y.Name)); - Assert.That(x.BioType, Is.EqualTo(y.BioType)); - Assert.That(x.AuthorType, Is.EqualTo(y.AuthorType)); + Assert.That(x.CEnum, Is.EqualTo(y.CEnum)); + Assert.That(x.CSet, Is.EqualTo(y.CSet)); + } } [Test] @@ -551,15 +611,15 @@ public async Task TestMySqlJsonDataType(string cJson) JsonElement? cParsedJson = null; if (cJson != null) cParsedJson = JsonDocument.Parse(cJson).RootElement; - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CJson = cParsedJson, CJsonStringOverride = cJson }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CJson = cParsedJson, CJsonStringOverride = cJson }); + var expected = new QuerySql.GetMysqlStringTypesRow { CJson = cParsedJson, CJsonStringOverride = cJson }; - var actual = await QuerySql.GetMysqlTypes(); + var actual = await QuerySql.GetMysqlStringTypes(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow y) + void AssertSingularEquals(QuerySql.GetMysqlStringTypesRow x, QuerySql.GetMysqlStringTypesRow y) { Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); if (x.CJson.HasValue) @@ -568,46 +628,14 @@ void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow } } - [Test] - [TestCase(100, "{\"name\": \"Swordfishtrombones\", \"year\": 1983}")] - [TestCase(10, null)] - public async Task TestJsonCopyFrom(int batchSize, string cJson) - { - JsonElement? cParsedJson = null; - if (cJson != null) - cParsedJson = JsonDocument.Parse(cJson).RootElement; - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CJson = cParsedJson }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow - { - Cnt = batchSize, - CJson = cParsedJson - }; - var actual = await QuerySql.GetMysqlTypesCnt(); - AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypesCntRow y) - { - Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); - Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); - if (x.CJson.HasValue) - Assert.That(x.CJson.Value.GetRawText(), Is.EqualTo(y.CJson.Value.GetRawText())); - } - } - - [Test] - public void TestMySqlInvalidJson() - { - Assert.ThrowsAsync(async () => await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CJsonStringOverride = "SOME INVALID JSON" })); - } - [Test] [TestCase(100, "D", "\u4321", "\u2345", "Parasite", "Clockwork Orange", "Dr. Strangelove", "Interview with a Vampire", "Memento")] [TestCase(10, null, null, null, null, null, null, null, null)] public async Task TestStringCopyFrom(int batchSize, string cChar, string cNchar, string cNationalChar, string cVarchar, string cTinytext, string cMediumtext, string cText, string cLongtext) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CChar = cChar, CNchar = cNchar, CNationalChar = cNationalChar, CVarchar = cVarchar, CTinytext = cTinytext, CMediumtext = cMediumtext, CText = cText, CLongtext = cLongtext }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlStringTypesBatchArgs { CChar = cChar, CNchar = cNchar, CNationalChar = cNationalChar, CVarchar = cVarchar, CTinytext = cTinytext, CMediumtext = cMediumtext, CText = cText, CLongtext = cLongtext }).ToList(); + await QuerySql.InsertMysqlStringTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlStringTypesCntRow { Cnt = batchSize, CChar = cChar, @@ -619,9 +647,9 @@ public async Task TestStringCopyFrom(int batchSize, string cChar, string cNchar, CText = cText, CLongtext = cLongtext }; - var actual = await QuerySql.GetMysqlTypesCnt(); + var actual = await QuerySql.GetMysqlStringTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypesCntRow y) + void AssertSingularEquals(QuerySql.GetMysqlStringTypesCntRow x, QuerySql.GetMysqlStringTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CChar, Is.EqualTo(y.CChar)); @@ -640,9 +668,9 @@ void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypes [TestCase(10, null, null, null, null, null, null, null, null)] public async Task TestIntegerCopyFrom(int batchSize, bool? cBool, bool? cBoolean, short? cTinyint, short? cSmallint, int? cMediumint, int? cInt, int? cInteger, long? cBigint) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CBool = cBool, CBoolean = cBoolean, CTinyint = cTinyint, CSmallint = cSmallint, CMediumint = cMediumint, CInt = cInt, CInteger = cInteger, CBigint = cBigint }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlNumericTypesBatchArgs { CBool = cBool, CBoolean = cBoolean, CTinyint = cTinyint, CSmallint = cSmallint, CMediumint = cMediumint, CInt = cInt, CInteger = cInteger, CBigint = cBigint }).ToList(); + await QuerySql.InsertMysqlNumericTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlNumericTypesCntRow { Cnt = batchSize, CBool = cBool, @@ -654,9 +682,9 @@ public async Task TestIntegerCopyFrom(int batchSize, bool? cBool, bool? cBoolean CInteger = cInteger, CBigint = cBigint }; - var actual = await QuerySql.GetMysqlTypesCnt(); + var actual = await QuerySql.GetMysqlNumericTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypesCntRow y) + void AssertSingularEquals(QuerySql.GetMysqlNumericTypesCntRow x, QuerySql.GetMysqlNumericTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CBool, Is.EqualTo(y.CBool)); @@ -675,9 +703,9 @@ void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypes [TestCase(10, null, null, null, null, null, null, null)] public async Task TestFloatingPointCopyFrom(int batchSize, float? cFloat, decimal? cNumeric, decimal? cDecimal, decimal? cDec, decimal? cFixed, double? cDouble, double? cDoublePrecision) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CFloat = cFloat, CNumeric = cNumeric, CDecimal = cDecimal, CDec = cDec, CFixed = cFixed, CDouble = cDouble, CDoublePrecision = cDoublePrecision }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlNumericTypesBatchArgs { CFloat = cFloat, CNumeric = cNumeric, CDecimal = cDecimal, CDec = cDec, CFixed = cFixed, CDouble = cDouble, CDoublePrecision = cDoublePrecision }).ToList(); + await QuerySql.InsertMysqlNumericTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlNumericTypesCntRow { Cnt = batchSize, CFloat = cFloat, @@ -688,37 +716,48 @@ public async Task TestFloatingPointCopyFrom(int batchSize, float? cFloat, decima CDouble = cDouble, CDoublePrecision = cDoublePrecision }; - var actual = await QuerySql.GetMysqlTypesCnt(); - Assert.That(actual.CFloat, Is.EqualTo(expected.CFloat)); - Assert.That(actual.CNumeric, Is.EqualTo(expected.CNumeric)); - Assert.That(actual.CDecimal, Is.EqualTo(expected.CDecimal)); - Assert.That(actual.CDec, Is.EqualTo(expected.CDec)); - Assert.That(actual.CFixed, Is.EqualTo(expected.CFixed)); - Assert.That(actual.CDouble, Is.EqualTo(expected.CDouble)); - Assert.That(actual.CDoublePrecision, Is.EqualTo(expected.CDoublePrecision)); + var actual = await QuerySql.GetMysqlNumericTypesCnt(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlNumericTypesCntRow x, QuerySql.GetMysqlNumericTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CFloat, Is.EqualTo(y.CFloat)); + Assert.That(x.CNumeric, Is.EqualTo(y.CNumeric)); + Assert.That(x.CDecimal, Is.EqualTo(y.CDecimal)); + Assert.That(x.CDec, Is.EqualTo(y.CDec)); + Assert.That(x.CFixed, Is.EqualTo(y.CFixed)); + Assert.That(x.CDouble, Is.EqualTo(y.CDouble)); + Assert.That(x.CDoublePrecision, Is.EqualTo(y.CDoublePrecision)); + } } [Test] - [TestCase(100, 1993, "2000-1-30", "1983-11-3 02:01:22", "2010-1-30 08:11:00")] - [TestCase(10, null, null, null, null)] - public async Task TestDateTimeCopyFrom(int batchSize, short? cYear, DateTime? cDate, DateTime? cDatetime, DateTime? cTimestamp) + [TestCase(100, 1993, "2000-1-30", "1983-11-3 02:01:22", "2010-1-30 08:11:00", "02:01:22")] + [TestCase(10, null, null, null, null, null)] + public async Task TestDateTimeCopyFrom(int batchSize, short? cYear, DateTime? cDate, DateTime? cDatetime, DateTime? cTimestamp, TimeSpan? cTime) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CYear = cYear, CDate = cDate, CDatetime = cDatetime, CTimestamp = cTimestamp }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlDatetimeTypesBatchArgs { CYear = cYear, CDate = cDate, CDatetime = cDatetime, CTimestamp = cTimestamp, CTime = cTime }).ToList(); + await QuerySql.InsertMysqlDatetimeTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlDatetimeTypesCntRow { Cnt = batchSize, CYear = cYear, CDate = cDate, CDatetime = cDatetime, - CTimestamp = cTimestamp + CTimestamp = cTimestamp, + CTime = cTime }; - var actual = await QuerySql.GetMysqlTypesCnt(); - Assert.That(actual.Cnt, Is.EqualTo(expected.Cnt)); - Assert.That(actual.CYear, Is.EqualTo(expected.CYear)); - Assert.That(actual.CDate, Is.EqualTo(expected.CDate)); - Assert.That(actual.CDatetime, Is.EqualTo(expected.CDatetime)); - Assert.That(actual.CTimestamp, Is.EqualTo(expected.CTimestamp)); + var actual = await QuerySql.GetMysqlDatetimeTypesCnt(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlDatetimeTypesCntRow x, QuerySql.GetMysqlDatetimeTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CYear, Is.EqualTo(y.CYear)); + Assert.That(x.CDate, Is.EqualTo(y.CDate)); + Assert.That(x.CDatetime, Is.EqualTo(y.CDatetime)); + Assert.That(x.CTimestamp, Is.EqualTo(y.CTimestamp)); + Assert.That(x.CTime, Is.EqualTo(y.CTime)); + } } [Test] @@ -727,9 +766,9 @@ public async Task TestDateTimeCopyFrom(int batchSize, short? cYear, DateTime? cD [TestCase(10, null, null, null, null, null, null, null)] public async Task TestBinaryCopyFrom(int batchSize, byte? cBit, byte[] cBinary, byte[] cVarbinary, byte[] cTinyblob, byte[] cBlob, byte[] cMediumblob, byte[] cLongblob) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CBit = cBit, CBinary = cBinary, CVarbinary = cVarbinary, CTinyblob = cTinyblob, CBlob = cBlob, CMediumblob = cMediumblob, CLongblob = cLongblob }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlBinaryTypesBatchArgs { CBit = cBit, CBinary = cBinary, CVarbinary = cVarbinary, CTinyblob = cTinyblob, CBlob = cBlob, CMediumblob = cMediumblob, CLongblob = cLongblob }).ToList(); + await QuerySql.InsertMysqlBinaryTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlBinaryTypesCntRow { Cnt = batchSize, CBit = cBit, @@ -740,39 +779,76 @@ public async Task TestBinaryCopyFrom(int batchSize, byte? cBit, byte[] cBinary, CMediumblob = cMediumblob, CLongblob = cLongblob }; - var actual = await QuerySql.GetMysqlTypesCnt(); - Assert.That(actual.Cnt, Is.EqualTo(expected.Cnt)); - Assert.That(actual.CBit, Is.EqualTo(expected.CBit)); - Assert.That(actual.CBinary, Is.EqualTo(expected.CBinary)); - Assert.That(actual.CVarbinary, Is.EqualTo(expected.CVarbinary)); - Assert.That(actual.CTinyblob, Is.EqualTo(expected.CTinyblob)); - Assert.That(actual.CBlob, Is.EqualTo(expected.CBlob)); - Assert.That(actual.CMediumblob, Is.EqualTo(expected.CMediumblob)); - Assert.That(actual.CLongblob, Is.EqualTo(expected.CLongblob)); + var actual = await QuerySql.GetMysqlBinaryTypesCnt(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlBinaryTypesCntRow x, QuerySql.GetMysqlBinaryTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CBit, Is.EqualTo(y.CBit)); + Assert.That(x.CBinary, Is.EqualTo(y.CBinary)); + Assert.That(x.CVarbinary, Is.EqualTo(y.CVarbinary)); + Assert.That(x.CTinyblob, Is.EqualTo(y.CTinyblob)); + Assert.That(x.CBlob, Is.EqualTo(y.CBlob)); + Assert.That(x.CMediumblob, Is.EqualTo(y.CMediumblob)); + Assert.That(x.CLongblob, Is.EqualTo(y.CLongblob)); + } + } + + private static IEnumerable MySqlEnumCopyFromTestCases + { + get + { + yield return new TestCaseData(100, MysqlStringTypesCEnum.Big, new HashSet { MysqlStringTypesCSet.Tea, MysqlStringTypesCSet.Coffee }).SetName("Valid Enum values"); + yield return new TestCaseData(10, null, null).SetName("Enum with null values"); + } } [Test] - [TestCase(100, MysqlTypesCEnum.Big, new[] { MysqlTypesCSet.Tea, MysqlTypesCSet.Coffee })] - [TestCase(500, MysqlTypesCEnum.Small, new[] { MysqlTypesCSet.Milk })] - [TestCase(10, null, null)] - public async Task TestCopyFrom(int batchSize, MysqlTypesCEnum? cEnum, MysqlTypesCSet[] cSet) + [TestCaseSource(nameof(MySqlEnumCopyFromTestCases))] + public async Task TestCopyFrom(int batchSize, MysqlStringTypesCEnum? cEnum, HashSet cSet) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CEnum = cEnum, CSet = cSet }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlStringTypesBatchArgs { CEnum = cEnum, CSet = cSet }).ToList(); + await QuerySql.InsertMysqlStringTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlStringTypesCntRow { Cnt = batchSize, CEnum = cEnum, CSet = cSet }; - var actual = await QuerySql.GetMysqlTypesCnt(); + var actual = await QuerySql.GetMysqlStringTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypesCntRow y) + void AssertSingularEquals(QuerySql.GetMysqlStringTypesCntRow x, QuerySql.GetMysqlStringTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CEnum, Is.EqualTo(y.CEnum)); Assert.That(x.CSet, Is.EqualTo(y.CSet)); } } + + [Test] + [TestCase(100, "{\"name\": \"Swordfishtrombones\", \"year\": 1983}")] + [TestCase(10, null)] + public async Task TestJsonCopyFrom(int batchSize, string cJson) + { + JsonElement? cParsedJson = null; + if (cJson != null) + cParsedJson = JsonDocument.Parse(cJson).RootElement; + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlStringTypesBatchArgs { CJson = cParsedJson }).ToList(); + await QuerySql.InsertMysqlStringTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlStringTypesCntRow + { + Cnt = batchSize, + CJson = cParsedJson + }; + var actual = await QuerySql.GetMysqlStringTypesCnt(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlStringTypesCntRow x, QuerySql.GetMysqlStringTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); + if (x.CJson.HasValue) + Assert.That(x.CJson.Value.GetRawText(), Is.EqualTo(y.CJson.Value.GetRawText())); + } + } } } diff --git a/end2end/EndToEndTestsLegacy/MySqlConnectorTester.cs b/end2end/EndToEndTestsLegacy/MySqlConnectorTester.cs index be0cf1b0..b0f68b1b 100644 --- a/end2end/EndToEndTestsLegacy/MySqlConnectorTester.cs +++ b/end2end/EndToEndTestsLegacy/MySqlConnectorTester.cs @@ -14,8 +14,11 @@ public partial class MySqlConnectorTester public async Task EmptyTestsTable() { await QuerySql.DeleteAllAuthors(); - await QuerySql.TruncateMysqlTypes(); await QuerySql.TruncateExtendedBios(); + await QuerySql.TruncateMysqlNumericTypes(); + await QuerySql.TruncateMysqlStringTypes(); + await QuerySql.TruncateMysqlDatetimeTypes(); + await QuerySql.TruncateMysqlBinaryTypes(); } } } \ No newline at end of file diff --git a/end2end/EndToEndTestsLegacy/MySqlConnectorTester.generated.cs b/end2end/EndToEndTestsLegacy/MySqlConnectorTester.generated.cs index b47d9870..3402c78d 100644 --- a/end2end/EndToEndTestsLegacy/MySqlConnectorTester.generated.cs +++ b/end2end/EndToEndTestsLegacy/MySqlConnectorTester.generated.cs @@ -24,12 +24,13 @@ public async Task TestOne() Bio = "Back in the 90s he was in a very famous TV show" }; var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -54,21 +55,18 @@ public async Task TestMany() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) - { - Assert.That(x.Id, Is.EqualTo(y.Id)); - Assert.That(x.Name, Is.EqualTo(y.Name)); - Assert.That(x.Bio, Is.EqualTo(y.Bio)); - } + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } - private static void AssertSequenceEquals(List x, List y) - { - Assert.That(x.Count, Is.EqualTo(y.Count)); - for (int i = 0; i < x.Count; i++) + void AssertSequenceEquals(List x, List y) { - AssertSingularEquals(x[i], y[i]); + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); } } @@ -106,6 +104,19 @@ public async Task TestExecRows() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -119,12 +130,13 @@ public async Task TestExecLastId() Bio = "Quote that everyone always attribute to Einstein" }; var actual = await QuerySql.GetAuthorById(new QuerySql.GetAuthorByIdArgs { Id = id1 }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -151,19 +163,23 @@ public async Task TestSelfJoinEmbed() } }; var actual = await QuerySql.GetDuplicateAuthors(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) - { - return SingularEquals(x.Author, y.Author) && SingularEquals(x.Author2, y.Author2); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) + { + Assert.That(x.Author.Id, Is.EqualTo(y.Author.Id)); + Assert.That(x.Author.Name, Is.EqualTo(y.Author.Name)); + Assert.That(x.Author.Bio, Is.EqualTo(y.Author.Bio)); + Assert.That(x.Author2.Id, Is.EqualTo(y.Author2.Id)); + Assert.That(x.Author2.Name, Is.EqualTo(y.Author2.Name)); + Assert.That(x.Author2.Bio, Is.EqualTo(y.Author2.Bio)); + } - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -207,31 +223,23 @@ public async Task TestJoinEmbed() } }; var actual = await QuerySql.ListAllAuthorsBooks(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) - { - return SingularEquals(x.Author, y.Author) && SingularEquals(x.Book, y.Book); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Author.Name + o.Book.Name).ToList(); - y = y.OrderBy(o => o.Author.Name + o.Book.Name).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } - - private static bool SingularEquals(Author x, Author y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) + { + Assert.That(x.Author.Id, Is.EqualTo(y.Author.Id)); + Assert.That(x.Author.Name, Is.EqualTo(y.Author.Name)); + Assert.That(x.Author.Bio, Is.EqualTo(y.Author.Bio)); + Assert.That(x.Book.Id, Is.EqualTo(y.Book.Id)); + Assert.That(x.Book.AuthorId, Is.EqualTo(y.Book.AuthorId)); + Assert.That(x.Book.Name, Is.EqualTo(y.Book.Name)); + } - private static bool SingularEquals(Book x, Book y) - { - return x.Id.Equals(y.Id) && x.AuthorId.Equals(y.AuthorId) && x.Name.Equals(y.Name); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -273,21 +281,20 @@ public async Task TestNargNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs()); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Id).ToList(); - y = y.OrderBy(o => o.Id).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } - private static bool SingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -305,7 +312,116 @@ public async Task TestNargNotNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs { NamePattern = "Bojack%" }); - Assert.That(SequenceEquals(expected, actual)); + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } + + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + } + + [Test] + public async Task TestMySqlTransaction() + { + var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)); + await connection.OpenAsync(); + var transaction = connection.BeginTransaction(); + var querySqlWithTx = QuerySql.WithTransaction(transaction); + await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + ClassicAssert.IsNull(actual); + await transaction.CommitAsync(); + var expected = new QuerySql.GetAuthorRow + { + Id = 1111, + Name = "Bojack Horseman", + Bio = "Back in the 90s he was in a very famous TV show" + }; + actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + } + + [Test] + public async Task TestMySqlTransactionRollback() + { + var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)); + await connection.OpenAsync(); + var transaction = connection.BeginTransaction(); + var querySqlWithTx = QuerySql.WithTransaction(transaction); + await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + await transaction.RollbackAsync(); + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + ClassicAssert.IsNull(actual); + } + + [Test] + [TestCase(-54355, "Scream of the Butterfly", "2025-06-29 12:00:00")] + [TestCase(null, null, "1971-01-01 00:00:00")] + public async Task TestMySqlDataTypesOverride(int? cInt, string cVarchar, DateTime cTimestamp) + { + await QuerySql.InsertMysqlNumericTypes(new QuerySql.InsertMysqlNumericTypesArgs { CInt = cInt }); + await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CVarchar = cVarchar }); + await QuerySql.InsertMysqlDatetimeTypes(new QuerySql.InsertMysqlDatetimeTypesArgs { CTimestamp = cTimestamp }); + var expected = new QuerySql.GetMysqlFunctionsRow + { + MaxInt = cInt, + MaxVarchar = cVarchar, + MaxTimestamp = cTimestamp + }; + var actual = await QuerySql.GetMysqlFunctions(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlFunctionsRow x, QuerySql.GetMysqlFunctionsRow y) + { + Assert.That(x.MaxInt, Is.EqualTo(y.MaxInt)); + Assert.That(x.MaxVarchar, Is.EqualTo(y.MaxVarchar)); + Assert.That(x.MaxTimestamp, Is.EqualTo(y.MaxTimestamp)); + } + } + + [Test] + public async Task TestMySqlScopedSchemaEnum() + { + await this.QuerySql.CreateExtendedBio(new QuerySql.CreateExtendedBioArgs { AuthorName = "Bojack Horseman", Name = "One Trick Pony", BioType = BiosBioType.Memoir, AuthorType = new HashSet { BiosAuthorType.Author, BiosAuthorType.Translator } }); + var expected = new QuerySql.GetFirstExtendedBioByTypeRow + { + AuthorName = "Bojack Horseman", + Name = "One Trick Pony", + BioType = BiosBioType.Memoir, + AuthorType = new HashSet + { + BiosAuthorType.Author, + BiosAuthorType.Translator + } + }; + var actual = await this.QuerySql.GetFirstExtendedBioByType(new QuerySql.GetFirstExtendedBioByTypeArgs { BioType = BiosBioType.Memoir }); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetFirstExtendedBioByTypeRow x, QuerySql.GetFirstExtendedBioByTypeRow y) + { + Assert.That(x.AuthorName, Is.EqualTo(y.AuthorName)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.BioType, Is.EqualTo(y.BioType)); + Assert.That(x.AuthorType, Is.EqualTo(y.AuthorType)); + } + } + + [Test] + public void TestMySqlInvalidJson() + { + Assert.ThrowsAsync(async () => await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CJsonStringOverride = "SOME INVALID JSON" })); } [Test] @@ -313,8 +429,8 @@ public async Task TestNargNotNull() [TestCase(null, null, null, null, null, null, null, null)] public async Task TestMySqlStringTypes(string cChar, string cNchar, string cNationalChar, string cVarchar, string cTinytext, string cMediumtext, string cText, string cLongtext) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CChar = cChar, CNchar = cNchar, CNationalChar = cNationalChar, CVarchar = cVarchar, CTinytext = cTinytext, CMediumtext = cMediumtext, CText = cText, CLongtext = cLongtext }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CChar = cChar, CNchar = cNchar, CNationalChar = cNationalChar, CVarchar = cVarchar, CTinytext = cTinytext, CMediumtext = cMediumtext, CText = cText, CLongtext = cLongtext }); + var expected = new QuerySql.GetMysqlStringTypesRow { CChar = cChar, CNchar = cNchar, @@ -325,15 +441,19 @@ public async Task TestMySqlStringTypes(string cChar, string cNchar, string cNati CText = cText, CLongtext = cLongtext }; - var actual = await QuerySql.GetMysqlTypes(); - Assert.That(actual.CChar, Is.EqualTo(expected.CChar)); - Assert.That(actual.CNchar, Is.EqualTo(expected.CNchar)); - Assert.That(actual.CNationalChar, Is.EqualTo(expected.CNationalChar)); - Assert.That(actual.CVarchar, Is.EqualTo(expected.CVarchar)); - Assert.That(actual.CTinytext, Is.EqualTo(expected.CTinytext)); - Assert.That(actual.CMediumtext, Is.EqualTo(expected.CMediumtext)); - Assert.That(actual.CText, Is.EqualTo(expected.CText)); - Assert.That(actual.CLongtext, Is.EqualTo(expected.CLongtext)); + var actual = await QuerySql.GetMysqlStringTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlStringTypesRow x, QuerySql.GetMysqlStringTypesRow y) + { + Assert.That(x.CChar, Is.EqualTo(y.CChar)); + Assert.That(x.CNchar, Is.EqualTo(y.CNchar)); + Assert.That(x.CNationalChar, Is.EqualTo(y.CNationalChar)); + Assert.That(x.CVarchar, Is.EqualTo(y.CVarchar)); + Assert.That(x.CTinytext, Is.EqualTo(y.CTinytext)); + Assert.That(x.CMediumtext, Is.EqualTo(y.CMediumtext)); + Assert.That(x.CText, Is.EqualTo(y.CText)); + Assert.That(x.CLongtext, Is.EqualTo(y.CLongtext)); + } } [Test] @@ -341,8 +461,8 @@ public async Task TestMySqlStringTypes(string cChar, string cNchar, string cNati [TestCase(null, null, null, null, null, null, null, null, null)] public async Task TestMySqlIntegerTypes(bool? cBool, bool? cBoolean, short? cTinyint, short? cYear, short? cSmallint, int? cMediumint, int? cInt, int? cInteger, long? cBigint) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CBool = cBool, CBoolean = cBoolean, CTinyint = cTinyint, CSmallint = cSmallint, CMediumint = cMediumint, CInt = cInt, CInteger = cInteger, CBigint = cBigint }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlNumericTypes(new QuerySql.InsertMysqlNumericTypesArgs { CBool = cBool, CBoolean = cBoolean, CTinyint = cTinyint, CSmallint = cSmallint, CMediumint = cMediumint, CInt = cInt, CInteger = cInteger, CBigint = cBigint }); + var expected = new QuerySql.GetMysqlNumericTypesRow { CBool = cBool, CBoolean = cBoolean, @@ -353,49 +473,19 @@ public async Task TestMySqlIntegerTypes(bool? cBool, bool? cBoolean, short? cTin CInteger = cInteger, CBigint = cBigint }; - var actual = await QuerySql.GetMysqlTypes(); - Assert.That(actual.CBool, Is.EqualTo(expected.CBool)); - Assert.That(actual.CBoolean, Is.EqualTo(expected.CBoolean)); - Assert.That(actual.CTinyint, Is.EqualTo(expected.CTinyint)); - Assert.That(actual.CSmallint, Is.EqualTo(expected.CSmallint)); - Assert.That(actual.CMediumint, Is.EqualTo(expected.CMediumint)); - Assert.That(actual.CInt, Is.EqualTo(expected.CInt)); - Assert.That(actual.CInteger, Is.EqualTo(expected.CInteger)); - Assert.That(actual.CBigint, Is.EqualTo(expected.CBigint)); - } - - [Test] - public async Task TestMySqlTransaction() - { - var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)); - await connection.OpenAsync(); - var transaction = connection.BeginTransaction(); - var querySqlWithTx = QuerySql.WithTransaction(transaction); - await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - var actualNull = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actualNull == null, "there is author"); // This is correct for nullable types - await transaction.CommitAsync(); - var expected = new QuerySql.GetAuthorRow + var actual = await QuerySql.GetMysqlNumericTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlNumericTypesRow x, QuerySql.GetMysqlNumericTypesRow y) { - Id = 1111, - Name = "Bojack Horseman", - Bio = "Back in the 90s he was in a very famous TV show" - }; - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual)); // Apply placeholder here - } - - [Test] - public async Task TestMySqlTransactionRollback() - { - var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)); - await connection.OpenAsync(); - var transaction = connection.BeginTransaction(); - var querySqlWithTx = QuerySql.WithTransaction(transaction); - await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - await transaction.RollbackAsync(); - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actual == null, "author should not exist after rollback"); + Assert.That(x.CBool, Is.EqualTo(y.CBool)); + Assert.That(x.CBoolean, Is.EqualTo(y.CBoolean)); + Assert.That(x.CTinyint, Is.EqualTo(y.CTinyint)); + Assert.That(x.CSmallint, Is.EqualTo(y.CSmallint)); + Assert.That(x.CMediumint, Is.EqualTo(y.CMediumint)); + Assert.That(x.CInt, Is.EqualTo(y.CInt)); + Assert.That(x.CInteger, Is.EqualTo(y.CInteger)); + Assert.That(x.CBigint, Is.EqualTo(y.CBigint)); + } } [Test] @@ -403,8 +493,8 @@ public async Task TestMySqlTransactionRollback() [TestCase(null, null, null, null, null, null, null)] public async Task TestMySqlFloatingPointTypes(float? cFloat, decimal? cNumeric, decimal? cDecimal, decimal? cDec, decimal? cFixed, double? cDouble, double? cDoublePrecision) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CFloat = cFloat, CNumeric = cNumeric, CDecimal = cDecimal, CDec = cDec, CFixed = cFixed, CDouble = cDouble, CDoublePrecision = cDoublePrecision }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlNumericTypes(new QuerySql.InsertMysqlNumericTypesArgs { CFloat = cFloat, CNumeric = cNumeric, CDecimal = cDecimal, CDec = cDec, CFixed = cFixed, CDouble = cDouble, CDoublePrecision = cDoublePrecision }); + var expected = new QuerySql.GetMysqlNumericTypesRow { CFloat = cFloat, CNumeric = cNumeric, @@ -414,32 +504,44 @@ public async Task TestMySqlFloatingPointTypes(float? cFloat, decimal? cNumeric, CDouble = cDouble, CDoublePrecision = cDoublePrecision }; - var actual = await QuerySql.GetMysqlTypes(); - Assert.That(actual.CFloat, Is.EqualTo(expected.CFloat)); - Assert.That(actual.CNumeric, Is.EqualTo(expected.CNumeric)); - Assert.That(actual.CDecimal, Is.EqualTo(expected.CDecimal)); - Assert.That(actual.CDec, Is.EqualTo(expected.CDec)); - Assert.That(actual.CFixed, Is.EqualTo(expected.CFixed)); - Assert.That(actual.CDouble, Is.EqualTo(expected.CDouble)); - Assert.That(actual.CDoublePrecision, Is.EqualTo(expected.CDoublePrecision)); + var actual = await QuerySql.GetMysqlNumericTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlNumericTypesRow x, QuerySql.GetMysqlNumericTypesRow y) + { + Assert.That(x.CFloat, Is.EqualTo(y.CFloat)); + Assert.That(x.CNumeric, Is.EqualTo(y.CNumeric)); + Assert.That(x.CDecimal, Is.EqualTo(y.CDecimal)); + Assert.That(x.CDec, Is.EqualTo(y.CDec)); + Assert.That(x.CFixed, Is.EqualTo(y.CFixed)); + Assert.That(x.CDouble, Is.EqualTo(y.CDouble)); + Assert.That(x.CDoublePrecision, Is.EqualTo(y.CDoublePrecision)); + } } [Test] - [TestCase(1999, "2000-1-30", "1983-11-3 02:01:22")] - [TestCase(null, null, "1970-1-1 00:00:01")] - public async Task TestMySqlDateTimeTypes(short? cYear, DateTime? cDate, DateTime? cTimestamp) + [TestCase(1999, "2000-1-30", "1983-11-3 02:01:22", "2010-1-30 08:11:00", "02:01:22")] + [TestCase(null, null, null, null, null)] + public async Task TestMySqlDateTimeTypes(short? cYear, DateTime? cDate, DateTime? cDatetime, DateTime? cTimestamp, TimeSpan? cTime) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CYear = cYear, CDate = cDate, CTimestamp = cTimestamp }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlDatetimeTypes(new QuerySql.InsertMysqlDatetimeTypesArgs { CYear = cYear, CDate = cDate, CDatetime = cDatetime, CTimestamp = cTimestamp, CTime = cTime }); + var expected = new QuerySql.GetMysqlDatetimeTypesRow { CYear = cYear, CDate = cDate, - CTimestamp = cTimestamp + CDatetime = cDatetime, + CTimestamp = cTimestamp, + CTime = cTime }; - var actual = await QuerySql.GetMysqlTypes(); - Assert.That(actual.CYear, Is.EqualTo(expected.CYear)); - Assert.That(actual.CDate, Is.EqualTo(expected.CDate)); - Assert.That(actual.CTimestamp, Is.EqualTo(expected.CTimestamp)); + var actual = await QuerySql.GetMysqlDatetimeTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlDatetimeTypesRow x, QuerySql.GetMysqlDatetimeTypesRow y) + { + Assert.That(x.CYear, Is.EqualTo(y.CYear)); + Assert.That(x.CDate, Is.EqualTo(y.CDate)); + Assert.That(x.CDatetime, Is.EqualTo(y.CDatetime)); + Assert.That(x.CTimestamp, Is.EqualTo(y.CTimestamp)); + Assert.That(x.CTime, Is.EqualTo(y.CTime)); + } } [Test] @@ -448,8 +550,8 @@ public async Task TestMySqlDateTimeTypes(short? cYear, DateTime? cDate, DateTime [TestCase(null, null, null, null, null, null, null)] public async Task TestMySqlBinaryTypes(byte? cBit, byte[] cBinary, byte[] cVarbinary, byte[] cTinyblob, byte[] cBlob, byte[] cMediumblob, byte[] cLongblob) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CBit = cBit, CBinary = cBinary, CVarbinary = cVarbinary, CTinyblob = cTinyblob, CBlob = cBlob, CMediumblob = cMediumblob, CLongblob = cLongblob }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlBinaryTypes(new QuerySql.InsertMysqlBinaryTypesArgs { CBit = cBit, CBinary = cBinary, CVarbinary = cVarbinary, CTinyblob = cTinyblob, CBlob = cBlob, CMediumblob = cMediumblob, CLongblob = cLongblob }); + var expected = new QuerySql.GetMysqlBinaryTypesRow { CBit = cBit, CBinary = cBinary, @@ -459,9 +561,9 @@ public async Task TestMySqlBinaryTypes(byte? cBit, byte[] cBinary, byte[] cVarbi CMediumblob = cMediumblob, CLongblob = cLongblob }; - var actual = await QuerySql.GetMysqlTypes(); + var actual = await QuerySql.GetMysqlBinaryTypes(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow y) + void AssertSingularEquals(QuerySql.GetMysqlBinaryTypesRow x, QuerySql.GetMysqlBinaryTypesRow y) { Assert.That(x.CBit, Is.EqualTo(y.CBit)); Assert.That(x.CBinary, Is.EqualTo(y.CBinary)); @@ -473,74 +575,32 @@ void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow } } - [Test] - [TestCase(MysqlTypesCEnum.Medium, new[] { MysqlTypesCSet.Tea, MysqlTypesCSet.Coffee })] - [TestCase(null, null)] - public async Task TestMySqlStringTypes(MysqlTypesCEnum? cEnum, MysqlTypesCSet[] cSet) + private static IEnumerable MySqlEnumTypesTestCases { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CEnum = cEnum, CSet = cSet }); - var expected = new QuerySql.GetMysqlTypesRow - { - CEnum = cEnum, - CSet = cSet - }; - var actual = await QuerySql.GetMysqlTypes(); - AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow y) + get { - Assert.That(x.CEnum, Is.EqualTo(y.CEnum)); - Assert.That(x.CSet, Is.EqualTo(y.CSet)); + yield return new TestCaseData(MysqlStringTypesCEnum.Medium, new HashSet { MysqlStringTypesCSet.Tea, MysqlStringTypesCSet.Coffee }).SetName("Valid Enum values"); + yield return new TestCaseData(null, null).SetName("Enum with null values"); } } [Test] - [TestCase(-54355, "Scream of the Butterfly", "2025-06-29 12:00:00")] - [TestCase(null, null, "1971-01-01 00:00:00")] - public async Task TestMySqlDataTypesOverride(int? cInt, string cVarchar, DateTime cTimestamp) + [TestCaseSource(nameof(MySqlEnumTypesTestCases))] + public async Task TestMySqlStringTypes(MysqlStringTypesCEnum? cEnum, HashSet cSet) { - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CInt = cInt, CVarchar = cVarchar, CTimestamp = cTimestamp }); - var expected = new QuerySql.GetMysqlFunctionsRow + await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CEnum = cEnum, CSet = cSet }); + var expected = new QuerySql.GetMysqlStringTypesRow { - MaxInt = cInt, - MaxVarchar = cVarchar, - MaxTimestamp = cTimestamp + CEnum = cEnum, + CSet = cSet }; - var actual = await QuerySql.GetMysqlFunctions(); + var actual = await QuerySql.GetMysqlStringTypes(); AssertSingularEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.GetMysqlFunctionsRow expected, QuerySql.GetMysqlFunctionsRow actual) - { - Assert.That(actual.MaxInt, Is.EqualTo(expected.MaxInt)); - Assert.That(actual.MaxVarchar, Is.EqualTo(expected.MaxVarchar)); - Assert.That(actual.MaxTimestamp, Is.EqualTo(expected.MaxTimestamp)); - } - - [Test] - public async Task TestMySqlScopedSchemaEnum() - { - await this.QuerySql.CreateExtendedBio(new QuerySql.CreateExtendedBioArgs { AuthorName = "Bojack Horseman", Name = "One Trick Pony", BioType = ExtendedBiosBioType.Memoir, AuthorType = new ExtendedBiosAuthorType[] { ExtendedBiosAuthorType.Author, ExtendedBiosAuthorType.Translator } }); - var expected = new QuerySql.GetFirstExtendedBioByTypeRow + void AssertSingularEquals(QuerySql.GetMysqlStringTypesRow x, QuerySql.GetMysqlStringTypesRow y) { - AuthorName = "Bojack Horseman", - Name = "One Trick Pony", - BioType = ExtendedBiosBioType.Memoir, - AuthorType = new ExtendedBiosAuthorType[] - { - ExtendedBiosAuthorType.Author, - ExtendedBiosAuthorType.Translator - } - }; - var actual = await this.QuerySql.GetFirstExtendedBioByType(new QuerySql.GetFirstExtendedBioByTypeArgs { BioType = ExtendedBiosBioType.Memoir }); - AssertSingularEquals(expected, actual); - } - - private void AssertSingularEquals(QuerySql.GetFirstExtendedBioByTypeRow x, QuerySql.GetFirstExtendedBioByTypeRow y) - { - Assert.That(x.AuthorName, Is.EqualTo(y.AuthorName)); - Assert.That(x.Name, Is.EqualTo(y.Name)); - Assert.That(x.BioType, Is.EqualTo(y.BioType)); - Assert.That(x.AuthorType, Is.EqualTo(y.AuthorType)); + Assert.That(x.CEnum, Is.EqualTo(y.CEnum)); + Assert.That(x.CSet, Is.EqualTo(y.CSet)); + } } [Test] @@ -551,15 +611,15 @@ public async Task TestMySqlJsonDataType(string cJson) JsonElement? cParsedJson = null; if (cJson != null) cParsedJson = JsonDocument.Parse(cJson).RootElement; - await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CJson = cParsedJson, CJsonStringOverride = cJson }); - var expected = new QuerySql.GetMysqlTypesRow + await QuerySql.InsertMysqlStringTypes(new QuerySql.InsertMysqlStringTypesArgs { CJson = cParsedJson, CJsonStringOverride = cJson }); + var expected = new QuerySql.GetMysqlStringTypesRow { CJson = cParsedJson, CJsonStringOverride = cJson }; - var actual = await QuerySql.GetMysqlTypes(); + var actual = await QuerySql.GetMysqlStringTypes(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow y) + void AssertSingularEquals(QuerySql.GetMysqlStringTypesRow x, QuerySql.GetMysqlStringTypesRow y) { Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); if (x.CJson.HasValue) @@ -568,46 +628,14 @@ void AssertSingularEquals(QuerySql.GetMysqlTypesRow x, QuerySql.GetMysqlTypesRow } } - [Test] - [TestCase(100, "{\"name\": \"Swordfishtrombones\", \"year\": 1983}")] - [TestCase(10, null)] - public async Task TestJsonCopyFrom(int batchSize, string cJson) - { - JsonElement? cParsedJson = null; - if (cJson != null) - cParsedJson = JsonDocument.Parse(cJson).RootElement; - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CJson = cParsedJson }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow - { - Cnt = batchSize, - CJson = cParsedJson - }; - var actual = await QuerySql.GetMysqlTypesCnt(); - AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypesCntRow y) - { - Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); - Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); - if (x.CJson.HasValue) - Assert.That(x.CJson.Value.GetRawText(), Is.EqualTo(y.CJson.Value.GetRawText())); - } - } - - [Test] - public void TestMySqlInvalidJson() - { - Assert.ThrowsAsync(async () => await QuerySql.InsertMysqlTypes(new QuerySql.InsertMysqlTypesArgs { CJsonStringOverride = "SOME INVALID JSON" })); - } - [Test] [TestCase(100, "D", "\u4321", "\u2345", "Parasite", "Clockwork Orange", "Dr. Strangelove", "Interview with a Vampire", "Memento")] [TestCase(10, null, null, null, null, null, null, null, null)] public async Task TestStringCopyFrom(int batchSize, string cChar, string cNchar, string cNationalChar, string cVarchar, string cTinytext, string cMediumtext, string cText, string cLongtext) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CChar = cChar, CNchar = cNchar, CNationalChar = cNationalChar, CVarchar = cVarchar, CTinytext = cTinytext, CMediumtext = cMediumtext, CText = cText, CLongtext = cLongtext }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlStringTypesBatchArgs { CChar = cChar, CNchar = cNchar, CNationalChar = cNationalChar, CVarchar = cVarchar, CTinytext = cTinytext, CMediumtext = cMediumtext, CText = cText, CLongtext = cLongtext }).ToList(); + await QuerySql.InsertMysqlStringTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlStringTypesCntRow { Cnt = batchSize, CChar = cChar, @@ -619,9 +647,9 @@ public async Task TestStringCopyFrom(int batchSize, string cChar, string cNchar, CText = cText, CLongtext = cLongtext }; - var actual = await QuerySql.GetMysqlTypesCnt(); + var actual = await QuerySql.GetMysqlStringTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypesCntRow y) + void AssertSingularEquals(QuerySql.GetMysqlStringTypesCntRow x, QuerySql.GetMysqlStringTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CChar, Is.EqualTo(y.CChar)); @@ -640,9 +668,9 @@ void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypes [TestCase(10, null, null, null, null, null, null, null, null)] public async Task TestIntegerCopyFrom(int batchSize, bool? cBool, bool? cBoolean, short? cTinyint, short? cSmallint, int? cMediumint, int? cInt, int? cInteger, long? cBigint) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CBool = cBool, CBoolean = cBoolean, CTinyint = cTinyint, CSmallint = cSmallint, CMediumint = cMediumint, CInt = cInt, CInteger = cInteger, CBigint = cBigint }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlNumericTypesBatchArgs { CBool = cBool, CBoolean = cBoolean, CTinyint = cTinyint, CSmallint = cSmallint, CMediumint = cMediumint, CInt = cInt, CInteger = cInteger, CBigint = cBigint }).ToList(); + await QuerySql.InsertMysqlNumericTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlNumericTypesCntRow { Cnt = batchSize, CBool = cBool, @@ -654,9 +682,9 @@ public async Task TestIntegerCopyFrom(int batchSize, bool? cBool, bool? cBoolean CInteger = cInteger, CBigint = cBigint }; - var actual = await QuerySql.GetMysqlTypesCnt(); + var actual = await QuerySql.GetMysqlNumericTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypesCntRow y) + void AssertSingularEquals(QuerySql.GetMysqlNumericTypesCntRow x, QuerySql.GetMysqlNumericTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CBool, Is.EqualTo(y.CBool)); @@ -675,9 +703,9 @@ void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypes [TestCase(10, null, null, null, null, null, null, null)] public async Task TestFloatingPointCopyFrom(int batchSize, float? cFloat, decimal? cNumeric, decimal? cDecimal, decimal? cDec, decimal? cFixed, double? cDouble, double? cDoublePrecision) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CFloat = cFloat, CNumeric = cNumeric, CDecimal = cDecimal, CDec = cDec, CFixed = cFixed, CDouble = cDouble, CDoublePrecision = cDoublePrecision }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlNumericTypesBatchArgs { CFloat = cFloat, CNumeric = cNumeric, CDecimal = cDecimal, CDec = cDec, CFixed = cFixed, CDouble = cDouble, CDoublePrecision = cDoublePrecision }).ToList(); + await QuerySql.InsertMysqlNumericTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlNumericTypesCntRow { Cnt = batchSize, CFloat = cFloat, @@ -688,37 +716,48 @@ public async Task TestFloatingPointCopyFrom(int batchSize, float? cFloat, decima CDouble = cDouble, CDoublePrecision = cDoublePrecision }; - var actual = await QuerySql.GetMysqlTypesCnt(); - Assert.That(actual.CFloat, Is.EqualTo(expected.CFloat)); - Assert.That(actual.CNumeric, Is.EqualTo(expected.CNumeric)); - Assert.That(actual.CDecimal, Is.EqualTo(expected.CDecimal)); - Assert.That(actual.CDec, Is.EqualTo(expected.CDec)); - Assert.That(actual.CFixed, Is.EqualTo(expected.CFixed)); - Assert.That(actual.CDouble, Is.EqualTo(expected.CDouble)); - Assert.That(actual.CDoublePrecision, Is.EqualTo(expected.CDoublePrecision)); + var actual = await QuerySql.GetMysqlNumericTypesCnt(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlNumericTypesCntRow x, QuerySql.GetMysqlNumericTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CFloat, Is.EqualTo(y.CFloat)); + Assert.That(x.CNumeric, Is.EqualTo(y.CNumeric)); + Assert.That(x.CDecimal, Is.EqualTo(y.CDecimal)); + Assert.That(x.CDec, Is.EqualTo(y.CDec)); + Assert.That(x.CFixed, Is.EqualTo(y.CFixed)); + Assert.That(x.CDouble, Is.EqualTo(y.CDouble)); + Assert.That(x.CDoublePrecision, Is.EqualTo(y.CDoublePrecision)); + } } [Test] - [TestCase(100, 1993, "2000-1-30", "1983-11-3 02:01:22", "2010-1-30 08:11:00")] - [TestCase(10, null, null, null, null)] - public async Task TestDateTimeCopyFrom(int batchSize, short? cYear, DateTime? cDate, DateTime? cDatetime, DateTime? cTimestamp) + [TestCase(100, 1993, "2000-1-30", "1983-11-3 02:01:22", "2010-1-30 08:11:00", "02:01:22")] + [TestCase(10, null, null, null, null, null)] + public async Task TestDateTimeCopyFrom(int batchSize, short? cYear, DateTime? cDate, DateTime? cDatetime, DateTime? cTimestamp, TimeSpan? cTime) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CYear = cYear, CDate = cDate, CDatetime = cDatetime, CTimestamp = cTimestamp }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlDatetimeTypesBatchArgs { CYear = cYear, CDate = cDate, CDatetime = cDatetime, CTimestamp = cTimestamp, CTime = cTime }).ToList(); + await QuerySql.InsertMysqlDatetimeTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlDatetimeTypesCntRow { Cnt = batchSize, CYear = cYear, CDate = cDate, CDatetime = cDatetime, - CTimestamp = cTimestamp + CTimestamp = cTimestamp, + CTime = cTime }; - var actual = await QuerySql.GetMysqlTypesCnt(); - Assert.That(actual.Cnt, Is.EqualTo(expected.Cnt)); - Assert.That(actual.CYear, Is.EqualTo(expected.CYear)); - Assert.That(actual.CDate, Is.EqualTo(expected.CDate)); - Assert.That(actual.CDatetime, Is.EqualTo(expected.CDatetime)); - Assert.That(actual.CTimestamp, Is.EqualTo(expected.CTimestamp)); + var actual = await QuerySql.GetMysqlDatetimeTypesCnt(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlDatetimeTypesCntRow x, QuerySql.GetMysqlDatetimeTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CYear, Is.EqualTo(y.CYear)); + Assert.That(x.CDate, Is.EqualTo(y.CDate)); + Assert.That(x.CDatetime, Is.EqualTo(y.CDatetime)); + Assert.That(x.CTimestamp, Is.EqualTo(y.CTimestamp)); + Assert.That(x.CTime, Is.EqualTo(y.CTime)); + } } [Test] @@ -727,9 +766,9 @@ public async Task TestDateTimeCopyFrom(int batchSize, short? cYear, DateTime? cD [TestCase(10, null, null, null, null, null, null, null)] public async Task TestBinaryCopyFrom(int batchSize, byte? cBit, byte[] cBinary, byte[] cVarbinary, byte[] cTinyblob, byte[] cBlob, byte[] cMediumblob, byte[] cLongblob) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CBit = cBit, CBinary = cBinary, CVarbinary = cVarbinary, CTinyblob = cTinyblob, CBlob = cBlob, CMediumblob = cMediumblob, CLongblob = cLongblob }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlBinaryTypesBatchArgs { CBit = cBit, CBinary = cBinary, CVarbinary = cVarbinary, CTinyblob = cTinyblob, CBlob = cBlob, CMediumblob = cMediumblob, CLongblob = cLongblob }).ToList(); + await QuerySql.InsertMysqlBinaryTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlBinaryTypesCntRow { Cnt = batchSize, CBit = cBit, @@ -740,39 +779,76 @@ public async Task TestBinaryCopyFrom(int batchSize, byte? cBit, byte[] cBinary, CMediumblob = cMediumblob, CLongblob = cLongblob }; - var actual = await QuerySql.GetMysqlTypesCnt(); - Assert.That(actual.Cnt, Is.EqualTo(expected.Cnt)); - Assert.That(actual.CBit, Is.EqualTo(expected.CBit)); - Assert.That(actual.CBinary, Is.EqualTo(expected.CBinary)); - Assert.That(actual.CVarbinary, Is.EqualTo(expected.CVarbinary)); - Assert.That(actual.CTinyblob, Is.EqualTo(expected.CTinyblob)); - Assert.That(actual.CBlob, Is.EqualTo(expected.CBlob)); - Assert.That(actual.CMediumblob, Is.EqualTo(expected.CMediumblob)); - Assert.That(actual.CLongblob, Is.EqualTo(expected.CLongblob)); + var actual = await QuerySql.GetMysqlBinaryTypesCnt(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlBinaryTypesCntRow x, QuerySql.GetMysqlBinaryTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CBit, Is.EqualTo(y.CBit)); + Assert.That(x.CBinary, Is.EqualTo(y.CBinary)); + Assert.That(x.CVarbinary, Is.EqualTo(y.CVarbinary)); + Assert.That(x.CTinyblob, Is.EqualTo(y.CTinyblob)); + Assert.That(x.CBlob, Is.EqualTo(y.CBlob)); + Assert.That(x.CMediumblob, Is.EqualTo(y.CMediumblob)); + Assert.That(x.CLongblob, Is.EqualTo(y.CLongblob)); + } + } + + private static IEnumerable MySqlEnumCopyFromTestCases + { + get + { + yield return new TestCaseData(100, MysqlStringTypesCEnum.Big, new HashSet { MysqlStringTypesCSet.Tea, MysqlStringTypesCSet.Coffee }).SetName("Valid Enum values"); + yield return new TestCaseData(10, null, null).SetName("Enum with null values"); + } } [Test] - [TestCase(100, MysqlTypesCEnum.Big, new[] { MysqlTypesCSet.Tea, MysqlTypesCSet.Coffee })] - [TestCase(500, MysqlTypesCEnum.Small, new[] { MysqlTypesCSet.Milk })] - [TestCase(10, null, null)] - public async Task TestCopyFrom(int batchSize, MysqlTypesCEnum? cEnum, MysqlTypesCSet[] cSet) + [TestCaseSource(nameof(MySqlEnumCopyFromTestCases))] + public async Task TestCopyFrom(int batchSize, MysqlStringTypesCEnum? cEnum, HashSet cSet) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlTypesBatchArgs { CEnum = cEnum, CSet = cSet }).ToList(); - await QuerySql.InsertMysqlTypesBatch(batchArgs); - var expected = new QuerySql.GetMysqlTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlStringTypesBatchArgs { CEnum = cEnum, CSet = cSet }).ToList(); + await QuerySql.InsertMysqlStringTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlStringTypesCntRow { Cnt = batchSize, CEnum = cEnum, CSet = cSet }; - var actual = await QuerySql.GetMysqlTypesCnt(); + var actual = await QuerySql.GetMysqlStringTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetMysqlTypesCntRow x, QuerySql.GetMysqlTypesCntRow y) + void AssertSingularEquals(QuerySql.GetMysqlStringTypesCntRow x, QuerySql.GetMysqlStringTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CEnum, Is.EqualTo(y.CEnum)); Assert.That(x.CSet, Is.EqualTo(y.CSet)); } } + + [Test] + [TestCase(100, "{\"name\": \"Swordfishtrombones\", \"year\": 1983}")] + [TestCase(10, null)] + public async Task TestJsonCopyFrom(int batchSize, string cJson) + { + JsonElement? cParsedJson = null; + if (cJson != null) + cParsedJson = JsonDocument.Parse(cJson).RootElement; + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertMysqlStringTypesBatchArgs { CJson = cParsedJson }).ToList(); + await QuerySql.InsertMysqlStringTypesBatch(batchArgs); + var expected = new QuerySql.GetMysqlStringTypesCntRow + { + Cnt = batchSize, + CJson = cParsedJson + }; + var actual = await QuerySql.GetMysqlStringTypesCnt(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetMysqlStringTypesCntRow x, QuerySql.GetMysqlStringTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); + if (x.CJson.HasValue) + Assert.That(x.CJson.Value.GetRawText(), Is.EqualTo(y.CJson.Value.GetRawText())); + } + } } } diff --git a/end2end/EndToEndTestsLegacy/NpgsqlDapperTester.cs b/end2end/EndToEndTestsLegacy/NpgsqlDapperTester.cs index faf30835..faab83e5 100644 --- a/end2end/EndToEndTestsLegacy/NpgsqlDapperTester.cs +++ b/end2end/EndToEndTestsLegacy/NpgsqlDapperTester.cs @@ -14,9 +14,13 @@ public partial class NpgsqlDapperTester public async Task EmptyTestsTable() { await QuerySql.TruncateAuthors(); - await QuerySql.TruncatePostgresTypes(); + await QuerySql.TruncatePostgresNumericTypes(); + await QuerySql.TruncatePostgresStringTypes(); + await QuerySql.TruncatePostgresDateTimeTypes(); await QuerySql.TruncatePostgresGeoTypes(); + await QuerySql.TruncatePostgresNetworkTypes(); await QuerySql.TruncatePostgresArrayTypes(); + await QuerySql.TruncatePostgresSpecialTypes(); } } } \ No newline at end of file diff --git a/end2end/EndToEndTestsLegacy/NpgsqlDapperTester.generated.cs b/end2end/EndToEndTestsLegacy/NpgsqlDapperTester.generated.cs index c96eab8b..3ff92ed6 100644 --- a/end2end/EndToEndTestsLegacy/NpgsqlDapperTester.generated.cs +++ b/end2end/EndToEndTestsLegacy/NpgsqlDapperTester.generated.cs @@ -28,12 +28,13 @@ public async Task TestOne() Bio = "Back in the 90s he was in a very famous TV show" }; var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -58,21 +59,18 @@ public async Task TestMany() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) - { - Assert.That(x.Id, Is.EqualTo(y.Id)); - Assert.That(x.Name, Is.EqualTo(y.Name)); - Assert.That(x.Bio, Is.EqualTo(y.Bio)); - } + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } - private static void AssertSequenceEquals(List x, List y) - { - Assert.That(x.Count, Is.EqualTo(y.Count)); - for (int i = 0; i < x.Count; i++) + void AssertSequenceEquals(List x, List y) { - AssertSingularEquals(x[i], y[i]); + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); } } @@ -110,6 +108,19 @@ public async Task TestExecRows() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -123,12 +134,13 @@ public async Task TestExecLastId() Bio = "Quote that everyone always attribute to Einstein" }; var actual = await QuerySql.GetAuthorById(new QuerySql.GetAuthorByIdArgs { Id = id1 }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -155,19 +167,23 @@ public async Task TestSelfJoinEmbed() } }; var actual = await QuerySql.GetDuplicateAuthors(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) - { - return SingularEquals(x.Author, y.Author) && SingularEquals(x.Author2, y.Author2); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) + { + Assert.That(x.Author.Id, Is.EqualTo(y.Author.Id)); + Assert.That(x.Author.Name, Is.EqualTo(y.Author.Name)); + Assert.That(x.Author.Bio, Is.EqualTo(y.Author.Bio)); + Assert.That(x.Author2.Id, Is.EqualTo(y.Author2.Id)); + Assert.That(x.Author2.Name, Is.EqualTo(y.Author2.Name)); + Assert.That(x.Author2.Bio, Is.EqualTo(y.Author2.Bio)); + } - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -211,31 +227,23 @@ public async Task TestJoinEmbed() } }; var actual = await QuerySql.ListAllAuthorsBooks(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) - { - return SingularEquals(x.Author, y.Author) && SingularEquals(x.Book, y.Book); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Author.Name + o.Book.Name).ToList(); - y = y.OrderBy(o => o.Author.Name + o.Book.Name).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } - - private static bool SingularEquals(Author x, Author y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) + { + Assert.That(x.Author.Id, Is.EqualTo(y.Author.Id)); + Assert.That(x.Author.Name, Is.EqualTo(y.Author.Name)); + Assert.That(x.Author.Bio, Is.EqualTo(y.Author.Bio)); + Assert.That(x.Book.Id, Is.EqualTo(y.Book.Id)); + Assert.That(x.Book.AuthorId, Is.EqualTo(y.Book.AuthorId)); + Assert.That(x.Book.Name, Is.EqualTo(y.Book.Name)); + } - private static bool SingularEquals(Book x, Book y) - { - return x.Id.Equals(y.Id) && x.AuthorId.Equals(y.AuthorId) && x.Name.Equals(y.Name); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -259,21 +267,20 @@ public async Task TestNargNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs()); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Id).ToList(); - y = y.OrderBy(o => o.Id).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } - private static bool SingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -291,7 +298,116 @@ public async Task TestNargNotNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs { NamePattern = "Bojack%" }); - Assert.That(SequenceEquals(expected, actual)); + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } + + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + } + + [Test] + public async Task TestPostgresTransaction() + { + var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv)); + await connection.OpenAsync(); + var transaction = connection.BeginTransaction(); + var querySqlWithTx = QuerySql.WithTransaction(transaction); + await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + ClassicAssert.IsNull(actual); + await transaction.CommitAsync(); + var expected = new QuerySql.GetAuthorRow + { + Id = 1111, + Name = "Bojack Horseman", + Bio = "Back in the 90s he was in a very famous TV show" + }; + actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + } + + [Test] + public async Task TestPostgresTransactionRollback() + { + var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv)); + await connection.OpenAsync(); + var transaction = connection.BeginTransaction(); + var sqlQueryWithTx = QuerySql.WithTransaction(transaction); + await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + await transaction.RollbackAsync(); + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + ClassicAssert.IsNull(actual); + } + + [Test] + public async Task TestArray() + { + var id1 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Quote that everyone always attribute to Einstein" }); + var bojackId = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + var actual = await QuerySql.GetAuthorsByIds(new QuerySql.GetAuthorsByIdsArgs { LongArr1 = new[] { id1, bojackId } }); + ClassicAssert.AreEqual(2, actual.Count); + } + + [Test] + public async Task TestMultipleArrays() + { + var id1 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Quote that everyone always attribute to Einstein" }); + var id2 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Only 2 things are infinite, the universe and human stupidity" }); + var bojackId = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + var actual = await QuerySql.GetAuthorsByIdsAndNames(new QuerySql.GetAuthorsByIdsAndNamesArgs { LongArr1 = new[] { id1, bojackId }, StringArr2 = new[] { "Albert Einstein" } }); + ClassicAssert.AreEqual(1, actual.Count); + } + + [Test] + [TestCase(-54355, "White Light from the Mouth of Infinity", "2022-10-2 15:44:01+09:00")] + [TestCase(null, null, "1970-01-01 00:00:00")] + public async Task TestPostgresDataTypesOverride(int? cInteger, string cVarchar, DateTime cTimestamp) + { + await QuerySql.InsertPostgresNumericTypes(new QuerySql.InsertPostgresNumericTypesArgs { CInteger = cInteger }); + await QuerySql.InsertPostgresDateTimeTypes(new QuerySql.InsertPostgresDateTimeTypesArgs { CTimestamp = cTimestamp }); + await QuerySql.InsertPostgresStringTypes(new QuerySql.InsertPostgresStringTypesArgs { CVarchar = cVarchar }); + var expected = new QuerySql.GetPostgresFunctionsRow + { + MaxInteger = cInteger, + MaxVarchar = cVarchar, + MaxTimestamp = cTimestamp + }; + var actual = await QuerySql.GetPostgresFunctions(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresFunctionsRow x, QuerySql.GetPostgresFunctionsRow y) + { + Assert.That(x.MaxInteger, Is.EqualTo(y.MaxInteger)); + Assert.That(x.MaxVarchar, Is.EqualTo(y.MaxVarchar)); + Assert.That(x.MaxTimestamp, Is.EqualTo(y.MaxTimestamp)); + } + } + + [Test] + public void TestPostgresInvalidJson() + { + Assert.ThrowsAsync(async () => await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CJsonStringOverride = "SOME INVALID JSON" })); + Assert.ThrowsAsync(async () => await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CJsonpath = "SOME INVALID JSONPATH" })); + } + + [Test] + public void TestPostgresInvalidXml() + { + Assert.ThrowsAsync(async () => await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CXmlStringOverride = "SOME INVALID XML" })); } [Test] @@ -299,8 +415,8 @@ public async Task TestNargNotNull() [TestCase(null, null, null, null, null)] public async Task TestPostgresStringTypes(string cChar, string cVarchar, string cCharacterVarying, string cBpchar, string cText) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CBpchar = cBpchar, CText = cText, }); - var expected = new QuerySql.GetPostgresTypesRow + await QuerySql.InsertPostgresStringTypes(new QuerySql.InsertPostgresStringTypesArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CBpchar = cBpchar, CText = cText, }); + var expected = new QuerySql.GetPostgresStringTypesRow { CChar = cChar, CVarchar = cVarchar, @@ -308,9 +424,9 @@ public async Task TestPostgresStringTypes(string cChar, string cVarchar, string CBpchar = cBpchar, CText = cText, }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresStringTypes(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresStringTypesRow x, QuerySql.GetPostgresStringTypesRow y) { Assert.That(x.CChar, Is.EqualTo(y.CChar)); Assert.That(x.CVarchar, Is.EqualTo(y.CVarchar)); @@ -325,19 +441,23 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTy [TestCase(null, null, null, null)] public async Task TestPostgresIntegerTypes(bool cBoolean, short cSmallint, int cInteger, long cBigint) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }); - var expected = new QuerySql.GetPostgresTypesRow + await QuerySql.InsertPostgresNumericTypes(new QuerySql.InsertPostgresNumericTypesArgs { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }); + var expected = new QuerySql.GetPostgresNumericTypesRow { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }; - var actual = await QuerySql.GetPostgresTypes(); - Assert.That(actual.CBoolean, Is.EqualTo(expected.CBoolean)); - Assert.That(actual.CSmallint, Is.EqualTo(expected.CSmallint)); - Assert.That(actual.CInteger, Is.EqualTo(expected.CInteger)); - Assert.That(actual.CBigint, Is.EqualTo(expected.CBigint)); + var actual = await QuerySql.GetPostgresNumericTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresNumericTypesRow x, QuerySql.GetPostgresNumericTypesRow y) + { + Assert.That(x.CBoolean, Is.EqualTo(y.CBoolean)); + Assert.That(x.CSmallint, Is.EqualTo(y.CSmallint)); + Assert.That(x.CInteger, Is.EqualTo(y.CInteger)); + Assert.That(x.CBigint, Is.EqualTo(y.CBigint)); + } } [Test] @@ -345,8 +465,8 @@ public async Task TestPostgresIntegerTypes(bool cBoolean, short cSmallint, int c [TestCase(null, null, null, null, null)] public async Task TestPostgresFloatingPointTypes(float? cReal, decimal? cNumeric, decimal? cDecimal, double? cDoublePrecision, decimal? cMoney) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CReal = cReal, CNumeric = cNumeric, CDecimal = cDecimal, CDoublePrecision = cDoublePrecision, CMoney = cMoney }); - var expected = new QuerySql.GetPostgresTypesRow + await QuerySql.InsertPostgresNumericTypes(new QuerySql.InsertPostgresNumericTypesArgs { CReal = cReal, CNumeric = cNumeric, CDecimal = cDecimal, CDoublePrecision = cDoublePrecision, CMoney = cMoney }); + var expected = new QuerySql.GetPostgresNumericTypesRow { CReal = cReal, CNumeric = cNumeric, @@ -354,9 +474,9 @@ public async Task TestPostgresFloatingPointTypes(float? cReal, decimal? cNumeric CDoublePrecision = cDoublePrecision, CMoney = cMoney }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresNumericTypes(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresNumericTypesRow x, QuerySql.GetPostgresNumericTypesRow y) { Assert.That(x.CReal, Is.EqualTo(y.CReal)); Assert.That(x.CNumeric, Is.EqualTo(y.CNumeric)); @@ -371,8 +491,8 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTy [TestCase(null, null, null, null, null)] public async Task TestPostgresDateTimeTypes(DateTime? cDate, TimeSpan? cTime, DateTime? cTimestamp, DateTime? cTimestampWithTz, TimeSpan? cInterval) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CDate = cDate, CTime = cTime, CTimestamp = cTimestamp, CTimestampWithTz = cTimestampWithTz, CInterval = cInterval }); - var expected = new QuerySql.GetPostgresTypesRow + await QuerySql.InsertPostgresDateTimeTypes(new QuerySql.InsertPostgresDateTimeTypesArgs { CDate = cDate, CTime = cTime, CTimestamp = cTimestamp, CTimestampWithTz = cTimestampWithTz, CInterval = cInterval }); + var expected = new QuerySql.GetPostgresDateTimeTypesRow { CDate = cDate, CTime = cTime, @@ -380,9 +500,9 @@ public async Task TestPostgresDateTimeTypes(DateTime? cDate, TimeSpan? cTime, Da CTimestampWithTz = cTimestampWithTz, CInterval = cInterval }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresDateTimeTypes(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresDateTimeTypesRow x, QuerySql.GetPostgresDateTimeTypesRow y) { Assert.That(x.CDate, Is.EqualTo(y.CDate)); Assert.That(x.CTime, Is.EqualTo(y.CTime)); @@ -431,52 +551,198 @@ void AssertSingularEquals(QuerySql.GetPostgresArrayTypesRow x, QuerySql.GetPostg } } + private static IEnumerable PostgresGuidDataTypesTestCases + { + get + { + yield return new TestCaseData(Guid.NewGuid()).SetName("Valid Guid"); + yield return new TestCaseData(null).SetName("Null Guid"); + } + } + [Test] - [TestCase(-54355, "White Light from the Mouth of Infinity", "2022-10-2 15:44:01+09:00")] - [TestCase(null, null, "1970-01-01 00:00:00")] - public async Task TestPostgresDataTypesOverride(int? cInteger, string cVarchar, DateTime cTimestamp) + [TestCaseSource(nameof(PostgresGuidDataTypesTestCases))] + public async Task TestPostgresGuidDataTypes(Guid? cUuid) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CInteger = cInteger, CVarchar = cVarchar, CTimestamp = cTimestamp }); - var expected = new QuerySql.GetPostgresFunctionsRow + await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CUuid = cUuid }); + var expected = new QuerySql.GetPostgresSpecialTypesRow { - MaxInteger = cInteger, - MaxVarchar = cVarchar, - MaxTimestamp = cTimestamp + CUuid = cUuid }; - var actual = await QuerySql.GetPostgresFunctions(); + var actual = await QuerySql.GetPostgresSpecialTypes(); AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPostgresSpecialTypesRow y) + { + Assert.That(x.CUuid, Is.EqualTo(y.CUuid)); + } } - private static void AssertSingularEquals(QuerySql.GetPostgresFunctionsRow expected, QuerySql.GetPostgresFunctionsRow actual) + [Test] + [Obsolete] // due to NpgsqlTsVector.Parse usage + public async Task TestPostgresFullTextSearchDataTypes() { - Assert.That(actual.MaxInteger, Is.EqualTo(expected.MaxInteger)); - Assert.That(actual.MaxVarchar, Is.EqualTo(expected.MaxVarchar)); - Assert.That(actual.MaxTimestamp, Is.EqualTo(expected.MaxTimestamp)); + await QuerySql.InsertPostgresStringTypes(new QuerySql.InsertPostgresStringTypesArgs { CText = "Hello world" }); + var actual = await QuerySql.GetPostgresStringTypesTextSearch(new QuerySql.GetPostgresStringTypesTextSearchArgs { ToTsquery = "Hello" }); + var expected = new QuerySql.GetPostgresStringTypesTextSearchRow + { + CText = "Hello world", + Query = new NpgsqlTsQueryLexeme("hello"), + Tsv = NpgsqlTsVector.Parse("hello:1 world:2"), + Rnk = 0.07f + }; + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresStringTypesTextSearchRow x, QuerySql.GetPostgresStringTypesTextSearchRow y) + { + Assert.That(y.CText, Is.EqualTo(x.CText)); + Assert.That(y.Query.ToString(), Is.EqualTo(x.Query.ToString())); + Assert.That(y.Tsv.ToString(), Is.EqualTo(x.Tsv.ToString())); + Assert.That(y.Rnk, Is.AtMost(x.Rnk)); + } } - private static IEnumerable PostgresGuidDataTypesTestCases + private static IEnumerable PostgresNetworkDataTypesTestCases { get { - yield return new TestCaseData(Guid.NewGuid()).SetName("Valid Guid"); - yield return new TestCaseData(null).SetName("Null Guid"); + yield return new TestCaseData(new NpgsqlCidr("192.168.1.0/24"), new IPAddress(new byte[] { 192, 168, 1, 1 }), new PhysicalAddress(new byte[] { 0x00, 0x1A, 0x2B, 0x3C, 0x4D, 0x5E }), "00:1a:2b:ff:fe:3c:4d:5e").SetName("Valid Network Data Types"); + yield return new TestCaseData(null, null, null, null).SetName("Null Network Data Types"); } } [Test] - [TestCaseSource(nameof(PostgresGuidDataTypesTestCases))] - public async Task TestPostgresGuidDataTypes(Guid? cUuid) + [TestCaseSource(nameof(PostgresNetworkDataTypesTestCases))] + public async Task TestPostgresNetworkDataTypes(NpgsqlCidr? cCidr, IPAddress cInet, PhysicalAddress cMacaddr, string cMacaddr8) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CUuid = cUuid }); - var expected = new QuerySql.GetPostgresTypesRow + await QuerySql.InsertPostgresNetworkTypes(new QuerySql.InsertPostgresNetworkTypesArgs { CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr, CMacaddr8 = cMacaddr8 }); + var expected = new QuerySql.GetPostgresNetworkTypesRow { - CUuid = cUuid + CCidr = cCidr, + CInet = cInet, + CMacaddr = cMacaddr, + CMacaddr8 = cMacaddr8 }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresNetworkTypes(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresNetworkTypesRow x, QuerySql.GetPostgresNetworkTypesRow y) { - Assert.That(x.CUuid, Is.EqualTo(y.CUuid)); + Assert.That(x.CCidr, Is.EqualTo(y.CCidr)); + Assert.That(x.CInet, Is.EqualTo(y.CInet)); + Assert.That(x.CMacaddr, Is.EqualTo(y.CMacaddr)); + Assert.That(x.CMacaddr8, Is.EqualTo(y.CMacaddr8)); + } + } + + private static IEnumerable PostgresGeoTypesTestCases + { + get + { + yield return new TestCaseData(new NpgsqlPoint(1, 2), new NpgsqlLine(3, 4, 5), new NpgsqlLSeg(1, 2, 3, 4), new NpgsqlBox(1, 2, 3, 4), new NpgsqlPath(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlPolygon(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlCircle(1, 2, 3)).SetName("Valid Geo Types"); + yield return new TestCaseData(null, null, null, null, null, null, null).SetName("Null Geo Types"); + } + } + + [Test] + [TestCaseSource(nameof(PostgresGeoTypesTestCases))] + public async Task TestPostgresGeoTypes(NpgsqlPoint? cPoint, NpgsqlLine? cLine, NpgsqlLSeg? cLSeg, NpgsqlBox? cBox, NpgsqlPath? cPath, NpgsqlPolygon? cPolygon, NpgsqlCircle? cCircle) + { + await QuerySql.InsertPostgresGeoTypes(new QuerySql.InsertPostgresGeoTypesArgs { CPoint = cPoint, CLine = cLine, CLseg = cLSeg, CBox = cBox, CPath = cPath, CPolygon = cPolygon, CCircle = cCircle }); + var expected = new QuerySql.GetPostgresGeoTypesRow + { + CPoint = cPoint, + CLine = cLine, + CLseg = cLSeg, + CBox = cBox, + CPath = cPath, + CPolygon = cPolygon, + CCircle = cCircle + }; + var actual = await QuerySql.GetPostgresGeoTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresGeoTypesRow x, QuerySql.GetPostgresGeoTypesRow y) + { + Assert.That(x.CPoint, Is.EqualTo(y.CPoint)); + Assert.That(x.CLine, Is.EqualTo(y.CLine)); + Assert.That(x.CLseg, Is.EqualTo(y.CLseg)); + Assert.That(x.CBox, Is.EqualTo(y.CBox)); + Assert.That(x.CPath, Is.EqualTo(y.CPath)); + Assert.That(x.CPolygon, Is.EqualTo(y.CPolygon)); + Assert.That(x.CCircle, Is.EqualTo(y.CCircle)); + } + } + + [Test] + [TestCase("{\"name\": \"Swordfishtrombones\", \"year\": 1983}", "$.\"name\"")] + [TestCase(null, null)] + public async Task TestPostgresJsonDataTypes(string cJson, string cJsonpath) + { + JsonElement? cParsedJson = null; + if (cJson != null) + cParsedJson = JsonDocument.Parse(cJson).RootElement; + await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CJson = cParsedJson, CJsonb = cParsedJson, CJsonStringOverride = cJson, CJsonpath = cJsonpath }); + var expected = new QuerySql.GetPostgresSpecialTypesRow + { + CJson = cParsedJson, + CJsonb = cParsedJson, + CJsonStringOverride = cJson, + CJsonpath = cJsonpath + }; + var actual = await QuerySql.GetPostgresSpecialTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPostgresSpecialTypesRow y) + { + Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); + if (x.CJson.HasValue) + Assert.That(x.CJson.Value.GetRawText(), Is.EqualTo(y.CJson.Value.GetRawText())); + Assert.That(x.CJsonb.HasValue, Is.EqualTo(y.CJsonb.HasValue)); + if (x.CJsonb.HasValue) + Assert.That(x.CJsonb.Value.GetRawText(), Is.EqualTo(y.CJsonb.Value.GetRawText())); + Assert.That(x.CJsonStringOverride, Is.EqualTo(y.CJsonStringOverride)); + Assert.That(x.CJsonpath, Is.EqualTo(y.CJsonpath)); + } + } + + [Test] + [TestCase("Good morning xml, the world says hello")] + [TestCase(null)] + public async Task TestPostgresXmlDataTypes(string cXml) + { + XmlDocument parsedXml = null; + if (cXml != null) + { + parsedXml = new XmlDocument(); + parsedXml.LoadXml(cXml); + } + + await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CXml = parsedXml }); + var expected = new QuerySql.GetPostgresSpecialTypesRow + { + CXml = parsedXml + }; + var actual = await QuerySql.GetPostgresSpecialTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPostgresSpecialTypesRow y) + { + Assert.That(x.CXml == null, Is.EqualTo(y.CXml == null)); + if (x.CXml != null) + Assert.That(x.CXml.OuterXml, Is.EqualTo(y.CXml.OuterXml)); + } + } + + [Test] + [TestCase(CEnum.Medium)] + [TestCase(null)] + public async Task TestPostgresStringTypes(CEnum? cEnum) + { + await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CEnum = cEnum }); + var expected = new QuerySql.GetPostgresSpecialTypesRow + { + CEnum = cEnum + }; + var actual = await QuerySql.GetPostgresSpecialTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPostgresSpecialTypesRow y) + { + Assert.That(x.CEnum, Is.EqualTo(y.CEnum)); } } @@ -485,9 +751,9 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTy [TestCase(10, null, null, null, null, null)] public async Task TestStringCopyFrom(int batchSize, string cChar, string cVarchar, string cCharacterVarying, string cBpchar, string cText) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CBpchar = cBpchar, CText = cText }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresStringTypesBatchArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CBpchar = cBpchar, CText = cText }).ToList(); + await QuerySql.InsertPostgresStringTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresStringTypesCntRow { Cnt = batchSize, CChar = cChar, @@ -496,9 +762,9 @@ public async Task TestStringCopyFrom(int batchSize, string cChar, string cVarcha CBpchar = cBpchar, CText = cText }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresStringTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresStringTypesCntRow x, QuerySql.GetPostgresStringTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CChar, Is.EqualTo(y.CChar)); @@ -509,49 +775,14 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgre } } - [Test] - public async Task TestPostgresTransaction() - { - var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv)); - await connection.OpenAsync(); - var transaction = connection.BeginTransaction(); - var querySqlWithTx = QuerySql.WithTransaction(transaction); - await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - // The GetAuthor method in NpgsqlExampleGen returns QuerySql.GetAuthorRow? (nullable record struct) - var actualNull = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actualNull == null, "there is author"); // This is correct for nullable types - await transaction.CommitAsync(); - var expected = new QuerySql.GetAuthorRow - { - Id = 1111, - Name = "Bojack Horseman", - Bio = "Back in the 90s he was in a very famous TV show" - }; - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual)); // Apply placeholder here - } - - [Test] - public async Task TestPostgresTransactionRollback() - { - var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv)); - await connection.OpenAsync(); - var transaction = connection.BeginTransaction(); - var sqlQueryWithTx = QuerySql.WithTransaction(transaction); - await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - await transaction.RollbackAsync(); - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actual == null, "author should not exist after rollback"); - } - [Test] [TestCase(100, true, 3, 453, -1445214231L)] [TestCase(10, null, null, null, null)] public async Task TestIntegerCopyFrom(int batchSize, bool? cBoolean, short? cSmallint, int? cInteger, long? cBigint) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresNumericTypesBatchArgs { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }).ToList(); + await QuerySql.InsertPostgresNumericTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresNumericTypesCntRow { Cnt = batchSize, CBoolean = cBoolean, @@ -559,9 +790,9 @@ public async Task TestIntegerCopyFrom(int batchSize, bool? cBoolean, short? cSma CInteger = cInteger, CBigint = cBigint }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresNumericTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresNumericTypesCntRow x, QuerySql.GetPostgresNumericTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CBoolean, Is.EqualTo(y.CBoolean)); @@ -576,9 +807,9 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgre [TestCase(10, null, null, null, null, null)] public async Task TestFloatingPointCopyFrom(int batchSize, float? cReal, decimal? cDecimal, decimal? cNumeric, double? cDoublePrecision, decimal? cMoney) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CReal = cReal, CDecimal = cDecimal, CNumeric = cNumeric, CDoublePrecision = cDoublePrecision, CMoney = cMoney }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresNumericTypesBatchArgs { CReal = cReal, CDecimal = cDecimal, CNumeric = cNumeric, CDoublePrecision = cDoublePrecision, CMoney = cMoney }).ToList(); + await QuerySql.InsertPostgresNumericTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresNumericTypesCntRow { Cnt = batchSize, CReal = cReal, @@ -587,9 +818,9 @@ public async Task TestFloatingPointCopyFrom(int batchSize, float? cReal, decimal CDoublePrecision = cDoublePrecision, CMoney = cMoney }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresNumericTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresNumericTypesCntRow x, QuerySql.GetPostgresNumericTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CReal, Is.EqualTo(y.CReal)); @@ -608,9 +839,9 @@ public async Task TestDateTimeCopyFrom(int batchSize, DateTime? cDate, TimeSpan? DateTime? cTimestampWithTzAsUtc = null; if (cTimestampWithTz != null) cTimestampWithTzAsUtc = DateTime.SpecifyKind(cTimestampWithTz.Value, DateTimeKind.Utc); - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CDate = cDate, CTime = cTime, CTimestamp = cTimestamp, CTimestampWithTz = cTimestampWithTzAsUtc, CInterval = cInterval }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresDateTimeTypesBatchArgs { CDate = cDate, CTime = cTime, CTimestamp = cTimestamp, CTimestampWithTz = cTimestampWithTzAsUtc, CInterval = cInterval }).ToList(); + await QuerySql.InsertPostgresDateTimeTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresDateTimeTypesCntRow { Cnt = batchSize, CDate = cDate, @@ -619,9 +850,9 @@ public async Task TestDateTimeCopyFrom(int batchSize, DateTime? cDate, TimeSpan? CTimestampWithTz = cTimestampWithTz, CInterval = cInterval }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresDateTimeTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresDateTimeTypesCntRow x, QuerySql.GetPostgresDateTimeTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CDate, Is.EqualTo(y.CDate)); @@ -645,16 +876,16 @@ private static IEnumerable PostgresGuidCopyFromTestCases [TestCaseSource(nameof(PostgresGuidCopyFromTestCases))] public async Task TestPostgresGuidCopyFrom(int batchSize, Guid? cUuid) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CUuid = cUuid }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresSpecialTypesBatchArgs { CUuid = cUuid }).ToList(); + await QuerySql.InsertPostgresSpecialTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresSpecialTypesCntRow { Cnt = batchSize, CUuid = cUuid }; - var actual = await QuerySql.GetPostgresTypesCnt(); - Assert.That(actual.Cnt, Is.EqualTo(expected.Cnt)); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + var actual = await QuerySql.GetPostgresSpecialTypesCnt(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesCntRow x, QuerySql.GetPostgresSpecialTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CUuid, Is.EqualTo(y.CUuid)); @@ -674,18 +905,18 @@ private static IEnumerable PostgresNetworkCopyFromTestCases [TestCaseSource(nameof(PostgresNetworkCopyFromTestCases))] public async Task TestPostgresNetworkCopyFrom(int batchSize, NpgsqlCidr? cCidr, IPAddress cInet, PhysicalAddress cMacaddr) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresNetworkTypesBatchArgs { CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr }).ToList(); + await QuerySql.InsertPostgresNetworkTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresNetworkTypesCntRow { Cnt = batchSize, CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresNetworkTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresNetworkTypesCntRow x, QuerySql.GetPostgresNetworkTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CCidr, Is.EqualTo(y.CCidr)); @@ -694,62 +925,43 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgre } } - [Test] - [TestCase(100, new byte[] { 0x53, 0x56 })] - [TestCase(10, new byte[] { })] - [TestCase(10, null)] - public async Task TestArrayCopyFrom(int batchSize, byte[] cBytea) - { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresArrayTypesBatchArgs { CBytea = cBytea }).ToList(); - await QuerySql.InsertPostgresArrayTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresArrayTypesCntRow - { - Cnt = batchSize, - CBytea = cBytea - }; - var actual = await QuerySql.GetPostgresArrayTypesCnt(); - AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresArrayTypesCntRow x, QuerySql.GetPostgresArrayTypesCntRow y) - { - Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); - } - } - - private static IEnumerable PostgresGeoTypesTestCases + private static IEnumerable PostgresArrayCopyFromTestCases { get { - yield return new TestCaseData(new NpgsqlPoint(1, 2), new NpgsqlLine(3, 4, 5), new NpgsqlLSeg(1, 2, 3, 4), new NpgsqlBox(1, 2, 3, 4), new NpgsqlPath(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlPolygon(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlCircle(1, 2, 3)).SetName("Valid Geo Types"); - yield return new TestCaseData(null, null, null, null, null, null, null).SetName("Null Geo Types"); + yield return new TestCaseData(100, new byte[] { 0x53, 0x56 }, new bool[] { true, false }, new string[] { "Sister Ray", "Venus in Furs" }, new int[] { 1, 2 }, new decimal[] { 132.13m, 23.22m }, new DateTime[] { new DateTime(1984, 8, 26), new DateTime(2000, 1, 2) }).SetName("Valid Array Copy From"); + yield return new TestCaseData(10, new byte[] { }, new bool[] { }, new string[] { }, new int[] { }, new decimal[] { }, new DateTime[] { }).SetName("Empty Array Copy From"); + yield return new TestCaseData(10, null, null, null, null, null, null).SetName("Null Array Copy From"); } } [Test] - [TestCaseSource(nameof(PostgresGeoTypesTestCases))] - public async Task TestPostgresGeoTypes(NpgsqlPoint? cPoint, NpgsqlLine? cLine, NpgsqlLSeg? cLSeg, NpgsqlBox? cBox, NpgsqlPath? cPath, NpgsqlPolygon? cPolygon, NpgsqlCircle? cCircle) + [TestCaseSource(nameof(PostgresArrayCopyFromTestCases))] + public async Task TestArrayCopyFrom(int batchSize, byte[] cBytea, bool[] cBooleanArray, string[] cTextArray, int[] cIntegerArray, decimal[] cDecimalArray, DateTime[] cTimestampArray) { - await QuerySql.InsertPostgresGeoTypes(new QuerySql.InsertPostgresGeoTypesArgs { CPoint = cPoint, CLine = cLine, CLseg = cLSeg, CBox = cBox, CPath = cPath, CPolygon = cPolygon, CCircle = cCircle }); - var expected = new QuerySql.GetPostgresGeoTypesRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresArrayTypesBatchArgs { CBytea = cBytea, CBooleanArray = cBooleanArray, CTextArray = cTextArray, CIntegerArray = cIntegerArray, CDecimalArray = cDecimalArray, CTimestampArray = cTimestampArray }).ToList(); + await QuerySql.InsertPostgresArrayTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresArrayTypesCntRow { - CPoint = cPoint, - CLine = cLine, - CLseg = cLSeg, - CBox = cBox, - CPath = cPath, - CPolygon = cPolygon, - CCircle = cCircle + Cnt = batchSize, + CBytea = cBytea, + CBooleanArray = cBooleanArray, + CTextArray = cTextArray, + CIntegerArray = cIntegerArray, + CDecimalArray = cDecimalArray, + CTimestampArray = cTimestampArray }; - var actual = await QuerySql.GetPostgresGeoTypes(); + var actual = await QuerySql.GetPostgresArrayTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresGeoTypesRow x, QuerySql.GetPostgresGeoTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresArrayTypesCntRow x, QuerySql.GetPostgresArrayTypesCntRow y) { - Assert.That(x.CPoint, Is.EqualTo(y.CPoint)); - Assert.That(x.CLine, Is.EqualTo(y.CLine)); - Assert.That(x.CLseg, Is.EqualTo(y.CLseg)); - Assert.That(x.CBox, Is.EqualTo(y.CBox)); - Assert.That(x.CPath, Is.EqualTo(y.CPath)); - Assert.That(x.CPolygon, Is.EqualTo(y.CPolygon)); - Assert.That(x.CCircle, Is.EqualTo(y.CCircle)); + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CBytea, Is.EqualTo(y.CBytea)); + Assert.That(x.CBooleanArray, Is.EqualTo(y.CBooleanArray)); + Assert.That(x.CTextArray, Is.EqualTo(y.CTextArray)); + Assert.That(x.CIntegerArray, Is.EqualTo(y.CIntegerArray)); + Assert.That(x.CDecimalArray, Is.EqualTo(y.CDecimalArray)); + Assert.That(x.CTimestampArray, Is.EqualTo(y.CTimestampArray)); } } @@ -791,121 +1003,5 @@ void AssertSingularEquals(QuerySql.GetPostgresGeoTypesRow x, QuerySql.GetPostgre Assert.That(x.CCircle, Is.EqualTo(y.CCircle)); } } - - private static IEnumerable PostgresNetworkDataTypesTestCases - { - get - { - yield return new TestCaseData(new NpgsqlCidr("192.168.1.0/24"), new IPAddress(new byte[] { 192, 168, 1, 1 }), new PhysicalAddress(new byte[] { 0x00, 0x1A, 0x2B, 0x3C, 0x4D, 0x5E }), "00:1a:2b:ff:fe:3c:4d:5e").SetName("Valid Network Data Types"); - yield return new TestCaseData(null, null, null, null).SetName("Null Network Data Types"); - } - } - - [Test] - [TestCaseSource(nameof(PostgresNetworkDataTypesTestCases))] - public async Task TestPostgresNetworkDataTypes(NpgsqlCidr? cCidr, IPAddress cInet, PhysicalAddress cMacaddr, string cMacaddr8) - { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr, CMacaddr8 = cMacaddr8 }); - var expected = new QuerySql.GetPostgresTypesRow - { - CCidr = cCidr, - CInet = cInet, - CMacaddr = cMacaddr, - CMacaddr8 = cMacaddr8 - }; - var actual = await QuerySql.GetPostgresTypes(); - AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) - { - Assert.That(x.CCidr, Is.EqualTo(y.CCidr)); - Assert.That(x.CInet, Is.EqualTo(y.CInet)); - Assert.That(x.CMacaddr, Is.EqualTo(y.CMacaddr)); - Assert.That(x.CMacaddr8, Is.EqualTo(y.CMacaddr8)); - } - } - - [Test] - [TestCase("{\"name\": \"Swordfishtrombones\", \"year\": 1983}", "$.\"name\"")] - [TestCase(null, null)] - public async Task TestPostgresJsonDataTypes(string cJson, string cJsonpath) - { - JsonElement? cParsedJson = null; - if (cJson != null) - cParsedJson = JsonDocument.Parse(cJson).RootElement; - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CJson = cParsedJson, CJsonb = cParsedJson, CJsonStringOverride = cJson, CJsonpath = cJsonpath }); - var expected = new QuerySql.GetPostgresTypesRow - { - CJson = cParsedJson, - CJsonb = cParsedJson, - CJsonStringOverride = cJson, - CJsonpath = cJsonpath - }; - var actual = await QuerySql.GetPostgresTypes(); - AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) - { - Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); - if (x.CJson.HasValue) - Assert.That(x.CJson.Value.GetRawText(), Is.EqualTo(y.CJson.Value.GetRawText())); - Assert.That(x.CJsonb.HasValue, Is.EqualTo(y.CJsonb.HasValue)); - if (x.CJsonb.HasValue) - Assert.That(x.CJsonb.Value.GetRawText(), Is.EqualTo(y.CJsonb.Value.GetRawText())); - Assert.That(x.CJsonStringOverride, Is.EqualTo(y.CJsonStringOverride)); - Assert.That(x.CJsonpath, Is.EqualTo(y.CJsonpath)); - } - } - - [Test] - public void TestPostgresInvalidJson() - { - Assert.ThrowsAsync(async () => await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CJsonStringOverride = "SOME INVALID JSON" })); - Assert.ThrowsAsync(async () => await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CJsonpath = "SOME INVALID JSONPATH" })); - } - - [Test] - [TestCase("Good morning xml, the world says hello")] - [TestCase(null)] - public async Task TestPostgresXmlDataTypes(string cXml) - { - XmlDocument parsedXml = null; - if (cXml != null) - { - parsedXml = new XmlDocument(); - parsedXml.LoadXml(cXml); - } - - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CXml = parsedXml }); - var expected = new QuerySql.GetPostgresTypesRow - { - CXml = parsedXml - }; - var actual = await QuerySql.GetPostgresTypes(); - AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) - { - if (x.CXml == null && y.CXml == null) - return; - Assert.That(x.CXml.OuterXml, Is.EqualTo(y.CXml.OuterXml)); - } - } - - [Test] - public async Task TestArray() - { - var id1 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Quote that everyone always attribute to Einstein" }); - var bojackId = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - var actual = await QuerySql.GetAuthorsByIds(new QuerySql.GetAuthorsByIdsArgs { LongArr1 = new[] { id1, bojackId } }); - ClassicAssert.AreEqual(2, actual.Count); - } - - [Test] - public async Task TestMultipleArrays() - { - var id1 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Quote that everyone always attribute to Einstein" }); - var id2 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Only 2 things are infinite, the universe and human stupidity" }); - var bojackId = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - var actual = await QuerySql.GetAuthorsByIdsAndNames(new QuerySql.GetAuthorsByIdsAndNamesArgs { LongArr1 = new[] { id1, bojackId }, StringArr2 = new[] { "Albert Einstein" } }); - ClassicAssert.AreEqual(1, actual.Count); - } } } diff --git a/end2end/EndToEndTestsLegacy/NpgsqlTester.cs b/end2end/EndToEndTestsLegacy/NpgsqlTester.cs index 202843f4..94ffb27c 100644 --- a/end2end/EndToEndTestsLegacy/NpgsqlTester.cs +++ b/end2end/EndToEndTestsLegacy/NpgsqlTester.cs @@ -14,9 +14,13 @@ public partial class NpgsqlTester public async Task EmptyTestsTable() { await QuerySql.TruncateAuthors(); - await QuerySql.TruncatePostgresTypes(); + await QuerySql.TruncatePostgresNumericTypes(); + await QuerySql.TruncatePostgresStringTypes(); + await QuerySql.TruncatePostgresDateTimeTypes(); await QuerySql.TruncatePostgresGeoTypes(); + await QuerySql.TruncatePostgresNetworkTypes(); await QuerySql.TruncatePostgresArrayTypes(); + await QuerySql.TruncatePostgresSpecialTypes(); } } } \ No newline at end of file diff --git a/end2end/EndToEndTestsLegacy/NpgsqlTester.generated.cs b/end2end/EndToEndTestsLegacy/NpgsqlTester.generated.cs index 233f3dcd..2f985f5e 100644 --- a/end2end/EndToEndTestsLegacy/NpgsqlTester.generated.cs +++ b/end2end/EndToEndTestsLegacy/NpgsqlTester.generated.cs @@ -28,12 +28,13 @@ public async Task TestOne() Bio = "Back in the 90s he was in a very famous TV show" }; var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -58,21 +59,18 @@ public async Task TestMany() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) - { - Assert.That(x.Id, Is.EqualTo(y.Id)); - Assert.That(x.Name, Is.EqualTo(y.Name)); - Assert.That(x.Bio, Is.EqualTo(y.Bio)); - } + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } - private static void AssertSequenceEquals(List x, List y) - { - Assert.That(x.Count, Is.EqualTo(y.Count)); - for (int i = 0; i < x.Count; i++) + void AssertSequenceEquals(List x, List y) { - AssertSingularEquals(x[i], y[i]); + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); } } @@ -110,6 +108,19 @@ public async Task TestExecRows() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -123,12 +134,13 @@ public async Task TestExecLastId() Bio = "Quote that everyone always attribute to Einstein" }; var actual = await QuerySql.GetAuthorById(new QuerySql.GetAuthorByIdArgs { Id = id1 }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -155,19 +167,23 @@ public async Task TestSelfJoinEmbed() } }; var actual = await QuerySql.GetDuplicateAuthors(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) - { - return SingularEquals(x.Author, y.Author) && SingularEquals(x.Author2, y.Author2); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) + { + Assert.That(x.Author.Id, Is.EqualTo(y.Author.Id)); + Assert.That(x.Author.Name, Is.EqualTo(y.Author.Name)); + Assert.That(x.Author.Bio, Is.EqualTo(y.Author.Bio)); + Assert.That(x.Author2.Id, Is.EqualTo(y.Author2.Id)); + Assert.That(x.Author2.Name, Is.EqualTo(y.Author2.Name)); + Assert.That(x.Author2.Bio, Is.EqualTo(y.Author2.Bio)); + } - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -211,31 +227,23 @@ public async Task TestJoinEmbed() } }; var actual = await QuerySql.ListAllAuthorsBooks(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) - { - return SingularEquals(x.Author, y.Author) && SingularEquals(x.Book, y.Book); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Author.Name + o.Book.Name).ToList(); - y = y.OrderBy(o => o.Author.Name + o.Book.Name).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } - - private static bool SingularEquals(Author x, Author y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) + { + Assert.That(x.Author.Id, Is.EqualTo(y.Author.Id)); + Assert.That(x.Author.Name, Is.EqualTo(y.Author.Name)); + Assert.That(x.Author.Bio, Is.EqualTo(y.Author.Bio)); + Assert.That(x.Book.Id, Is.EqualTo(y.Book.Id)); + Assert.That(x.Book.AuthorId, Is.EqualTo(y.Book.AuthorId)); + Assert.That(x.Book.Name, Is.EqualTo(y.Book.Name)); + } - private static bool SingularEquals(Book x, Book y) - { - return x.Id.Equals(y.Id) && x.AuthorId.Equals(y.AuthorId) && x.Name.Equals(y.Name); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -259,21 +267,20 @@ public async Task TestNargNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs()); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Id).ToList(); - y = y.OrderBy(o => o.Id).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } - private static bool SingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -291,7 +298,116 @@ public async Task TestNargNotNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs { NamePattern = "Bojack%" }); - Assert.That(SequenceEquals(expected, actual)); + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } + + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + } + + [Test] + public async Task TestPostgresTransaction() + { + var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv)); + await connection.OpenAsync(); + var transaction = connection.BeginTransaction(); + var querySqlWithTx = QuerySql.WithTransaction(transaction); + await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + ClassicAssert.IsNull(actual); + await transaction.CommitAsync(); + var expected = new QuerySql.GetAuthorRow + { + Id = 1111, + Name = "Bojack Horseman", + Bio = "Back in the 90s he was in a very famous TV show" + }; + actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + } + + [Test] + public async Task TestPostgresTransactionRollback() + { + var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv)); + await connection.OpenAsync(); + var transaction = connection.BeginTransaction(); + var sqlQueryWithTx = QuerySql.WithTransaction(transaction); + await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + await transaction.RollbackAsync(); + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + ClassicAssert.IsNull(actual); + } + + [Test] + public async Task TestArray() + { + var id1 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Quote that everyone always attribute to Einstein" }); + var bojackId = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + var actual = await QuerySql.GetAuthorsByIds(new QuerySql.GetAuthorsByIdsArgs { LongArr1 = new[] { id1, bojackId } }); + ClassicAssert.AreEqual(2, actual.Count); + } + + [Test] + public async Task TestMultipleArrays() + { + var id1 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Quote that everyone always attribute to Einstein" }); + var id2 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Only 2 things are infinite, the universe and human stupidity" }); + var bojackId = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); + var actual = await QuerySql.GetAuthorsByIdsAndNames(new QuerySql.GetAuthorsByIdsAndNamesArgs { LongArr1 = new[] { id1, bojackId }, StringArr2 = new[] { "Albert Einstein" } }); + ClassicAssert.AreEqual(1, actual.Count); + } + + [Test] + [TestCase(-54355, "White Light from the Mouth of Infinity", "2022-10-2 15:44:01+09:00")] + [TestCase(null, null, "1970-01-01 00:00:00")] + public async Task TestPostgresDataTypesOverride(int? cInteger, string cVarchar, DateTime cTimestamp) + { + await QuerySql.InsertPostgresNumericTypes(new QuerySql.InsertPostgresNumericTypesArgs { CInteger = cInteger }); + await QuerySql.InsertPostgresDateTimeTypes(new QuerySql.InsertPostgresDateTimeTypesArgs { CTimestamp = cTimestamp }); + await QuerySql.InsertPostgresStringTypes(new QuerySql.InsertPostgresStringTypesArgs { CVarchar = cVarchar }); + var expected = new QuerySql.GetPostgresFunctionsRow + { + MaxInteger = cInteger, + MaxVarchar = cVarchar, + MaxTimestamp = cTimestamp + }; + var actual = await QuerySql.GetPostgresFunctions(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresFunctionsRow x, QuerySql.GetPostgresFunctionsRow y) + { + Assert.That(x.MaxInteger, Is.EqualTo(y.MaxInteger)); + Assert.That(x.MaxVarchar, Is.EqualTo(y.MaxVarchar)); + Assert.That(x.MaxTimestamp, Is.EqualTo(y.MaxTimestamp)); + } + } + + [Test] + public void TestPostgresInvalidJson() + { + Assert.ThrowsAsync(async () => await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CJsonStringOverride = "SOME INVALID JSON" })); + Assert.ThrowsAsync(async () => await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CJsonpath = "SOME INVALID JSONPATH" })); + } + + [Test] + public void TestPostgresInvalidXml() + { + Assert.ThrowsAsync(async () => await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CXmlStringOverride = "SOME INVALID XML" })); } [Test] @@ -299,8 +415,8 @@ public async Task TestNargNotNull() [TestCase(null, null, null, null, null)] public async Task TestPostgresStringTypes(string cChar, string cVarchar, string cCharacterVarying, string cBpchar, string cText) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CBpchar = cBpchar, CText = cText, }); - var expected = new QuerySql.GetPostgresTypesRow + await QuerySql.InsertPostgresStringTypes(new QuerySql.InsertPostgresStringTypesArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CBpchar = cBpchar, CText = cText, }); + var expected = new QuerySql.GetPostgresStringTypesRow { CChar = cChar, CVarchar = cVarchar, @@ -308,9 +424,9 @@ public async Task TestPostgresStringTypes(string cChar, string cVarchar, string CBpchar = cBpchar, CText = cText, }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresStringTypes(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresStringTypesRow x, QuerySql.GetPostgresStringTypesRow y) { Assert.That(x.CChar, Is.EqualTo(y.CChar)); Assert.That(x.CVarchar, Is.EqualTo(y.CVarchar)); @@ -325,19 +441,23 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTy [TestCase(null, null, null, null)] public async Task TestPostgresIntegerTypes(bool cBoolean, short cSmallint, int cInteger, long cBigint) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }); - var expected = new QuerySql.GetPostgresTypesRow + await QuerySql.InsertPostgresNumericTypes(new QuerySql.InsertPostgresNumericTypesArgs { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }); + var expected = new QuerySql.GetPostgresNumericTypesRow { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }; - var actual = await QuerySql.GetPostgresTypes(); - Assert.That(actual.CBoolean, Is.EqualTo(expected.CBoolean)); - Assert.That(actual.CSmallint, Is.EqualTo(expected.CSmallint)); - Assert.That(actual.CInteger, Is.EqualTo(expected.CInteger)); - Assert.That(actual.CBigint, Is.EqualTo(expected.CBigint)); + var actual = await QuerySql.GetPostgresNumericTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresNumericTypesRow x, QuerySql.GetPostgresNumericTypesRow y) + { + Assert.That(x.CBoolean, Is.EqualTo(y.CBoolean)); + Assert.That(x.CSmallint, Is.EqualTo(y.CSmallint)); + Assert.That(x.CInteger, Is.EqualTo(y.CInteger)); + Assert.That(x.CBigint, Is.EqualTo(y.CBigint)); + } } [Test] @@ -345,8 +465,8 @@ public async Task TestPostgresIntegerTypes(bool cBoolean, short cSmallint, int c [TestCase(null, null, null, null, null)] public async Task TestPostgresFloatingPointTypes(float? cReal, decimal? cNumeric, decimal? cDecimal, double? cDoublePrecision, decimal? cMoney) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CReal = cReal, CNumeric = cNumeric, CDecimal = cDecimal, CDoublePrecision = cDoublePrecision, CMoney = cMoney }); - var expected = new QuerySql.GetPostgresTypesRow + await QuerySql.InsertPostgresNumericTypes(new QuerySql.InsertPostgresNumericTypesArgs { CReal = cReal, CNumeric = cNumeric, CDecimal = cDecimal, CDoublePrecision = cDoublePrecision, CMoney = cMoney }); + var expected = new QuerySql.GetPostgresNumericTypesRow { CReal = cReal, CNumeric = cNumeric, @@ -354,9 +474,9 @@ public async Task TestPostgresFloatingPointTypes(float? cReal, decimal? cNumeric CDoublePrecision = cDoublePrecision, CMoney = cMoney }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresNumericTypes(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresNumericTypesRow x, QuerySql.GetPostgresNumericTypesRow y) { Assert.That(x.CReal, Is.EqualTo(y.CReal)); Assert.That(x.CNumeric, Is.EqualTo(y.CNumeric)); @@ -371,8 +491,8 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTy [TestCase(null, null, null, null, null)] public async Task TestPostgresDateTimeTypes(DateTime? cDate, TimeSpan? cTime, DateTime? cTimestamp, DateTime? cTimestampWithTz, TimeSpan? cInterval) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CDate = cDate, CTime = cTime, CTimestamp = cTimestamp, CTimestampWithTz = cTimestampWithTz, CInterval = cInterval }); - var expected = new QuerySql.GetPostgresTypesRow + await QuerySql.InsertPostgresDateTimeTypes(new QuerySql.InsertPostgresDateTimeTypesArgs { CDate = cDate, CTime = cTime, CTimestamp = cTimestamp, CTimestampWithTz = cTimestampWithTz, CInterval = cInterval }); + var expected = new QuerySql.GetPostgresDateTimeTypesRow { CDate = cDate, CTime = cTime, @@ -380,9 +500,9 @@ public async Task TestPostgresDateTimeTypes(DateTime? cDate, TimeSpan? cTime, Da CTimestampWithTz = cTimestampWithTz, CInterval = cInterval }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresDateTimeTypes(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresDateTimeTypesRow x, QuerySql.GetPostgresDateTimeTypesRow y) { Assert.That(x.CDate, Is.EqualTo(y.CDate)); Assert.That(x.CTime, Is.EqualTo(y.CTime)); @@ -431,52 +551,198 @@ void AssertSingularEquals(QuerySql.GetPostgresArrayTypesRow x, QuerySql.GetPostg } } + private static IEnumerable PostgresGuidDataTypesTestCases + { + get + { + yield return new TestCaseData(Guid.NewGuid()).SetName("Valid Guid"); + yield return new TestCaseData(null).SetName("Null Guid"); + } + } + [Test] - [TestCase(-54355, "White Light from the Mouth of Infinity", "2022-10-2 15:44:01+09:00")] - [TestCase(null, null, "1970-01-01 00:00:00")] - public async Task TestPostgresDataTypesOverride(int? cInteger, string cVarchar, DateTime cTimestamp) + [TestCaseSource(nameof(PostgresGuidDataTypesTestCases))] + public async Task TestPostgresGuidDataTypes(Guid? cUuid) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CInteger = cInteger, CVarchar = cVarchar, CTimestamp = cTimestamp }); - var expected = new QuerySql.GetPostgresFunctionsRow + await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CUuid = cUuid }); + var expected = new QuerySql.GetPostgresSpecialTypesRow { - MaxInteger = cInteger, - MaxVarchar = cVarchar, - MaxTimestamp = cTimestamp + CUuid = cUuid }; - var actual = await QuerySql.GetPostgresFunctions(); + var actual = await QuerySql.GetPostgresSpecialTypes(); AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPostgresSpecialTypesRow y) + { + Assert.That(x.CUuid, Is.EqualTo(y.CUuid)); + } } - private static void AssertSingularEquals(QuerySql.GetPostgresFunctionsRow expected, QuerySql.GetPostgresFunctionsRow actual) + [Test] + [Obsolete] // due to NpgsqlTsVector.Parse usage + public async Task TestPostgresFullTextSearchDataTypes() { - Assert.That(actual.MaxInteger, Is.EqualTo(expected.MaxInteger)); - Assert.That(actual.MaxVarchar, Is.EqualTo(expected.MaxVarchar)); - Assert.That(actual.MaxTimestamp, Is.EqualTo(expected.MaxTimestamp)); + await QuerySql.InsertPostgresStringTypes(new QuerySql.InsertPostgresStringTypesArgs { CText = "Hello world" }); + var actual = await QuerySql.GetPostgresStringTypesTextSearch(new QuerySql.GetPostgresStringTypesTextSearchArgs { ToTsquery = "Hello" }); + var expected = new QuerySql.GetPostgresStringTypesTextSearchRow + { + CText = "Hello world", + Query = new NpgsqlTsQueryLexeme("hello"), + Tsv = NpgsqlTsVector.Parse("hello:1 world:2"), + Rnk = 0.07f + }; + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresStringTypesTextSearchRow x, QuerySql.GetPostgresStringTypesTextSearchRow y) + { + Assert.That(y.CText, Is.EqualTo(x.CText)); + Assert.That(y.Query.ToString(), Is.EqualTo(x.Query.ToString())); + Assert.That(y.Tsv.ToString(), Is.EqualTo(x.Tsv.ToString())); + Assert.That(y.Rnk, Is.AtMost(x.Rnk)); + } } - private static IEnumerable PostgresGuidDataTypesTestCases + private static IEnumerable PostgresNetworkDataTypesTestCases { get { - yield return new TestCaseData(Guid.NewGuid()).SetName("Valid Guid"); - yield return new TestCaseData(null).SetName("Null Guid"); + yield return new TestCaseData(new NpgsqlCidr("192.168.1.0/24"), new IPAddress(new byte[] { 192, 168, 1, 1 }), new PhysicalAddress(new byte[] { 0x00, 0x1A, 0x2B, 0x3C, 0x4D, 0x5E }), "00:1a:2b:ff:fe:3c:4d:5e").SetName("Valid Network Data Types"); + yield return new TestCaseData(null, null, null, null).SetName("Null Network Data Types"); } } [Test] - [TestCaseSource(nameof(PostgresGuidDataTypesTestCases))] - public async Task TestPostgresGuidDataTypes(Guid? cUuid) + [TestCaseSource(nameof(PostgresNetworkDataTypesTestCases))] + public async Task TestPostgresNetworkDataTypes(NpgsqlCidr? cCidr, IPAddress cInet, PhysicalAddress cMacaddr, string cMacaddr8) { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CUuid = cUuid }); - var expected = new QuerySql.GetPostgresTypesRow + await QuerySql.InsertPostgresNetworkTypes(new QuerySql.InsertPostgresNetworkTypesArgs { CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr, CMacaddr8 = cMacaddr8 }); + var expected = new QuerySql.GetPostgresNetworkTypesRow { - CUuid = cUuid + CCidr = cCidr, + CInet = cInet, + CMacaddr = cMacaddr, + CMacaddr8 = cMacaddr8 }; - var actual = await QuerySql.GetPostgresTypes(); + var actual = await QuerySql.GetPostgresNetworkTypes(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresNetworkTypesRow x, QuerySql.GetPostgresNetworkTypesRow y) { - Assert.That(x.CUuid, Is.EqualTo(y.CUuid)); + Assert.That(x.CCidr, Is.EqualTo(y.CCidr)); + Assert.That(x.CInet, Is.EqualTo(y.CInet)); + Assert.That(x.CMacaddr, Is.EqualTo(y.CMacaddr)); + Assert.That(x.CMacaddr8, Is.EqualTo(y.CMacaddr8)); + } + } + + private static IEnumerable PostgresGeoTypesTestCases + { + get + { + yield return new TestCaseData(new NpgsqlPoint(1, 2), new NpgsqlLine(3, 4, 5), new NpgsqlLSeg(1, 2, 3, 4), new NpgsqlBox(1, 2, 3, 4), new NpgsqlPath(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlPolygon(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlCircle(1, 2, 3)).SetName("Valid Geo Types"); + yield return new TestCaseData(null, null, null, null, null, null, null).SetName("Null Geo Types"); + } + } + + [Test] + [TestCaseSource(nameof(PostgresGeoTypesTestCases))] + public async Task TestPostgresGeoTypes(NpgsqlPoint? cPoint, NpgsqlLine? cLine, NpgsqlLSeg? cLSeg, NpgsqlBox? cBox, NpgsqlPath? cPath, NpgsqlPolygon? cPolygon, NpgsqlCircle? cCircle) + { + await QuerySql.InsertPostgresGeoTypes(new QuerySql.InsertPostgresGeoTypesArgs { CPoint = cPoint, CLine = cLine, CLseg = cLSeg, CBox = cBox, CPath = cPath, CPolygon = cPolygon, CCircle = cCircle }); + var expected = new QuerySql.GetPostgresGeoTypesRow + { + CPoint = cPoint, + CLine = cLine, + CLseg = cLSeg, + CBox = cBox, + CPath = cPath, + CPolygon = cPolygon, + CCircle = cCircle + }; + var actual = await QuerySql.GetPostgresGeoTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresGeoTypesRow x, QuerySql.GetPostgresGeoTypesRow y) + { + Assert.That(x.CPoint, Is.EqualTo(y.CPoint)); + Assert.That(x.CLine, Is.EqualTo(y.CLine)); + Assert.That(x.CLseg, Is.EqualTo(y.CLseg)); + Assert.That(x.CBox, Is.EqualTo(y.CBox)); + Assert.That(x.CPath, Is.EqualTo(y.CPath)); + Assert.That(x.CPolygon, Is.EqualTo(y.CPolygon)); + Assert.That(x.CCircle, Is.EqualTo(y.CCircle)); + } + } + + [Test] + [TestCase("{\"name\": \"Swordfishtrombones\", \"year\": 1983}", "$.\"name\"")] + [TestCase(null, null)] + public async Task TestPostgresJsonDataTypes(string cJson, string cJsonpath) + { + JsonElement? cParsedJson = null; + if (cJson != null) + cParsedJson = JsonDocument.Parse(cJson).RootElement; + await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CJson = cParsedJson, CJsonb = cParsedJson, CJsonStringOverride = cJson, CJsonpath = cJsonpath }); + var expected = new QuerySql.GetPostgresSpecialTypesRow + { + CJson = cParsedJson, + CJsonb = cParsedJson, + CJsonStringOverride = cJson, + CJsonpath = cJsonpath + }; + var actual = await QuerySql.GetPostgresSpecialTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPostgresSpecialTypesRow y) + { + Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); + if (x.CJson.HasValue) + Assert.That(x.CJson.Value.GetRawText(), Is.EqualTo(y.CJson.Value.GetRawText())); + Assert.That(x.CJsonb.HasValue, Is.EqualTo(y.CJsonb.HasValue)); + if (x.CJsonb.HasValue) + Assert.That(x.CJsonb.Value.GetRawText(), Is.EqualTo(y.CJsonb.Value.GetRawText())); + Assert.That(x.CJsonStringOverride, Is.EqualTo(y.CJsonStringOverride)); + Assert.That(x.CJsonpath, Is.EqualTo(y.CJsonpath)); + } + } + + [Test] + [TestCase("Good morning xml, the world says hello")] + [TestCase(null)] + public async Task TestPostgresXmlDataTypes(string cXml) + { + XmlDocument parsedXml = null; + if (cXml != null) + { + parsedXml = new XmlDocument(); + parsedXml.LoadXml(cXml); + } + + await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CXml = parsedXml }); + var expected = new QuerySql.GetPostgresSpecialTypesRow + { + CXml = parsedXml + }; + var actual = await QuerySql.GetPostgresSpecialTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPostgresSpecialTypesRow y) + { + Assert.That(x.CXml == null, Is.EqualTo(y.CXml == null)); + if (x.CXml != null) + Assert.That(x.CXml.OuterXml, Is.EqualTo(y.CXml.OuterXml)); + } + } + + [Test] + [TestCase(CEnum.Medium)] + [TestCase(null)] + public async Task TestPostgresStringTypes(CEnum? cEnum) + { + await QuerySql.InsertPostgresSpecialTypes(new QuerySql.InsertPostgresSpecialTypesArgs { CEnum = cEnum }); + var expected = new QuerySql.GetPostgresSpecialTypesRow + { + CEnum = cEnum + }; + var actual = await QuerySql.GetPostgresSpecialTypes(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPostgresSpecialTypesRow y) + { + Assert.That(x.CEnum, Is.EqualTo(y.CEnum)); } } @@ -485,9 +751,9 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTy [TestCase(10, null, null, null, null, null)] public async Task TestStringCopyFrom(int batchSize, string cChar, string cVarchar, string cCharacterVarying, string cBpchar, string cText) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CBpchar = cBpchar, CText = cText }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresStringTypesBatchArgs { CChar = cChar, CVarchar = cVarchar, CCharacterVarying = cCharacterVarying, CBpchar = cBpchar, CText = cText }).ToList(); + await QuerySql.InsertPostgresStringTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresStringTypesCntRow { Cnt = batchSize, CChar = cChar, @@ -496,9 +762,9 @@ public async Task TestStringCopyFrom(int batchSize, string cChar, string cVarcha CBpchar = cBpchar, CText = cText }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresStringTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresStringTypesCntRow x, QuerySql.GetPostgresStringTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CChar, Is.EqualTo(y.CChar)); @@ -509,49 +775,14 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgre } } - [Test] - public async Task TestPostgresTransaction() - { - var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv)); - await connection.OpenAsync(); - var transaction = connection.BeginTransaction(); - var querySqlWithTx = QuerySql.WithTransaction(transaction); - await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - // The GetAuthor method in NpgsqlExampleGen returns QuerySql.GetAuthorRow? (nullable record struct) - var actualNull = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actualNull == null, "there is author"); // This is correct for nullable types - await transaction.CommitAsync(); - var expected = new QuerySql.GetAuthorRow - { - Id = 1111, - Name = "Bojack Horseman", - Bio = "Back in the 90s he was in a very famous TV show" - }; - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual)); // Apply placeholder here - } - - [Test] - public async Task TestPostgresTransactionRollback() - { - var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv)); - await connection.OpenAsync(); - var transaction = connection.BeginTransaction(); - var sqlQueryWithTx = QuerySql.WithTransaction(transaction); - await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - await transaction.RollbackAsync(); - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actual == null, "author should not exist after rollback"); - } - [Test] [TestCase(100, true, 3, 453, -1445214231L)] [TestCase(10, null, null, null, null)] public async Task TestIntegerCopyFrom(int batchSize, bool? cBoolean, short? cSmallint, int? cInteger, long? cBigint) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresNumericTypesBatchArgs { CBoolean = cBoolean, CSmallint = cSmallint, CInteger = cInteger, CBigint = cBigint }).ToList(); + await QuerySql.InsertPostgresNumericTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresNumericTypesCntRow { Cnt = batchSize, CBoolean = cBoolean, @@ -559,9 +790,9 @@ public async Task TestIntegerCopyFrom(int batchSize, bool? cBoolean, short? cSma CInteger = cInteger, CBigint = cBigint }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresNumericTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresNumericTypesCntRow x, QuerySql.GetPostgresNumericTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CBoolean, Is.EqualTo(y.CBoolean)); @@ -576,9 +807,9 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgre [TestCase(10, null, null, null, null, null)] public async Task TestFloatingPointCopyFrom(int batchSize, float? cReal, decimal? cDecimal, decimal? cNumeric, double? cDoublePrecision, decimal? cMoney) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CReal = cReal, CDecimal = cDecimal, CNumeric = cNumeric, CDoublePrecision = cDoublePrecision, CMoney = cMoney }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresNumericTypesBatchArgs { CReal = cReal, CDecimal = cDecimal, CNumeric = cNumeric, CDoublePrecision = cDoublePrecision, CMoney = cMoney }).ToList(); + await QuerySql.InsertPostgresNumericTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresNumericTypesCntRow { Cnt = batchSize, CReal = cReal, @@ -587,9 +818,9 @@ public async Task TestFloatingPointCopyFrom(int batchSize, float? cReal, decimal CDoublePrecision = cDoublePrecision, CMoney = cMoney }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresNumericTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresNumericTypesCntRow x, QuerySql.GetPostgresNumericTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CReal, Is.EqualTo(y.CReal)); @@ -608,9 +839,9 @@ public async Task TestDateTimeCopyFrom(int batchSize, DateTime? cDate, TimeSpan? DateTime? cTimestampWithTzAsUtc = null; if (cTimestampWithTz != null) cTimestampWithTzAsUtc = DateTime.SpecifyKind(cTimestampWithTz.Value, DateTimeKind.Utc); - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CDate = cDate, CTime = cTime, CTimestamp = cTimestamp, CTimestampWithTz = cTimestampWithTzAsUtc, CInterval = cInterval }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresDateTimeTypesBatchArgs { CDate = cDate, CTime = cTime, CTimestamp = cTimestamp, CTimestampWithTz = cTimestampWithTzAsUtc, CInterval = cInterval }).ToList(); + await QuerySql.InsertPostgresDateTimeTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresDateTimeTypesCntRow { Cnt = batchSize, CDate = cDate, @@ -619,9 +850,9 @@ public async Task TestDateTimeCopyFrom(int batchSize, DateTime? cDate, TimeSpan? CTimestampWithTz = cTimestampWithTz, CInterval = cInterval }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresDateTimeTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresDateTimeTypesCntRow x, QuerySql.GetPostgresDateTimeTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CDate, Is.EqualTo(y.CDate)); @@ -645,16 +876,16 @@ private static IEnumerable PostgresGuidCopyFromTestCases [TestCaseSource(nameof(PostgresGuidCopyFromTestCases))] public async Task TestPostgresGuidCopyFrom(int batchSize, Guid? cUuid) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CUuid = cUuid }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresSpecialTypesBatchArgs { CUuid = cUuid }).ToList(); + await QuerySql.InsertPostgresSpecialTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresSpecialTypesCntRow { Cnt = batchSize, CUuid = cUuid }; - var actual = await QuerySql.GetPostgresTypesCnt(); - Assert.That(actual.Cnt, Is.EqualTo(expected.Cnt)); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + var actual = await QuerySql.GetPostgresSpecialTypesCnt(); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesCntRow x, QuerySql.GetPostgresSpecialTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CUuid, Is.EqualTo(y.CUuid)); @@ -674,18 +905,18 @@ private static IEnumerable PostgresNetworkCopyFromTestCases [TestCaseSource(nameof(PostgresNetworkCopyFromTestCases))] public async Task TestPostgresNetworkCopyFrom(int batchSize, NpgsqlCidr? cCidr, IPAddress cInet, PhysicalAddress cMacaddr) { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresTypesBatchArgs { CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr }).ToList(); - await QuerySql.InsertPostgresTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresTypesCntRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresNetworkTypesBatchArgs { CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr }).ToList(); + await QuerySql.InsertPostgresNetworkTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresNetworkTypesCntRow { Cnt = batchSize, CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr }; - var actual = await QuerySql.GetPostgresTypesCnt(); + var actual = await QuerySql.GetPostgresNetworkTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgresTypesCntRow y) + void AssertSingularEquals(QuerySql.GetPostgresNetworkTypesCntRow x, QuerySql.GetPostgresNetworkTypesCntRow y) { Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); Assert.That(x.CCidr, Is.EqualTo(y.CCidr)); @@ -694,62 +925,43 @@ void AssertSingularEquals(QuerySql.GetPostgresTypesCntRow x, QuerySql.GetPostgre } } - [Test] - [TestCase(100, new byte[] { 0x53, 0x56 })] - [TestCase(10, new byte[] { })] - [TestCase(10, null)] - public async Task TestArrayCopyFrom(int batchSize, byte[] cBytea) - { - var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresArrayTypesBatchArgs { CBytea = cBytea }).ToList(); - await QuerySql.InsertPostgresArrayTypesBatch(batchArgs); - var expected = new QuerySql.GetPostgresArrayTypesCntRow - { - Cnt = batchSize, - CBytea = cBytea - }; - var actual = await QuerySql.GetPostgresArrayTypesCnt(); - AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresArrayTypesCntRow x, QuerySql.GetPostgresArrayTypesCntRow y) - { - Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); - } - } - - private static IEnumerable PostgresGeoTypesTestCases + private static IEnumerable PostgresArrayCopyFromTestCases { get { - yield return new TestCaseData(new NpgsqlPoint(1, 2), new NpgsqlLine(3, 4, 5), new NpgsqlLSeg(1, 2, 3, 4), new NpgsqlBox(1, 2, 3, 4), new NpgsqlPath(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlPolygon(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlCircle(1, 2, 3)).SetName("Valid Geo Types"); - yield return new TestCaseData(null, null, null, null, null, null, null).SetName("Null Geo Types"); + yield return new TestCaseData(100, new byte[] { 0x53, 0x56 }, new bool[] { true, false }, new string[] { "Sister Ray", "Venus in Furs" }, new int[] { 1, 2 }, new decimal[] { 132.13m, 23.22m }, new DateTime[] { new DateTime(1984, 8, 26), new DateTime(2000, 1, 2) }).SetName("Valid Array Copy From"); + yield return new TestCaseData(10, new byte[] { }, new bool[] { }, new string[] { }, new int[] { }, new decimal[] { }, new DateTime[] { }).SetName("Empty Array Copy From"); + yield return new TestCaseData(10, null, null, null, null, null, null).SetName("Null Array Copy From"); } } [Test] - [TestCaseSource(nameof(PostgresGeoTypesTestCases))] - public async Task TestPostgresGeoTypes(NpgsqlPoint? cPoint, NpgsqlLine? cLine, NpgsqlLSeg? cLSeg, NpgsqlBox? cBox, NpgsqlPath? cPath, NpgsqlPolygon? cPolygon, NpgsqlCircle? cCircle) + [TestCaseSource(nameof(PostgresArrayCopyFromTestCases))] + public async Task TestArrayCopyFrom(int batchSize, byte[] cBytea, bool[] cBooleanArray, string[] cTextArray, int[] cIntegerArray, decimal[] cDecimalArray, DateTime[] cTimestampArray) { - await QuerySql.InsertPostgresGeoTypes(new QuerySql.InsertPostgresGeoTypesArgs { CPoint = cPoint, CLine = cLine, CLseg = cLSeg, CBox = cBox, CPath = cPath, CPolygon = cPolygon, CCircle = cCircle }); - var expected = new QuerySql.GetPostgresGeoTypesRow + var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresArrayTypesBatchArgs { CBytea = cBytea, CBooleanArray = cBooleanArray, CTextArray = cTextArray, CIntegerArray = cIntegerArray, CDecimalArray = cDecimalArray, CTimestampArray = cTimestampArray }).ToList(); + await QuerySql.InsertPostgresArrayTypesBatch(batchArgs); + var expected = new QuerySql.GetPostgresArrayTypesCntRow { - CPoint = cPoint, - CLine = cLine, - CLseg = cLSeg, - CBox = cBox, - CPath = cPath, - CPolygon = cPolygon, - CCircle = cCircle + Cnt = batchSize, + CBytea = cBytea, + CBooleanArray = cBooleanArray, + CTextArray = cTextArray, + CIntegerArray = cIntegerArray, + CDecimalArray = cDecimalArray, + CTimestampArray = cTimestampArray }; - var actual = await QuerySql.GetPostgresGeoTypes(); + var actual = await QuerySql.GetPostgresArrayTypesCnt(); AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresGeoTypesRow x, QuerySql.GetPostgresGeoTypesRow y) + void AssertSingularEquals(QuerySql.GetPostgresArrayTypesCntRow x, QuerySql.GetPostgresArrayTypesCntRow y) { - Assert.That(x.CPoint, Is.EqualTo(y.CPoint)); - Assert.That(x.CLine, Is.EqualTo(y.CLine)); - Assert.That(x.CLseg, Is.EqualTo(y.CLseg)); - Assert.That(x.CBox, Is.EqualTo(y.CBox)); - Assert.That(x.CPath, Is.EqualTo(y.CPath)); - Assert.That(x.CPolygon, Is.EqualTo(y.CPolygon)); - Assert.That(x.CCircle, Is.EqualTo(y.CCircle)); + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CBytea, Is.EqualTo(y.CBytea)); + Assert.That(x.CBooleanArray, Is.EqualTo(y.CBooleanArray)); + Assert.That(x.CTextArray, Is.EqualTo(y.CTextArray)); + Assert.That(x.CIntegerArray, Is.EqualTo(y.CIntegerArray)); + Assert.That(x.CDecimalArray, Is.EqualTo(y.CDecimalArray)); + Assert.That(x.CTimestampArray, Is.EqualTo(y.CTimestampArray)); } } @@ -791,121 +1003,5 @@ void AssertSingularEquals(QuerySql.GetPostgresGeoTypesRow x, QuerySql.GetPostgre Assert.That(x.CCircle, Is.EqualTo(y.CCircle)); } } - - private static IEnumerable PostgresNetworkDataTypesTestCases - { - get - { - yield return new TestCaseData(new NpgsqlCidr("192.168.1.0/24"), new IPAddress(new byte[] { 192, 168, 1, 1 }), new PhysicalAddress(new byte[] { 0x00, 0x1A, 0x2B, 0x3C, 0x4D, 0x5E }), "00:1a:2b:ff:fe:3c:4d:5e").SetName("Valid Network Data Types"); - yield return new TestCaseData(null, null, null, null).SetName("Null Network Data Types"); - } - } - - [Test] - [TestCaseSource(nameof(PostgresNetworkDataTypesTestCases))] - public async Task TestPostgresNetworkDataTypes(NpgsqlCidr? cCidr, IPAddress cInet, PhysicalAddress cMacaddr, string cMacaddr8) - { - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CCidr = cCidr, CInet = cInet, CMacaddr = cMacaddr, CMacaddr8 = cMacaddr8 }); - var expected = new QuerySql.GetPostgresTypesRow - { - CCidr = cCidr, - CInet = cInet, - CMacaddr = cMacaddr, - CMacaddr8 = cMacaddr8 - }; - var actual = await QuerySql.GetPostgresTypes(); - AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) - { - Assert.That(x.CCidr, Is.EqualTo(y.CCidr)); - Assert.That(x.CInet, Is.EqualTo(y.CInet)); - Assert.That(x.CMacaddr, Is.EqualTo(y.CMacaddr)); - Assert.That(x.CMacaddr8, Is.EqualTo(y.CMacaddr8)); - } - } - - [Test] - [TestCase("{\"name\": \"Swordfishtrombones\", \"year\": 1983}", "$.\"name\"")] - [TestCase(null, null)] - public async Task TestPostgresJsonDataTypes(string cJson, string cJsonpath) - { - JsonElement? cParsedJson = null; - if (cJson != null) - cParsedJson = JsonDocument.Parse(cJson).RootElement; - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CJson = cParsedJson, CJsonb = cParsedJson, CJsonStringOverride = cJson, CJsonpath = cJsonpath }); - var expected = new QuerySql.GetPostgresTypesRow - { - CJson = cParsedJson, - CJsonb = cParsedJson, - CJsonStringOverride = cJson, - CJsonpath = cJsonpath - }; - var actual = await QuerySql.GetPostgresTypes(); - AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) - { - Assert.That(x.CJson.HasValue, Is.EqualTo(y.CJson.HasValue)); - if (x.CJson.HasValue) - Assert.That(x.CJson.Value.GetRawText(), Is.EqualTo(y.CJson.Value.GetRawText())); - Assert.That(x.CJsonb.HasValue, Is.EqualTo(y.CJsonb.HasValue)); - if (x.CJsonb.HasValue) - Assert.That(x.CJsonb.Value.GetRawText(), Is.EqualTo(y.CJsonb.Value.GetRawText())); - Assert.That(x.CJsonStringOverride, Is.EqualTo(y.CJsonStringOverride)); - Assert.That(x.CJsonpath, Is.EqualTo(y.CJsonpath)); - } - } - - [Test] - public void TestPostgresInvalidJson() - { - Assert.ThrowsAsync(async () => await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CJsonStringOverride = "SOME INVALID JSON" })); - Assert.ThrowsAsync(async () => await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CJsonpath = "SOME INVALID JSONPATH" })); - } - - [Test] - [TestCase("Good morning xml, the world says hello")] - [TestCase(null)] - public async Task TestPostgresXmlDataTypes(string cXml) - { - XmlDocument parsedXml = null; - if (cXml != null) - { - parsedXml = new XmlDocument(); - parsedXml.LoadXml(cXml); - } - - await QuerySql.InsertPostgresTypes(new QuerySql.InsertPostgresTypesArgs { CXml = parsedXml }); - var expected = new QuerySql.GetPostgresTypesRow - { - CXml = parsedXml - }; - var actual = await QuerySql.GetPostgresTypes(); - AssertSingularEquals(expected, actual); - void AssertSingularEquals(QuerySql.GetPostgresTypesRow x, QuerySql.GetPostgresTypesRow y) - { - if (x.CXml == null && y.CXml == null) - return; - Assert.That(x.CXml.OuterXml, Is.EqualTo(y.CXml.OuterXml)); - } - } - - [Test] - public async Task TestArray() - { - var id1 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Quote that everyone always attribute to Einstein" }); - var bojackId = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - var actual = await QuerySql.GetAuthorsByIds(new QuerySql.GetAuthorsByIdsArgs { LongArr1 = new[] { id1, bojackId } }); - ClassicAssert.AreEqual(2, actual.Count); - } - - [Test] - public async Task TestMultipleArrays() - { - var id1 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Quote that everyone always attribute to Einstein" }); - var id2 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Albert Einstein", Bio = "Only 2 things are infinite, the universe and human stupidity" }); - var bojackId = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs { Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - var actual = await QuerySql.GetAuthorsByIdsAndNames(new QuerySql.GetAuthorsByIdsAndNamesArgs { LongArr1 = new[] { id1, bojackId }, StringArr2 = new[] { "Albert Einstein" } }); - ClassicAssert.AreEqual(1, actual.Count); - } } } diff --git a/end2end/EndToEndTestsLegacy/SqliteDapperTester.generated.cs b/end2end/EndToEndTestsLegacy/SqliteDapperTester.generated.cs index 166a6016..b71db001 100644 --- a/end2end/EndToEndTestsLegacy/SqliteDapperTester.generated.cs +++ b/end2end/EndToEndTestsLegacy/SqliteDapperTester.generated.cs @@ -23,12 +23,13 @@ public async Task TestOne() Bio = "Back in the 90s he was in a very famous TV show" }; var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -53,21 +54,18 @@ public async Task TestMany() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) - { - Assert.That(x.Id, Is.EqualTo(y.Id)); - Assert.That(x.Name, Is.EqualTo(y.Name)); - Assert.That(x.Bio, Is.EqualTo(y.Bio)); - } + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } - private static void AssertSequenceEquals(List x, List y) - { - Assert.That(x.Count, Is.EqualTo(y.Count)); - for (int i = 0; i < x.Count; i++) + void AssertSequenceEquals(List x, List y) { - AssertSingularEquals(x[i], y[i]); + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); } } @@ -105,6 +103,19 @@ public async Task TestExecRows() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -118,12 +129,13 @@ public async Task TestExecLastId() Bio = "Quote that everyone always attribute to Einstein" }; var actual = await QuerySql.GetAuthorById(new QuerySql.GetAuthorByIdArgs { Id = id1 }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -150,19 +162,23 @@ public async Task TestSelfJoinEmbed() } }; var actual = await QuerySql.GetDuplicateAuthors(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) - { - return SingularEquals(x.Author, y.Author) && SingularEquals(x.Author2, y.Author2); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) + { + Assert.That(x.Author.Id, Is.EqualTo(y.Author.Id)); + Assert.That(x.Author.Name, Is.EqualTo(y.Author.Name)); + Assert.That(x.Author.Bio, Is.EqualTo(y.Author.Bio)); + Assert.That(x.Author2.Id, Is.EqualTo(y.Author2.Id)); + Assert.That(x.Author2.Name, Is.EqualTo(y.Author2.Name)); + Assert.That(x.Author2.Bio, Is.EqualTo(y.Author2.Bio)); + } - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -206,31 +222,23 @@ public async Task TestJoinEmbed() } }; var actual = await QuerySql.ListAllAuthorsBooks(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) - { - return SingularEquals(x.Author, y.Author) && SingularEquals(x.Book, y.Book); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Author.Name + o.Book.Name).ToList(); - y = y.OrderBy(o => o.Author.Name + o.Book.Name).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } - - private static bool SingularEquals(Author x, Author y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) + { + Assert.That(x.Author.Id, Is.EqualTo(y.Author.Id)); + Assert.That(x.Author.Name, Is.EqualTo(y.Author.Name)); + Assert.That(x.Author.Bio, Is.EqualTo(y.Author.Bio)); + Assert.That(x.Book.Id, Is.EqualTo(y.Book.Id)); + Assert.That(x.Book.AuthorId, Is.EqualTo(y.Book.AuthorId)); + Assert.That(x.Book.Name, Is.EqualTo(y.Book.Name)); + } - private static bool SingularEquals(Book x, Book y) - { - return x.Id.Equals(y.Id) && x.AuthorId.Equals(y.AuthorId) && x.Name.Equals(y.Name); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -272,21 +280,20 @@ public async Task TestNargNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs()); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Id).ToList(); - y = y.OrderBy(o => o.Id).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } - private static bool SingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -304,7 +311,20 @@ public async Task TestNargNotNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs { NamePattern = "Bojack%" }); - Assert.That(SequenceEquals(expected, actual)); + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } + + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -323,14 +343,13 @@ public async Task TestSqliteTypes(int? cInteger, decimal? cReal, string cText, b }; var actual = await QuerySql.GetSqliteTypes(); AssertSingularEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.GetSqliteTypesRow expected, QuerySql.GetSqliteTypesRow actual) - { - Assert.That(actual.CInteger, Is.EqualTo(expected.CInteger)); - Assert.That(actual.CReal, Is.EqualTo(expected.CReal)); - Assert.That(actual.CText, Is.EqualTo(expected.CText)); - Assert.That(actual.CBlob, Is.EqualTo(expected.CBlob)); + void AssertSingularEquals(QuerySql.GetSqliteTypesRow x, QuerySql.GetSqliteTypesRow y) + { + Assert.That(x.CInteger, Is.EqualTo(y.CInteger)); + Assert.That(x.CReal, Is.EqualTo(y.CReal)); + Assert.That(x.CText, Is.EqualTo(y.CText)); + Assert.That(x.CBlob, Is.EqualTo(y.CBlob)); + } } [Test] @@ -344,12 +363,13 @@ public async Task TestGetAuthorByIdWithMultipleNamedParam() Bio = "Back in the 90s he was in a very famous TV show" }; var actual = await this.QuerySql.GetAuthorByIdWithMultipleNamedParam(new QuerySql.GetAuthorByIdWithMultipleNamedParamArgs { IdArg = 1111, Take = 1 }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorByIdWithMultipleNamedParamRow x, QuerySql.GetAuthorByIdWithMultipleNamedParamRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorByIdWithMultipleNamedParamRow x, QuerySql.GetAuthorByIdWithMultipleNamedParamRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -366,13 +386,12 @@ public async Task TestSqliteDataTypesOverride(int? cInteger, decimal cReal, stri }; var actual = await QuerySql.GetSqliteFunctions(); AssertSingularEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.GetSqliteFunctionsRow expected, QuerySql.GetSqliteFunctionsRow actual) - { - Assert.That(actual.MaxInteger, Is.EqualTo(expected.MaxInteger)); - Assert.That(actual.MaxReal, Is.EqualTo(expected.MaxReal)); - Assert.That(actual.MaxText, Is.EqualTo(expected.MaxText)); + void AssertSingularEquals(QuerySql.GetSqliteFunctionsRow x, QuerySql.GetSqliteFunctionsRow y) + { + Assert.That(x.MaxInteger, Is.EqualTo(y.MaxInteger)); + Assert.That(x.MaxReal, Is.EqualTo(y.MaxReal)); + Assert.That(x.MaxText, Is.EqualTo(y.MaxText)); + } } [Test] @@ -392,14 +411,13 @@ public async Task TestCopyFrom(int batchSize, int? cInteger, decimal? cReal, str }; var actual = await QuerySql.GetSqliteTypesCnt(); AssertSingularEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.GetSqliteTypesCntRow expected, QuerySql.GetSqliteTypesCntRow actual) - { - Assert.That(actual.Cnt, Is.EqualTo(expected.Cnt)); - Assert.That(actual.CInteger, Is.EqualTo(expected.CInteger)); - Assert.That(actual.CReal, Is.EqualTo(expected.CReal)); - Assert.That(actual.CText, Is.EqualTo(expected.CText)); + void AssertSingularEquals(QuerySql.GetSqliteTypesCntRow x, QuerySql.GetSqliteTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CInteger, Is.EqualTo(y.CInteger)); + Assert.That(x.CReal, Is.EqualTo(y.CReal)); + Assert.That(x.CText, Is.EqualTo(y.CText)); + } } [Test] @@ -410,9 +428,8 @@ public async Task TestSqliteTransaction() var transaction = connection.BeginTransaction(); var querySqlWithTx = QuerySql.WithTransaction(transaction); await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - // The GetAuthor method in SqliteExampleGen returns QuerySql.GetAuthorRow? (nullable record struct/class) - var actualNull = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actualNull == null, "there is author"); // This is correct for nullable types + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + ClassicAssert.IsNull(actual); transaction.Commit(); var expected = new QuerySql.GetAuthorRow { @@ -420,8 +437,14 @@ public async Task TestSqliteTransaction() Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }; - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual)); // Apply placeholder here + actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -434,7 +457,7 @@ public async Task TestSqliteTransactionRollback() await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); transaction.Rollback(); var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actual == null, "author should not exist after rollback"); + ClassicAssert.IsNull(actual); } } } diff --git a/end2end/EndToEndTestsLegacy/SqliteTester.generated.cs b/end2end/EndToEndTestsLegacy/SqliteTester.generated.cs index 70ea0b2b..2e434715 100644 --- a/end2end/EndToEndTestsLegacy/SqliteTester.generated.cs +++ b/end2end/EndToEndTestsLegacy/SqliteTester.generated.cs @@ -23,12 +23,13 @@ public async Task TestOne() Bio = "Back in the 90s he was in a very famous TV show" }; var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -53,21 +54,18 @@ public async Task TestMany() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) - { - Assert.That(x.Id, Is.EqualTo(y.Id)); - Assert.That(x.Name, Is.EqualTo(y.Name)); - Assert.That(x.Bio, Is.EqualTo(y.Bio)); - } + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } - private static void AssertSequenceEquals(List x, List y) - { - Assert.That(x.Count, Is.EqualTo(y.Count)); - for (int i = 0; i < x.Count; i++) + void AssertSequenceEquals(List x, List y) { - AssertSingularEquals(x[i], y[i]); + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); } } @@ -105,6 +103,19 @@ public async Task TestExecRows() }; var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs { Limit = 2, Offset = 0 }); AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAuthorsRow x, QuerySql.ListAuthorsRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } + + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -118,12 +129,13 @@ public async Task TestExecLastId() Bio = "Quote that everyone always attribute to Einstein" }; var actual = await QuerySql.GetAuthorById(new QuerySql.GetAuthorByIdArgs { Id = id1 }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -150,19 +162,23 @@ public async Task TestSelfJoinEmbed() } }; var actual = await QuerySql.GetDuplicateAuthors(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) - { - return SingularEquals(x.Author, y.Author) && SingularEquals(x.Author2, y.Author2); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetDuplicateAuthorsRow x, QuerySql.GetDuplicateAuthorsRow y) + { + Assert.That(x.Author.Id, Is.EqualTo(y.Author.Id)); + Assert.That(x.Author.Name, Is.EqualTo(y.Author.Name)); + Assert.That(x.Author.Bio, Is.EqualTo(y.Author.Bio)); + Assert.That(x.Author2.Id, Is.EqualTo(y.Author2.Id)); + Assert.That(x.Author2.Name, Is.EqualTo(y.Author2.Name)); + Assert.That(x.Author2.Bio, Is.EqualTo(y.Author2.Bio)); + } - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -206,31 +222,23 @@ public async Task TestJoinEmbed() } }; var actual = await QuerySql.ListAllAuthorsBooks(); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) - { - return SingularEquals(x.Author, y.Author) && SingularEquals(x.Book, y.Book); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Author.Name + o.Book.Name).ToList(); - y = y.OrderBy(o => o.Author.Name + o.Book.Name).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } - - private static bool SingularEquals(Author x, Author y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); - } + AssertSequenceEquals(expected, actual); + void AssertSingularEquals(QuerySql.ListAllAuthorsBooksRow x, QuerySql.ListAllAuthorsBooksRow y) + { + Assert.That(x.Author.Id, Is.EqualTo(y.Author.Id)); + Assert.That(x.Author.Name, Is.EqualTo(y.Author.Name)); + Assert.That(x.Author.Bio, Is.EqualTo(y.Author.Bio)); + Assert.That(x.Book.Id, Is.EqualTo(y.Book.Id)); + Assert.That(x.Book.AuthorId, Is.EqualTo(y.Book.AuthorId)); + Assert.That(x.Book.Name, Is.EqualTo(y.Book.Name)); + } - private static bool SingularEquals(Book x, Book y) - { - return x.Id.Equals(y.Id) && x.AuthorId.Equals(y.AuthorId) && x.Name.Equals(y.Name); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } } [Test] @@ -272,21 +280,20 @@ public async Task TestNargNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs()); - Assert.That(SequenceEquals(expected, actual)); - } - - private static bool SequenceEquals(List x, List y) - { - if (x.Count != y.Count) - return false; - x = x.OrderBy(o => o.Id).ToList(); - y = y.OrderBy(o => o.Id).ToList(); - return !x.Where((t, i) => !SingularEquals(t, y[i])).Any(); - } + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } - private static bool SingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -304,7 +311,20 @@ public async Task TestNargNotNull() } }; var actual = await this.QuerySql.GetAuthorByNamePattern(new QuerySql.GetAuthorByNamePatternArgs { NamePattern = "Bojack%" }); - Assert.That(SequenceEquals(expected, actual)); + AssertSequenceEquals(expected, actual); + void AssertSequenceEquals(List x, List y) + { + Assert.That(x.Count, Is.EqualTo(y.Count)); + for (int i = 0; i < x.Count; i++) + AssertSingularEquals(x[i], y[i]); + } + + void AssertSingularEquals(QuerySql.GetAuthorByNamePatternRow x, QuerySql.GetAuthorByNamePatternRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -323,14 +343,13 @@ public async Task TestSqliteTypes(int? cInteger, decimal? cReal, string cText, b }; var actual = await QuerySql.GetSqliteTypes(); AssertSingularEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.GetSqliteTypesRow expected, QuerySql.GetSqliteTypesRow actual) - { - Assert.That(actual.CInteger, Is.EqualTo(expected.CInteger)); - Assert.That(actual.CReal, Is.EqualTo(expected.CReal)); - Assert.That(actual.CText, Is.EqualTo(expected.CText)); - Assert.That(actual.CBlob, Is.EqualTo(expected.CBlob)); + void AssertSingularEquals(QuerySql.GetSqliteTypesRow x, QuerySql.GetSqliteTypesRow y) + { + Assert.That(x.CInteger, Is.EqualTo(y.CInteger)); + Assert.That(x.CReal, Is.EqualTo(y.CReal)); + Assert.That(x.CText, Is.EqualTo(y.CText)); + Assert.That(x.CBlob, Is.EqualTo(y.CBlob)); + } } [Test] @@ -344,12 +363,13 @@ public async Task TestGetAuthorByIdWithMultipleNamedParam() Bio = "Back in the 90s he was in a very famous TV show" }; var actual = await this.QuerySql.GetAuthorByIdWithMultipleNamedParam(new QuerySql.GetAuthorByIdWithMultipleNamedParamArgs { IdArg = 1111, Take = 1 }); - Assert.That(SingularEquals(expected, actual)); - } - - private static bool SingularEquals(QuerySql.GetAuthorByIdWithMultipleNamedParamRow x, QuerySql.GetAuthorByIdWithMultipleNamedParamRow y) - { - return x.Id.Equals(y.Id) && x.Name.Equals(y.Name) && x.Bio.Equals(y.Bio); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorByIdWithMultipleNamedParamRow x, QuerySql.GetAuthorByIdWithMultipleNamedParamRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -366,13 +386,12 @@ public async Task TestSqliteDataTypesOverride(int? cInteger, decimal cReal, stri }; var actual = await QuerySql.GetSqliteFunctions(); AssertSingularEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.GetSqliteFunctionsRow expected, QuerySql.GetSqliteFunctionsRow actual) - { - Assert.That(actual.MaxInteger, Is.EqualTo(expected.MaxInteger)); - Assert.That(actual.MaxReal, Is.EqualTo(expected.MaxReal)); - Assert.That(actual.MaxText, Is.EqualTo(expected.MaxText)); + void AssertSingularEquals(QuerySql.GetSqliteFunctionsRow x, QuerySql.GetSqliteFunctionsRow y) + { + Assert.That(x.MaxInteger, Is.EqualTo(y.MaxInteger)); + Assert.That(x.MaxReal, Is.EqualTo(y.MaxReal)); + Assert.That(x.MaxText, Is.EqualTo(y.MaxText)); + } } [Test] @@ -392,14 +411,13 @@ public async Task TestCopyFrom(int batchSize, int? cInteger, decimal? cReal, str }; var actual = await QuerySql.GetSqliteTypesCnt(); AssertSingularEquals(expected, actual); - } - - private static void AssertSingularEquals(QuerySql.GetSqliteTypesCntRow expected, QuerySql.GetSqliteTypesCntRow actual) - { - Assert.That(actual.Cnt, Is.EqualTo(expected.Cnt)); - Assert.That(actual.CInteger, Is.EqualTo(expected.CInteger)); - Assert.That(actual.CReal, Is.EqualTo(expected.CReal)); - Assert.That(actual.CText, Is.EqualTo(expected.CText)); + void AssertSingularEquals(QuerySql.GetSqliteTypesCntRow x, QuerySql.GetSqliteTypesCntRow y) + { + Assert.That(x.Cnt, Is.EqualTo(y.Cnt)); + Assert.That(x.CInteger, Is.EqualTo(y.CInteger)); + Assert.That(x.CReal, Is.EqualTo(y.CReal)); + Assert.That(x.CText, Is.EqualTo(y.CText)); + } } [Test] @@ -410,9 +428,8 @@ public async Task TestSqliteTransaction() var transaction = connection.BeginTransaction(); var querySqlWithTx = QuerySql.WithTransaction(transaction); await querySqlWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); - // The GetAuthor method in SqliteExampleGen returns QuerySql.GetAuthorRow? (nullable record struct/class) - var actualNull = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actualNull == null, "there is author"); // This is correct for nullable types + var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + ClassicAssert.IsNull(actual); transaction.Commit(); var expected = new QuerySql.GetAuthorRow { @@ -420,8 +437,14 @@ public async Task TestSqliteTransaction() Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }; - var actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(SingularEquals(expected, actual)); // Apply placeholder here + actual = await QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); + AssertSingularEquals(expected, actual); + void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y) + { + Assert.That(x.Id, Is.EqualTo(y.Id)); + Assert.That(x.Name, Is.EqualTo(y.Name)); + Assert.That(x.Bio, Is.EqualTo(y.Bio)); + } } [Test] @@ -434,7 +457,7 @@ public async Task TestSqliteTransactionRollback() await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" }); transaction.Rollback(); var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" }); - Assert.That(actual == null, "author should not exist after rollback"); + ClassicAssert.IsNull(actual); } } } diff --git a/examples/MySqlConnectorDapperExample/Models.cs b/examples/MySqlConnectorDapperExample/Models.cs index 299063de..84b866b4 100644 --- a/examples/MySqlConnectorDapperExample/Models.cs +++ b/examples/MySqlConnectorDapperExample/Models.cs @@ -18,7 +18,7 @@ public class Book public required long AuthorId { get; init; } public string? Description { get; init; } }; -public class MysqlType +public class MysqlNumericType { public bool? CBool { get; init; } public bool? CBoolean { get; init; } @@ -35,11 +35,9 @@ public class MysqlType public decimal? CFixed { get; init; } public double? CDouble { get; init; } public double? CDoublePrecision { get; init; } - public short? CYear { get; init; } - public DateTime? CDate { get; init; } - public string? CTime { get; init; } - public DateTime? CDatetime { get; init; } - public DateTime? CTimestamp { get; init; } +}; +public class MysqlStringType +{ public string? CChar { get; init; } public string? CNchar { get; init; } public string? CNationalChar { get; init; } @@ -50,8 +48,19 @@ public class MysqlType public string? CLongtext { get; init; } public JsonElement? CJson { get; init; } public JsonElement? CJsonStringOverride { get; init; } - public MysqlTypesCEnum? CEnum { get; init; } - public MysqlTypesCSet[]? CSet { get; init; } + public MysqlStringTypesCEnum? CEnum { get; init; } + public HashSet? CSet { get; init; } +}; +public class MysqlDatetimeType +{ + public short? CYear { get; init; } + public DateTime? CDate { get; init; } + public DateTime? CDatetime { get; init; } + public DateTime? CTimestamp { get; init; } + public TimeSpan? CTime { get; init; } +}; +public class MysqlBinaryType +{ public byte? CBit { get; init; } public byte[]? CBinary { get; init; } public byte[]? CVarbinary { get; init; } @@ -64,117 +73,165 @@ public class ExtendedBio { public string? AuthorName { get; init; } public string? Name { get; init; } - public ExtendedBiosBioType? BioType { get; init; } - public ExtendedBiosAuthorType[]? AuthorType { get; init; } + public BiosBioType? BioType { get; init; } + public HashSet? AuthorType { get; init; } }; -public enum MysqlTypesCEnum +public enum BiosBioType { Invalid = 0, // reserved for invalid enum value - Small = 1, - Medium = 2, - Big = 3 + Autobiography = 1, + Biography = 2, + Memoir = 3 } -public static class MysqlTypesCEnumExtensions +public static class BiosBioTypeExtensions { - private static readonly Dictionary StringToEnum = new Dictionary() + private static readonly Dictionary StringToEnum = new Dictionary() + { + [string.Empty] = BiosBioType.Invalid, + ["Autobiography"] = BiosBioType.Autobiography, + ["Biography"] = BiosBioType.Biography, + ["Memoir"] = BiosBioType.Memoir + }; + private static readonly Dictionary EnumToString = new Dictionary() { - [string.Empty] = MysqlTypesCEnum.Invalid, - ["small"] = MysqlTypesCEnum.Small, - ["medium"] = MysqlTypesCEnum.Medium, - ["big"] = MysqlTypesCEnum.Big + [BiosBioType.Invalid] = string.Empty, + [BiosBioType.Autobiography] = "Autobiography", + [BiosBioType.Biography] = "Biography", + [BiosBioType.Memoir] = "Memoir" }; - public static MysqlTypesCEnum ToMysqlTypesCEnum(this string me) + public static BiosBioType ToBiosBioType(this string me) { return StringToEnum[me]; } - public static MysqlTypesCEnum[] ToMysqlTypesCEnumArr(this string me) + public static string Stringify(this BiosBioType me) { - return me.Split(',').ToList().Select(v => StringToEnum[v]).ToArray(); + return EnumToString[me]; + } + + public static HashSet ToBiosBioTypeSet(this string me) + { + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); } } -public enum MysqlTypesCSet +public enum BiosAuthorType { Invalid = 0, // reserved for invalid enum value - Tea = 1, - Coffee = 2, - Milk = 3 + Author = 1, + Editor = 2, + Translator = 3 } -public static class MysqlTypesCSetExtensions +public static class BiosAuthorTypeExtensions { - private static readonly Dictionary StringToEnum = new Dictionary() + private static readonly Dictionary StringToEnum = new Dictionary() + { + [string.Empty] = BiosAuthorType.Invalid, + ["Author"] = BiosAuthorType.Author, + ["Editor"] = BiosAuthorType.Editor, + ["Translator"] = BiosAuthorType.Translator + }; + private static readonly Dictionary EnumToString = new Dictionary() { - [string.Empty] = MysqlTypesCSet.Invalid, - ["tea"] = MysqlTypesCSet.Tea, - ["coffee"] = MysqlTypesCSet.Coffee, - ["milk"] = MysqlTypesCSet.Milk + [BiosAuthorType.Invalid] = string.Empty, + [BiosAuthorType.Author] = "Author", + [BiosAuthorType.Editor] = "Editor", + [BiosAuthorType.Translator] = "Translator" }; - public static MysqlTypesCSet ToMysqlTypesCSet(this string me) + public static BiosAuthorType ToBiosAuthorType(this string me) { return StringToEnum[me]; } - public static MysqlTypesCSet[] ToMysqlTypesCSetArr(this string me) + public static string Stringify(this BiosAuthorType me) { - return me.Split(',').ToList().Select(v => StringToEnum[v]).ToArray(); + return EnumToString[me]; + } + + public static HashSet ToBiosAuthorTypeSet(this string me) + { + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); } } -public enum ExtendedBiosBioType +public enum MysqlStringTypesCEnum { Invalid = 0, // reserved for invalid enum value - Autobiography = 1, - Biography = 2, - Memoir = 3 + Small = 1, + Medium = 2, + Big = 3 } -public static class ExtendedBiosBioTypeExtensions +public static class MysqlStringTypesCEnumExtensions { - private static readonly Dictionary StringToEnum = new Dictionary() + private static readonly Dictionary StringToEnum = new Dictionary() + { + [string.Empty] = MysqlStringTypesCEnum.Invalid, + ["small"] = MysqlStringTypesCEnum.Small, + ["medium"] = MysqlStringTypesCEnum.Medium, + ["big"] = MysqlStringTypesCEnum.Big + }; + private static readonly Dictionary EnumToString = new Dictionary() { - [string.Empty] = ExtendedBiosBioType.Invalid, - ["Autobiography"] = ExtendedBiosBioType.Autobiography, - ["Biography"] = ExtendedBiosBioType.Biography, - ["Memoir"] = ExtendedBiosBioType.Memoir + [MysqlStringTypesCEnum.Invalid] = string.Empty, + [MysqlStringTypesCEnum.Small] = "small", + [MysqlStringTypesCEnum.Medium] = "medium", + [MysqlStringTypesCEnum.Big] = "big" }; - public static ExtendedBiosBioType ToExtendedBiosBioType(this string me) + public static MysqlStringTypesCEnum ToMysqlStringTypesCEnum(this string me) { return StringToEnum[me]; } - public static ExtendedBiosBioType[] ToExtendedBiosBioTypeArr(this string me) + public static string Stringify(this MysqlStringTypesCEnum me) { - return me.Split(',').ToList().Select(v => StringToEnum[v]).ToArray(); + return EnumToString[me]; + } + + public static HashSet ToMysqlStringTypesCEnumSet(this string me) + { + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); } } -public enum ExtendedBiosAuthorType +public enum MysqlStringTypesCSet { Invalid = 0, // reserved for invalid enum value - Author = 1, - Editor = 2, - Translator = 3 + Tea = 1, + Coffee = 2, + Milk = 3 } -public static class ExtendedBiosAuthorTypeExtensions +public static class MysqlStringTypesCSetExtensions { - private static readonly Dictionary StringToEnum = new Dictionary() + private static readonly Dictionary StringToEnum = new Dictionary() + { + [string.Empty] = MysqlStringTypesCSet.Invalid, + ["tea"] = MysqlStringTypesCSet.Tea, + ["coffee"] = MysqlStringTypesCSet.Coffee, + ["milk"] = MysqlStringTypesCSet.Milk + }; + private static readonly Dictionary EnumToString = new Dictionary() { - [string.Empty] = ExtendedBiosAuthorType.Invalid, - ["Author"] = ExtendedBiosAuthorType.Author, - ["Editor"] = ExtendedBiosAuthorType.Editor, - ["Translator"] = ExtendedBiosAuthorType.Translator + [MysqlStringTypesCSet.Invalid] = string.Empty, + [MysqlStringTypesCSet.Tea] = "tea", + [MysqlStringTypesCSet.Coffee] = "coffee", + [MysqlStringTypesCSet.Milk] = "milk" }; - public static ExtendedBiosAuthorType ToExtendedBiosAuthorType(this string me) + public static MysqlStringTypesCSet ToMysqlStringTypesCSet(this string me) { return StringToEnum[me]; } - public static ExtendedBiosAuthorType[] ToExtendedBiosAuthorTypeArr(this string me) + public static string Stringify(this MysqlStringTypesCSet me) + { + return EnumToString[me]; + } + + public static HashSet ToMysqlStringTypesCSetSet(this string me) { - return me.Split(',').ToList().Select(v => StringToEnum[v]).ToArray(); + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); } } \ No newline at end of file diff --git a/examples/MySqlConnectorDapperExample/QuerySql.cs b/examples/MySqlConnectorDapperExample/QuerySql.cs index bbf56feb..1f610152 100644 --- a/examples/MySqlConnectorDapperExample/QuerySql.cs +++ b/examples/MySqlConnectorDapperExample/QuerySql.cs @@ -69,14 +69,11 @@ public class GetAuthorArgs } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -123,18 +120,12 @@ public async Task CreateAuthor(CreateAuthorArgs args) if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) - { await connection.ExecuteAsync(CreateAuthorSql, queryParams); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); await this.Transaction.Connection.ExecuteAsync(CreateAuthorSql, queryParams, transaction: this.Transaction); } @@ -152,16 +143,11 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) - { return await connection.QuerySingleAsync(CreateAuthorReturnIdSql, queryParams); - } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); return await this.Transaction.Connection.QuerySingleAsync(CreateAuthorReturnIdSql, queryParams, transaction: this.Transaction); } @@ -190,14 +176,11 @@ public class GetAuthorByIdArgs } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -226,7 +209,7 @@ 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; } @@ -238,18 +221,12 @@ public async Task DeleteAuthor(DeleteAuthorArgs args) if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) - { await connection.ExecuteAsync(DeleteAuthorSql, queryParams); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); await this.Transaction.Connection.ExecuteAsync(DeleteAuthorSql, queryParams, transaction: this.Transaction); } @@ -259,22 +236,16 @@ public async Task DeleteAllAuthors() if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) - { await connection.ExecuteAsync(DeleteAllAuthorsSql); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -286,16 +257,11 @@ public async Task UpdateAuthors(UpdateAuthorsArgs args) if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) - { return await connection.ExecuteAsync(UpdateAuthorsSql, queryParams); - } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); return await this.Transaction.Connection.ExecuteAsync(UpdateAuthorsSql, queryParams, transaction: this.Transaction); } @@ -381,20 +347,15 @@ public async Task CreateBook(CreateBookArgs args) if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) - { return await connection.QuerySingleAsync(CreateBookSql, queryParams); - } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -436,7 +397,7 @@ 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; } @@ -478,7 +439,7 @@ 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; } @@ -528,10 +489,81 @@ public async Task> GetAuthorsByBookName(GetAuthors } } - private const string InsertMysqlTypesSql = "INSERT INTO mysql_types (c_bit, 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, 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, c_year, c_date, c_datetime, c_timestamp, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob) VALUES ( @c_bit, @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, @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, @c_year, @c_date, @c_datetime, @c_timestamp, @c_binary, @c_varbinary, @c_tinyblob, @c_blob, @c_mediumblob, @c_longblob ) "; - public class InsertMysqlTypesArgs + private const string CreateExtendedBioSql = "INSERT INTO extended.bios (author_name, name, bio_type, author_type) VALUES (@author_name, @name, @bio_type, @author_type)"; + public class CreateExtendedBioArgs + { + public string? AuthorName { get; init; } + public string? Name { get; init; } + public BiosBioType? BioType { get; init; } + public HashSet? AuthorType { get; init; } + }; + public async Task CreateExtendedBio(CreateExtendedBioArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("author_name", args.AuthorName); + queryParams.Add("name", args.Name); + queryParams.Add("bio_type", args.BioType); + queryParams.Add("author_type", args.AuthorType != null ? string.Join(",", args.AuthorType) : null); + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + await connection.ExecuteAsync(CreateExtendedBioSql, queryParams); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(CreateExtendedBioSql, queryParams, transaction: this.Transaction); + } + + private const string GetFirstExtendedBioByTypeSql = "SELECT author_name, name, bio_type, author_type FROM extended.bios WHERE bio_type = @bio_type LIMIT 1"; + public class GetFirstExtendedBioByTypeRow + { + public string? AuthorName { get; init; } + public string? Name { get; init; } + public BiosBioType? BioType { get; init; } + public HashSet? AuthorType { get; init; } + }; + public class GetFirstExtendedBioByTypeArgs + { + public BiosBioType? BioType { get; init; } + }; + public async Task GetFirstExtendedBioByType(GetFirstExtendedBioByTypeArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("bio_type", args.BioType); + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetFirstExtendedBioByTypeSql, queryParams); + return result; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetFirstExtendedBioByTypeSql, queryParams, transaction: this.Transaction); + } + + private const string TruncateExtendedBiosSql = "TRUNCATE TABLE extended.bios"; + public async Task TruncateExtendedBios() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncateExtendedBiosSql); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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)"; + public class InsertMysqlNumericTypesArgs { - public byte? CBit { get; init; } public bool? CBool { get; init; } public bool? CBoolean { get; init; } public short? CTinyint { get; init; } @@ -547,33 +579,10 @@ public class InsertMysqlTypesArgs public double? CFloat { get; init; } public double? CDouble { get; init; } public double? CDoublePrecision { get; init; } - public string? CChar { get; init; } - public string? CNchar { get; init; } - public string? CNationalChar { get; init; } - public string? CVarchar { get; init; } - public string? CTinytext { get; init; } - public string? CMediumtext { get; init; } - public string? CText { get; init; } - public string? CLongtext { get; init; } - public JsonElement? CJson { get; init; } - public string? CJsonStringOverride { get; init; } - public MysqlTypesCEnum? CEnum { get; init; } - public MysqlTypesCSet[]? CSet { get; init; } - public short? CYear { get; init; } - public DateTime? CDate { get; init; } - public DateTime? CDatetime { get; init; } - public DateTime? CTimestamp { get; init; } - public byte[]? CBinary { get; init; } - public byte[]? CVarbinary { get; init; } - public byte[]? CTinyblob { get; init; } - public byte[]? CBlob { get; init; } - public byte[]? CMediumblob { get; init; } - public byte[]? CLongblob { get; init; } }; - public async Task InsertMysqlTypes(InsertMysqlTypesArgs args) + public async Task InsertMysqlNumericTypes(InsertMysqlNumericTypesArgs args) { var queryParams = new Dictionary(); - queryParams.Add("c_bit", args.CBit); queryParams.Add("c_bool", args.CBool); queryParams.Add("c_boolean", args.CBoolean); queryParams.Add("c_tinyint", args.CTinyint); @@ -589,49 +598,20 @@ public async Task InsertMysqlTypes(InsertMysqlTypesArgs args) queryParams.Add("c_float", args.CFloat); queryParams.Add("c_double", args.CDouble); queryParams.Add("c_double_precision", args.CDoublePrecision); - queryParams.Add("c_char", args.CChar); - queryParams.Add("c_nchar", args.CNchar); - queryParams.Add("c_national_char", args.CNationalChar); - queryParams.Add("c_varchar", args.CVarchar); - queryParams.Add("c_tinytext", args.CTinytext); - queryParams.Add("c_mediumtext", args.CMediumtext); - queryParams.Add("c_text", args.CText); - queryParams.Add("c_longtext", args.CLongtext); - queryParams.Add("c_json", args.CJson?.GetRawText() ?? null); - queryParams.Add("c_json_string_override", args.CJsonStringOverride); - queryParams.Add("c_enum", args.CEnum); - queryParams.Add("c_set", args.CSet != null ? string.Join(",", args.CSet) : null); - queryParams.Add("c_year", args.CYear); - queryParams.Add("c_date", args.CDate); - queryParams.Add("c_datetime", args.CDatetime); - queryParams.Add("c_timestamp", args.CTimestamp); - queryParams.Add("c_binary", args.CBinary); - queryParams.Add("c_varbinary", args.CVarbinary); - queryParams.Add("c_tinyblob", args.CTinyblob); - queryParams.Add("c_blob", args.CBlob); - queryParams.Add("c_mediumblob", args.CMediumblob); - queryParams.Add("c_longblob", args.CLongblob); if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) - { - await connection.ExecuteAsync(InsertMysqlTypesSql, queryParams); - } - + await connection.ExecuteAsync(InsertMysqlNumericTypesSql, queryParams); return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - - await this.Transaction.Connection.ExecuteAsync(InsertMysqlTypesSql, queryParams, transaction: this.Transaction); + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertMysqlNumericTypesSql, queryParams, transaction: this.Transaction); } - public class InsertMysqlTypesBatchArgs + public class InsertMysqlNumericTypesBatchArgs { - public byte? CBit { get; init; } public bool? CBool { get; init; } public bool? CBoolean { get; init; } public short? CTinyint { get; init; } @@ -647,30 +627,8 @@ public class InsertMysqlTypesBatchArgs public decimal? CFixed { get; init; } public double? CDouble { get; init; } public double? CDoublePrecision { get; init; } - public string? CChar { get; init; } - public string? CNchar { get; init; } - public string? CNationalChar { get; init; } - public string? CVarchar { get; init; } - public string? CTinytext { get; init; } - public string? CMediumtext { get; init; } - public string? CText { get; init; } - public string? CLongtext { get; init; } - public JsonElement? CJson { get; init; } - public string? CJsonStringOverride { get; init; } - public MysqlTypesCEnum? CEnum { get; init; } - public MysqlTypesCSet[]? CSet { get; init; } - public short? CYear { get; init; } - public DateTime? CDate { get; init; } - public DateTime? CDatetime { get; init; } - public DateTime? CTimestamp { get; init; } - public byte[]? CBinary { get; init; } - public byte[]? CVarbinary { get; init; } - public byte[]? CTinyblob { get; init; } - public byte[]? CBlob { get; init; } - public byte[]? CMediumblob { get; init; } - public byte[]? CLongblob { get; init; } }; - public async Task InsertMysqlTypesBatch(List args) + public async Task InsertMysqlNumericTypesBatch(List args) { const string supportedDateTimeFormat = "yyyy-MM-dd H:mm:ss"; var config = new CsvConfiguration(CultureInfo.CurrentCulture) @@ -693,21 +651,11 @@ public async Task InsertMysqlTypesBatch(List args) csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); csvWriter.Context.TypeConverterCache.AddConverter(new Utils.BoolToBitCsvConverter()); csvWriter.Context.TypeConverterCache.AddConverter(new Utils.BoolToBitCsvConverter()); - csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteCsvConverter()); - csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteCsvConverter()); - csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteArrayCsvConverter()); - csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteArrayCsvConverter()); - csvWriter.Context.TypeConverterCache.AddConverter(new Utils.MysqlTypesCSetCsvConverter()); - csvWriter.Context.TypeConverterCache.AddConverter(new Utils.MysqlTypesCSetCsvConverter()); csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); - csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); - csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); - csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); - csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); await csvWriter.WriteRecordsAsync(args); } @@ -717,7 +665,7 @@ public async Task InsertMysqlTypesBatch(List args) var loader = new MySqlBulkLoader(connection) { Local = true, - TableName = "mysql_types", + TableName = "mysql_numeric_types", FileName = "input.csv", FieldTerminator = ",", FieldQuotationCharacter = '"', @@ -725,14 +673,14 @@ public async Task InsertMysqlTypesBatch(List args) NumberOfLinesToSkip = 1, LineTerminator = "\n" }; - loader.Columns.AddRange(new List { "c_bit", "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", "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", "c_year", "c_date", "c_datetime", "c_timestamp", "c_binary", "c_varbinary", "c_tinyblob", "c_blob", "c_mediumblob", "c_longblob" }); + loader.Columns.AddRange(new List { "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" }); await loader.LoadAsync(); await connection.CloseAsync(); } } - private const string GetMysqlTypesSql = "SELECT c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_decimal, c_dec, c_numeric, c_fixed, c_double, c_double_precision, c_year, c_date, c_time, c_datetime, c_timestamp, 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, c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_types LIMIT 1"; - public class GetMysqlTypesRow + private const string GetMysqlNumericTypesSql = "SELECT c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_decimal, c_dec, c_numeric, c_fixed, c_double, c_double_precision FROM mysql_numeric_types LIMIT 1"; + public class GetMysqlNumericTypesRow { public bool? CBool { get; init; } public bool? CBoolean { get; init; } @@ -749,57 +697,29 @@ public class GetMysqlTypesRow public decimal? CFixed { get; init; } public double? CDouble { get; init; } public double? CDoublePrecision { get; init; } - public short? CYear { get; init; } - public DateTime? CDate { get; init; } - public string? CTime { get; init; } - public DateTime? CDatetime { get; init; } - public DateTime? CTimestamp { get; init; } - public string? CChar { get; init; } - public string? CNchar { get; init; } - public string? CNationalChar { get; init; } - public string? CVarchar { get; init; } - public string? CTinytext { get; init; } - public string? CMediumtext { get; init; } - public string? CText { get; init; } - public string? CLongtext { get; init; } - public JsonElement? CJson { get; init; } - public string? CJsonStringOverride { get; init; } - public MysqlTypesCEnum? CEnum { get; init; } - public MysqlTypesCSet[]? CSet { get; init; } - public byte? CBit { get; init; } - public byte[]? CBinary { get; init; } - public byte[]? CVarbinary { get; init; } - public byte[]? CTinyblob { get; init; } - public byte[]? CBlob { get; init; } - public byte[]? CMediumblob { get; init; } - public byte[]? CLongblob { get; init; } }; - public async Task GetMysqlTypes() + public async Task GetMysqlNumericTypes() { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { - var result = await connection.QueryFirstOrDefaultAsync(GetMysqlTypesSql); + var result = await connection.QueryFirstOrDefaultAsync(GetMysqlNumericTypesSql); return result; } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - - return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlTypesSql, transaction: this.Transaction); + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlNumericTypesSql, transaction: this.Transaction); } - private const string GetMysqlTypesCntSql = "SELECT COUNT(1) AS cnt, c_bool, c_boolean, c_bit, 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, 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, c_year, c_date, c_datetime, c_timestamp, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_types GROUP BY c_bool , c_boolean, c_bit, 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, 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, c_year, c_date, c_datetime, c_timestamp, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob LIMIT 1 "; - public class GetMysqlTypesCntRow + 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; } public bool? CBool { get; init; } public bool? CBoolean { get; init; } - public byte? CBit { get; init; } public short? CTinyint { get; init; } public short? CSmallint { get; init; } public int? CMediumint { get; init; } @@ -813,179 +733,556 @@ public class GetMysqlTypesCntRow public decimal? CFixed { get; init; } public double? CDouble { get; init; } public double? CDoublePrecision { get; init; } - public string? CChar { get; init; } - public string? CNchar { get; init; } - public string? CNationalChar { get; init; } - public string? CVarchar { get; init; } - public string? CTinytext { get; init; } - public string? CMediumtext { get; init; } - public string? CText { get; init; } - public string? CLongtext { get; init; } - public JsonElement? CJson { get; init; } - public string? CJsonStringOverride { get; init; } - public MysqlTypesCEnum? CEnum { get; init; } - public MysqlTypesCSet[]? CSet { get; init; } - public short? CYear { get; init; } - public DateTime? CDate { get; init; } - public DateTime? CDatetime { get; init; } - public DateTime? CTimestamp { get; init; } - public byte[]? CBinary { get; init; } - public byte[]? CVarbinary { get; init; } - public byte[]? CTinyblob { get; init; } - public byte[]? CBlob { get; init; } - public byte[]? CMediumblob { get; init; } - public byte[]? CLongblob { get; init; } }; - public async Task GetMysqlTypesCnt() + public async Task GetMysqlNumericTypesCnt() { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { - var result = await connection.QueryFirstOrDefaultAsync(GetMysqlTypesCntSql); + var result = await connection.QueryFirstOrDefaultAsync(GetMysqlNumericTypesCntSql); return result; } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - - return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlTypesCntSql, transaction: this.Transaction); + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlNumericTypesCntSql, 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_types "; - public class GetMysqlFunctionsRow - { - public int? MaxInt { get; init; } - public string? MaxVarchar { get; init; } - public required DateTime MaxTimestamp { get; init; } - }; - public async Task GetMysqlFunctions() + private const string TruncateMysqlNumericTypesSql = "TRUNCATE TABLE mysql_numeric_types"; + public async Task TruncateMysqlNumericTypes() { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) - { - var result = await connection.QueryFirstOrDefaultAsync(GetMysqlFunctionsSql); - return result; - } + await connection.ExecuteAsync(TruncateMysqlNumericTypesSql); + return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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)"; + public class InsertMysqlStringTypesArgs + { + public string? CChar { get; init; } + public string? CNchar { get; init; } + public string? CNationalChar { get; init; } + public string? CVarchar { get; init; } + public string? CTinytext { get; init; } + public string? CMediumtext { get; init; } + public string? CText { get; init; } + public string? CLongtext { get; init; } + public JsonElement? CJson { get; init; } + public string? CJsonStringOverride { get; init; } + public MysqlStringTypesCEnum? CEnum { get; init; } + public HashSet? CSet { get; init; } + }; + public async Task InsertMysqlStringTypes(InsertMysqlStringTypesArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("c_char", args.CChar); + queryParams.Add("c_nchar", args.CNchar); + queryParams.Add("c_national_char", args.CNationalChar); + queryParams.Add("c_varchar", args.CVarchar); + queryParams.Add("c_tinytext", args.CTinytext); + queryParams.Add("c_mediumtext", args.CMediumtext); + queryParams.Add("c_text", args.CText); + queryParams.Add("c_longtext", args.CLongtext); + queryParams.Add("c_json", args.CJson?.GetRawText() ?? null); + queryParams.Add("c_json_string_override", args.CJsonStringOverride); + queryParams.Add("c_enum", args.CEnum); + queryParams.Add("c_set", args.CSet != null ? string.Join(",", args.CSet) : null); + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + await connection.ExecuteAsync(InsertMysqlStringTypesSql, queryParams); + return; } - return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlFunctionsSql, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertMysqlStringTypesSql, queryParams, transaction: this.Transaction); + } + + public class InsertMysqlStringTypesBatchArgs + { + public string? CChar { get; init; } + public string? CNchar { get; init; } + public string? CNationalChar { get; init; } + public string? CVarchar { get; init; } + public string? CTinytext { get; init; } + public string? CMediumtext { get; init; } + public string? CText { get; init; } + public string? CLongtext { get; init; } + public JsonElement? CJson { get; init; } + public string? CJsonStringOverride { get; init; } + public MysqlStringTypesCEnum? CEnum { get; init; } + public HashSet? CSet { get; init; } + }; + public async Task InsertMysqlStringTypesBatch(List args) + { + const string supportedDateTimeFormat = "yyyy-MM-dd H:mm:ss"; + var config = new CsvConfiguration(CultureInfo.CurrentCulture) + { + Delimiter = ",", + NewLine = "\n" + }; + var nullConverterFn = new Utils.NullToStringCsvConverter(); + using (var writer = new StreamWriter("input.csv", false, new UTF8Encoding(false))) + using (var csvWriter = new CsvWriter(writer, config)) + { + var options = new TypeConverterOptions + { + Formats = new[] + { + supportedDateTimeFormat + } + }; + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterCache.AddConverter>(new Utils.MysqlStringTypesCSetCsvConverter()); + csvWriter.Context.TypeConverterCache.AddConverter?>(new Utils.MysqlStringTypesCSetCsvConverter()); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + await csvWriter.WriteRecordsAsync(args); + } + + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + var loader = new MySqlBulkLoader(connection) + { + Local = true, + TableName = "mysql_string_types", + FileName = "input.csv", + FieldTerminator = ",", + FieldQuotationCharacter = '"', + FieldQuotationOptional = true, + NumberOfLinesToSkip = 1, + LineTerminator = "\n" + }; + loader.Columns.AddRange(new List { "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" }); + await loader.LoadAsync(); + await connection.CloseAsync(); + } } - private const string TruncateMysqlTypesSql = "TRUNCATE TABLE mysql_types"; - public async Task TruncateMysqlTypes() + private const string GetMysqlStringTypesSql = "SELECT 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 LIMIT 1"; + public class GetMysqlStringTypesRow + { + public string? CChar { get; init; } + public string? CNchar { get; init; } + public string? CNationalChar { get; init; } + public string? CVarchar { get; init; } + public string? CTinytext { get; init; } + public string? CMediumtext { get; init; } + public string? CText { get; init; } + public string? CLongtext { get; init; } + public JsonElement? CJson { get; init; } + public string? CJsonStringOverride { get; init; } + public MysqlStringTypesCEnum? CEnum { get; init; } + public HashSet? CSet { get; init; } + }; + public async Task GetMysqlStringTypes() { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { - await connection.ExecuteAsync(TruncateMysqlTypesSql); + var result = await connection.QueryFirstOrDefaultAsync(GetMysqlStringTypesSql); + return result; } + } - return; + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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"; + public class GetMysqlStringTypesCntRow + { + public required long Cnt { get; init; } + public string? CChar { get; init; } + public string? CNchar { get; init; } + public string? CNationalChar { get; init; } + public string? CVarchar { get; init; } + public string? CTinytext { get; init; } + public string? CMediumtext { get; init; } + public string? CText { get; init; } + public string? CLongtext { get; init; } + public JsonElement? CJson { get; init; } + public string? CJsonStringOverride { get; init; } + public MysqlStringTypesCEnum? CEnum { get; init; } + public HashSet? CSet { get; init; } + }; + public async Task GetMysqlStringTypesCnt() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetMysqlStringTypesCntSql); + return result; + } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlStringTypesCntSql, transaction: this.Transaction); + } + + private const string TruncateMysqlStringTypesSql = "TRUNCATE TABLE mysql_string_types"; + public async Task TruncateMysqlStringTypes() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new MySqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncateMysqlStringTypesSql); + return; } - await this.Transaction.Connection.ExecuteAsync(TruncateMysqlTypesSql, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncateMysqlStringTypesSql, transaction: this.Transaction); } - private const string CreateExtendedBioSql = "INSERT INTO extended.bios (author_name, name, bio_type, author_type) VALUES (@author_name, @name, @bio_type, @author_type)"; - public class CreateExtendedBioArgs + private const string InsertMysqlDatetimeTypesSql = " INSERT INTO mysql_datetime_types ( c_year, c_date, c_datetime, c_timestamp, c_time ) VALUES (@c_year, @c_date, @c_datetime, @c_timestamp, @c_time)"; + public class InsertMysqlDatetimeTypesArgs { - public string? AuthorName { get; init; } - public string? Name { get; init; } - public ExtendedBiosBioType? BioType { get; init; } - public ExtendedBiosAuthorType[]? AuthorType { get; init; } + public short? CYear { get; init; } + public DateTime? CDate { get; init; } + public DateTime? CDatetime { get; init; } + public DateTime? CTimestamp { get; init; } + public TimeSpan? CTime { get; init; } }; - public async Task CreateExtendedBio(CreateExtendedBioArgs args) + public async Task InsertMysqlDatetimeTypes(InsertMysqlDatetimeTypesArgs args) { var queryParams = new Dictionary(); - queryParams.Add("author_name", args.AuthorName); - queryParams.Add("name", args.Name); - queryParams.Add("bio_type", args.BioType); - queryParams.Add("author_type", args.AuthorType != null ? string.Join(",", args.AuthorType) : null); + queryParams.Add("c_year", args.CYear); + queryParams.Add("c_date", args.CDate); + queryParams.Add("c_datetime", args.CDatetime); + queryParams.Add("c_timestamp", args.CTimestamp); + queryParams.Add("c_time", args.CTime); if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) - { - await connection.ExecuteAsync(CreateExtendedBioSql, queryParams); - } - + await connection.ExecuteAsync(InsertMysqlDatetimeTypesSql, queryParams); return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertMysqlDatetimeTypesSql, queryParams, transaction: this.Transaction); + } + + public class InsertMysqlDatetimeTypesBatchArgs + { + public short? CYear { get; init; } + public DateTime? CDate { get; init; } + public DateTime? CDatetime { get; init; } + public DateTime? CTimestamp { get; init; } + public TimeSpan? CTime { get; init; } + }; + public async Task InsertMysqlDatetimeTypesBatch(List args) + { + const string supportedDateTimeFormat = "yyyy-MM-dd H:mm:ss"; + var config = new CsvConfiguration(CultureInfo.CurrentCulture) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + Delimiter = ",", + NewLine = "\n" + }; + var nullConverterFn = new Utils.NullToStringCsvConverter(); + using (var writer = new StreamWriter("input.csv", false, new UTF8Encoding(false))) + using (var csvWriter = new CsvWriter(writer, config)) + { + var options = new TypeConverterOptions + { + Formats = new[] + { + supportedDateTimeFormat + } + }; + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + await csvWriter.WriteRecordsAsync(args); } - await this.Transaction.Connection.ExecuteAsync(CreateExtendedBioSql, queryParams, transaction: this.Transaction); + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + var loader = new MySqlBulkLoader(connection) + { + Local = true, + TableName = "mysql_datetime_types", + FileName = "input.csv", + FieldTerminator = ",", + FieldQuotationCharacter = '"', + FieldQuotationOptional = true, + NumberOfLinesToSkip = 1, + LineTerminator = "\n" + }; + loader.Columns.AddRange(new List { "c_year", "c_date", "c_datetime", "c_timestamp", "c_time" }); + await loader.LoadAsync(); + await connection.CloseAsync(); + } } - private const string GetFirstExtendedBioByTypeSql = "SELECT author_name, name, bio_type, author_type FROM extended.bios WHERE bio_type = @bio_type LIMIT 1"; - public class GetFirstExtendedBioByTypeRow + private const string GetMysqlDatetimeTypesSql = "SELECT c_year, c_date, c_datetime, c_timestamp, c_time FROM mysql_datetime_types LIMIT 1"; + public class GetMysqlDatetimeTypesRow { - public string? AuthorName { get; init; } - public string? Name { get; init; } - public ExtendedBiosBioType? BioType { get; init; } - public ExtendedBiosAuthorType[]? AuthorType { get; init; } + public short? CYear { get; init; } + public DateTime? CDate { get; init; } + public DateTime? CDatetime { get; init; } + public DateTime? CTimestamp { get; init; } + public TimeSpan? CTime { get; init; } }; - public class GetFirstExtendedBioByTypeArgs + public async Task GetMysqlDatetimeTypes() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetMysqlDatetimeTypesSql); + return result; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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"; + public class GetMysqlDatetimeTypesCntRow { - public ExtendedBiosBioType? BioType { get; init; } + public required long Cnt { get; init; } + public short? CYear { get; init; } + public DateTime? CDate { get; init; } + public DateTime? CDatetime { get; init; } + public DateTime? CTimestamp { get; init; } + public TimeSpan? CTime { get; init; } }; - public async Task GetFirstExtendedBioByType(GetFirstExtendedBioByTypeArgs args) + public async Task GetMysqlDatetimeTypesCnt() { - var queryParams = new Dictionary(); - queryParams.Add("bio_type", args.BioType); if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { - var result = await connection.QueryFirstOrDefaultAsync(GetFirstExtendedBioByTypeSql, queryParams); + var result = await connection.QueryFirstOrDefaultAsync(GetMysqlDatetimeTypesCntSql); return result; } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlDatetimeTypesCntSql, transaction: this.Transaction); + } + + private const string TruncateMysqlDatetimeTypesSql = "TRUNCATE TABLE mysql_datetime_types"; + public async Task TruncateMysqlDatetimeTypes() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new MySqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncateMysqlDatetimeTypesSql); + return; } - return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetFirstExtendedBioByTypeSql, queryParams, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncateMysqlDatetimeTypesSql, transaction: this.Transaction); } - private const string TruncateExtendedBiosSql = "TRUNCATE TABLE extended.bios"; - public async Task TruncateExtendedBios() + 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; } + public byte[]? CBinary { get; init; } + public byte[]? CVarbinary { get; init; } + public byte[]? CTinyblob { get; init; } + public byte[]? CBlob { get; init; } + public byte[]? CMediumblob { get; init; } + public byte[]? CLongblob { get; init; } + }; + public async Task InsertMysqlBinaryTypes(InsertMysqlBinaryTypesArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("c_bit", args.CBit); + queryParams.Add("c_binary", args.CBinary); + queryParams.Add("c_varbinary", args.CVarbinary); + queryParams.Add("c_tinyblob", args.CTinyblob); + queryParams.Add("c_blob", args.CBlob); + queryParams.Add("c_mediumblob", args.CMediumblob); + queryParams.Add("c_longblob", args.CLongblob); if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) + await connection.ExecuteAsync(InsertMysqlBinaryTypesSql, queryParams); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertMysqlBinaryTypesSql, queryParams, transaction: this.Transaction); + } + + public class InsertMysqlBinaryTypesBatchArgs + { + public byte? CBit { get; init; } + public byte[]? CBinary { get; init; } + public byte[]? CVarbinary { get; init; } + public byte[]? CTinyblob { get; init; } + public byte[]? CBlob { get; init; } + public byte[]? CMediumblob { get; init; } + public byte[]? CLongblob { get; init; } + }; + public async Task InsertMysqlBinaryTypesBatch(List args) + { + const string supportedDateTimeFormat = "yyyy-MM-dd H:mm:ss"; + var config = new CsvConfiguration(CultureInfo.CurrentCulture) + { + Delimiter = ",", + NewLine = "\n" + }; + var nullConverterFn = new Utils.NullToStringCsvConverter(); + using (var writer = new StreamWriter("input.csv", false, new UTF8Encoding(false))) + using (var csvWriter = new CsvWriter(writer, config)) + { + var options = new TypeConverterOptions { - await connection.ExecuteAsync(TruncateExtendedBiosSql); + Formats = new[] + { + supportedDateTimeFormat + } + }; + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteCsvConverter()); + csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteCsvConverter()); + csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteArrayCsvConverter()); + csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteArrayCsvConverter()); + await csvWriter.WriteRecordsAsync(args); + } + + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + var loader = new MySqlBulkLoader(connection) + { + Local = true, + TableName = "mysql_binary_types", + FileName = "input.csv", + FieldTerminator = ",", + FieldQuotationCharacter = '"', + FieldQuotationOptional = true, + NumberOfLinesToSkip = 1, + LineTerminator = "\n" + }; + loader.Columns.AddRange(new List { "c_bit", "c_binary", "c_varbinary", "c_tinyblob", "c_blob", "c_mediumblob", "c_longblob" }); + await loader.LoadAsync(); + await connection.CloseAsync(); + } + } + + private const string GetMysqlBinaryTypesSql = "SELECT c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_binary_types LIMIT 1"; + public class GetMysqlBinaryTypesRow + { + public byte? CBit { get; init; } + public byte[]? CBinary { get; init; } + public byte[]? CVarbinary { get; init; } + public byte[]? CTinyblob { get; init; } + public byte[]? CBlob { get; init; } + public byte[]? CMediumblob { get; init; } + public byte[]? CLongblob { get; init; } + }; + public async Task GetMysqlBinaryTypes() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetMysqlBinaryTypesSql); + return result; } + } + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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"; + public class GetMysqlBinaryTypesCntRow + { + public required long Cnt { get; init; } + public byte? CBit { get; init; } + public byte[]? CBinary { get; init; } + public byte[]? CVarbinary { get; init; } + public byte[]? CTinyblob { get; init; } + public byte[]? CBlob { get; init; } + public byte[]? CMediumblob { get; init; } + public byte[]? CLongblob { get; init; } + }; + public async Task GetMysqlBinaryTypesCnt() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetMysqlBinaryTypesCntSql); + return result; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlBinaryTypesCntSql, transaction: this.Transaction); + } + + private const string TruncateMysqlBinaryTypesSql = "TRUNCATE TABLE mysql_binary_types"; + public async Task TruncateMysqlBinaryTypes() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncateMysqlBinaryTypesSql); return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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"; + public class GetMysqlFunctionsRow + { + public int? MaxInt { get; init; } + public string? MaxVarchar { get; init; } + public required DateTime MaxTimestamp { get; init; } + }; + public async Task GetMysqlFunctions() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new MySqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetMysqlFunctionsSql); + return result; + } } - await this.Transaction.Connection.ExecuteAsync(TruncateExtendedBiosSql, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlFunctionsSql, transaction: this.Transaction); } } \ No newline at end of file diff --git a/examples/MySqlConnectorDapperExample/Utils.cs b/examples/MySqlConnectorDapperExample/Utils.cs index b2b76e0f..f8bb27fe 100644 --- a/examples/MySqlConnectorDapperExample/Utils.cs +++ b/examples/MySqlConnectorDapperExample/Utils.cs @@ -3,6 +3,7 @@ using CsvHelper.Configuration; using CsvHelper.TypeConversion; using Dapper; +using System.Collections.Generic; using System.Data; using System.Linq; using System.Text.Json; @@ -28,8 +29,8 @@ public override void SetValue(IDbDataParameter parameter, JsonElement value) public static void ConfigureSqlMapper() { SqlMapper.AddTypeHandler(typeof(JsonElement), new JsonElementTypeHandler()); - SqlMapper.AddTypeHandler(typeof(MysqlTypesCSet[]), new MysqlTypesCSetTypeHandler()); - SqlMapper.AddTypeHandler(typeof(ExtendedBiosAuthorType[]), new ExtendedBiosAuthorTypeTypeHandler()); + SqlMapper.AddTypeHandler(typeof(HashSet), new BiosAuthorTypeTypeHandler()); + SqlMapper.AddTypeHandler(typeof(HashSet), new MysqlStringTypesCSetTypeHandler()); } public static string TransformQueryForSliceArgs(string originalSql, int sliceSize, string paramName) @@ -38,44 +39,44 @@ public static string TransformQueryForSliceArgs(string originalSql, int sliceSiz return originalSql.Replace($"/*SLICE:{paramName}*/@{paramName}", string.Join(",", paramArgs)); } - private class MysqlTypesCSetTypeHandler : SqlMapper.TypeHandler + private class BiosAuthorTypeTypeHandler : SqlMapper.TypeHandler> { - public override MysqlTypesCSet[] Parse(object value) + public override HashSet Parse(object value) { if (value is string s) - return s.ToMysqlTypesCSetArr(); - throw new DataException($"Cannot convert {value?.GetType()} to MysqlTypesCSet[]"); + return s.ToBiosAuthorTypeSet(); + throw new DataException($"Cannot convert {value?.GetType()} to HashSet"); } - public override void SetValue(IDbDataParameter parameter, MysqlTypesCSet[] value) + public override void SetValue(IDbDataParameter parameter, HashSet value) { parameter.Value = string.Join(",", value); } } - private class ExtendedBiosAuthorTypeTypeHandler : SqlMapper.TypeHandler + private class MysqlStringTypesCSetTypeHandler : SqlMapper.TypeHandler> { - public override ExtendedBiosAuthorType[] Parse(object value) + public override HashSet Parse(object value) { if (value is string s) - return s.ToExtendedBiosAuthorTypeArr(); - throw new DataException($"Cannot convert {value?.GetType()} to ExtendedBiosAuthorType[]"); + return s.ToMysqlStringTypesCSetSet(); + throw new DataException($"Cannot convert {value?.GetType()} to HashSet"); } - public override void SetValue(IDbDataParameter parameter, ExtendedBiosAuthorType[] value) + public override void SetValue(IDbDataParameter parameter, HashSet value) { parameter.Value = string.Join(",", value); } } - public class MysqlTypesCSetCsvConverter : DefaultTypeConverter + public class MysqlStringTypesCSetCsvConverter : DefaultTypeConverter { public override string? ConvertToString(object? value, IWriterRow row, MemberMapData memberMapData) { if (value == null) return @"\N"; - if (value is MysqlTypesCSet[] arrVal) - return string.Join(",", arrVal); + if (value is HashSet setVal) + return string.Join(",", setVal); return base.ConvertToString(value, row, memberMapData); } } diff --git a/examples/MySqlConnectorDapperExample/request.json b/examples/MySqlConnectorDapperExample/request.json index c9ba1e68..23d0fc09 100644 --- a/examples/MySqlConnectorDapperExample/request.json +++ b/examples/MySqlConnectorDapperExample/request.json @@ -3,10 +3,12 @@ "version": "2", "engine": "mysql", "schema": [ - "examples/config/mysql/schema.sql" + "examples/config/mysql/authors/schema.sql", + "examples/config/mysql/types/schema.sql" ], "queries": [ - "examples/config/mysql/query.sql" + "examples/config/mysql/authors/query.sql", + "examples/config/mysql/types/query.sql" ], "codegen": { "out": "examples/MySqlConnectorDapperExample", @@ -114,14 +116,14 @@ }, { "rel": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "columns": [ { "name": "c_bool", "length": 1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "tinyint" @@ -131,7 +133,7 @@ "name": "c_boolean", "length": 1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "tinyint" @@ -141,7 +143,7 @@ "name": "c_tinyint", "length": 3, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "tinyint" @@ -151,7 +153,7 @@ "name": "c_smallint", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "smallint" @@ -161,7 +163,7 @@ "name": "c_mediumint", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "mediumint" @@ -171,7 +173,7 @@ "name": "c_int", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "int" @@ -181,7 +183,7 @@ "name": "c_integer", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "int" @@ -191,7 +193,7 @@ "name": "c_bigint", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "bigint" @@ -201,7 +203,7 @@ "name": "c_float", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "float" @@ -211,7 +213,7 @@ "name": "c_decimal", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -221,7 +223,7 @@ "name": "c_dec", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -231,7 +233,7 @@ "name": "c_numeric", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -241,7 +243,7 @@ "name": "c_fixed", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -251,7 +253,7 @@ "name": "c_double", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "double" @@ -261,187 +263,208 @@ "name": "c_double_precision", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "double" } - }, + } + ] + }, + { + "rel": { + "name": "mysql_string_types" + }, + "columns": [ { - "name": "c_year", + "name": "c_char", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "year" + "name": "char" } }, { - "name": "c_date", + "name": "c_nchar", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "date" + "name": "char" } }, { - "name": "c_time", - "length": 10, + "name": "c_national_char", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "time" + "name": "char" } }, { - "name": "c_datetime", - "length": 19, + "name": "c_varchar", + "length": 100, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "datetime" + "name": "varchar" } }, { - "name": "c_timestamp", - "length": 19, + "name": "c_tinytext", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "timestamp" + "name": "tinytext" } }, { - "name": "c_char", + "name": "c_mediumtext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "char" + "name": "mediumtext" } }, { - "name": "c_nchar", + "name": "c_text", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "char" + "name": "text" } }, { - "name": "c_national_char", + "name": "c_longtext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "char" + "name": "longtext" } }, { - "name": "c_varchar", - "length": 100, + "name": "c_json", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "varchar" + "name": "json" } }, { - "name": "c_tinytext", + "name": "c_json_string_override", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "tinytext" + "name": "json" } }, { - "name": "c_mediumtext", - "length": -1, + "name": "c_enum", + "length": 6, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mediumtext" + "name": "mysql_string_types_c_enum" } }, { - "name": "c_text", - "length": -1, + "name": "c_set", + "length": 15, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "text" + "name": "mysql_string_types_c_set" } - }, + } + ] + }, + { + "rel": { + "name": "mysql_datetime_types" + }, + "columns": [ { - "name": "c_longtext", + "name": "c_year", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "longtext" + "name": "year" } }, { - "name": "c_json", + "name": "c_date", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "json" + "name": "date" } }, { - "name": "c_json_string_override", - "length": -1, + "name": "c_datetime", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "json" + "name": "datetime" } }, { - "name": "c_enum", - "length": 6, + "name": "c_timestamp", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "mysql_types_c_enum" + "name": "timestamp" } }, { - "name": "c_set", - "length": 15, + "name": "c_time", + "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "mysql_types_c_set" + "name": "time" } - }, + } + ] + }, + { + "rel": { + "name": "mysql_binary_types" + }, + "columns": [ { "name": "c_bit", "length": 8, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "bit" @@ -451,7 +474,7 @@ "name": "c_binary", "length": 3, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "binary" @@ -461,7 +484,7 @@ "name": "c_varbinary", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "varbinary" @@ -471,7 +494,7 @@ "name": "c_tinyblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "tinyblob" @@ -481,7 +504,7 @@ "name": "c_blob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "blob" @@ -491,7 +514,7 @@ "name": "c_mediumblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "mediumblob" @@ -501,7 +524,7 @@ "name": "c_longblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "longblob" @@ -511,22 +534,6 @@ } ], "enums": [ - { - "name": "mysql_types_c_enum", - "vals": [ - "small", - "medium", - "big" - ] - }, - { - "name": "mysql_types_c_set", - "vals": [ - "tea", - "coffee", - "milk" - ] - }, { "name": "bios_bio_type", "vals": [ @@ -542,6 +549,22 @@ "Editor", "Translator" ] + }, + { + "name": "mysql_string_types_c_enum", + "vals": [ + "small", + "medium", + "big" + ] + }, + { + "name": "mysql_string_types_c_set", + "vals": [ + "tea", + "coffee", + "milk" + ] } ] }, @@ -1306,93 +1329,229 @@ "filename": "query.sql" }, { - "text": "INSERT INTO mysql_types \n(c_bit, c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, \n c_decimal, c_dec, c_numeric, c_fixed, c_float, c_double, c_double_precision, \n c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, \n c_json, c_json_string_override, c_enum, c_set, c_year, c_date, c_datetime, c_timestamp, \n c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - "name": "InsertMysqlTypes", + "text": "INSERT INTO extended.bios (author_name, name, bio_type, author_type) VALUES (?, ?, ?, ?)", + "name": "CreateExtendedBio", "cmd": ":exec", "parameters": [ { "number": 1, "column": { - "name": "c_bit", - "length": 8, + "name": "author_name", + "length": 100, "table": { - "schema": "public", - "name": "mysql_types" + "schema": "extended", + "name": "bios" }, "type": { - "name": "bit" + "name": "varchar" }, - "originalName": "c_bit" + "originalName": "author_name" } }, { "number": 2, "column": { - "name": "c_bool", - "length": 1, + "name": "name", + "length": 100, "table": { - "schema": "public", - "name": "mysql_types" + "schema": "extended", + "name": "bios" }, "type": { - "name": "tinyint" + "name": "varchar" }, - "originalName": "c_bool" + "originalName": "name" } }, { "number": 3, "column": { - "name": "c_boolean", - "length": 1, + "name": "bio_type", + "length": 13, "table": { - "schema": "public", - "name": "mysql_types" + "schema": "extended", + "name": "bios" }, "type": { - "name": "tinyint" + "name": "bios_bio_type" }, - "originalName": "c_boolean" + "originalName": "bio_type" } }, { "number": 4, "column": { - "name": "c_tinyint", - "length": 3, + "name": "author_type", + "length": 24, "table": { - "schema": "public", - "name": "mysql_types" + "schema": "extended", + "name": "bios" }, "type": { - "name": "tinyint" + "name": "bios_author_type" }, - "originalName": "c_tinyint" + "originalName": "author_type" } + } + ], + "filename": "query.sql", + "insert_into_table": { + "schema": "extended", + "name": "bios" + } + }, + { + "text": "SELECT author_name, name, bio_type, author_type FROM extended.bios WHERE bio_type = ? LIMIT 1", + "name": "GetFirstExtendedBioByType", + "cmd": ":one", + "columns": [ + { + "name": "author_name", + "length": 100, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "varchar" + }, + "originalName": "author_name" }, { - "number": 5, + "name": "name", + "length": 100, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "varchar" + }, + "originalName": "name" + }, + { + "name": "bio_type", + "length": 13, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "bios_bio_type" + }, + "originalName": "bio_type" + }, + { + "name": "author_type", + "length": 24, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "bios_author_type" + }, + "originalName": "author_type" + } + ], + "parameters": [ + { + "number": 1, "column": { - "name": "c_smallint", - "length": -1, + "name": "bio_type", + "length": 13, "table": { - "schema": "public", - "name": "mysql_types" + "schema": "extended", + "name": "bios" }, "type": { - "name": "smallint" + "name": "bios_bio_type" }, - "originalName": "c_smallint" + "originalName": "bio_type" } - }, + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE extended.bios", + "name": "TruncateExtendedBios", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO mysql_numeric_types \n(\n c_bool,\n c_boolean,\n c_tinyint,\n c_smallint,\n c_mediumint,\n c_int,\n c_integer,\n c_bigint, \n c_decimal, \n c_dec, \n c_numeric, \n c_fixed, \n c_float, \n c_double, \n c_double_precision\n) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlNumericTypes", + "cmd": ":exec", + "parameters": [ { - "number": 6, + "number": 1, + "column": { + "name": "c_bool", + "length": 1, + "table": { + "schema": "public", + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_bool" + } + }, + { + "number": 2, + "column": { + "name": "c_boolean", + "length": 1, + "table": { + "schema": "public", + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_boolean" + } + }, + { + "number": 3, + "column": { + "name": "c_tinyint", + "length": 3, + "table": { + "schema": "public", + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_tinyint" + } + }, + { + "number": 4, + "column": { + "name": "c_smallint", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_numeric_types" + }, + "type": { + "name": "smallint" + }, + "originalName": "c_smallint" + } + }, + { + "number": 5, "column": { "name": "c_mediumint", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "mediumint" @@ -1401,13 +1560,13 @@ } }, { - "number": 7, + "number": 6, "column": { "name": "c_int", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "int" @@ -1416,13 +1575,13 @@ } }, { - "number": 8, + "number": 7, "column": { "name": "c_integer", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "int" @@ -1431,13 +1590,13 @@ } }, { - "number": 9, + "number": 8, "column": { "name": "c_bigint", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "bigint" @@ -1446,13 +1605,13 @@ } }, { - "number": 10, + "number": 9, "column": { "name": "c_decimal", "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -1461,13 +1620,13 @@ } }, { - "number": 11, + "number": 10, "column": { "name": "c_dec", "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -1476,13 +1635,13 @@ } }, { - "number": 12, + "number": 11, "column": { "name": "c_numeric", "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -1491,13 +1650,13 @@ } }, { - "number": 13, + "number": 12, "column": { "name": "c_fixed", "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -1506,13 +1665,13 @@ } }, { - "number": 14, + "number": 13, "column": { "name": "c_float", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "float" @@ -1521,13 +1680,13 @@ } }, { - "number": 15, + "number": 14, "column": { "name": "c_double", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "double" @@ -1536,609 +1695,639 @@ } }, { - "number": 16, + "number": 15, "column": { "name": "c_double_precision", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "double" }, "originalName": "c_double_precision" } - }, + } + ], + "comments": [ + " Numeric types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_numeric_types" + } + }, + { + "text": "INSERT INTO mysql_numeric_types \n(\n c_bool,\n c_boolean,\n c_tinyint,\n c_smallint,\n c_mediumint,\n c_int,\n c_integer,\n c_bigint, \n c_float, \n c_numeric, \n c_decimal, \n c_dec, \n c_fixed, \n c_double, \n c_double_precision\n) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlNumericTypesBatch", + "cmd": ":copyfrom", + "parameters": [ { - "number": 17, + "number": 1, "column": { - "name": "c_char", - "length": -1, + "name": "c_bool", + "length": 1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "char" + "name": "tinyint" }, - "originalName": "c_char" + "originalName": "c_bool" } }, { - "number": 18, + "number": 2, "column": { - "name": "c_nchar", - "length": -1, + "name": "c_boolean", + "length": 1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "char" + "name": "tinyint" }, - "originalName": "c_nchar" + "originalName": "c_boolean" } }, { - "number": 19, + "number": 3, "column": { - "name": "c_national_char", - "length": -1, + "name": "c_tinyint", + "length": 3, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "char" + "name": "tinyint" }, - "originalName": "c_national_char" + "originalName": "c_tinyint" } }, { - "number": 20, + "number": 4, "column": { - "name": "c_varchar", - "length": 100, + "name": "c_smallint", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "varchar" + "name": "smallint" }, - "originalName": "c_varchar" + "originalName": "c_smallint" } }, { - "number": 21, + "number": 5, "column": { - "name": "c_tinytext", + "name": "c_mediumint", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "tinytext" + "name": "mediumint" }, - "originalName": "c_tinytext" + "originalName": "c_mediumint" } }, { - "number": 22, + "number": 6, "column": { - "name": "c_mediumtext", + "name": "c_int", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "mediumtext" + "name": "int" }, - "originalName": "c_mediumtext" + "originalName": "c_int" } }, { - "number": 23, + "number": 7, "column": { - "name": "c_text", + "name": "c_integer", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "text" + "name": "int" }, - "originalName": "c_text" + "originalName": "c_integer" } }, { - "number": 24, + "number": 8, "column": { - "name": "c_longtext", + "name": "c_bigint", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "longtext" + "name": "bigint" }, - "originalName": "c_longtext" + "originalName": "c_bigint" } }, { - "number": 25, + "number": 9, "column": { - "name": "c_json", + "name": "c_float", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "json" + "name": "float" }, - "originalName": "c_json" + "originalName": "c_float" } }, { - "number": 26, + "number": 10, "column": { - "name": "c_json_string_override", - "length": -1, + "name": "c_numeric", + "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "json" + "name": "decimal" }, - "originalName": "c_json_string_override" + "originalName": "c_numeric" } }, { - "number": 27, + "number": 11, "column": { - "name": "c_enum", - "length": 6, + "name": "c_decimal", + "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "mysql_types_c_enum" + "name": "decimal" }, - "originalName": "c_enum" + "originalName": "c_decimal" } }, { - "number": 28, + "number": 12, "column": { - "name": "c_set", - "length": 15, + "name": "c_dec", + "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "mysql_types_c_set" + "name": "decimal" }, - "originalName": "c_set" + "originalName": "c_dec" } }, { - "number": 29, + "number": 13, "column": { - "name": "c_year", - "length": -1, + "name": "c_fixed", + "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "year" + "name": "decimal" }, - "originalName": "c_year" + "originalName": "c_fixed" } }, { - "number": 30, + "number": 14, "column": { - "name": "c_date", + "name": "c_double", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "date" + "name": "double" }, - "originalName": "c_date" + "originalName": "c_double" } }, { - "number": 31, + "number": 15, "column": { - "name": "c_datetime", - "length": 19, + "name": "c_double_precision", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "datetime" + "name": "double" }, - "originalName": "c_datetime" + "originalName": "c_double_precision" } - }, + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_numeric_types" + } + }, + { + "text": "SELECT c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_decimal, c_dec, c_numeric, c_fixed, c_double, c_double_precision FROM mysql_numeric_types LIMIT 1", + "name": "GetMysqlNumericTypes", + "cmd": ":one", + "columns": [ { - "number": 32, - "column": { - "name": "c_timestamp", - "length": 19, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "timestamp" - }, - "originalName": "c_timestamp" - } + "name": "c_bool", + "length": 1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_bool" }, { - "number": 33, - "column": { - "name": "c_binary", - "length": 3, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "binary" - }, - "originalName": "c_binary" - } + "name": "c_boolean", + "length": 1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_boolean" }, { - "number": 34, - "column": { - "name": "c_varbinary", - "length": 10, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "varbinary" - }, - "originalName": "c_varbinary" - } + "name": "c_tinyint", + "length": 3, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_tinyint" }, { - "number": 35, - "column": { - "name": "c_tinyblob", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "tinyblob" - }, - "originalName": "c_tinyblob" - } + "name": "c_smallint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "smallint" + }, + "originalName": "c_smallint" }, { - "number": 36, - "column": { - "name": "c_blob", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "blob" - }, - "originalName": "c_blob" - } + "name": "c_mediumint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "mediumint" + }, + "originalName": "c_mediumint" }, { - "number": 37, - "column": { - "name": "c_mediumblob", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "mediumblob" - }, - "originalName": "c_mediumblob" - } + "name": "c_int", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "int" + }, + "originalName": "c_int" }, { - "number": 38, - "column": { - "name": "c_longblob", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "longblob" - }, - "originalName": "c_longblob" - } + "name": "c_integer", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "int" + }, + "originalName": "c_integer" + }, + { + "name": "c_bigint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "bigint" + }, + "originalName": "c_bigint" + }, + { + "name": "c_float", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "float" + }, + "originalName": "c_float" + }, + { + "name": "c_decimal", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_decimal" + }, + { + "name": "c_dec", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_dec" + }, + { + "name": "c_numeric", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_numeric" + }, + { + "name": "c_fixed", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_fixed" + }, + { + "name": "c_double", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "double" + }, + "originalName": "c_double" + }, + { + "name": "c_double_precision", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "double" + }, + "originalName": "c_double_precision" } ], - "filename": "query.sql", - "insert_into_table": { - "name": "mysql_types" - } + "filename": "query.sql" }, { - "text": "INSERT INTO mysql_types \n(c_bit, c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, \n c_float, c_numeric, c_decimal, c_dec, c_fixed, c_double, c_double_precision, \n c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, \n c_json, c_json_string_override, c_enum, c_set, c_year, c_date, c_datetime, c_timestamp,\n c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - "name": "InsertMysqlTypesBatch", - "cmd": ":copyfrom", - "parameters": [ - { - "number": 1, - "column": { - "name": "c_bit", - "length": 8, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "bit" - }, - "originalName": "c_bit" - } - }, + "text": "SELECT\n COUNT(*) AS cnt,\n c_bool,\n c_boolean,\n c_tinyint,\n c_smallint,\n c_mediumint,\n c_int,\n c_integer,\n c_bigint,\n c_float,\n c_numeric,\n c_decimal,\n c_dec,\n c_fixed,\n c_double,\n c_double_precision\nFROM mysql_numeric_types\nGROUP BY\n c_bool,\n c_boolean,\n c_tinyint,\n c_smallint,\n c_mediumint,\n c_int,\n c_integer,\n c_bigint,\n c_float,\n c_numeric,\n c_decimal,\n c_dec,\n c_fixed,\n c_double,\n c_double_precision\nLIMIT 1", + "name": "GetMysqlNumericTypesCnt", + "cmd": ":one", + "columns": [ { - "number": 2, - "column": { - "name": "c_bool", - "length": 1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_bool" + "name": "cnt", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "bigint" } }, { - "number": 3, - "column": { - "name": "c_boolean", - "length": 1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_boolean" - } + "name": "c_bool", + "length": 1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_bool" }, { - "number": 4, - "column": { - "name": "c_tinyint", - "length": 3, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_tinyint" - } + "name": "c_boolean", + "length": 1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_boolean" }, { - "number": 5, - "column": { - "name": "c_smallint", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "smallint" - }, - "originalName": "c_smallint" - } + "name": "c_tinyint", + "length": 3, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_tinyint" }, { - "number": 6, - "column": { - "name": "c_mediumint", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "mediumint" - }, - "originalName": "c_mediumint" - } + "name": "c_smallint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "smallint" + }, + "originalName": "c_smallint" }, { - "number": 7, - "column": { - "name": "c_int", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "int" - }, - "originalName": "c_int" - } + "name": "c_mediumint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "mediumint" + }, + "originalName": "c_mediumint" }, { - "number": 8, - "column": { - "name": "c_integer", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "int" - }, - "originalName": "c_integer" - } + "name": "c_int", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "int" + }, + "originalName": "c_int" }, { - "number": 9, - "column": { - "name": "c_bigint", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "bigint" - }, - "originalName": "c_bigint" - } + "name": "c_integer", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "int" + }, + "originalName": "c_integer" }, { - "number": 10, - "column": { - "name": "c_float", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "float" - }, - "originalName": "c_float" - } + "name": "c_bigint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "bigint" + }, + "originalName": "c_bigint" }, { - "number": 11, - "column": { - "name": "c_numeric", - "length": 10, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_numeric" - } + "name": "c_float", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "float" + }, + "originalName": "c_float" }, { - "number": 12, - "column": { - "name": "c_decimal", - "length": 10, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_decimal" - } + "name": "c_numeric", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_numeric" }, { - "number": 13, - "column": { - "name": "c_dec", - "length": 10, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_dec" - } + "name": "c_decimal", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_decimal" }, { - "number": 14, - "column": { - "name": "c_fixed", - "length": 10, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_fixed" - } + "name": "c_dec", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_dec" }, { - "number": 15, - "column": { - "name": "c_double", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "double" - }, - "originalName": "c_double" - } + "name": "c_fixed", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_fixed" }, { - "number": 16, - "column": { - "name": "c_double_precision", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "double" - }, - "originalName": "c_double_precision" - } + "name": "c_double", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "double" + }, + "originalName": "c_double" }, { - "number": 17, + "name": "c_double_precision", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "double" + }, + "originalName": "c_double_precision" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE mysql_numeric_types", + "name": "TruncateMysqlNumericTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO mysql_string_types \n(\n c_char,\n c_nchar,\n c_national_char,\n c_varchar,\n c_tinytext,\n c_mediumtext,\n c_text,\n c_longtext, \n c_json,\n c_json_string_override,\n c_enum,\n c_set\n) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlStringTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, "column": { "name": "c_char", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2147,13 +2336,13 @@ } }, { - "number": 18, + "number": 2, "column": { "name": "c_nchar", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2162,13 +2351,13 @@ } }, { - "number": 19, + "number": 3, "column": { "name": "c_national_char", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2177,13 +2366,13 @@ } }, { - "number": 20, + "number": 4, "column": { "name": "c_varchar", "length": 100, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "varchar" @@ -2192,511 +2381,335 @@ } }, { - "number": 21, + "number": 5, "column": { "name": "c_tinytext", "length": -1, "table": { "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "tinytext" - }, - "originalName": "c_tinytext" - } - }, - { - "number": 22, - "column": { - "name": "c_mediumtext", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "mediumtext" - }, - "originalName": "c_mediumtext" - } - }, - { - "number": 23, - "column": { - "name": "c_text", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "text" - }, - "originalName": "c_text" - } - }, - { - "number": 24, - "column": { - "name": "c_longtext", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "longtext" - }, - "originalName": "c_longtext" - } - }, - { - "number": 25, - "column": { - "name": "c_json", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "json" - }, - "originalName": "c_json" - } - }, - { - "number": 26, - "column": { - "name": "c_json_string_override", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "json" + "name": "tinytext" }, - "originalName": "c_json_string_override" + "originalName": "c_tinytext" } }, { - "number": 27, + "number": 6, "column": { - "name": "c_enum", - "length": 6, + "name": "c_mediumtext", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mysql_types_c_enum" + "name": "mediumtext" }, - "originalName": "c_enum" + "originalName": "c_mediumtext" } }, { - "number": 28, + "number": 7, "column": { - "name": "c_set", - "length": 15, + "name": "c_text", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mysql_types_c_set" + "name": "text" }, - "originalName": "c_set" + "originalName": "c_text" } }, { - "number": 29, + "number": 8, "column": { - "name": "c_year", + "name": "c_longtext", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "year" + "name": "longtext" }, - "originalName": "c_year" + "originalName": "c_longtext" } }, { - "number": 30, + "number": 9, "column": { - "name": "c_date", + "name": "c_json", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "date" + "name": "json" }, - "originalName": "c_date" + "originalName": "c_json" } }, { - "number": 31, + "number": 10, "column": { - "name": "c_datetime", - "length": 19, + "name": "c_json_string_override", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "datetime" + "name": "json" }, - "originalName": "c_datetime" + "originalName": "c_json_string_override" } }, { - "number": 32, + "number": 11, "column": { - "name": "c_timestamp", - "length": 19, + "name": "c_enum", + "length": 6, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "timestamp" + "name": "mysql_string_types_c_enum" }, - "originalName": "c_timestamp" + "originalName": "c_enum" } }, { - "number": 33, + "number": 12, "column": { - "name": "c_binary", - "length": 3, + "name": "c_set", + "length": 15, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "binary" + "name": "mysql_string_types_c_set" }, - "originalName": "c_binary" + "originalName": "c_set" } - }, + } + ], + "comments": [ + " String types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_string_types" + } + }, + { + "text": "INSERT INTO mysql_string_types \n(\n c_char,\n c_nchar,\n c_national_char,\n c_varchar,\n c_tinytext,\n c_mediumtext,\n c_text,\n c_longtext, \n c_json,\n c_json_string_override,\n c_enum,\n c_set\n) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlStringTypesBatch", + "cmd": ":copyfrom", + "parameters": [ { - "number": 34, + "number": 1, "column": { - "name": "c_varbinary", - "length": 10, + "name": "c_char", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "varbinary" + "name": "char" }, - "originalName": "c_varbinary" + "originalName": "c_char" } }, { - "number": 35, + "number": 2, "column": { - "name": "c_tinyblob", + "name": "c_nchar", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "tinyblob" + "name": "char" }, - "originalName": "c_tinyblob" + "originalName": "c_nchar" } }, { - "number": 36, + "number": 3, "column": { - "name": "c_blob", + "name": "c_national_char", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "blob" + "name": "char" }, - "originalName": "c_blob" + "originalName": "c_national_char" } }, { - "number": 37, + "number": 4, "column": { - "name": "c_mediumblob", - "length": -1, + "name": "c_varchar", + "length": 100, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mediumblob" + "name": "varchar" }, - "originalName": "c_mediumblob" + "originalName": "c_varchar" } }, { - "number": 38, + "number": 5, "column": { - "name": "c_longblob", + "name": "c_tinytext", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "longblob" + "name": "tinytext" }, - "originalName": "c_longblob" + "originalName": "c_tinytext" } - } - ], - "filename": "query.sql", - "insert_into_table": { - "name": "mysql_types" - } - }, - { - "text": "SELECT c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_decimal, c_dec, c_numeric, c_fixed, c_double, c_double_precision, c_year, c_date, c_time, c_datetime, c_timestamp, 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, c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_types LIMIT 1", - "name": "GetMysqlTypes", - "cmd": ":one", - "columns": [ - { - "name": "c_bool", - "length": 1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_bool" - }, - { - "name": "c_boolean", - "length": 1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_boolean" - }, - { - "name": "c_tinyint", - "length": 3, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_tinyint" - }, - { - "name": "c_smallint", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "smallint" - }, - "originalName": "c_smallint" - }, - { - "name": "c_mediumint", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "mediumint" - }, - "originalName": "c_mediumint" - }, - { - "name": "c_int", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "int" - }, - "originalName": "c_int" - }, - { - "name": "c_integer", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "int" - }, - "originalName": "c_integer" - }, - { - "name": "c_bigint", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "bigint" - }, - "originalName": "c_bigint" - }, - { - "name": "c_float", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "float" - }, - "originalName": "c_float" - }, - { - "name": "c_decimal", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_decimal" - }, - { - "name": "c_dec", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_dec" - }, - { - "name": "c_numeric", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_numeric" - }, - { - "name": "c_fixed", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_fixed" - }, - { - "name": "c_double", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "double" - }, - "originalName": "c_double" }, { - "name": "c_double_precision", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "double" - }, - "originalName": "c_double_precision" + "number": 6, + "column": { + "name": "c_mediumtext", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "mediumtext" + }, + "originalName": "c_mediumtext" + } }, { - "name": "c_year", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "year" - }, - "originalName": "c_year" + "number": 7, + "column": { + "name": "c_text", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "text" + }, + "originalName": "c_text" + } }, { - "name": "c_date", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "date" - }, - "originalName": "c_date" + "number": 8, + "column": { + "name": "c_longtext", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "longtext" + }, + "originalName": "c_longtext" + } }, { - "name": "c_time", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "time" - }, - "originalName": "c_time" + "number": 9, + "column": { + "name": "c_json", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "json" + }, + "originalName": "c_json" + } }, { - "name": "c_datetime", - "length": 19, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "datetime" - }, - "originalName": "c_datetime" + "number": 10, + "column": { + "name": "c_json_string_override", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "json" + }, + "originalName": "c_json_string_override" + } }, { - "name": "c_timestamp", - "length": 19, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "timestamp" - }, - "originalName": "c_timestamp" + "number": 11, + "column": { + "name": "c_enum", + "length": 6, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "mysql_string_types_c_enum" + }, + "originalName": "c_enum" + } }, + { + "number": 12, + "column": { + "name": "c_set", + "length": 15, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "mysql_string_types_c_set" + }, + "originalName": "c_set" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_string_types" + } + }, + { + "text": "SELECT 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 LIMIT 1", + "name": "GetMysqlStringTypes", + "cmd": ":one", + "columns": [ { "name": "c_char", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2707,7 +2720,7 @@ "name": "c_nchar", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2718,7 +2731,7 @@ "name": "c_national_char", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2729,7 +2742,7 @@ "name": "c_varchar", "length": 100, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "varchar" @@ -2740,7 +2753,7 @@ "name": "c_tinytext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "tinytext" @@ -2751,7 +2764,7 @@ "name": "c_mediumtext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "mediumtext" @@ -2762,7 +2775,7 @@ "name": "c_text", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "text" @@ -2773,7 +2786,7 @@ "name": "c_longtext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "longtext" @@ -2784,7 +2797,7 @@ "name": "c_json", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "json" @@ -2795,7 +2808,7 @@ "name": "c_json_string_override", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "json" @@ -2806,10 +2819,10 @@ "name": "c_enum", "length": 6, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mysql_types_c_enum" + "name": "mysql_string_types_c_enum" }, "originalName": "c_enum" }, @@ -2817,96 +2830,19 @@ "name": "c_set", "length": 15, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mysql_types_c_set" + "name": "mysql_string_types_c_set" }, "originalName": "c_set" - }, - { - "name": "c_bit", - "length": 8, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "bit" - }, - "originalName": "c_bit" - }, - { - "name": "c_binary", - "length": 3, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "binary" - }, - "originalName": "c_binary" - }, - { - "name": "c_varbinary", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "varbinary" - }, - "originalName": "c_varbinary" - }, - { - "name": "c_tinyblob", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "tinyblob" - }, - "originalName": "c_tinyblob" - }, - { - "name": "c_blob", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "blob" - }, - "originalName": "c_blob" - }, - { - "name": "c_mediumblob", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "mediumblob" - }, - "originalName": "c_mediumblob" - }, - { - "name": "c_longblob", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "longblob" - }, - "originalName": "c_longblob" } ], "filename": "query.sql" }, { - "text": "SELECT COUNT(1) AS cnt, c_bool, c_boolean, c_bit, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, \n c_float, c_numeric, c_decimal, c_dec, c_fixed, c_double, c_double_precision, \n c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, \n c_json, c_json_string_override, c_enum, c_set, c_year, c_date, c_datetime, c_timestamp, \n c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob\nFROM mysql_types\nGROUP BY c_bool, c_boolean, c_bit, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, \n c_float, c_numeric, c_decimal, c_dec, c_fixed, c_double, c_double_precision, \n c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, \n c_json, c_json_string_override, c_enum, c_set, c_year, c_date, c_datetime, c_timestamp, \n c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob\nLIMIT 1", - "name": "GetMysqlTypesCnt", + "text": "SELECT\n COUNT(*) AS cnt,\n c_char,\n c_nchar,\n c_national_char,\n c_varchar,\n c_tinytext,\n c_mediumtext,\n c_text,\n c_longtext,\n c_json,\n c_json_string_override,\n c_enum,\n c_set\nFROM mysql_string_types\nGROUP BY\n c_char,\n c_nchar,\n c_national_char,\n c_varchar,\n c_tinytext,\n c_mediumtext,\n c_text,\n c_longtext,\n c_json,\n c_json_string_override,\n c_enum,\n c_set\nLIMIT 1", + "name": "GetMysqlStringTypesCnt", "cmd": ":one", "columns": [ { @@ -2919,362 +2855,812 @@ } }, { - "name": "c_bool", - "length": 1, + "name": "c_char", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "tinyint" + "name": "char" }, - "originalName": "c_bool" + "originalName": "c_char" }, { - "name": "c_boolean", - "length": 1, + "name": "c_nchar", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "tinyint" + "name": "char" }, - "originalName": "c_boolean" + "originalName": "c_nchar" }, { - "name": "c_bit", - "length": 8, + "name": "c_national_char", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "bit" + "name": "char" }, - "originalName": "c_bit" + "originalName": "c_national_char" }, { - "name": "c_tinyint", - "length": 3, + "name": "c_varchar", + "length": 100, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "tinyint" + "name": "varchar" }, - "originalName": "c_tinyint" + "originalName": "c_varchar" }, { - "name": "c_smallint", + "name": "c_tinytext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "smallint" + "name": "tinytext" + }, + "originalName": "c_tinytext" + }, + { + "name": "c_mediumtext", + "length": -1, + "table": { + "name": "mysql_string_types" + }, + "type": { + "name": "mediumtext" }, - "originalName": "c_smallint" + "originalName": "c_mediumtext" }, { - "name": "c_mediumint", + "name": "c_text", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mediumint" + "name": "text" }, - "originalName": "c_mediumint" + "originalName": "c_text" }, { - "name": "c_int", + "name": "c_longtext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "int" + "name": "longtext" }, - "originalName": "c_int" + "originalName": "c_longtext" }, { - "name": "c_integer", + "name": "c_json", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "int" + "name": "json" }, - "originalName": "c_integer" + "originalName": "c_json" }, { - "name": "c_bigint", + "name": "c_json_string_override", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "bigint" + "name": "json" }, - "originalName": "c_bigint" + "originalName": "c_json_string_override" }, { - "name": "c_float", - "length": -1, + "name": "c_enum", + "length": 6, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "float" + "name": "mysql_string_types_c_enum" }, - "originalName": "c_float" + "originalName": "c_enum" }, { - "name": "c_numeric", - "length": 10, + "name": "c_set", + "length": 15, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "decimal" + "name": "mysql_string_types_c_set" }, - "originalName": "c_numeric" + "originalName": "c_set" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE mysql_string_types", + "name": "TruncateMysqlStringTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO mysql_datetime_types \n(\n c_year,\n c_date,\n c_datetime,\n c_timestamp,\n c_time\n) \nVALUES (?, ?, ?, ?, ?)", + "name": "InsertMysqlDatetimeTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_year", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "year" + }, + "originalName": "c_year" + } }, { - "name": "c_decimal", - "length": 10, + "number": 2, + "column": { + "name": "c_date", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "date" + }, + "originalName": "c_date" + } + }, + { + "number": 3, + "column": { + "name": "c_datetime", + "length": 19, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "datetime" + }, + "originalName": "c_datetime" + } + }, + { + "number": 4, + "column": { + "name": "c_timestamp", + "length": 19, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "timestamp" + }, + "originalName": "c_timestamp" + } + }, + { + "number": 5, + "column": { + "name": "c_time", + "length": 10, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "time" + }, + "originalName": "c_time" + } + } + ], + "comments": [ + " Datetime types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_datetime_types" + } + }, + { + "text": "INSERT INTO mysql_datetime_types \n(\n c_year,\n c_date,\n c_datetime,\n c_timestamp,\n c_time\n) \nVALUES (?, ?, ?, ?, ?)", + "name": "InsertMysqlDatetimeTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_year", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "year" + }, + "originalName": "c_year" + } + }, + { + "number": 2, + "column": { + "name": "c_date", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "date" + }, + "originalName": "c_date" + } + }, + { + "number": 3, + "column": { + "name": "c_datetime", + "length": 19, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "datetime" + }, + "originalName": "c_datetime" + } + }, + { + "number": 4, + "column": { + "name": "c_timestamp", + "length": 19, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "timestamp" + }, + "originalName": "c_timestamp" + } + }, + { + "number": 5, + "column": { + "name": "c_time", + "length": 10, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "time" + }, + "originalName": "c_time" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_datetime_types" + } + }, + { + "text": "SELECT c_year, c_date, c_datetime, c_timestamp, c_time FROM mysql_datetime_types LIMIT 1", + "name": "GetMysqlDatetimeTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_year", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "decimal" + "name": "year" }, - "originalName": "c_decimal" + "originalName": "c_year" }, { - "name": "c_dec", - "length": 10, + "name": "c_date", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "decimal" + "name": "date" }, - "originalName": "c_dec" + "originalName": "c_date" }, { - "name": "c_fixed", - "length": 10, + "name": "c_datetime", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "decimal" + "name": "datetime" }, - "originalName": "c_fixed" + "originalName": "c_datetime" }, { - "name": "c_double", - "length": -1, + "name": "c_timestamp", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "double" + "name": "timestamp" }, - "originalName": "c_double" + "originalName": "c_timestamp" }, { - "name": "c_double_precision", - "length": -1, + "name": "c_time", + "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "double" + "name": "time" }, - "originalName": "c_double_precision" + "originalName": "c_time" + } + ], + "filename": "query.sql" + }, + { + "text": "SELECT\n COUNT(*) AS cnt,\n c_year,\n c_date,\n c_datetime,\n c_timestamp,\n c_time\nFROM mysql_datetime_types\nGROUP BY\n c_year,\n c_date,\n c_datetime,\n c_timestamp,\n c_time\nLIMIT 1", + "name": "GetMysqlDatetimeTypesCnt", + "cmd": ":one", + "columns": [ + { + "name": "cnt", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "bigint" + } }, { - "name": "c_char", + "name": "c_year", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "char" + "name": "year" }, - "originalName": "c_char" + "originalName": "c_year" }, { - "name": "c_nchar", + "name": "c_date", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "char" + "name": "date" }, - "originalName": "c_nchar" + "originalName": "c_date" }, { - "name": "c_national_char", - "length": -1, + "name": "c_datetime", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "char" + "name": "datetime" }, - "originalName": "c_national_char" + "originalName": "c_datetime" }, { - "name": "c_varchar", - "length": 100, + "name": "c_timestamp", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "varchar" + "name": "timestamp" }, - "originalName": "c_varchar" + "originalName": "c_timestamp" }, { - "name": "c_tinytext", - "length": -1, + "name": "c_time", + "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "tinytext" + "name": "time" }, - "originalName": "c_tinytext" + "originalName": "c_time" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE mysql_datetime_types", + "name": "TruncateMysqlDatetimeTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO mysql_binary_types \n(\n c_bit,\n c_binary, \n c_varbinary, \n c_tinyblob, \n c_blob, \n c_mediumblob, \n c_longblob\n) \nVALUES (?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlBinaryTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_bit", + "length": 8, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "bit" + }, + "originalName": "c_bit" + } + }, + { + "number": 2, + "column": { + "name": "c_binary", + "length": 3, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "binary" + }, + "originalName": "c_binary" + } + }, + { + "number": 3, + "column": { + "name": "c_varbinary", + "length": 10, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "varbinary" + }, + "originalName": "c_varbinary" + } + }, + { + "number": 4, + "column": { + "name": "c_tinyblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "tinyblob" + }, + "originalName": "c_tinyblob" + } + }, + { + "number": 5, + "column": { + "name": "c_blob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "blob" + }, + "originalName": "c_blob" + } + }, + { + "number": 6, + "column": { + "name": "c_mediumblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "mediumblob" + }, + "originalName": "c_mediumblob" + } + }, + { + "number": 7, + "column": { + "name": "c_longblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "longblob" + }, + "originalName": "c_longblob" + } + } + ], + "comments": [ + " Binary types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_binary_types" + } + }, + { + "text": "INSERT INTO mysql_binary_types \n(\n c_bit,\n c_binary, \n c_varbinary, \n c_tinyblob, \n c_blob, \n c_mediumblob, \n c_longblob\n) \nVALUES (?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlBinaryTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_bit", + "length": 8, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "bit" + }, + "originalName": "c_bit" + } + }, + { + "number": 2, + "column": { + "name": "c_binary", + "length": 3, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "binary" + }, + "originalName": "c_binary" + } + }, + { + "number": 3, + "column": { + "name": "c_varbinary", + "length": 10, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "varbinary" + }, + "originalName": "c_varbinary" + } + }, + { + "number": 4, + "column": { + "name": "c_tinyblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "tinyblob" + }, + "originalName": "c_tinyblob" + } + }, + { + "number": 5, + "column": { + "name": "c_blob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "blob" + }, + "originalName": "c_blob" + } + }, + { + "number": 6, + "column": { + "name": "c_mediumblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "mediumblob" + }, + "originalName": "c_mediumblob" + } }, { - "name": "c_mediumtext", - "length": -1, + "number": 7, + "column": { + "name": "c_longblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "longblob" + }, + "originalName": "c_longblob" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_binary_types" + } + }, + { + "text": "SELECT c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_binary_types LIMIT 1", + "name": "GetMysqlBinaryTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_bit", + "length": 8, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "mediumtext" + "name": "bit" }, - "originalName": "c_mediumtext" + "originalName": "c_bit" }, { - "name": "c_text", - "length": -1, + "name": "c_binary", + "length": 3, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "text" + "name": "binary" }, - "originalName": "c_text" + "originalName": "c_binary" }, { - "name": "c_longtext", - "length": -1, + "name": "c_varbinary", + "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "longtext" + "name": "varbinary" }, - "originalName": "c_longtext" + "originalName": "c_varbinary" }, { - "name": "c_json", + "name": "c_tinyblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "json" + "name": "tinyblob" }, - "originalName": "c_json" + "originalName": "c_tinyblob" }, { - "name": "c_json_string_override", + "name": "c_blob", "length": -1, "table": { - "name": "mysql_types" - }, - "type": { - "name": "json" - }, - "originalName": "c_json_string_override" - }, - { - "name": "c_enum", - "length": 6, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "mysql_types_c_enum" - }, - "originalName": "c_enum" - }, - { - "name": "c_set", - "length": 15, - "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "mysql_types_c_set" + "name": "blob" }, - "originalName": "c_set" + "originalName": "c_blob" }, { - "name": "c_year", + "name": "c_mediumblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "year" + "name": "mediumblob" }, - "originalName": "c_year" + "originalName": "c_mediumblob" }, { - "name": "c_date", + "name": "c_longblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "date" + "name": "longblob" }, - "originalName": "c_date" - }, + "originalName": "c_longblob" + } + ], + "filename": "query.sql" + }, + { + "text": "SELECT\n COUNT(*) AS cnt,\n c_bit,\n c_binary,\n c_varbinary,\n c_tinyblob,\n c_blob,\n c_mediumblob,\n c_longblob\nFROM mysql_binary_types\nGROUP BY\n c_bit,\n c_binary,\n c_varbinary,\n c_tinyblob,\n c_blob,\n c_mediumblob,\n c_longblob\nLIMIT 1", + "name": "GetMysqlBinaryTypesCnt", + "cmd": ":one", + "columns": [ { - "name": "c_datetime", - "length": 19, - "table": { - "name": "mysql_types" - }, + "name": "cnt", + "notNull": true, + "length": -1, + "isFuncCall": true, "type": { - "name": "datetime" - }, - "originalName": "c_datetime" + "name": "bigint" + } }, { - "name": "c_timestamp", - "length": 19, + "name": "c_bit", + "length": 8, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "timestamp" + "name": "bit" }, - "originalName": "c_timestamp" + "originalName": "c_bit" }, { "name": "c_binary", "length": 3, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "binary" @@ -3285,7 +3671,7 @@ "name": "c_varbinary", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "varbinary" @@ -3296,7 +3682,7 @@ "name": "c_tinyblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "tinyblob" @@ -3307,7 +3693,7 @@ "name": "c_blob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "blob" @@ -3318,7 +3704,7 @@ "name": "c_mediumblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "mediumblob" @@ -3329,7 +3715,7 @@ "name": "c_longblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "longblob" @@ -3340,7 +3726,13 @@ "filename": "query.sql" }, { - "text": "SELECT MAX(c_int) AS max_int, MAX(c_varchar) AS max_varchar, MAX(c_timestamp) AS max_timestamp\nFROM mysql_types", + "text": "TRUNCATE TABLE mysql_binary_types", + "name": "TruncateMysqlBinaryTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "\nSELECT\n MAX(c_int) AS max_int,\n MAX(c_varchar) AS max_varchar,\n MAX(c_timestamp) AS max_timestamp\nFROM mysql_numeric_types\nCROSS JOIN mysql_string_types\nCROSS JOIN mysql_datetime_types", "name": "GetMysqlFunctions", "cmd": ":one", "columns": [ @@ -3372,164 +3764,10 @@ } } ], - "filename": "query.sql" - }, - { - "text": "TRUNCATE TABLE mysql_types", - "name": "TruncateMysqlTypes", - "cmd": ":exec", - "filename": "query.sql" - }, - { - "text": "INSERT INTO extended.bios (author_name, name, bio_type, author_type) VALUES (?, ?, ?, ?)", - "name": "CreateExtendedBio", - "cmd": ":exec", - "parameters": [ - { - "number": 1, - "column": { - "name": "author_name", - "length": 100, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "varchar" - }, - "originalName": "author_name" - } - }, - { - "number": 2, - "column": { - "name": "name", - "length": 100, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "varchar" - }, - "originalName": "name" - } - }, - { - "number": 3, - "column": { - "name": "bio_type", - "length": 13, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "bios_bio_type" - }, - "originalName": "bio_type" - } - }, - { - "number": 4, - "column": { - "name": "author_type", - "length": 24, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "bios_author_type" - }, - "originalName": "author_type" - } - } - ], - "filename": "query.sql", - "insert_into_table": { - "schema": "extended", - "name": "bios" - } - }, - { - "text": "SELECT author_name, name, bio_type, author_type FROM extended.bios WHERE bio_type = ? LIMIT 1", - "name": "GetFirstExtendedBioByType", - "cmd": ":one", - "columns": [ - { - "name": "author_name", - "length": 100, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "varchar" - }, - "originalName": "author_name" - }, - { - "name": "name", - "length": 100, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "varchar" - }, - "originalName": "name" - }, - { - "name": "bio_type", - "length": 13, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "bios_bio_type" - }, - "originalName": "bio_type" - }, - { - "name": "author_type", - "length": 24, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "bios_author_type" - }, - "originalName": "author_type" - } - ], - "parameters": [ - { - "number": 1, - "column": { - "name": "bio_type", - "length": 13, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "bios_bio_type" - }, - "originalName": "bio_type" - } - } + "comments": [ + " Functions " ], "filename": "query.sql" - }, - { - "text": "TRUNCATE TABLE extended.bios", - "name": "TruncateExtendedBios", - "cmd": ":exec", - "filename": "query.sql" } ], "sqlc_version": "v1.27.0", diff --git a/examples/MySqlConnectorDapperExample/request.message b/examples/MySqlConnectorDapperExample/request.message index 124f5e87..29881c40 100644 Binary files a/examples/MySqlConnectorDapperExample/request.message and b/examples/MySqlConnectorDapperExample/request.message differ diff --git a/examples/MySqlConnectorDapperLegacyExample/Models.cs b/examples/MySqlConnectorDapperLegacyExample/Models.cs index 5ec196f7..f9ff3f99 100644 --- a/examples/MySqlConnectorDapperLegacyExample/Models.cs +++ b/examples/MySqlConnectorDapperLegacyExample/Models.cs @@ -19,7 +19,7 @@ public class Book public long AuthorId { get; set; } public string Description { get; set; } }; - public class MysqlType + public class MysqlNumericType { public bool? CBool { get; set; } public bool? CBoolean { get; set; } @@ -36,11 +36,9 @@ public class MysqlType public decimal? CFixed { get; set; } public double? CDouble { get; set; } public double? CDoublePrecision { get; set; } - public short? CYear { get; set; } - public DateTime? CDate { get; set; } - public string CTime { get; set; } - public DateTime? CDatetime { get; set; } - public DateTime? CTimestamp { get; set; } + }; + public class MysqlStringType + { public string CChar { get; set; } public string CNchar { get; set; } public string CNationalChar { get; set; } @@ -51,8 +49,19 @@ public class MysqlType public string CLongtext { get; set; } public JsonElement? CJson { get; set; } public JsonElement? CJsonStringOverride { get; set; } - public MysqlTypesCEnum? CEnum { get; set; } - public MysqlTypesCSet[] CSet { get; set; } + public MysqlStringTypesCEnum? CEnum { get; set; } + public HashSet CSet { get; set; } + }; + public class MysqlDatetimeType + { + public short? CYear { get; set; } + public DateTime? CDate { get; set; } + public DateTime? CDatetime { get; set; } + public DateTime? CTimestamp { get; set; } + public TimeSpan? CTime { get; set; } + }; + public class MysqlBinaryType + { public byte? CBit { get; set; } public byte[] CBinary { get; set; } public byte[] CVarbinary { get; set; } @@ -65,118 +74,166 @@ public class ExtendedBio { public string AuthorName { get; set; } public string Name { get; set; } - public ExtendedBiosBioType? BioType { get; set; } - public ExtendedBiosAuthorType[] AuthorType { get; set; } + public BiosBioType? BioType { get; set; } + public HashSet AuthorType { get; set; } }; - public enum MysqlTypesCEnum + public enum BiosBioType { Invalid = 0, // reserved for invalid enum value - Small = 1, - Medium = 2, - Big = 3 + Autobiography = 1, + Biography = 2, + Memoir = 3 } - public static class MysqlTypesCEnumExtensions + public static class BiosBioTypeExtensions { - private static readonly Dictionary StringToEnum = new Dictionary() + private static readonly Dictionary StringToEnum = new Dictionary() + { + [string.Empty] = BiosBioType.Invalid, + ["Autobiography"] = BiosBioType.Autobiography, + ["Biography"] = BiosBioType.Biography, + ["Memoir"] = BiosBioType.Memoir + }; + private static readonly Dictionary EnumToString = new Dictionary() { - [string.Empty] = MysqlTypesCEnum.Invalid, - ["small"] = MysqlTypesCEnum.Small, - ["medium"] = MysqlTypesCEnum.Medium, - ["big"] = MysqlTypesCEnum.Big + [BiosBioType.Invalid] = string.Empty, + [BiosBioType.Autobiography] = "Autobiography", + [BiosBioType.Biography] = "Biography", + [BiosBioType.Memoir] = "Memoir" }; - public static MysqlTypesCEnum ToMysqlTypesCEnum(this string me) + public static BiosBioType ToBiosBioType(this string me) { return StringToEnum[me]; } - public static MysqlTypesCEnum[] ToMysqlTypesCEnumArr(this string me) + public static string Stringify(this BiosBioType me) { - return me.Split(',').ToList().Select(v => StringToEnum[v]).ToArray(); + return EnumToString[me]; + } + + public static HashSet ToBiosBioTypeSet(this string me) + { + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); } } - public enum MysqlTypesCSet + public enum BiosAuthorType { Invalid = 0, // reserved for invalid enum value - Tea = 1, - Coffee = 2, - Milk = 3 + Author = 1, + Editor = 2, + Translator = 3 } - public static class MysqlTypesCSetExtensions + public static class BiosAuthorTypeExtensions { - private static readonly Dictionary StringToEnum = new Dictionary() + private static readonly Dictionary StringToEnum = new Dictionary() + { + [string.Empty] = BiosAuthorType.Invalid, + ["Author"] = BiosAuthorType.Author, + ["Editor"] = BiosAuthorType.Editor, + ["Translator"] = BiosAuthorType.Translator + }; + private static readonly Dictionary EnumToString = new Dictionary() { - [string.Empty] = MysqlTypesCSet.Invalid, - ["tea"] = MysqlTypesCSet.Tea, - ["coffee"] = MysqlTypesCSet.Coffee, - ["milk"] = MysqlTypesCSet.Milk + [BiosAuthorType.Invalid] = string.Empty, + [BiosAuthorType.Author] = "Author", + [BiosAuthorType.Editor] = "Editor", + [BiosAuthorType.Translator] = "Translator" }; - public static MysqlTypesCSet ToMysqlTypesCSet(this string me) + public static BiosAuthorType ToBiosAuthorType(this string me) { return StringToEnum[me]; } - public static MysqlTypesCSet[] ToMysqlTypesCSetArr(this string me) + public static string Stringify(this BiosAuthorType me) { - return me.Split(',').ToList().Select(v => StringToEnum[v]).ToArray(); + return EnumToString[me]; + } + + public static HashSet ToBiosAuthorTypeSet(this string me) + { + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); } } - public enum ExtendedBiosBioType + public enum MysqlStringTypesCEnum { Invalid = 0, // reserved for invalid enum value - Autobiography = 1, - Biography = 2, - Memoir = 3 + Small = 1, + Medium = 2, + Big = 3 } - public static class ExtendedBiosBioTypeExtensions + public static class MysqlStringTypesCEnumExtensions { - private static readonly Dictionary StringToEnum = new Dictionary() + private static readonly Dictionary StringToEnum = new Dictionary() + { + [string.Empty] = MysqlStringTypesCEnum.Invalid, + ["small"] = MysqlStringTypesCEnum.Small, + ["medium"] = MysqlStringTypesCEnum.Medium, + ["big"] = MysqlStringTypesCEnum.Big + }; + private static readonly Dictionary EnumToString = new Dictionary() { - [string.Empty] = ExtendedBiosBioType.Invalid, - ["Autobiography"] = ExtendedBiosBioType.Autobiography, - ["Biography"] = ExtendedBiosBioType.Biography, - ["Memoir"] = ExtendedBiosBioType.Memoir + [MysqlStringTypesCEnum.Invalid] = string.Empty, + [MysqlStringTypesCEnum.Small] = "small", + [MysqlStringTypesCEnum.Medium] = "medium", + [MysqlStringTypesCEnum.Big] = "big" }; - public static ExtendedBiosBioType ToExtendedBiosBioType(this string me) + public static MysqlStringTypesCEnum ToMysqlStringTypesCEnum(this string me) { return StringToEnum[me]; } - public static ExtendedBiosBioType[] ToExtendedBiosBioTypeArr(this string me) + public static string Stringify(this MysqlStringTypesCEnum me) { - return me.Split(',').ToList().Select(v => StringToEnum[v]).ToArray(); + return EnumToString[me]; + } + + public static HashSet ToMysqlStringTypesCEnumSet(this string me) + { + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); } } - public enum ExtendedBiosAuthorType + public enum MysqlStringTypesCSet { Invalid = 0, // reserved for invalid enum value - Author = 1, - Editor = 2, - Translator = 3 + Tea = 1, + Coffee = 2, + Milk = 3 } - public static class ExtendedBiosAuthorTypeExtensions + public static class MysqlStringTypesCSetExtensions { - private static readonly Dictionary StringToEnum = new Dictionary() + private static readonly Dictionary StringToEnum = new Dictionary() + { + [string.Empty] = MysqlStringTypesCSet.Invalid, + ["tea"] = MysqlStringTypesCSet.Tea, + ["coffee"] = MysqlStringTypesCSet.Coffee, + ["milk"] = MysqlStringTypesCSet.Milk + }; + private static readonly Dictionary EnumToString = new Dictionary() { - [string.Empty] = ExtendedBiosAuthorType.Invalid, - ["Author"] = ExtendedBiosAuthorType.Author, - ["Editor"] = ExtendedBiosAuthorType.Editor, - ["Translator"] = ExtendedBiosAuthorType.Translator + [MysqlStringTypesCSet.Invalid] = string.Empty, + [MysqlStringTypesCSet.Tea] = "tea", + [MysqlStringTypesCSet.Coffee] = "coffee", + [MysqlStringTypesCSet.Milk] = "milk" }; - public static ExtendedBiosAuthorType ToExtendedBiosAuthorType(this string me) + public static MysqlStringTypesCSet ToMysqlStringTypesCSet(this string me) { return StringToEnum[me]; } - public static ExtendedBiosAuthorType[] ToExtendedBiosAuthorTypeArr(this string me) + public static string Stringify(this MysqlStringTypesCSet me) + { + return EnumToString[me]; + } + + public static HashSet ToMysqlStringTypesCSetSet(this string me) { - return me.Split(',').ToList().Select(v => StringToEnum[v]).ToArray(); + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); } } } \ No newline at end of file diff --git a/examples/MySqlConnectorDapperLegacyExample/QuerySql.cs b/examples/MySqlConnectorDapperLegacyExample/QuerySql.cs index 80f6df60..d196b9ff 100644 --- a/examples/MySqlConnectorDapperLegacyExample/QuerySql.cs +++ b/examples/MySqlConnectorDapperLegacyExample/QuerySql.cs @@ -70,14 +70,11 @@ public async Task GetAuthor(GetAuthorArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -124,18 +121,12 @@ public async Task CreateAuthor(CreateAuthorArgs args) if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) - { await connection.ExecuteAsync(CreateAuthorSql, queryParams); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); await this.Transaction.Connection.ExecuteAsync(CreateAuthorSql, queryParams, transaction: this.Transaction); } @@ -153,16 +144,11 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) - { return await connection.QuerySingleAsync(CreateAuthorReturnIdSql, queryParams); - } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); return await this.Transaction.Connection.QuerySingleAsync(CreateAuthorReturnIdSql, queryParams, transaction: this.Transaction); } @@ -191,14 +177,11 @@ public async Task GetAuthorById(GetAuthorByIdArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -227,7 +210,7 @@ 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; } @@ -239,18 +222,12 @@ public async Task DeleteAuthor(DeleteAuthorArgs args) if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) - { await connection.ExecuteAsync(DeleteAuthorSql, queryParams); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); await this.Transaction.Connection.ExecuteAsync(DeleteAuthorSql, queryParams, transaction: this.Transaction); } @@ -260,22 +237,16 @@ public async Task DeleteAllAuthors() if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) - { await connection.ExecuteAsync(DeleteAllAuthorsSql); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -287,16 +258,11 @@ public async Task UpdateAuthors(UpdateAuthorsArgs args) if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) - { return await connection.ExecuteAsync(UpdateAuthorsSql, queryParams); - } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); return await this.Transaction.Connection.ExecuteAsync(UpdateAuthorsSql, queryParams, transaction: this.Transaction); } @@ -382,20 +348,15 @@ public async Task CreateBook(CreateBookArgs args) if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) - { return await connection.QuerySingleAsync(CreateBookSql, queryParams); - } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -437,7 +398,7 @@ 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; } @@ -479,7 +440,7 @@ 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; } @@ -529,10 +490,81 @@ public async Task> GetAuthorsByBookName(GetAuthors } } - private const string InsertMysqlTypesSql = "INSERT INTO mysql_types (c_bit, 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, 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, c_year, c_date, c_datetime, c_timestamp, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob) VALUES ( @c_bit, @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, @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, @c_year, @c_date, @c_datetime, @c_timestamp, @c_binary, @c_varbinary, @c_tinyblob, @c_blob, @c_mediumblob, @c_longblob ) "; - public class InsertMysqlTypesArgs + private const string CreateExtendedBioSql = "INSERT INTO extended.bios (author_name, name, bio_type, author_type) VALUES (@author_name, @name, @bio_type, @author_type)"; + public class CreateExtendedBioArgs + { + public string AuthorName { get; set; } + public string Name { get; set; } + public BiosBioType? BioType { get; set; } + public HashSet AuthorType { get; set; } + }; + public async Task CreateExtendedBio(CreateExtendedBioArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("author_name", args.AuthorName); + queryParams.Add("name", args.Name); + queryParams.Add("bio_type", args.BioType); + queryParams.Add("author_type", args.AuthorType != null ? string.Join(",", args.AuthorType) : null); + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + await connection.ExecuteAsync(CreateExtendedBioSql, queryParams); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(CreateExtendedBioSql, queryParams, transaction: this.Transaction); + } + + private const string GetFirstExtendedBioByTypeSql = "SELECT author_name, name, bio_type, author_type FROM extended.bios WHERE bio_type = @bio_type LIMIT 1"; + public class GetFirstExtendedBioByTypeRow + { + public string AuthorName { get; set; } + public string Name { get; set; } + public BiosBioType? BioType { get; set; } + public HashSet AuthorType { get; set; } + }; + public class GetFirstExtendedBioByTypeArgs + { + public BiosBioType? BioType { get; set; } + }; + public async Task GetFirstExtendedBioByType(GetFirstExtendedBioByTypeArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("bio_type", args.BioType); + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetFirstExtendedBioByTypeSql, queryParams); + return result; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetFirstExtendedBioByTypeSql, queryParams, transaction: this.Transaction); + } + + private const string TruncateExtendedBiosSql = "TRUNCATE TABLE extended.bios"; + public async Task TruncateExtendedBios() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncateExtendedBiosSql); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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)"; + public class InsertMysqlNumericTypesArgs { - public byte? CBit { get; set; } public bool? CBool { get; set; } public bool? CBoolean { get; set; } public short? CTinyint { get; set; } @@ -548,33 +580,10 @@ public class InsertMysqlTypesArgs public double? CFloat { get; set; } public double? CDouble { get; set; } public double? CDoublePrecision { get; set; } - public string CChar { get; set; } - public string CNchar { get; set; } - public string CNationalChar { get; set; } - public string CVarchar { get; set; } - public string CTinytext { get; set; } - public string CMediumtext { get; set; } - public string CText { get; set; } - public string CLongtext { get; set; } - public JsonElement? CJson { get; set; } - public string CJsonStringOverride { get; set; } - public MysqlTypesCEnum? CEnum { get; set; } - public MysqlTypesCSet[] CSet { get; set; } - public short? CYear { get; set; } - public DateTime? CDate { get; set; } - public DateTime? CDatetime { get; set; } - public DateTime? CTimestamp { get; set; } - public byte[] CBinary { get; set; } - public byte[] CVarbinary { get; set; } - public byte[] CTinyblob { get; set; } - public byte[] CBlob { get; set; } - public byte[] CMediumblob { get; set; } - public byte[] CLongblob { get; set; } }; - public async Task InsertMysqlTypes(InsertMysqlTypesArgs args) + public async Task InsertMysqlNumericTypes(InsertMysqlNumericTypesArgs args) { var queryParams = new Dictionary(); - queryParams.Add("c_bit", args.CBit); queryParams.Add("c_bool", args.CBool); queryParams.Add("c_boolean", args.CBoolean); queryParams.Add("c_tinyint", args.CTinyint); @@ -590,49 +599,20 @@ public async Task InsertMysqlTypes(InsertMysqlTypesArgs args) queryParams.Add("c_float", args.CFloat); queryParams.Add("c_double", args.CDouble); queryParams.Add("c_double_precision", args.CDoublePrecision); - queryParams.Add("c_char", args.CChar); - queryParams.Add("c_nchar", args.CNchar); - queryParams.Add("c_national_char", args.CNationalChar); - queryParams.Add("c_varchar", args.CVarchar); - queryParams.Add("c_tinytext", args.CTinytext); - queryParams.Add("c_mediumtext", args.CMediumtext); - queryParams.Add("c_text", args.CText); - queryParams.Add("c_longtext", args.CLongtext); - queryParams.Add("c_json", args.CJson?.GetRawText() ?? null); - queryParams.Add("c_json_string_override", args.CJsonStringOverride); - queryParams.Add("c_enum", args.CEnum); - queryParams.Add("c_set", args.CSet != null ? string.Join(",", args.CSet) : null); - queryParams.Add("c_year", args.CYear); - queryParams.Add("c_date", args.CDate); - queryParams.Add("c_datetime", args.CDatetime); - queryParams.Add("c_timestamp", args.CTimestamp); - queryParams.Add("c_binary", args.CBinary); - queryParams.Add("c_varbinary", args.CVarbinary); - queryParams.Add("c_tinyblob", args.CTinyblob); - queryParams.Add("c_blob", args.CBlob); - queryParams.Add("c_mediumblob", args.CMediumblob); - queryParams.Add("c_longblob", args.CLongblob); if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) - { - await connection.ExecuteAsync(InsertMysqlTypesSql, queryParams); - } - + await connection.ExecuteAsync(InsertMysqlNumericTypesSql, queryParams); return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - - await this.Transaction.Connection.ExecuteAsync(InsertMysqlTypesSql, queryParams, transaction: this.Transaction); + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertMysqlNumericTypesSql, queryParams, transaction: this.Transaction); } - public class InsertMysqlTypesBatchArgs + public class InsertMysqlNumericTypesBatchArgs { - public byte? CBit { get; set; } public bool? CBool { get; set; } public bool? CBoolean { get; set; } public short? CTinyint { get; set; } @@ -648,30 +628,8 @@ public class InsertMysqlTypesBatchArgs public decimal? CFixed { get; set; } public double? CDouble { get; set; } public double? CDoublePrecision { get; set; } - public string CChar { get; set; } - public string CNchar { get; set; } - public string CNationalChar { get; set; } - public string CVarchar { get; set; } - public string CTinytext { get; set; } - public string CMediumtext { get; set; } - public string CText { get; set; } - public string CLongtext { get; set; } - public JsonElement? CJson { get; set; } - public string CJsonStringOverride { get; set; } - public MysqlTypesCEnum? CEnum { get; set; } - public MysqlTypesCSet[] CSet { get; set; } - public short? CYear { get; set; } - public DateTime? CDate { get; set; } - public DateTime? CDatetime { get; set; } - public DateTime? CTimestamp { get; set; } - public byte[] CBinary { get; set; } - public byte[] CVarbinary { get; set; } - public byte[] CTinyblob { get; set; } - public byte[] CBlob { get; set; } - public byte[] CMediumblob { get; set; } - public byte[] CLongblob { get; set; } }; - public async Task InsertMysqlTypesBatch(List args) + public async Task InsertMysqlNumericTypesBatch(List args) { const string supportedDateTimeFormat = "yyyy-MM-dd H:mm:ss"; var config = new CsvConfiguration(CultureInfo.CurrentCulture) @@ -694,19 +652,11 @@ public async Task InsertMysqlTypesBatch(List args) csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); csvWriter.Context.TypeConverterCache.AddConverter(new Utils.BoolToBitCsvConverter()); csvWriter.Context.TypeConverterCache.AddConverter(new Utils.BoolToBitCsvConverter()); - csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteCsvConverter()); - csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteCsvConverter()); - csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteArrayCsvConverter()); - csvWriter.Context.TypeConverterCache.AddConverter(new Utils.MysqlTypesCSetCsvConverter()); csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); - csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); - csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); - csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); - csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); await csvWriter.WriteRecordsAsync(args); } @@ -716,7 +666,7 @@ public async Task InsertMysqlTypesBatch(List args) var loader = new MySqlBulkLoader(connection) { Local = true, - TableName = "mysql_types", + TableName = "mysql_numeric_types", FileName = "input.csv", FieldTerminator = ",", FieldQuotationCharacter = '"', @@ -724,14 +674,14 @@ public async Task InsertMysqlTypesBatch(List args) NumberOfLinesToSkip = 1, LineTerminator = "\n" }; - loader.Columns.AddRange(new List { "c_bit", "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", "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", "c_year", "c_date", "c_datetime", "c_timestamp", "c_binary", "c_varbinary", "c_tinyblob", "c_blob", "c_mediumblob", "c_longblob" }); + loader.Columns.AddRange(new List { "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" }); await loader.LoadAsync(); await connection.CloseAsync(); } } - private const string GetMysqlTypesSql = "SELECT c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_decimal, c_dec, c_numeric, c_fixed, c_double, c_double_precision, c_year, c_date, c_time, c_datetime, c_timestamp, 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, c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_types LIMIT 1"; - public class GetMysqlTypesRow + private const string GetMysqlNumericTypesSql = "SELECT c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_decimal, c_dec, c_numeric, c_fixed, c_double, c_double_precision FROM mysql_numeric_types LIMIT 1"; + public class GetMysqlNumericTypesRow { public bool? CBool { get; set; } public bool? CBoolean { get; set; } @@ -748,57 +698,29 @@ public class GetMysqlTypesRow public decimal? CFixed { get; set; } public double? CDouble { get; set; } public double? CDoublePrecision { get; set; } - public short? CYear { get; set; } - public DateTime? CDate { get; set; } - public string CTime { get; set; } - public DateTime? CDatetime { get; set; } - public DateTime? CTimestamp { get; set; } - public string CChar { get; set; } - public string CNchar { get; set; } - public string CNationalChar { get; set; } - public string CVarchar { get; set; } - public string CTinytext { get; set; } - public string CMediumtext { get; set; } - public string CText { get; set; } - public string CLongtext { get; set; } - public JsonElement? CJson { get; set; } - public string CJsonStringOverride { get; set; } - public MysqlTypesCEnum? CEnum { get; set; } - public MysqlTypesCSet[] CSet { get; set; } - public byte? CBit { get; set; } - public byte[] CBinary { get; set; } - public byte[] CVarbinary { get; set; } - public byte[] CTinyblob { get; set; } - public byte[] CBlob { get; set; } - public byte[] CMediumblob { get; set; } - public byte[] CLongblob { get; set; } }; - public async Task GetMysqlTypes() + public async Task GetMysqlNumericTypes() { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { - var result = await connection.QueryFirstOrDefaultAsync(GetMysqlTypesSql); + var result = await connection.QueryFirstOrDefaultAsync(GetMysqlNumericTypesSql); return result; } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - - return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlTypesSql, transaction: this.Transaction); + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlNumericTypesSql, transaction: this.Transaction); } - private const string GetMysqlTypesCntSql = "SELECT COUNT(1) AS cnt, c_bool, c_boolean, c_bit, 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, 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, c_year, c_date, c_datetime, c_timestamp, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_types GROUP BY c_bool , c_boolean, c_bit, 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, 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, c_year, c_date, c_datetime, c_timestamp, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob LIMIT 1 "; - public class GetMysqlTypesCntRow + 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; } public bool? CBool { get; set; } public bool? CBoolean { get; set; } - public byte? CBit { get; set; } public short? CTinyint { get; set; } public short? CSmallint { get; set; } public int? CMediumint { get; set; } @@ -812,180 +734,555 @@ public class GetMysqlTypesCntRow public decimal? CFixed { get; set; } public double? CDouble { get; set; } public double? CDoublePrecision { get; set; } - public string CChar { get; set; } - public string CNchar { get; set; } - public string CNationalChar { get; set; } - public string CVarchar { get; set; } - public string CTinytext { get; set; } - public string CMediumtext { get; set; } - public string CText { get; set; } - public string CLongtext { get; set; } - public JsonElement? CJson { get; set; } - public string CJsonStringOverride { get; set; } - public MysqlTypesCEnum? CEnum { get; set; } - public MysqlTypesCSet[] CSet { get; set; } - public short? CYear { get; set; } - public DateTime? CDate { get; set; } - public DateTime? CDatetime { get; set; } - public DateTime? CTimestamp { get; set; } - public byte[] CBinary { get; set; } - public byte[] CVarbinary { get; set; } - public byte[] CTinyblob { get; set; } - public byte[] CBlob { get; set; } - public byte[] CMediumblob { get; set; } - public byte[] CLongblob { get; set; } }; - public async Task GetMysqlTypesCnt() + public async Task GetMysqlNumericTypesCnt() { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { - var result = await connection.QueryFirstOrDefaultAsync(GetMysqlTypesCntSql); + var result = await connection.QueryFirstOrDefaultAsync(GetMysqlNumericTypesCntSql); return result; } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - - return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlTypesCntSql, transaction: this.Transaction); + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlNumericTypesCntSql, 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_types "; - public class GetMysqlFunctionsRow - { - public int? MaxInt { get; set; } - public string MaxVarchar { get; set; } - public DateTime MaxTimestamp { get; set; } - }; - public async Task GetMysqlFunctions() + private const string TruncateMysqlNumericTypesSql = "TRUNCATE TABLE mysql_numeric_types"; + public async Task TruncateMysqlNumericTypes() { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) - { - var result = await connection.QueryFirstOrDefaultAsync(GetMysqlFunctionsSql); - return result; - } + await connection.ExecuteAsync(TruncateMysqlNumericTypesSql); + return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncateMysqlNumericTypesSql, transaction: this.Transaction); + } - return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlFunctionsSql, 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)"; + public class InsertMysqlStringTypesArgs + { + public string CChar { get; set; } + public string CNchar { get; set; } + public string CNationalChar { get; set; } + public string CVarchar { get; set; } + public string CTinytext { get; set; } + public string CMediumtext { get; set; } + public string CText { get; set; } + public string CLongtext { get; set; } + public JsonElement? CJson { get; set; } + public string CJsonStringOverride { get; set; } + public MysqlStringTypesCEnum? CEnum { get; set; } + public HashSet CSet { get; set; } + }; + public async Task InsertMysqlStringTypes(InsertMysqlStringTypesArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("c_char", args.CChar); + queryParams.Add("c_nchar", args.CNchar); + queryParams.Add("c_national_char", args.CNationalChar); + queryParams.Add("c_varchar", args.CVarchar); + queryParams.Add("c_tinytext", args.CTinytext); + queryParams.Add("c_mediumtext", args.CMediumtext); + queryParams.Add("c_text", args.CText); + queryParams.Add("c_longtext", args.CLongtext); + queryParams.Add("c_json", args.CJson?.GetRawText() ?? null); + queryParams.Add("c_json_string_override", args.CJsonStringOverride); + queryParams.Add("c_enum", args.CEnum); + queryParams.Add("c_set", args.CSet != null ? string.Join(",", args.CSet) : null); + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + await connection.ExecuteAsync(InsertMysqlStringTypesSql, queryParams); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertMysqlStringTypesSql, queryParams, transaction: this.Transaction); + } + + public class InsertMysqlStringTypesBatchArgs + { + public string CChar { get; set; } + public string CNchar { get; set; } + public string CNationalChar { get; set; } + public string CVarchar { get; set; } + public string CTinytext { get; set; } + public string CMediumtext { get; set; } + public string CText { get; set; } + public string CLongtext { get; set; } + public JsonElement? CJson { get; set; } + public string CJsonStringOverride { get; set; } + public MysqlStringTypesCEnum? CEnum { get; set; } + public HashSet CSet { get; set; } + }; + public async Task InsertMysqlStringTypesBatch(List args) + { + const string supportedDateTimeFormat = "yyyy-MM-dd H:mm:ss"; + var config = new CsvConfiguration(CultureInfo.CurrentCulture) + { + Delimiter = ",", + NewLine = "\n" + }; + var nullConverterFn = new Utils.NullToStringCsvConverter(); + using (var writer = new StreamWriter("input.csv", false, new UTF8Encoding(false))) + using (var csvWriter = new CsvWriter(writer, config)) + { + var options = new TypeConverterOptions + { + Formats = new[] + { + supportedDateTimeFormat + } + }; + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterCache.AddConverter>(new Utils.MysqlStringTypesCSetCsvConverter()); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + await csvWriter.WriteRecordsAsync(args); + } + + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + var loader = new MySqlBulkLoader(connection) + { + Local = true, + TableName = "mysql_string_types", + FileName = "input.csv", + FieldTerminator = ",", + FieldQuotationCharacter = '"', + FieldQuotationOptional = true, + NumberOfLinesToSkip = 1, + LineTerminator = "\n" + }; + loader.Columns.AddRange(new List { "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" }); + await loader.LoadAsync(); + await connection.CloseAsync(); + } } - private const string TruncateMysqlTypesSql = "TRUNCATE TABLE mysql_types"; - public async Task TruncateMysqlTypes() + private const string GetMysqlStringTypesSql = "SELECT 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 LIMIT 1"; + public class GetMysqlStringTypesRow + { + public string CChar { get; set; } + public string CNchar { get; set; } + public string CNationalChar { get; set; } + public string CVarchar { get; set; } + public string CTinytext { get; set; } + public string CMediumtext { get; set; } + public string CText { get; set; } + public string CLongtext { get; set; } + public JsonElement? CJson { get; set; } + public string CJsonStringOverride { get; set; } + public MysqlStringTypesCEnum? CEnum { get; set; } + public HashSet CSet { get; set; } + }; + public async Task GetMysqlStringTypes() { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { - await connection.ExecuteAsync(TruncateMysqlTypesSql); + var result = await connection.QueryFirstOrDefaultAsync(GetMysqlStringTypesSql); + return result; } + } - return; + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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"; + public class GetMysqlStringTypesCntRow + { + public long Cnt { get; set; } + public string CChar { get; set; } + public string CNchar { get; set; } + public string CNationalChar { get; set; } + public string CVarchar { get; set; } + public string CTinytext { get; set; } + public string CMediumtext { get; set; } + public string CText { get; set; } + public string CLongtext { get; set; } + public JsonElement? CJson { get; set; } + public string CJsonStringOverride { get; set; } + public MysqlStringTypesCEnum? CEnum { get; set; } + public HashSet CSet { get; set; } + }; + public async Task GetMysqlStringTypesCnt() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetMysqlStringTypesCntSql); + return result; + } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlStringTypesCntSql, transaction: this.Transaction); + } + + private const string TruncateMysqlStringTypesSql = "TRUNCATE TABLE mysql_string_types"; + public async Task TruncateMysqlStringTypes() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new MySqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncateMysqlStringTypesSql); + return; } - await this.Transaction.Connection.ExecuteAsync(TruncateMysqlTypesSql, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncateMysqlStringTypesSql, transaction: this.Transaction); } - private const string CreateExtendedBioSql = "INSERT INTO extended.bios (author_name, name, bio_type, author_type) VALUES (@author_name, @name, @bio_type, @author_type)"; - public class CreateExtendedBioArgs + private const string InsertMysqlDatetimeTypesSql = " INSERT INTO mysql_datetime_types ( c_year, c_date, c_datetime, c_timestamp, c_time ) VALUES (@c_year, @c_date, @c_datetime, @c_timestamp, @c_time)"; + public class InsertMysqlDatetimeTypesArgs { - public string AuthorName { get; set; } - public string Name { get; set; } - public ExtendedBiosBioType? BioType { get; set; } - public ExtendedBiosAuthorType[] AuthorType { get; set; } + public short? CYear { get; set; } + public DateTime? CDate { get; set; } + public DateTime? CDatetime { get; set; } + public DateTime? CTimestamp { get; set; } + public TimeSpan? CTime { get; set; } }; - public async Task CreateExtendedBio(CreateExtendedBioArgs args) + public async Task InsertMysqlDatetimeTypes(InsertMysqlDatetimeTypesArgs args) { var queryParams = new Dictionary(); - queryParams.Add("author_name", args.AuthorName); - queryParams.Add("name", args.Name); - queryParams.Add("bio_type", args.BioType); - queryParams.Add("author_type", args.AuthorType != null ? string.Join(",", args.AuthorType) : null); + queryParams.Add("c_year", args.CYear); + queryParams.Add("c_date", args.CDate); + queryParams.Add("c_datetime", args.CDatetime); + queryParams.Add("c_timestamp", args.CTimestamp); + queryParams.Add("c_time", args.CTime); if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) - { - await connection.ExecuteAsync(CreateExtendedBioSql, queryParams); - } - + await connection.ExecuteAsync(InsertMysqlDatetimeTypesSql, queryParams); return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertMysqlDatetimeTypesSql, queryParams, transaction: this.Transaction); + } + + public class InsertMysqlDatetimeTypesBatchArgs + { + public short? CYear { get; set; } + public DateTime? CDate { get; set; } + public DateTime? CDatetime { get; set; } + public DateTime? CTimestamp { get; set; } + public TimeSpan? CTime { get; set; } + }; + public async Task InsertMysqlDatetimeTypesBatch(List args) + { + const string supportedDateTimeFormat = "yyyy-MM-dd H:mm:ss"; + var config = new CsvConfiguration(CultureInfo.CurrentCulture) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + Delimiter = ",", + NewLine = "\n" + }; + var nullConverterFn = new Utils.NullToStringCsvConverter(); + using (var writer = new StreamWriter("input.csv", false, new UTF8Encoding(false))) + using (var csvWriter = new CsvWriter(writer, config)) + { + var options = new TypeConverterOptions + { + Formats = new[] + { + supportedDateTimeFormat + } + }; + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + await csvWriter.WriteRecordsAsync(args); } - await this.Transaction.Connection.ExecuteAsync(CreateExtendedBioSql, queryParams, transaction: this.Transaction); + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + var loader = new MySqlBulkLoader(connection) + { + Local = true, + TableName = "mysql_datetime_types", + FileName = "input.csv", + FieldTerminator = ",", + FieldQuotationCharacter = '"', + FieldQuotationOptional = true, + NumberOfLinesToSkip = 1, + LineTerminator = "\n" + }; + loader.Columns.AddRange(new List { "c_year", "c_date", "c_datetime", "c_timestamp", "c_time" }); + await loader.LoadAsync(); + await connection.CloseAsync(); + } } - private const string GetFirstExtendedBioByTypeSql = "SELECT author_name, name, bio_type, author_type FROM extended.bios WHERE bio_type = @bio_type LIMIT 1"; - public class GetFirstExtendedBioByTypeRow + private const string GetMysqlDatetimeTypesSql = "SELECT c_year, c_date, c_datetime, c_timestamp, c_time FROM mysql_datetime_types LIMIT 1"; + public class GetMysqlDatetimeTypesRow { - public string AuthorName { get; set; } - public string Name { get; set; } - public ExtendedBiosBioType? BioType { get; set; } - public ExtendedBiosAuthorType[] AuthorType { get; set; } + public short? CYear { get; set; } + public DateTime? CDate { get; set; } + public DateTime? CDatetime { get; set; } + public DateTime? CTimestamp { get; set; } + public TimeSpan? CTime { get; set; } }; - public class GetFirstExtendedBioByTypeArgs + public async Task GetMysqlDatetimeTypes() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetMysqlDatetimeTypesSql); + return result; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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"; + public class GetMysqlDatetimeTypesCntRow { - public ExtendedBiosBioType? BioType { get; set; } + public long Cnt { get; set; } + public short? CYear { get; set; } + public DateTime? CDate { get; set; } + public DateTime? CDatetime { get; set; } + public DateTime? CTimestamp { get; set; } + public TimeSpan? CTime { get; set; } }; - public async Task GetFirstExtendedBioByType(GetFirstExtendedBioByTypeArgs args) + public async Task GetMysqlDatetimeTypesCnt() { - var queryParams = new Dictionary(); - queryParams.Add("bio_type", args.BioType); if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { - var result = await connection.QueryFirstOrDefaultAsync(GetFirstExtendedBioByTypeSql, queryParams); + var result = await connection.QueryFirstOrDefaultAsync(GetMysqlDatetimeTypesCntSql); return result; } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlDatetimeTypesCntSql, transaction: this.Transaction); + } + + private const string TruncateMysqlDatetimeTypesSql = "TRUNCATE TABLE mysql_datetime_types"; + public async Task TruncateMysqlDatetimeTypes() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new MySqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncateMysqlDatetimeTypesSql); + return; } - return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetFirstExtendedBioByTypeSql, queryParams, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncateMysqlDatetimeTypesSql, transaction: this.Transaction); } - private const string TruncateExtendedBiosSql = "TRUNCATE TABLE extended.bios"; - public async Task TruncateExtendedBios() + 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; } + public byte[] CBinary { get; set; } + public byte[] CVarbinary { get; set; } + public byte[] CTinyblob { get; set; } + public byte[] CBlob { get; set; } + public byte[] CMediumblob { get; set; } + public byte[] CLongblob { get; set; } + }; + public async Task InsertMysqlBinaryTypes(InsertMysqlBinaryTypesArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("c_bit", args.CBit); + queryParams.Add("c_binary", args.CBinary); + queryParams.Add("c_varbinary", args.CVarbinary); + queryParams.Add("c_tinyblob", args.CTinyblob); + queryParams.Add("c_blob", args.CBlob); + queryParams.Add("c_mediumblob", args.CMediumblob); + queryParams.Add("c_longblob", args.CLongblob); if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) + await connection.ExecuteAsync(InsertMysqlBinaryTypesSql, queryParams); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertMysqlBinaryTypesSql, queryParams, transaction: this.Transaction); + } + + public class InsertMysqlBinaryTypesBatchArgs + { + public byte? CBit { get; set; } + public byte[] CBinary { get; set; } + public byte[] CVarbinary { get; set; } + public byte[] CTinyblob { get; set; } + public byte[] CBlob { get; set; } + public byte[] CMediumblob { get; set; } + public byte[] CLongblob { get; set; } + }; + public async Task InsertMysqlBinaryTypesBatch(List args) + { + const string supportedDateTimeFormat = "yyyy-MM-dd H:mm:ss"; + var config = new CsvConfiguration(CultureInfo.CurrentCulture) + { + Delimiter = ",", + NewLine = "\n" + }; + var nullConverterFn = new Utils.NullToStringCsvConverter(); + using (var writer = new StreamWriter("input.csv", false, new UTF8Encoding(false))) + using (var csvWriter = new CsvWriter(writer, config)) + { + var options = new TypeConverterOptions { - await connection.ExecuteAsync(TruncateExtendedBiosSql); + Formats = new[] + { + supportedDateTimeFormat + } + }; + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteCsvConverter()); + csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteCsvConverter()); + csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteArrayCsvConverter()); + await csvWriter.WriteRecordsAsync(args); + } + + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + var loader = new MySqlBulkLoader(connection) + { + Local = true, + TableName = "mysql_binary_types", + FileName = "input.csv", + FieldTerminator = ",", + FieldQuotationCharacter = '"', + FieldQuotationOptional = true, + NumberOfLinesToSkip = 1, + LineTerminator = "\n" + }; + loader.Columns.AddRange(new List { "c_bit", "c_binary", "c_varbinary", "c_tinyblob", "c_blob", "c_mediumblob", "c_longblob" }); + await loader.LoadAsync(); + await connection.CloseAsync(); + } + } + + private const string GetMysqlBinaryTypesSql = "SELECT c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_binary_types LIMIT 1"; + public class GetMysqlBinaryTypesRow + { + public byte? CBit { get; set; } + public byte[] CBinary { get; set; } + public byte[] CVarbinary { get; set; } + public byte[] CTinyblob { get; set; } + public byte[] CBlob { get; set; } + public byte[] CMediumblob { get; set; } + public byte[] CLongblob { get; set; } + }; + public async Task GetMysqlBinaryTypes() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetMysqlBinaryTypesSql); + return result; } + } + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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"; + public class GetMysqlBinaryTypesCntRow + { + public long Cnt { get; set; } + public byte? CBit { get; set; } + public byte[] CBinary { get; set; } + public byte[] CVarbinary { get; set; } + public byte[] CTinyblob { get; set; } + public byte[] CBlob { get; set; } + public byte[] CMediumblob { get; set; } + public byte[] CLongblob { get; set; } + }; + public async Task GetMysqlBinaryTypesCnt() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetMysqlBinaryTypesCntSql); + return result; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlBinaryTypesCntSql, transaction: this.Transaction); + } + + private const string TruncateMysqlBinaryTypesSql = "TRUNCATE TABLE mysql_binary_types"; + public async Task TruncateMysqlBinaryTypes() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncateMysqlBinaryTypesSql); return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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"; + public class GetMysqlFunctionsRow + { + public int? MaxInt { get; set; } + public string MaxVarchar { get; set; } + public DateTime MaxTimestamp { get; set; } + }; + public async Task GetMysqlFunctions() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new MySqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetMysqlFunctionsSql); + return result; + } } - await this.Transaction.Connection.ExecuteAsync(TruncateExtendedBiosSql, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetMysqlFunctionsSql, transaction: this.Transaction); } } } \ No newline at end of file diff --git a/examples/MySqlConnectorDapperLegacyExample/Utils.cs b/examples/MySqlConnectorDapperLegacyExample/Utils.cs index 0bc1ed4a..47c4f482 100644 --- a/examples/MySqlConnectorDapperLegacyExample/Utils.cs +++ b/examples/MySqlConnectorDapperLegacyExample/Utils.cs @@ -5,6 +5,7 @@ namespace MySqlConnectorDapperLegacyExampleGen using CsvHelper.Configuration; using CsvHelper.TypeConversion; using Dapper; + using System.Collections.Generic; using System.Data; using System.Linq; using System.Text.Json; @@ -29,8 +30,8 @@ public override void SetValue(IDbDataParameter parameter, JsonElement value) public static void ConfigureSqlMapper() { SqlMapper.AddTypeHandler(typeof(JsonElement), new JsonElementTypeHandler()); - SqlMapper.AddTypeHandler(typeof(MysqlTypesCSet[]), new MysqlTypesCSetTypeHandler()); - SqlMapper.AddTypeHandler(typeof(ExtendedBiosAuthorType[]), new ExtendedBiosAuthorTypeTypeHandler()); + SqlMapper.AddTypeHandler(typeof(HashSet), new BiosAuthorTypeTypeHandler()); + SqlMapper.AddTypeHandler(typeof(HashSet), new MysqlStringTypesCSetTypeHandler()); } public static string TransformQueryForSliceArgs(string originalSql, int sliceSize, string paramName) @@ -39,44 +40,44 @@ public static string TransformQueryForSliceArgs(string originalSql, int sliceSiz return originalSql.Replace($"/*SLICE:{paramName}*/@{paramName}", string.Join(",", paramArgs)); } - private class MysqlTypesCSetTypeHandler : SqlMapper.TypeHandler + private class BiosAuthorTypeTypeHandler : SqlMapper.TypeHandler> { - public override MysqlTypesCSet[] Parse(object value) + public override HashSet Parse(object value) { if (value is string s) - return s.ToMysqlTypesCSetArr(); - throw new DataException($"Cannot convert {value?.GetType()} to MysqlTypesCSet[]"); + return s.ToBiosAuthorTypeSet(); + throw new DataException($"Cannot convert {value?.GetType()} to HashSet"); } - public override void SetValue(IDbDataParameter parameter, MysqlTypesCSet[] value) + public override void SetValue(IDbDataParameter parameter, HashSet value) { parameter.Value = string.Join(",", value); } } - private class ExtendedBiosAuthorTypeTypeHandler : SqlMapper.TypeHandler + private class MysqlStringTypesCSetTypeHandler : SqlMapper.TypeHandler> { - public override ExtendedBiosAuthorType[] Parse(object value) + public override HashSet Parse(object value) { if (value is string s) - return s.ToExtendedBiosAuthorTypeArr(); - throw new DataException($"Cannot convert {value?.GetType()} to ExtendedBiosAuthorType[]"); + return s.ToMysqlStringTypesCSetSet(); + throw new DataException($"Cannot convert {value?.GetType()} to HashSet"); } - public override void SetValue(IDbDataParameter parameter, ExtendedBiosAuthorType[] value) + public override void SetValue(IDbDataParameter parameter, HashSet value) { parameter.Value = string.Join(",", value); } } - public class MysqlTypesCSetCsvConverter : DefaultTypeConverter + public class MysqlStringTypesCSetCsvConverter : DefaultTypeConverter { public override string ConvertToString(object value, IWriterRow row, MemberMapData memberMapData) { if (value == null) return @"\N"; - if (value is MysqlTypesCSet[] arrVal) - return string.Join(",", arrVal); + if (value is HashSet setVal) + return string.Join(",", setVal); return base.ConvertToString(value, row, memberMapData); } } diff --git a/examples/MySqlConnectorDapperLegacyExample/request.json b/examples/MySqlConnectorDapperLegacyExample/request.json index 3e1218db..f2f8ce44 100644 --- a/examples/MySqlConnectorDapperLegacyExample/request.json +++ b/examples/MySqlConnectorDapperLegacyExample/request.json @@ -3,10 +3,12 @@ "version": "2", "engine": "mysql", "schema": [ - "examples/config/mysql/schema.sql" + "examples/config/mysql/authors/schema.sql", + "examples/config/mysql/types/schema.sql" ], "queries": [ - "examples/config/mysql/query.sql" + "examples/config/mysql/authors/query.sql", + "examples/config/mysql/types/query.sql" ], "codegen": { "out": "examples/MySqlConnectorDapperLegacyExample", @@ -114,14 +116,14 @@ }, { "rel": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "columns": [ { "name": "c_bool", "length": 1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "tinyint" @@ -131,7 +133,7 @@ "name": "c_boolean", "length": 1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "tinyint" @@ -141,7 +143,7 @@ "name": "c_tinyint", "length": 3, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "tinyint" @@ -151,7 +153,7 @@ "name": "c_smallint", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "smallint" @@ -161,7 +163,7 @@ "name": "c_mediumint", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "mediumint" @@ -171,7 +173,7 @@ "name": "c_int", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "int" @@ -181,7 +183,7 @@ "name": "c_integer", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "int" @@ -191,7 +193,7 @@ "name": "c_bigint", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "bigint" @@ -201,7 +203,7 @@ "name": "c_float", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "float" @@ -211,7 +213,7 @@ "name": "c_decimal", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -221,7 +223,7 @@ "name": "c_dec", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -231,7 +233,7 @@ "name": "c_numeric", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -241,7 +243,7 @@ "name": "c_fixed", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -251,7 +253,7 @@ "name": "c_double", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "double" @@ -261,187 +263,208 @@ "name": "c_double_precision", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "double" } - }, + } + ] + }, + { + "rel": { + "name": "mysql_string_types" + }, + "columns": [ { - "name": "c_year", + "name": "c_char", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "year" + "name": "char" } }, { - "name": "c_date", + "name": "c_nchar", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "date" + "name": "char" } }, { - "name": "c_time", - "length": 10, + "name": "c_national_char", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "time" + "name": "char" } }, { - "name": "c_datetime", - "length": 19, + "name": "c_varchar", + "length": 100, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "datetime" + "name": "varchar" } }, { - "name": "c_timestamp", - "length": 19, + "name": "c_tinytext", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "timestamp" + "name": "tinytext" } }, { - "name": "c_char", + "name": "c_mediumtext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "char" + "name": "mediumtext" } }, { - "name": "c_nchar", + "name": "c_text", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "char" + "name": "text" } }, { - "name": "c_national_char", + "name": "c_longtext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "char" + "name": "longtext" } }, { - "name": "c_varchar", - "length": 100, + "name": "c_json", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "varchar" + "name": "json" } }, { - "name": "c_tinytext", + "name": "c_json_string_override", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "tinytext" + "name": "json" } }, { - "name": "c_mediumtext", - "length": -1, + "name": "c_enum", + "length": 6, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mediumtext" + "name": "mysql_string_types_c_enum" } }, { - "name": "c_text", - "length": -1, + "name": "c_set", + "length": 15, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "text" + "name": "mysql_string_types_c_set" } - }, + } + ] + }, + { + "rel": { + "name": "mysql_datetime_types" + }, + "columns": [ { - "name": "c_longtext", + "name": "c_year", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "longtext" + "name": "year" } }, { - "name": "c_json", + "name": "c_date", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "json" + "name": "date" } }, { - "name": "c_json_string_override", - "length": -1, + "name": "c_datetime", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "json" + "name": "datetime" } }, { - "name": "c_enum", - "length": 6, + "name": "c_timestamp", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "mysql_types_c_enum" + "name": "timestamp" } }, { - "name": "c_set", - "length": 15, + "name": "c_time", + "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "mysql_types_c_set" + "name": "time" } - }, + } + ] + }, + { + "rel": { + "name": "mysql_binary_types" + }, + "columns": [ { "name": "c_bit", "length": 8, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "bit" @@ -451,7 +474,7 @@ "name": "c_binary", "length": 3, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "binary" @@ -461,7 +484,7 @@ "name": "c_varbinary", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "varbinary" @@ -471,7 +494,7 @@ "name": "c_tinyblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "tinyblob" @@ -481,7 +504,7 @@ "name": "c_blob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "blob" @@ -491,7 +514,7 @@ "name": "c_mediumblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "mediumblob" @@ -501,7 +524,7 @@ "name": "c_longblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "longblob" @@ -511,22 +534,6 @@ } ], "enums": [ - { - "name": "mysql_types_c_enum", - "vals": [ - "small", - "medium", - "big" - ] - }, - { - "name": "mysql_types_c_set", - "vals": [ - "tea", - "coffee", - "milk" - ] - }, { "name": "bios_bio_type", "vals": [ @@ -542,6 +549,22 @@ "Editor", "Translator" ] + }, + { + "name": "mysql_string_types_c_enum", + "vals": [ + "small", + "medium", + "big" + ] + }, + { + "name": "mysql_string_types_c_set", + "vals": [ + "tea", + "coffee", + "milk" + ] } ] }, @@ -1306,93 +1329,229 @@ "filename": "query.sql" }, { - "text": "INSERT INTO mysql_types \n(c_bit, c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, \n c_decimal, c_dec, c_numeric, c_fixed, c_float, c_double, c_double_precision, \n c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, \n c_json, c_json_string_override, c_enum, c_set, c_year, c_date, c_datetime, c_timestamp, \n c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - "name": "InsertMysqlTypes", + "text": "INSERT INTO extended.bios (author_name, name, bio_type, author_type) VALUES (?, ?, ?, ?)", + "name": "CreateExtendedBio", "cmd": ":exec", "parameters": [ { "number": 1, "column": { - "name": "c_bit", - "length": 8, + "name": "author_name", + "length": 100, "table": { - "schema": "public", - "name": "mysql_types" + "schema": "extended", + "name": "bios" }, "type": { - "name": "bit" + "name": "varchar" }, - "originalName": "c_bit" + "originalName": "author_name" } }, { "number": 2, "column": { - "name": "c_bool", - "length": 1, + "name": "name", + "length": 100, "table": { - "schema": "public", - "name": "mysql_types" + "schema": "extended", + "name": "bios" }, "type": { - "name": "tinyint" + "name": "varchar" }, - "originalName": "c_bool" + "originalName": "name" } }, { "number": 3, "column": { - "name": "c_boolean", - "length": 1, + "name": "bio_type", + "length": 13, "table": { - "schema": "public", - "name": "mysql_types" + "schema": "extended", + "name": "bios" }, "type": { - "name": "tinyint" + "name": "bios_bio_type" }, - "originalName": "c_boolean" + "originalName": "bio_type" } }, { "number": 4, "column": { - "name": "c_tinyint", - "length": 3, + "name": "author_type", + "length": 24, "table": { - "schema": "public", - "name": "mysql_types" + "schema": "extended", + "name": "bios" }, "type": { - "name": "tinyint" + "name": "bios_author_type" }, - "originalName": "c_tinyint" + "originalName": "author_type" } + } + ], + "filename": "query.sql", + "insert_into_table": { + "schema": "extended", + "name": "bios" + } + }, + { + "text": "SELECT author_name, name, bio_type, author_type FROM extended.bios WHERE bio_type = ? LIMIT 1", + "name": "GetFirstExtendedBioByType", + "cmd": ":one", + "columns": [ + { + "name": "author_name", + "length": 100, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "varchar" + }, + "originalName": "author_name" }, { - "number": 5, + "name": "name", + "length": 100, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "varchar" + }, + "originalName": "name" + }, + { + "name": "bio_type", + "length": 13, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "bios_bio_type" + }, + "originalName": "bio_type" + }, + { + "name": "author_type", + "length": 24, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "bios_author_type" + }, + "originalName": "author_type" + } + ], + "parameters": [ + { + "number": 1, "column": { - "name": "c_smallint", - "length": -1, + "name": "bio_type", + "length": 13, "table": { - "schema": "public", - "name": "mysql_types" + "schema": "extended", + "name": "bios" }, "type": { - "name": "smallint" + "name": "bios_bio_type" }, - "originalName": "c_smallint" + "originalName": "bio_type" } - }, + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE extended.bios", + "name": "TruncateExtendedBios", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO mysql_numeric_types \n(\n c_bool,\n c_boolean,\n c_tinyint,\n c_smallint,\n c_mediumint,\n c_int,\n c_integer,\n c_bigint, \n c_decimal, \n c_dec, \n c_numeric, \n c_fixed, \n c_float, \n c_double, \n c_double_precision\n) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlNumericTypes", + "cmd": ":exec", + "parameters": [ { - "number": 6, + "number": 1, + "column": { + "name": "c_bool", + "length": 1, + "table": { + "schema": "public", + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_bool" + } + }, + { + "number": 2, + "column": { + "name": "c_boolean", + "length": 1, + "table": { + "schema": "public", + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_boolean" + } + }, + { + "number": 3, + "column": { + "name": "c_tinyint", + "length": 3, + "table": { + "schema": "public", + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_tinyint" + } + }, + { + "number": 4, + "column": { + "name": "c_smallint", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_numeric_types" + }, + "type": { + "name": "smallint" + }, + "originalName": "c_smallint" + } + }, + { + "number": 5, "column": { "name": "c_mediumint", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "mediumint" @@ -1401,13 +1560,13 @@ } }, { - "number": 7, + "number": 6, "column": { "name": "c_int", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "int" @@ -1416,13 +1575,13 @@ } }, { - "number": 8, + "number": 7, "column": { "name": "c_integer", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "int" @@ -1431,13 +1590,13 @@ } }, { - "number": 9, + "number": 8, "column": { "name": "c_bigint", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "bigint" @@ -1446,13 +1605,13 @@ } }, { - "number": 10, + "number": 9, "column": { "name": "c_decimal", "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -1461,13 +1620,13 @@ } }, { - "number": 11, + "number": 10, "column": { "name": "c_dec", "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -1476,13 +1635,13 @@ } }, { - "number": 12, + "number": 11, "column": { "name": "c_numeric", "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -1491,13 +1650,13 @@ } }, { - "number": 13, + "number": 12, "column": { "name": "c_fixed", "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -1506,13 +1665,13 @@ } }, { - "number": 14, + "number": 13, "column": { "name": "c_float", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "float" @@ -1521,13 +1680,13 @@ } }, { - "number": 15, + "number": 14, "column": { "name": "c_double", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "double" @@ -1536,609 +1695,639 @@ } }, { - "number": 16, + "number": 15, "column": { "name": "c_double_precision", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "double" }, "originalName": "c_double_precision" } - }, + } + ], + "comments": [ + " Numeric types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_numeric_types" + } + }, + { + "text": "INSERT INTO mysql_numeric_types \n(\n c_bool,\n c_boolean,\n c_tinyint,\n c_smallint,\n c_mediumint,\n c_int,\n c_integer,\n c_bigint, \n c_float, \n c_numeric, \n c_decimal, \n c_dec, \n c_fixed, \n c_double, \n c_double_precision\n) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlNumericTypesBatch", + "cmd": ":copyfrom", + "parameters": [ { - "number": 17, + "number": 1, "column": { - "name": "c_char", - "length": -1, + "name": "c_bool", + "length": 1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "char" + "name": "tinyint" }, - "originalName": "c_char" + "originalName": "c_bool" } }, { - "number": 18, + "number": 2, "column": { - "name": "c_nchar", - "length": -1, + "name": "c_boolean", + "length": 1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "char" + "name": "tinyint" }, - "originalName": "c_nchar" + "originalName": "c_boolean" } }, { - "number": 19, + "number": 3, "column": { - "name": "c_national_char", - "length": -1, + "name": "c_tinyint", + "length": 3, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "char" + "name": "tinyint" }, - "originalName": "c_national_char" + "originalName": "c_tinyint" } }, { - "number": 20, + "number": 4, "column": { - "name": "c_varchar", - "length": 100, + "name": "c_smallint", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "varchar" + "name": "smallint" }, - "originalName": "c_varchar" + "originalName": "c_smallint" } }, { - "number": 21, + "number": 5, "column": { - "name": "c_tinytext", + "name": "c_mediumint", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "tinytext" + "name": "mediumint" }, - "originalName": "c_tinytext" + "originalName": "c_mediumint" } }, { - "number": 22, + "number": 6, "column": { - "name": "c_mediumtext", + "name": "c_int", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "mediumtext" + "name": "int" }, - "originalName": "c_mediumtext" + "originalName": "c_int" } }, { - "number": 23, + "number": 7, "column": { - "name": "c_text", + "name": "c_integer", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "text" + "name": "int" }, - "originalName": "c_text" + "originalName": "c_integer" } }, { - "number": 24, + "number": 8, "column": { - "name": "c_longtext", + "name": "c_bigint", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "longtext" + "name": "bigint" }, - "originalName": "c_longtext" + "originalName": "c_bigint" } }, { - "number": 25, + "number": 9, "column": { - "name": "c_json", + "name": "c_float", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "json" + "name": "float" }, - "originalName": "c_json" + "originalName": "c_float" } }, { - "number": 26, + "number": 10, "column": { - "name": "c_json_string_override", - "length": -1, + "name": "c_numeric", + "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "json" + "name": "decimal" }, - "originalName": "c_json_string_override" + "originalName": "c_numeric" } }, { - "number": 27, + "number": 11, "column": { - "name": "c_enum", - "length": 6, + "name": "c_decimal", + "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "mysql_types_c_enum" + "name": "decimal" }, - "originalName": "c_enum" + "originalName": "c_decimal" } }, { - "number": 28, + "number": 12, "column": { - "name": "c_set", - "length": 15, + "name": "c_dec", + "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "mysql_types_c_set" + "name": "decimal" }, - "originalName": "c_set" + "originalName": "c_dec" } }, { - "number": 29, + "number": 13, "column": { - "name": "c_year", - "length": -1, + "name": "c_fixed", + "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "year" + "name": "decimal" }, - "originalName": "c_year" + "originalName": "c_fixed" } }, { - "number": 30, + "number": 14, "column": { - "name": "c_date", + "name": "c_double", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "date" + "name": "double" }, - "originalName": "c_date" + "originalName": "c_double" } }, { - "number": 31, + "number": 15, "column": { - "name": "c_datetime", - "length": 19, + "name": "c_double_precision", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "datetime" + "name": "double" }, - "originalName": "c_datetime" + "originalName": "c_double_precision" } - }, + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_numeric_types" + } + }, + { + "text": "SELECT c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_decimal, c_dec, c_numeric, c_fixed, c_double, c_double_precision FROM mysql_numeric_types LIMIT 1", + "name": "GetMysqlNumericTypes", + "cmd": ":one", + "columns": [ { - "number": 32, - "column": { - "name": "c_timestamp", - "length": 19, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "timestamp" - }, - "originalName": "c_timestamp" - } + "name": "c_bool", + "length": 1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_bool" }, { - "number": 33, - "column": { - "name": "c_binary", - "length": 3, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "binary" - }, - "originalName": "c_binary" - } + "name": "c_boolean", + "length": 1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_boolean" }, { - "number": 34, - "column": { - "name": "c_varbinary", - "length": 10, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "varbinary" - }, - "originalName": "c_varbinary" - } + "name": "c_tinyint", + "length": 3, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_tinyint" }, { - "number": 35, - "column": { - "name": "c_tinyblob", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "tinyblob" - }, - "originalName": "c_tinyblob" - } + "name": "c_smallint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "smallint" + }, + "originalName": "c_smallint" }, { - "number": 36, - "column": { - "name": "c_blob", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "blob" - }, - "originalName": "c_blob" - } + "name": "c_mediumint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "mediumint" + }, + "originalName": "c_mediumint" }, { - "number": 37, - "column": { - "name": "c_mediumblob", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "mediumblob" - }, - "originalName": "c_mediumblob" - } + "name": "c_int", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "int" + }, + "originalName": "c_int" }, { - "number": 38, - "column": { - "name": "c_longblob", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "longblob" - }, - "originalName": "c_longblob" - } + "name": "c_integer", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "int" + }, + "originalName": "c_integer" + }, + { + "name": "c_bigint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "bigint" + }, + "originalName": "c_bigint" + }, + { + "name": "c_float", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "float" + }, + "originalName": "c_float" + }, + { + "name": "c_decimal", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_decimal" + }, + { + "name": "c_dec", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_dec" + }, + { + "name": "c_numeric", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_numeric" + }, + { + "name": "c_fixed", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_fixed" + }, + { + "name": "c_double", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "double" + }, + "originalName": "c_double" + }, + { + "name": "c_double_precision", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "double" + }, + "originalName": "c_double_precision" } ], - "filename": "query.sql", - "insert_into_table": { - "name": "mysql_types" - } + "filename": "query.sql" }, { - "text": "INSERT INTO mysql_types \n(c_bit, c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, \n c_float, c_numeric, c_decimal, c_dec, c_fixed, c_double, c_double_precision, \n c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, \n c_json, c_json_string_override, c_enum, c_set, c_year, c_date, c_datetime, c_timestamp,\n c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - "name": "InsertMysqlTypesBatch", - "cmd": ":copyfrom", - "parameters": [ - { - "number": 1, - "column": { - "name": "c_bit", - "length": 8, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "bit" - }, - "originalName": "c_bit" - } - }, + "text": "SELECT\n COUNT(*) AS cnt,\n c_bool,\n c_boolean,\n c_tinyint,\n c_smallint,\n c_mediumint,\n c_int,\n c_integer,\n c_bigint,\n c_float,\n c_numeric,\n c_decimal,\n c_dec,\n c_fixed,\n c_double,\n c_double_precision\nFROM mysql_numeric_types\nGROUP BY\n c_bool,\n c_boolean,\n c_tinyint,\n c_smallint,\n c_mediumint,\n c_int,\n c_integer,\n c_bigint,\n c_float,\n c_numeric,\n c_decimal,\n c_dec,\n c_fixed,\n c_double,\n c_double_precision\nLIMIT 1", + "name": "GetMysqlNumericTypesCnt", + "cmd": ":one", + "columns": [ { - "number": 2, - "column": { - "name": "c_bool", - "length": 1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_bool" + "name": "cnt", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "bigint" } }, { - "number": 3, - "column": { - "name": "c_boolean", - "length": 1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_boolean" - } + "name": "c_bool", + "length": 1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_bool" }, { - "number": 4, - "column": { - "name": "c_tinyint", - "length": 3, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_tinyint" - } + "name": "c_boolean", + "length": 1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_boolean" }, { - "number": 5, - "column": { - "name": "c_smallint", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "smallint" - }, - "originalName": "c_smallint" - } + "name": "c_tinyint", + "length": 3, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_tinyint" }, { - "number": 6, - "column": { - "name": "c_mediumint", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "mediumint" - }, - "originalName": "c_mediumint" - } + "name": "c_smallint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "smallint" + }, + "originalName": "c_smallint" }, { - "number": 7, - "column": { - "name": "c_int", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "int" - }, - "originalName": "c_int" - } + "name": "c_mediumint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "mediumint" + }, + "originalName": "c_mediumint" }, { - "number": 8, - "column": { - "name": "c_integer", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "int" - }, - "originalName": "c_integer" - } + "name": "c_int", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "int" + }, + "originalName": "c_int" }, { - "number": 9, - "column": { - "name": "c_bigint", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "bigint" - }, - "originalName": "c_bigint" - } + "name": "c_integer", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "int" + }, + "originalName": "c_integer" }, { - "number": 10, - "column": { - "name": "c_float", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "float" - }, - "originalName": "c_float" - } + "name": "c_bigint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "bigint" + }, + "originalName": "c_bigint" }, { - "number": 11, - "column": { - "name": "c_numeric", - "length": 10, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_numeric" - } + "name": "c_float", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "float" + }, + "originalName": "c_float" }, { - "number": 12, - "column": { - "name": "c_decimal", - "length": 10, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_decimal" - } + "name": "c_numeric", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_numeric" }, { - "number": 13, - "column": { - "name": "c_dec", - "length": 10, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_dec" - } + "name": "c_decimal", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_decimal" }, { - "number": 14, - "column": { - "name": "c_fixed", - "length": 10, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_fixed" - } + "name": "c_dec", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_dec" }, { - "number": 15, - "column": { - "name": "c_double", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "double" - }, - "originalName": "c_double" - } + "name": "c_fixed", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_fixed" }, { - "number": 16, - "column": { - "name": "c_double_precision", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "double" - }, - "originalName": "c_double_precision" - } + "name": "c_double", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "double" + }, + "originalName": "c_double" }, { - "number": 17, + "name": "c_double_precision", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "double" + }, + "originalName": "c_double_precision" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE mysql_numeric_types", + "name": "TruncateMysqlNumericTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO mysql_string_types \n(\n c_char,\n c_nchar,\n c_national_char,\n c_varchar,\n c_tinytext,\n c_mediumtext,\n c_text,\n c_longtext, \n c_json,\n c_json_string_override,\n c_enum,\n c_set\n) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlStringTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, "column": { "name": "c_char", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2147,13 +2336,13 @@ } }, { - "number": 18, + "number": 2, "column": { "name": "c_nchar", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2162,13 +2351,13 @@ } }, { - "number": 19, + "number": 3, "column": { "name": "c_national_char", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2177,13 +2366,13 @@ } }, { - "number": 20, + "number": 4, "column": { "name": "c_varchar", "length": 100, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "varchar" @@ -2192,511 +2381,335 @@ } }, { - "number": 21, + "number": 5, "column": { "name": "c_tinytext", "length": -1, "table": { "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "tinytext" - }, - "originalName": "c_tinytext" - } - }, - { - "number": 22, - "column": { - "name": "c_mediumtext", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "mediumtext" - }, - "originalName": "c_mediumtext" - } - }, - { - "number": 23, - "column": { - "name": "c_text", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "text" - }, - "originalName": "c_text" - } - }, - { - "number": 24, - "column": { - "name": "c_longtext", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "longtext" - }, - "originalName": "c_longtext" - } - }, - { - "number": 25, - "column": { - "name": "c_json", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "json" - }, - "originalName": "c_json" - } - }, - { - "number": 26, - "column": { - "name": "c_json_string_override", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "json" + "name": "tinytext" }, - "originalName": "c_json_string_override" + "originalName": "c_tinytext" } }, { - "number": 27, + "number": 6, "column": { - "name": "c_enum", - "length": 6, + "name": "c_mediumtext", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mysql_types_c_enum" + "name": "mediumtext" }, - "originalName": "c_enum" + "originalName": "c_mediumtext" } }, { - "number": 28, + "number": 7, "column": { - "name": "c_set", - "length": 15, + "name": "c_text", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mysql_types_c_set" + "name": "text" }, - "originalName": "c_set" + "originalName": "c_text" } }, { - "number": 29, + "number": 8, "column": { - "name": "c_year", + "name": "c_longtext", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "year" + "name": "longtext" }, - "originalName": "c_year" + "originalName": "c_longtext" } }, { - "number": 30, + "number": 9, "column": { - "name": "c_date", + "name": "c_json", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "date" + "name": "json" }, - "originalName": "c_date" + "originalName": "c_json" } }, { - "number": 31, + "number": 10, "column": { - "name": "c_datetime", - "length": 19, + "name": "c_json_string_override", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "datetime" + "name": "json" }, - "originalName": "c_datetime" + "originalName": "c_json_string_override" } }, { - "number": 32, + "number": 11, "column": { - "name": "c_timestamp", - "length": 19, + "name": "c_enum", + "length": 6, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "timestamp" + "name": "mysql_string_types_c_enum" }, - "originalName": "c_timestamp" + "originalName": "c_enum" } }, { - "number": 33, + "number": 12, "column": { - "name": "c_binary", - "length": 3, + "name": "c_set", + "length": 15, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "binary" + "name": "mysql_string_types_c_set" }, - "originalName": "c_binary" + "originalName": "c_set" } - }, + } + ], + "comments": [ + " String types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_string_types" + } + }, + { + "text": "INSERT INTO mysql_string_types \n(\n c_char,\n c_nchar,\n c_national_char,\n c_varchar,\n c_tinytext,\n c_mediumtext,\n c_text,\n c_longtext, \n c_json,\n c_json_string_override,\n c_enum,\n c_set\n) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlStringTypesBatch", + "cmd": ":copyfrom", + "parameters": [ { - "number": 34, + "number": 1, "column": { - "name": "c_varbinary", - "length": 10, + "name": "c_char", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "varbinary" + "name": "char" }, - "originalName": "c_varbinary" + "originalName": "c_char" } }, { - "number": 35, + "number": 2, "column": { - "name": "c_tinyblob", + "name": "c_nchar", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "tinyblob" + "name": "char" }, - "originalName": "c_tinyblob" + "originalName": "c_nchar" } }, { - "number": 36, + "number": 3, "column": { - "name": "c_blob", + "name": "c_national_char", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "blob" + "name": "char" }, - "originalName": "c_blob" + "originalName": "c_national_char" } }, { - "number": 37, + "number": 4, "column": { - "name": "c_mediumblob", - "length": -1, + "name": "c_varchar", + "length": 100, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mediumblob" + "name": "varchar" }, - "originalName": "c_mediumblob" + "originalName": "c_varchar" } }, { - "number": 38, + "number": 5, "column": { - "name": "c_longblob", + "name": "c_tinytext", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "longblob" + "name": "tinytext" }, - "originalName": "c_longblob" + "originalName": "c_tinytext" } - } - ], - "filename": "query.sql", - "insert_into_table": { - "name": "mysql_types" - } - }, - { - "text": "SELECT c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_decimal, c_dec, c_numeric, c_fixed, c_double, c_double_precision, c_year, c_date, c_time, c_datetime, c_timestamp, 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, c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_types LIMIT 1", - "name": "GetMysqlTypes", - "cmd": ":one", - "columns": [ - { - "name": "c_bool", - "length": 1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_bool" - }, - { - "name": "c_boolean", - "length": 1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_boolean" - }, - { - "name": "c_tinyint", - "length": 3, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_tinyint" - }, - { - "name": "c_smallint", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "smallint" - }, - "originalName": "c_smallint" - }, - { - "name": "c_mediumint", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "mediumint" - }, - "originalName": "c_mediumint" - }, - { - "name": "c_int", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "int" - }, - "originalName": "c_int" - }, - { - "name": "c_integer", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "int" - }, - "originalName": "c_integer" - }, - { - "name": "c_bigint", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "bigint" - }, - "originalName": "c_bigint" - }, - { - "name": "c_float", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "float" - }, - "originalName": "c_float" - }, - { - "name": "c_decimal", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_decimal" - }, - { - "name": "c_dec", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_dec" - }, - { - "name": "c_numeric", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_numeric" - }, - { - "name": "c_fixed", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_fixed" - }, - { - "name": "c_double", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "double" - }, - "originalName": "c_double" }, { - "name": "c_double_precision", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "double" - }, - "originalName": "c_double_precision" + "number": 6, + "column": { + "name": "c_mediumtext", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "mediumtext" + }, + "originalName": "c_mediumtext" + } }, { - "name": "c_year", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "year" - }, - "originalName": "c_year" + "number": 7, + "column": { + "name": "c_text", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "text" + }, + "originalName": "c_text" + } }, { - "name": "c_date", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "date" - }, - "originalName": "c_date" + "number": 8, + "column": { + "name": "c_longtext", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "longtext" + }, + "originalName": "c_longtext" + } }, { - "name": "c_time", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "time" - }, - "originalName": "c_time" + "number": 9, + "column": { + "name": "c_json", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "json" + }, + "originalName": "c_json" + } }, { - "name": "c_datetime", - "length": 19, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "datetime" - }, - "originalName": "c_datetime" + "number": 10, + "column": { + "name": "c_json_string_override", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "json" + }, + "originalName": "c_json_string_override" + } }, { - "name": "c_timestamp", - "length": 19, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "timestamp" - }, - "originalName": "c_timestamp" + "number": 11, + "column": { + "name": "c_enum", + "length": 6, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "mysql_string_types_c_enum" + }, + "originalName": "c_enum" + } }, + { + "number": 12, + "column": { + "name": "c_set", + "length": 15, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "mysql_string_types_c_set" + }, + "originalName": "c_set" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_string_types" + } + }, + { + "text": "SELECT 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 LIMIT 1", + "name": "GetMysqlStringTypes", + "cmd": ":one", + "columns": [ { "name": "c_char", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2707,7 +2720,7 @@ "name": "c_nchar", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2718,7 +2731,7 @@ "name": "c_national_char", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2729,7 +2742,7 @@ "name": "c_varchar", "length": 100, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "varchar" @@ -2740,7 +2753,7 @@ "name": "c_tinytext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "tinytext" @@ -2751,7 +2764,7 @@ "name": "c_mediumtext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "mediumtext" @@ -2762,7 +2775,7 @@ "name": "c_text", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "text" @@ -2773,7 +2786,7 @@ "name": "c_longtext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "longtext" @@ -2784,7 +2797,7 @@ "name": "c_json", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "json" @@ -2795,7 +2808,7 @@ "name": "c_json_string_override", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "json" @@ -2806,10 +2819,10 @@ "name": "c_enum", "length": 6, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mysql_types_c_enum" + "name": "mysql_string_types_c_enum" }, "originalName": "c_enum" }, @@ -2817,96 +2830,19 @@ "name": "c_set", "length": 15, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mysql_types_c_set" + "name": "mysql_string_types_c_set" }, "originalName": "c_set" - }, - { - "name": "c_bit", - "length": 8, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "bit" - }, - "originalName": "c_bit" - }, - { - "name": "c_binary", - "length": 3, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "binary" - }, - "originalName": "c_binary" - }, - { - "name": "c_varbinary", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "varbinary" - }, - "originalName": "c_varbinary" - }, - { - "name": "c_tinyblob", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "tinyblob" - }, - "originalName": "c_tinyblob" - }, - { - "name": "c_blob", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "blob" - }, - "originalName": "c_blob" - }, - { - "name": "c_mediumblob", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "mediumblob" - }, - "originalName": "c_mediumblob" - }, - { - "name": "c_longblob", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "longblob" - }, - "originalName": "c_longblob" } ], "filename": "query.sql" }, { - "text": "SELECT COUNT(1) AS cnt, c_bool, c_boolean, c_bit, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, \n c_float, c_numeric, c_decimal, c_dec, c_fixed, c_double, c_double_precision, \n c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, \n c_json, c_json_string_override, c_enum, c_set, c_year, c_date, c_datetime, c_timestamp, \n c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob\nFROM mysql_types\nGROUP BY c_bool, c_boolean, c_bit, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, \n c_float, c_numeric, c_decimal, c_dec, c_fixed, c_double, c_double_precision, \n c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, \n c_json, c_json_string_override, c_enum, c_set, c_year, c_date, c_datetime, c_timestamp, \n c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob\nLIMIT 1", - "name": "GetMysqlTypesCnt", + "text": "SELECT\n COUNT(*) AS cnt,\n c_char,\n c_nchar,\n c_national_char,\n c_varchar,\n c_tinytext,\n c_mediumtext,\n c_text,\n c_longtext,\n c_json,\n c_json_string_override,\n c_enum,\n c_set\nFROM mysql_string_types\nGROUP BY\n c_char,\n c_nchar,\n c_national_char,\n c_varchar,\n c_tinytext,\n c_mediumtext,\n c_text,\n c_longtext,\n c_json,\n c_json_string_override,\n c_enum,\n c_set\nLIMIT 1", + "name": "GetMysqlStringTypesCnt", "cmd": ":one", "columns": [ { @@ -2919,362 +2855,812 @@ } }, { - "name": "c_bool", - "length": 1, + "name": "c_char", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "tinyint" + "name": "char" }, - "originalName": "c_bool" + "originalName": "c_char" }, { - "name": "c_boolean", - "length": 1, + "name": "c_nchar", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "tinyint" + "name": "char" }, - "originalName": "c_boolean" + "originalName": "c_nchar" }, { - "name": "c_bit", - "length": 8, + "name": "c_national_char", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "bit" + "name": "char" }, - "originalName": "c_bit" + "originalName": "c_national_char" }, { - "name": "c_tinyint", - "length": 3, + "name": "c_varchar", + "length": 100, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "tinyint" + "name": "varchar" }, - "originalName": "c_tinyint" + "originalName": "c_varchar" }, { - "name": "c_smallint", + "name": "c_tinytext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "smallint" + "name": "tinytext" + }, + "originalName": "c_tinytext" + }, + { + "name": "c_mediumtext", + "length": -1, + "table": { + "name": "mysql_string_types" + }, + "type": { + "name": "mediumtext" }, - "originalName": "c_smallint" + "originalName": "c_mediumtext" }, { - "name": "c_mediumint", + "name": "c_text", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mediumint" + "name": "text" }, - "originalName": "c_mediumint" + "originalName": "c_text" }, { - "name": "c_int", + "name": "c_longtext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "int" + "name": "longtext" }, - "originalName": "c_int" + "originalName": "c_longtext" }, { - "name": "c_integer", + "name": "c_json", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "int" + "name": "json" }, - "originalName": "c_integer" + "originalName": "c_json" }, { - "name": "c_bigint", + "name": "c_json_string_override", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "bigint" + "name": "json" }, - "originalName": "c_bigint" + "originalName": "c_json_string_override" }, { - "name": "c_float", - "length": -1, + "name": "c_enum", + "length": 6, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "float" + "name": "mysql_string_types_c_enum" }, - "originalName": "c_float" + "originalName": "c_enum" }, { - "name": "c_numeric", - "length": 10, + "name": "c_set", + "length": 15, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "decimal" + "name": "mysql_string_types_c_set" }, - "originalName": "c_numeric" + "originalName": "c_set" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE mysql_string_types", + "name": "TruncateMysqlStringTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO mysql_datetime_types \n(\n c_year,\n c_date,\n c_datetime,\n c_timestamp,\n c_time\n) \nVALUES (?, ?, ?, ?, ?)", + "name": "InsertMysqlDatetimeTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_year", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "year" + }, + "originalName": "c_year" + } }, { - "name": "c_decimal", - "length": 10, + "number": 2, + "column": { + "name": "c_date", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "date" + }, + "originalName": "c_date" + } + }, + { + "number": 3, + "column": { + "name": "c_datetime", + "length": 19, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "datetime" + }, + "originalName": "c_datetime" + } + }, + { + "number": 4, + "column": { + "name": "c_timestamp", + "length": 19, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "timestamp" + }, + "originalName": "c_timestamp" + } + }, + { + "number": 5, + "column": { + "name": "c_time", + "length": 10, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "time" + }, + "originalName": "c_time" + } + } + ], + "comments": [ + " Datetime types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_datetime_types" + } + }, + { + "text": "INSERT INTO mysql_datetime_types \n(\n c_year,\n c_date,\n c_datetime,\n c_timestamp,\n c_time\n) \nVALUES (?, ?, ?, ?, ?)", + "name": "InsertMysqlDatetimeTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_year", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "year" + }, + "originalName": "c_year" + } + }, + { + "number": 2, + "column": { + "name": "c_date", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "date" + }, + "originalName": "c_date" + } + }, + { + "number": 3, + "column": { + "name": "c_datetime", + "length": 19, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "datetime" + }, + "originalName": "c_datetime" + } + }, + { + "number": 4, + "column": { + "name": "c_timestamp", + "length": 19, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "timestamp" + }, + "originalName": "c_timestamp" + } + }, + { + "number": 5, + "column": { + "name": "c_time", + "length": 10, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "time" + }, + "originalName": "c_time" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_datetime_types" + } + }, + { + "text": "SELECT c_year, c_date, c_datetime, c_timestamp, c_time FROM mysql_datetime_types LIMIT 1", + "name": "GetMysqlDatetimeTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_year", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "decimal" + "name": "year" }, - "originalName": "c_decimal" + "originalName": "c_year" }, { - "name": "c_dec", - "length": 10, + "name": "c_date", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "decimal" + "name": "date" }, - "originalName": "c_dec" + "originalName": "c_date" }, { - "name": "c_fixed", - "length": 10, + "name": "c_datetime", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "decimal" + "name": "datetime" }, - "originalName": "c_fixed" + "originalName": "c_datetime" }, { - "name": "c_double", - "length": -1, + "name": "c_timestamp", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "double" + "name": "timestamp" }, - "originalName": "c_double" + "originalName": "c_timestamp" }, { - "name": "c_double_precision", - "length": -1, + "name": "c_time", + "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "double" + "name": "time" }, - "originalName": "c_double_precision" + "originalName": "c_time" + } + ], + "filename": "query.sql" + }, + { + "text": "SELECT\n COUNT(*) AS cnt,\n c_year,\n c_date,\n c_datetime,\n c_timestamp,\n c_time\nFROM mysql_datetime_types\nGROUP BY\n c_year,\n c_date,\n c_datetime,\n c_timestamp,\n c_time\nLIMIT 1", + "name": "GetMysqlDatetimeTypesCnt", + "cmd": ":one", + "columns": [ + { + "name": "cnt", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "bigint" + } }, { - "name": "c_char", + "name": "c_year", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "char" + "name": "year" }, - "originalName": "c_char" + "originalName": "c_year" }, { - "name": "c_nchar", + "name": "c_date", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "char" + "name": "date" }, - "originalName": "c_nchar" + "originalName": "c_date" }, { - "name": "c_national_char", - "length": -1, + "name": "c_datetime", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "char" + "name": "datetime" }, - "originalName": "c_national_char" + "originalName": "c_datetime" }, { - "name": "c_varchar", - "length": 100, + "name": "c_timestamp", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "varchar" + "name": "timestamp" }, - "originalName": "c_varchar" + "originalName": "c_timestamp" }, { - "name": "c_tinytext", - "length": -1, + "name": "c_time", + "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "tinytext" + "name": "time" }, - "originalName": "c_tinytext" + "originalName": "c_time" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE mysql_datetime_types", + "name": "TruncateMysqlDatetimeTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO mysql_binary_types \n(\n c_bit,\n c_binary, \n c_varbinary, \n c_tinyblob, \n c_blob, \n c_mediumblob, \n c_longblob\n) \nVALUES (?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlBinaryTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_bit", + "length": 8, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "bit" + }, + "originalName": "c_bit" + } + }, + { + "number": 2, + "column": { + "name": "c_binary", + "length": 3, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "binary" + }, + "originalName": "c_binary" + } + }, + { + "number": 3, + "column": { + "name": "c_varbinary", + "length": 10, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "varbinary" + }, + "originalName": "c_varbinary" + } + }, + { + "number": 4, + "column": { + "name": "c_tinyblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "tinyblob" + }, + "originalName": "c_tinyblob" + } + }, + { + "number": 5, + "column": { + "name": "c_blob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "blob" + }, + "originalName": "c_blob" + } + }, + { + "number": 6, + "column": { + "name": "c_mediumblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "mediumblob" + }, + "originalName": "c_mediumblob" + } + }, + { + "number": 7, + "column": { + "name": "c_longblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "longblob" + }, + "originalName": "c_longblob" + } + } + ], + "comments": [ + " Binary types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_binary_types" + } + }, + { + "text": "INSERT INTO mysql_binary_types \n(\n c_bit,\n c_binary, \n c_varbinary, \n c_tinyblob, \n c_blob, \n c_mediumblob, \n c_longblob\n) \nVALUES (?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlBinaryTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_bit", + "length": 8, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "bit" + }, + "originalName": "c_bit" + } + }, + { + "number": 2, + "column": { + "name": "c_binary", + "length": 3, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "binary" + }, + "originalName": "c_binary" + } + }, + { + "number": 3, + "column": { + "name": "c_varbinary", + "length": 10, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "varbinary" + }, + "originalName": "c_varbinary" + } + }, + { + "number": 4, + "column": { + "name": "c_tinyblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "tinyblob" + }, + "originalName": "c_tinyblob" + } + }, + { + "number": 5, + "column": { + "name": "c_blob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "blob" + }, + "originalName": "c_blob" + } + }, + { + "number": 6, + "column": { + "name": "c_mediumblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "mediumblob" + }, + "originalName": "c_mediumblob" + } }, { - "name": "c_mediumtext", - "length": -1, + "number": 7, + "column": { + "name": "c_longblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "longblob" + }, + "originalName": "c_longblob" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_binary_types" + } + }, + { + "text": "SELECT c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_binary_types LIMIT 1", + "name": "GetMysqlBinaryTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_bit", + "length": 8, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "mediumtext" + "name": "bit" }, - "originalName": "c_mediumtext" + "originalName": "c_bit" }, { - "name": "c_text", - "length": -1, + "name": "c_binary", + "length": 3, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "text" + "name": "binary" }, - "originalName": "c_text" + "originalName": "c_binary" }, { - "name": "c_longtext", - "length": -1, + "name": "c_varbinary", + "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "longtext" + "name": "varbinary" }, - "originalName": "c_longtext" + "originalName": "c_varbinary" }, { - "name": "c_json", + "name": "c_tinyblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "json" + "name": "tinyblob" }, - "originalName": "c_json" + "originalName": "c_tinyblob" }, { - "name": "c_json_string_override", + "name": "c_blob", "length": -1, "table": { - "name": "mysql_types" - }, - "type": { - "name": "json" - }, - "originalName": "c_json_string_override" - }, - { - "name": "c_enum", - "length": 6, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "mysql_types_c_enum" - }, - "originalName": "c_enum" - }, - { - "name": "c_set", - "length": 15, - "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "mysql_types_c_set" + "name": "blob" }, - "originalName": "c_set" + "originalName": "c_blob" }, { - "name": "c_year", + "name": "c_mediumblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "year" + "name": "mediumblob" }, - "originalName": "c_year" + "originalName": "c_mediumblob" }, { - "name": "c_date", + "name": "c_longblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "date" + "name": "longblob" }, - "originalName": "c_date" - }, + "originalName": "c_longblob" + } + ], + "filename": "query.sql" + }, + { + "text": "SELECT\n COUNT(*) AS cnt,\n c_bit,\n c_binary,\n c_varbinary,\n c_tinyblob,\n c_blob,\n c_mediumblob,\n c_longblob\nFROM mysql_binary_types\nGROUP BY\n c_bit,\n c_binary,\n c_varbinary,\n c_tinyblob,\n c_blob,\n c_mediumblob,\n c_longblob\nLIMIT 1", + "name": "GetMysqlBinaryTypesCnt", + "cmd": ":one", + "columns": [ { - "name": "c_datetime", - "length": 19, - "table": { - "name": "mysql_types" - }, + "name": "cnt", + "notNull": true, + "length": -1, + "isFuncCall": true, "type": { - "name": "datetime" - }, - "originalName": "c_datetime" + "name": "bigint" + } }, { - "name": "c_timestamp", - "length": 19, + "name": "c_bit", + "length": 8, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "timestamp" + "name": "bit" }, - "originalName": "c_timestamp" + "originalName": "c_bit" }, { "name": "c_binary", "length": 3, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "binary" @@ -3285,7 +3671,7 @@ "name": "c_varbinary", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "varbinary" @@ -3296,7 +3682,7 @@ "name": "c_tinyblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "tinyblob" @@ -3307,7 +3693,7 @@ "name": "c_blob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "blob" @@ -3318,7 +3704,7 @@ "name": "c_mediumblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "mediumblob" @@ -3329,7 +3715,7 @@ "name": "c_longblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "longblob" @@ -3340,7 +3726,13 @@ "filename": "query.sql" }, { - "text": "SELECT MAX(c_int) AS max_int, MAX(c_varchar) AS max_varchar, MAX(c_timestamp) AS max_timestamp\nFROM mysql_types", + "text": "TRUNCATE TABLE mysql_binary_types", + "name": "TruncateMysqlBinaryTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "\nSELECT\n MAX(c_int) AS max_int,\n MAX(c_varchar) AS max_varchar,\n MAX(c_timestamp) AS max_timestamp\nFROM mysql_numeric_types\nCROSS JOIN mysql_string_types\nCROSS JOIN mysql_datetime_types", "name": "GetMysqlFunctions", "cmd": ":one", "columns": [ @@ -3372,164 +3764,10 @@ } } ], - "filename": "query.sql" - }, - { - "text": "TRUNCATE TABLE mysql_types", - "name": "TruncateMysqlTypes", - "cmd": ":exec", - "filename": "query.sql" - }, - { - "text": "INSERT INTO extended.bios (author_name, name, bio_type, author_type) VALUES (?, ?, ?, ?)", - "name": "CreateExtendedBio", - "cmd": ":exec", - "parameters": [ - { - "number": 1, - "column": { - "name": "author_name", - "length": 100, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "varchar" - }, - "originalName": "author_name" - } - }, - { - "number": 2, - "column": { - "name": "name", - "length": 100, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "varchar" - }, - "originalName": "name" - } - }, - { - "number": 3, - "column": { - "name": "bio_type", - "length": 13, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "bios_bio_type" - }, - "originalName": "bio_type" - } - }, - { - "number": 4, - "column": { - "name": "author_type", - "length": 24, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "bios_author_type" - }, - "originalName": "author_type" - } - } - ], - "filename": "query.sql", - "insert_into_table": { - "schema": "extended", - "name": "bios" - } - }, - { - "text": "SELECT author_name, name, bio_type, author_type FROM extended.bios WHERE bio_type = ? LIMIT 1", - "name": "GetFirstExtendedBioByType", - "cmd": ":one", - "columns": [ - { - "name": "author_name", - "length": 100, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "varchar" - }, - "originalName": "author_name" - }, - { - "name": "name", - "length": 100, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "varchar" - }, - "originalName": "name" - }, - { - "name": "bio_type", - "length": 13, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "bios_bio_type" - }, - "originalName": "bio_type" - }, - { - "name": "author_type", - "length": 24, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "bios_author_type" - }, - "originalName": "author_type" - } - ], - "parameters": [ - { - "number": 1, - "column": { - "name": "bio_type", - "length": 13, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "bios_bio_type" - }, - "originalName": "bio_type" - } - } + "comments": [ + " Functions " ], "filename": "query.sql" - }, - { - "text": "TRUNCATE TABLE extended.bios", - "name": "TruncateExtendedBios", - "cmd": ":exec", - "filename": "query.sql" } ], "sqlc_version": "v1.27.0", diff --git a/examples/MySqlConnectorDapperLegacyExample/request.message b/examples/MySqlConnectorDapperLegacyExample/request.message index 2ab67f13..31569fb1 100644 Binary files a/examples/MySqlConnectorDapperLegacyExample/request.message and b/examples/MySqlConnectorDapperLegacyExample/request.message differ diff --git a/examples/MySqlConnectorExample/Models.cs b/examples/MySqlConnectorExample/Models.cs index 9a1e896c..864e31fd 100644 --- a/examples/MySqlConnectorExample/Models.cs +++ b/examples/MySqlConnectorExample/Models.cs @@ -7,116 +7,167 @@ namespace MySqlConnectorExampleGen; public readonly record struct Author(long Id, string Name, string? Bio); public readonly record struct Book(long Id, string Name, long AuthorId, string? Description); -public readonly record struct MysqlType(bool? CBool, bool? CBoolean, short? CTinyint, short? CSmallint, int? CMediumint, int? CInt, int? CInteger, long? CBigint, double? CFloat, decimal? CDecimal, decimal? CDec, decimal? CNumeric, decimal? CFixed, double? CDouble, double? CDoublePrecision, short? CYear, DateTime? CDate, string? CTime, DateTime? CDatetime, DateTime? CTimestamp, string? CChar, string? CNchar, string? CNationalChar, string? CVarchar, string? CTinytext, string? CMediumtext, string? CText, string? CLongtext, JsonElement? CJson, JsonElement? CJsonStringOverride, MysqlTypesCEnum? CEnum, MysqlTypesCSet[]? CSet, byte? CBit, byte[]? CBinary, byte[]? CVarbinary, byte[]? CTinyblob, byte[]? CBlob, byte[]? CMediumblob, byte[]? CLongblob); -public readonly record struct ExtendedBio(string? AuthorName, string? Name, ExtendedBiosBioType? BioType, ExtendedBiosAuthorType[]? AuthorType); -public enum MysqlTypesCEnum +public readonly record struct MysqlNumericType(bool? CBool, bool? CBoolean, short? CTinyint, short? CSmallint, int? CMediumint, int? CInt, int? CInteger, long? CBigint, double? CFloat, decimal? CDecimal, decimal? CDec, decimal? CNumeric, decimal? CFixed, double? CDouble, double? CDoublePrecision); +public readonly record struct MysqlStringType(string? CChar, string? CNchar, string? CNationalChar, string? CVarchar, string? CTinytext, string? CMediumtext, string? CText, string? CLongtext, JsonElement? CJson, JsonElement? CJsonStringOverride, MysqlStringTypesCEnum? CEnum, HashSet? CSet); +public readonly record struct MysqlDatetimeType(short? CYear, DateTime? CDate, DateTime? CDatetime, DateTime? CTimestamp, TimeSpan? CTime); +public readonly record struct MysqlBinaryType(byte? CBit, byte[]? CBinary, byte[]? CVarbinary, byte[]? CTinyblob, byte[]? CBlob, byte[]? CMediumblob, byte[]? CLongblob); +public readonly record struct ExtendedBio(string? AuthorName, string? Name, BiosBioType? BioType, HashSet? AuthorType); +public enum BiosBioType { Invalid = 0, // reserved for invalid enum value - Small = 1, - Medium = 2, - Big = 3 + Autobiography = 1, + Biography = 2, + Memoir = 3 } -public static class MysqlTypesCEnumExtensions +public static class BiosBioTypeExtensions { - private static readonly Dictionary StringToEnum = new Dictionary() + private static readonly Dictionary StringToEnum = new Dictionary() { - [string.Empty] = MysqlTypesCEnum.Invalid, - ["small"] = MysqlTypesCEnum.Small, - ["medium"] = MysqlTypesCEnum.Medium, - ["big"] = MysqlTypesCEnum.Big + [string.Empty] = BiosBioType.Invalid, + ["Autobiography"] = BiosBioType.Autobiography, + ["Biography"] = BiosBioType.Biography, + ["Memoir"] = BiosBioType.Memoir }; - public static MysqlTypesCEnum ToMysqlTypesCEnum(this string me) + private static readonly Dictionary EnumToString = new Dictionary() + { + [BiosBioType.Invalid] = string.Empty, + [BiosBioType.Autobiography] = "Autobiography", + [BiosBioType.Biography] = "Biography", + [BiosBioType.Memoir] = "Memoir" + }; + public static BiosBioType ToBiosBioType(this string me) { return StringToEnum[me]; } - public static MysqlTypesCEnum[] ToMysqlTypesCEnumArr(this string me) + public static string Stringify(this BiosBioType me) + { + return EnumToString[me]; + } + + public static HashSet ToBiosBioTypeSet(this string me) { - return me.Split(',').ToList().Select(v => StringToEnum[v]).ToArray(); + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); } } -public enum MysqlTypesCSet +public enum BiosAuthorType { Invalid = 0, // reserved for invalid enum value - Tea = 1, - Coffee = 2, - Milk = 3 + Author = 1, + Editor = 2, + Translator = 3 } -public static class MysqlTypesCSetExtensions +public static class BiosAuthorTypeExtensions { - private static readonly Dictionary StringToEnum = new Dictionary() + private static readonly Dictionary StringToEnum = new Dictionary() { - [string.Empty] = MysqlTypesCSet.Invalid, - ["tea"] = MysqlTypesCSet.Tea, - ["coffee"] = MysqlTypesCSet.Coffee, - ["milk"] = MysqlTypesCSet.Milk + [string.Empty] = BiosAuthorType.Invalid, + ["Author"] = BiosAuthorType.Author, + ["Editor"] = BiosAuthorType.Editor, + ["Translator"] = BiosAuthorType.Translator }; - public static MysqlTypesCSet ToMysqlTypesCSet(this string me) + private static readonly Dictionary EnumToString = new Dictionary() + { + [BiosAuthorType.Invalid] = string.Empty, + [BiosAuthorType.Author] = "Author", + [BiosAuthorType.Editor] = "Editor", + [BiosAuthorType.Translator] = "Translator" + }; + public static BiosAuthorType ToBiosAuthorType(this string me) { return StringToEnum[me]; } - public static MysqlTypesCSet[] ToMysqlTypesCSetArr(this string me) + public static string Stringify(this BiosAuthorType me) + { + return EnumToString[me]; + } + + public static HashSet ToBiosAuthorTypeSet(this string me) { - return me.Split(',').ToList().Select(v => StringToEnum[v]).ToArray(); + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); } } -public enum ExtendedBiosBioType +public enum MysqlStringTypesCEnum { Invalid = 0, // reserved for invalid enum value - Autobiography = 1, - Biography = 2, - Memoir = 3 + Small = 1, + Medium = 2, + Big = 3 } -public static class ExtendedBiosBioTypeExtensions +public static class MysqlStringTypesCEnumExtensions { - private static readonly Dictionary StringToEnum = new Dictionary() + private static readonly Dictionary StringToEnum = new Dictionary() { - [string.Empty] = ExtendedBiosBioType.Invalid, - ["Autobiography"] = ExtendedBiosBioType.Autobiography, - ["Biography"] = ExtendedBiosBioType.Biography, - ["Memoir"] = ExtendedBiosBioType.Memoir + [string.Empty] = MysqlStringTypesCEnum.Invalid, + ["small"] = MysqlStringTypesCEnum.Small, + ["medium"] = MysqlStringTypesCEnum.Medium, + ["big"] = MysqlStringTypesCEnum.Big }; - public static ExtendedBiosBioType ToExtendedBiosBioType(this string me) + private static readonly Dictionary EnumToString = new Dictionary() + { + [MysqlStringTypesCEnum.Invalid] = string.Empty, + [MysqlStringTypesCEnum.Small] = "small", + [MysqlStringTypesCEnum.Medium] = "medium", + [MysqlStringTypesCEnum.Big] = "big" + }; + public static MysqlStringTypesCEnum ToMysqlStringTypesCEnum(this string me) { return StringToEnum[me]; } - public static ExtendedBiosBioType[] ToExtendedBiosBioTypeArr(this string me) + public static string Stringify(this MysqlStringTypesCEnum me) + { + return EnumToString[me]; + } + + public static HashSet ToMysqlStringTypesCEnumSet(this string me) { - return me.Split(',').ToList().Select(v => StringToEnum[v]).ToArray(); + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); } } -public enum ExtendedBiosAuthorType +public enum MysqlStringTypesCSet { Invalid = 0, // reserved for invalid enum value - Author = 1, - Editor = 2, - Translator = 3 + Tea = 1, + Coffee = 2, + Milk = 3 } -public static class ExtendedBiosAuthorTypeExtensions +public static class MysqlStringTypesCSetExtensions { - private static readonly Dictionary StringToEnum = new Dictionary() + private static readonly Dictionary StringToEnum = new Dictionary() { - [string.Empty] = ExtendedBiosAuthorType.Invalid, - ["Author"] = ExtendedBiosAuthorType.Author, - ["Editor"] = ExtendedBiosAuthorType.Editor, - ["Translator"] = ExtendedBiosAuthorType.Translator + [string.Empty] = MysqlStringTypesCSet.Invalid, + ["tea"] = MysqlStringTypesCSet.Tea, + ["coffee"] = MysqlStringTypesCSet.Coffee, + ["milk"] = MysqlStringTypesCSet.Milk }; - public static ExtendedBiosAuthorType ToExtendedBiosAuthorType(this string me) + private static readonly Dictionary EnumToString = new Dictionary() + { + [MysqlStringTypesCSet.Invalid] = string.Empty, + [MysqlStringTypesCSet.Tea] = "tea", + [MysqlStringTypesCSet.Coffee] = "coffee", + [MysqlStringTypesCSet.Milk] = "milk" + }; + public static MysqlStringTypesCSet ToMysqlStringTypesCSet(this string me) { return StringToEnum[me]; } - public static ExtendedBiosAuthorType[] ToExtendedBiosAuthorTypeArr(this string me) + public static string Stringify(this MysqlStringTypesCSet me) + { + return EnumToString[me]; + } + + public static HashSet ToMysqlStringTypesCSetSet(this string me) { - return me.Split(',').ToList().Select(v => StringToEnum[v]).ToArray(); + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); } } \ No newline at end of file diff --git a/examples/MySqlConnectorExample/QuerySql.cs b/examples/MySqlConnectorExample/QuerySql.cs index 378f5ff2..0caaf50b 100644 --- a/examples/MySqlConnectorExample/QuerySql.cs +++ b/examples/MySqlConnectorExample/QuerySql.cs @@ -73,10 +73,7 @@ public static QuerySql WithTransaction(MySqlTransaction transaction) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetAuthorSql; @@ -99,7 +96,7 @@ 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) @@ -164,10 +161,7 @@ public async Task CreateAuthor(CreateAuthorArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = CreateAuthorSql; @@ -199,10 +193,7 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = CreateAuthorReturnIdSql; @@ -246,10 +237,7 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetAuthorByIdSql; @@ -272,7 +260,7 @@ 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) @@ -313,7 +301,7 @@ 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) { @@ -333,10 +321,7 @@ public async Task DeleteAuthor(DeleteAuthorArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = DeleteAuthorSql; @@ -364,10 +349,7 @@ public async Task DeleteAllAuthors() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = DeleteAllAuthorsSql; @@ -376,7 +358,7 @@ 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) { @@ -394,10 +376,7 @@ public async Task UpdateAuthors(UpdateAuthorsArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = UpdateAuthorsSql; @@ -522,10 +501,7 @@ public async Task CreateBook(CreateBookArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = CreateBookSql; @@ -537,7 +513,7 @@ 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() { @@ -575,7 +551,7 @@ 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() { @@ -613,7 +589,7 @@ 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) @@ -654,18 +630,137 @@ public async Task> GetAuthorsByBookName(GetAuthors } } - private const string InsertMysqlTypesSql = "INSERT INTO mysql_types (c_bit, 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, 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, c_year, c_date, c_datetime, c_timestamp, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob) VALUES ( @c_bit, @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, @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, @c_year, @c_date, @c_datetime, @c_timestamp, @c_binary, @c_varbinary, @c_tinyblob, @c_blob, @c_mediumblob, @c_longblob ) "; - public readonly record struct InsertMysqlTypesArgs(byte? CBit, 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, string? CChar, string? CNchar, string? CNationalChar, string? CVarchar, string? CTinytext, string? CMediumtext, string? CText, string? CLongtext, JsonElement? CJson, string? CJsonStringOverride, MysqlTypesCEnum? CEnum, MysqlTypesCSet[]? CSet, short? CYear, DateTime? CDate, DateTime? CDatetime, DateTime? CTimestamp, byte[]? CBinary, byte[]? CVarbinary, byte[]? CTinyblob, byte[]? CBlob, byte[]? CMediumblob, byte[]? CLongblob); - public async Task InsertMysqlTypes(InsertMysqlTypesArgs args) + private const string CreateExtendedBioSql = "INSERT INTO extended.bios (author_name, name, bio_type, author_type) VALUES (@author_name, @name, @bio_type, @author_type)"; + public readonly record struct CreateExtendedBioArgs(string? AuthorName, string? Name, BiosBioType? BioType, HashSet? AuthorType); + public async Task CreateExtendedBio(CreateExtendedBioArgs args) { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { await connection.OpenAsync(); - using (var command = new MySqlCommand(InsertMysqlTypesSql, connection)) + using (var command = new MySqlCommand(CreateExtendedBioSql, connection)) + { + command.Parameters.AddWithValue("@author_name", args.AuthorName ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@name", args.Name ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@bio_type", args.BioType ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@author_type", args.AuthorType != null ? string.Join(",", args.AuthorType) : (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = CreateExtendedBioSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@author_name", args.AuthorName ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@name", args.Name ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@bio_type", args.BioType ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@author_type", args.AuthorType != null ? string.Join(",", args.AuthorType) : (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + private const string GetFirstExtendedBioByTypeSql = "SELECT author_name, name, bio_type, author_type FROM extended.bios WHERE bio_type = @bio_type LIMIT 1"; + public readonly record struct GetFirstExtendedBioByTypeRow(string? AuthorName, string? Name, BiosBioType? BioType, HashSet? AuthorType); + public readonly record struct GetFirstExtendedBioByTypeArgs(BiosBioType? BioType); + public async Task GetFirstExtendedBioByType(GetFirstExtendedBioByTypeArgs args) + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(GetFirstExtendedBioByTypeSql, connection)) + { + command.Parameters.AddWithValue("@bio_type", args.BioType ?? (object)DBNull.Value); + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetFirstExtendedBioByTypeRow + { + AuthorName = reader.IsDBNull(0) ? null : reader.GetString(0), + Name = reader.IsDBNull(1) ? null : reader.GetString(1), + BioType = reader.IsDBNull(2) ? null : reader.GetString(2).ToBiosBioType(), + AuthorType = reader.IsDBNull(3) ? null : reader.GetString(3).ToBiosAuthorTypeSet() + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetFirstExtendedBioByTypeSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@bio_type", args.BioType ?? (object)DBNull.Value); + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetFirstExtendedBioByTypeRow + { + AuthorName = reader.IsDBNull(0) ? null : reader.GetString(0), + Name = reader.IsDBNull(1) ? null : reader.GetString(1), + BioType = reader.IsDBNull(2) ? null : reader.GetString(2).ToBiosBioType(), + AuthorType = reader.IsDBNull(3) ? null : reader.GetString(3).ToBiosAuthorTypeSet() + }; + } + } + } + + return null; + } + + private const string TruncateExtendedBiosSql = "TRUNCATE TABLE extended.bios"; + public async Task TruncateExtendedBios() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(TruncateExtendedBiosSql, connection)) + { + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncateExtendedBiosSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } + + 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) + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(InsertMysqlNumericTypesSql, connection)) { - command.Parameters.AddWithValue("@c_bit", args.CBit ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_bool", args.CBool ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_boolean", args.CBoolean ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_tinyint", args.CTinyint ?? (object)DBNull.Value); @@ -681,28 +776,6 @@ public async Task InsertMysqlTypes(InsertMysqlTypesArgs args) command.Parameters.AddWithValue("@c_float", args.CFloat ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_double", args.CDouble ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_double_precision", args.CDoublePrecision ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_char", args.CChar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_nchar", args.CNchar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_national_char", args.CNationalChar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_varchar", args.CVarchar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_tinytext", args.CTinytext ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_mediumtext", args.CMediumtext ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_text", args.CText ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_longtext", args.CLongtext ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_json", args.CJson?.GetRawText() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_json_string_override", args.CJsonStringOverride ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_enum", args.CEnum ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_set", args.CSet != null ? string.Join(",", args.CSet) : (object)DBNull.Value); - command.Parameters.AddWithValue("@c_year", args.CYear ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_date", args.CDate ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_datetime", args.CDatetime ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_timestamp", args.CTimestamp ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_binary", args.CBinary ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_varbinary", args.CVarbinary ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_tinyblob", args.CTinyblob ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_blob", args.CBlob ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_mediumblob", args.CMediumblob ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_longblob", args.CLongblob ?? (object)DBNull.Value); await command.ExecuteNonQueryAsync(); } } @@ -711,15 +784,11 @@ public async Task InsertMysqlTypes(InsertMysqlTypesArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = InsertMysqlTypesSql; + command.CommandText = InsertMysqlNumericTypesSql; command.Transaction = this.Transaction; - command.Parameters.AddWithValue("@c_bit", args.CBit ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_bool", args.CBool ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_boolean", args.CBoolean ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_tinyint", args.CTinyint ?? (object)DBNull.Value); @@ -735,34 +804,12 @@ public async Task InsertMysqlTypes(InsertMysqlTypesArgs args) command.Parameters.AddWithValue("@c_float", args.CFloat ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_double", args.CDouble ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_double_precision", args.CDoublePrecision ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_char", args.CChar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_nchar", args.CNchar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_national_char", args.CNationalChar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_varchar", args.CVarchar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_tinytext", args.CTinytext ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_mediumtext", args.CMediumtext ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_text", args.CText ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_longtext", args.CLongtext ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_json", args.CJson?.GetRawText() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_json_string_override", args.CJsonStringOverride ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_enum", args.CEnum ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_set", args.CSet != null ? string.Join(",", args.CSet) : (object)DBNull.Value); - command.Parameters.AddWithValue("@c_year", args.CYear ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_date", args.CDate ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_datetime", args.CDatetime ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_timestamp", args.CTimestamp ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_binary", args.CBinary ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_varbinary", args.CVarbinary ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_tinyblob", args.CTinyblob ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_blob", args.CBlob ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_mediumblob", args.CMediumblob ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_longblob", args.CLongblob ?? (object)DBNull.Value); await command.ExecuteNonQueryAsync(); } } - public readonly record struct InsertMysqlTypesBatchArgs(byte? CBit, bool? CBool, bool? CBoolean, short? CTinyint, short? CSmallint, int? CMediumint, int? CInt, int? CInteger, long? CBigint, double? CFloat, decimal? CNumeric, decimal? CDecimal, decimal? CDec, decimal? CFixed, double? CDouble, double? CDoublePrecision, string? CChar, string? CNchar, string? CNationalChar, string? CVarchar, string? CTinytext, string? CMediumtext, string? CText, string? CLongtext, JsonElement? CJson, string? CJsonStringOverride, MysqlTypesCEnum? CEnum, MysqlTypesCSet[]? CSet, short? CYear, DateTime? CDate, DateTime? CDatetime, DateTime? CTimestamp, byte[]? CBinary, byte[]? CVarbinary, byte[]? CTinyblob, byte[]? CBlob, byte[]? CMediumblob, byte[]? CLongblob); - public async Task InsertMysqlTypesBatch(List args) + public readonly record struct InsertMysqlNumericTypesBatchArgs(bool? CBool, bool? CBoolean, short? CTinyint, short? CSmallint, int? CMediumint, int? CInt, int? CInteger, long? CBigint, double? CFloat, decimal? CNumeric, decimal? CDecimal, decimal? CDec, decimal? CFixed, double? CDouble, double? CDoublePrecision); + public async Task InsertMysqlNumericTypesBatch(List args) { const string supportedDateTimeFormat = "yyyy-MM-dd H:mm:ss"; var config = new CsvConfiguration(CultureInfo.CurrentCulture) @@ -785,21 +832,11 @@ public async Task InsertMysqlTypesBatch(List args) csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); csvWriter.Context.TypeConverterCache.AddConverter(new Utils.BoolToBitCsvConverter()); csvWriter.Context.TypeConverterCache.AddConverter(new Utils.BoolToBitCsvConverter()); - csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteCsvConverter()); - csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteCsvConverter()); - csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteArrayCsvConverter()); - csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteArrayCsvConverter()); - csvWriter.Context.TypeConverterCache.AddConverter(new Utils.MysqlTypesCSetCsvConverter()); - csvWriter.Context.TypeConverterCache.AddConverter(new Utils.MysqlTypesCSetCsvConverter()); csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); - csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); - csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); - csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); - csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); await csvWriter.WriteRecordsAsync(args); } @@ -809,7 +846,7 @@ public async Task InsertMysqlTypesBatch(List args) var loader = new MySqlBulkLoader(connection) { Local = true, - TableName = "mysql_types", + TableName = "mysql_numeric_types", FileName = "input.csv", FieldTerminator = ",", FieldQuotationCharacter = '"', @@ -817,28 +854,28 @@ public async Task InsertMysqlTypesBatch(List args) NumberOfLinesToSkip = 1, LineTerminator = "\n" }; - loader.Columns.AddRange(new List { "c_bit", "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", "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", "c_year", "c_date", "c_datetime", "c_timestamp", "c_binary", "c_varbinary", "c_tinyblob", "c_blob", "c_mediumblob", "c_longblob" }); + loader.Columns.AddRange(new List { "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" }); await loader.LoadAsync(); await connection.CloseAsync(); } } - private const string GetMysqlTypesSql = "SELECT c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_decimal, c_dec, c_numeric, c_fixed, c_double, c_double_precision, c_year, c_date, c_time, c_datetime, c_timestamp, 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, c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_types LIMIT 1"; - public readonly record struct GetMysqlTypesRow(bool? CBool, bool? CBoolean, short? CTinyint, short? CSmallint, int? CMediumint, int? CInt, int? CInteger, long? CBigint, double? CFloat, decimal? CDecimal, decimal? CDec, decimal? CNumeric, decimal? CFixed, double? CDouble, double? CDoublePrecision, short? CYear, DateTime? CDate, string? CTime, DateTime? CDatetime, DateTime? CTimestamp, string? CChar, string? CNchar, string? CNationalChar, string? CVarchar, string? CTinytext, string? CMediumtext, string? CText, string? CLongtext, JsonElement? CJson, string? CJsonStringOverride, MysqlTypesCEnum? CEnum, MysqlTypesCSet[]? CSet, byte? CBit, byte[]? CBinary, byte[]? CVarbinary, byte[]? CTinyblob, byte[]? CBlob, byte[]? CMediumblob, byte[]? CLongblob); - public async Task GetMysqlTypes() + private const string GetMysqlNumericTypesSql = "SELECT c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_decimal, c_dec, c_numeric, c_fixed, c_double, c_double_precision FROM mysql_numeric_types LIMIT 1"; + public readonly record struct GetMysqlNumericTypesRow(bool? CBool, bool? CBoolean, short? CTinyint, short? CSmallint, int? CMediumint, int? CInt, int? CInteger, long? CBigint, double? CFloat, decimal? CDecimal, decimal? CDec, decimal? CNumeric, decimal? CFixed, double? CDouble, double? CDoublePrecision); + public async Task GetMysqlNumericTypes() { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { await connection.OpenAsync(); - using (var command = new MySqlCommand(GetMysqlTypesSql, connection)) + using (var command = new MySqlCommand(GetMysqlNumericTypesSql, connection)) { using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetMysqlTypesRow + return new GetMysqlNumericTypesRow { CBool = reader.IsDBNull(0) ? null : reader.GetBoolean(0), CBoolean = reader.IsDBNull(1) ? null : reader.GetBoolean(1), @@ -854,31 +891,7 @@ public async Task InsertMysqlTypesBatch(List args) CNumeric = reader.IsDBNull(11) ? null : reader.GetDecimal(11), CFixed = reader.IsDBNull(12) ? null : reader.GetDecimal(12), CDouble = reader.IsDBNull(13) ? null : reader.GetDouble(13), - CDoublePrecision = reader.IsDBNull(14) ? null : reader.GetDouble(14), - CYear = reader.IsDBNull(15) ? null : reader.GetInt16(15), - CDate = reader.IsDBNull(16) ? null : reader.GetDateTime(16), - CTime = reader.IsDBNull(17) ? null : reader.GetString(17), - CDatetime = reader.IsDBNull(18) ? null : reader.GetDateTime(18), - CTimestamp = reader.IsDBNull(19) ? null : reader.GetDateTime(19), - CChar = reader.IsDBNull(20) ? null : reader.GetString(20), - CNchar = reader.IsDBNull(21) ? null : reader.GetString(21), - CNationalChar = reader.IsDBNull(22) ? null : reader.GetString(22), - CVarchar = reader.IsDBNull(23) ? null : reader.GetString(23), - CTinytext = reader.IsDBNull(24) ? null : reader.GetString(24), - CMediumtext = reader.IsDBNull(25) ? null : reader.GetString(25), - CText = reader.IsDBNull(26) ? null : reader.GetString(26), - CLongtext = reader.IsDBNull(27) ? null : reader.GetString(27), - CJson = reader.IsDBNull(28) ? null : JsonSerializer.Deserialize(reader.GetString(28)), - CJsonStringOverride = reader.IsDBNull(29) ? null : reader.GetString(29), - CEnum = reader.IsDBNull(30) ? null : reader.GetString(30).ToMysqlTypesCEnum(), - CSet = reader.IsDBNull(31) ? null : reader.GetString(31).ToMysqlTypesCSetArr(), - CBit = reader.IsDBNull(32) ? null : reader.GetFieldValue(32), - CBinary = reader.IsDBNull(33) ? null : reader.GetFieldValue(33), - CVarbinary = reader.IsDBNull(34) ? null : reader.GetFieldValue(34), - CTinyblob = reader.IsDBNull(35) ? null : reader.GetFieldValue(35), - CBlob = reader.IsDBNull(36) ? null : reader.GetFieldValue(36), - CMediumblob = reader.IsDBNull(37) ? null : reader.GetFieldValue(37), - CLongblob = reader.IsDBNull(38) ? null : reader.GetFieldValue(38) + CDoublePrecision = reader.IsDBNull(14) ? null : reader.GetDouble(14) }; } } @@ -889,19 +902,16 @@ public async Task InsertMysqlTypesBatch(List args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = GetMysqlTypesSql; + command.CommandText = GetMysqlNumericTypesSql; command.Transaction = this.Transaction; using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetMysqlTypesRow + return new GetMysqlNumericTypesRow { CBool = reader.IsDBNull(0) ? null : reader.GetBoolean(0), CBoolean = reader.IsDBNull(1) ? null : reader.GetBoolean(1), @@ -917,31 +927,7 @@ public async Task InsertMysqlTypesBatch(List args) CNumeric = reader.IsDBNull(11) ? null : reader.GetDecimal(11), CFixed = reader.IsDBNull(12) ? null : reader.GetDecimal(12), CDouble = reader.IsDBNull(13) ? null : reader.GetDouble(13), - CDoublePrecision = reader.IsDBNull(14) ? null : reader.GetDouble(14), - CYear = reader.IsDBNull(15) ? null : reader.GetInt16(15), - CDate = reader.IsDBNull(16) ? null : reader.GetDateTime(16), - CTime = reader.IsDBNull(17) ? null : reader.GetString(17), - CDatetime = reader.IsDBNull(18) ? null : reader.GetDateTime(18), - CTimestamp = reader.IsDBNull(19) ? null : reader.GetDateTime(19), - CChar = reader.IsDBNull(20) ? null : reader.GetString(20), - CNchar = reader.IsDBNull(21) ? null : reader.GetString(21), - CNationalChar = reader.IsDBNull(22) ? null : reader.GetString(22), - CVarchar = reader.IsDBNull(23) ? null : reader.GetString(23), - CTinytext = reader.IsDBNull(24) ? null : reader.GetString(24), - CMediumtext = reader.IsDBNull(25) ? null : reader.GetString(25), - CText = reader.IsDBNull(26) ? null : reader.GetString(26), - CLongtext = reader.IsDBNull(27) ? null : reader.GetString(27), - CJson = reader.IsDBNull(28) ? null : JsonSerializer.Deserialize(reader.GetString(28)), - CJsonStringOverride = reader.IsDBNull(29) ? null : reader.GetString(29), - CEnum = reader.IsDBNull(30) ? null : reader.GetString(30).ToMysqlTypesCEnum(), - CSet = reader.IsDBNull(31) ? null : reader.GetString(31).ToMysqlTypesCSetArr(), - CBit = reader.IsDBNull(32) ? null : reader.GetFieldValue(32), - CBinary = reader.IsDBNull(33) ? null : reader.GetFieldValue(33), - CVarbinary = reader.IsDBNull(34) ? null : reader.GetFieldValue(34), - CTinyblob = reader.IsDBNull(35) ? null : reader.GetFieldValue(35), - CBlob = reader.IsDBNull(36) ? null : reader.GetFieldValue(36), - CMediumblob = reader.IsDBNull(37) ? null : reader.GetFieldValue(37), - CLongblob = reader.IsDBNull(38) ? null : reader.GetFieldValue(38) + CDoublePrecision = reader.IsDBNull(14) ? null : reader.GetDouble(14) }; } } @@ -950,62 +936,39 @@ public async Task InsertMysqlTypesBatch(List args) return null; } - private const string GetMysqlTypesCntSql = "SELECT COUNT(1) AS cnt, c_bool, c_boolean, c_bit, 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, 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, c_year, c_date, c_datetime, c_timestamp, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_types GROUP BY c_bool , c_boolean, c_bit, 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, 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, c_year, c_date, c_datetime, c_timestamp, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob LIMIT 1 "; - public readonly record struct GetMysqlTypesCntRow(long Cnt, bool? CBool, bool? CBoolean, byte? CBit, short? CTinyint, short? CSmallint, int? CMediumint, int? CInt, int? CInteger, long? CBigint, double? CFloat, decimal? CNumeric, decimal? CDecimal, decimal? CDec, decimal? CFixed, double? CDouble, double? CDoublePrecision, string? CChar, string? CNchar, string? CNationalChar, string? CVarchar, string? CTinytext, string? CMediumtext, string? CText, string? CLongtext, JsonElement? CJson, string? CJsonStringOverride, MysqlTypesCEnum? CEnum, MysqlTypesCSet[]? CSet, short? CYear, DateTime? CDate, DateTime? CDatetime, DateTime? CTimestamp, byte[]? CBinary, byte[]? CVarbinary, byte[]? CTinyblob, byte[]? CBlob, byte[]? CMediumblob, byte[]? CLongblob); - public async Task GetMysqlTypesCnt() + 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 readonly record struct GetMysqlNumericTypesCntRow(long Cnt, bool? CBool, bool? CBoolean, short? CTinyint, short? CSmallint, int? CMediumint, int? CInt, int? CInteger, long? CBigint, double? CFloat, decimal? CNumeric, decimal? CDecimal, decimal? CDec, decimal? CFixed, double? CDouble, double? CDoublePrecision); + public async Task GetMysqlNumericTypesCnt() { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { await connection.OpenAsync(); - using (var command = new MySqlCommand(GetMysqlTypesCntSql, connection)) + using (var command = new MySqlCommand(GetMysqlNumericTypesCntSql, connection)) { using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetMysqlTypesCntRow + return new GetMysqlNumericTypesCntRow { Cnt = reader.GetInt64(0), CBool = reader.IsDBNull(1) ? null : reader.GetBoolean(1), CBoolean = reader.IsDBNull(2) ? null : reader.GetBoolean(2), - CBit = reader.IsDBNull(3) ? null : reader.GetFieldValue(3), - CTinyint = reader.IsDBNull(4) ? null : reader.GetInt16(4), - CSmallint = reader.IsDBNull(5) ? null : reader.GetInt16(5), - CMediumint = reader.IsDBNull(6) ? null : reader.GetInt32(6), - CInt = reader.IsDBNull(7) ? null : reader.GetInt32(7), - CInteger = reader.IsDBNull(8) ? null : reader.GetInt32(8), - CBigint = reader.IsDBNull(9) ? null : reader.GetInt64(9), - CFloat = reader.IsDBNull(10) ? null : reader.GetDouble(10), - CNumeric = reader.IsDBNull(11) ? null : reader.GetDecimal(11), - CDecimal = reader.IsDBNull(12) ? null : reader.GetDecimal(12), - CDec = reader.IsDBNull(13) ? null : reader.GetDecimal(13), - CFixed = reader.IsDBNull(14) ? null : reader.GetDecimal(14), - CDouble = reader.IsDBNull(15) ? null : reader.GetDouble(15), - CDoublePrecision = reader.IsDBNull(16) ? null : reader.GetDouble(16), - CChar = reader.IsDBNull(17) ? null : reader.GetString(17), - CNchar = reader.IsDBNull(18) ? null : reader.GetString(18), - CNationalChar = reader.IsDBNull(19) ? null : reader.GetString(19), - CVarchar = reader.IsDBNull(20) ? null : reader.GetString(20), - CTinytext = reader.IsDBNull(21) ? null : reader.GetString(21), - CMediumtext = reader.IsDBNull(22) ? null : reader.GetString(22), - CText = reader.IsDBNull(23) ? null : reader.GetString(23), - CLongtext = reader.IsDBNull(24) ? null : reader.GetString(24), - CJson = reader.IsDBNull(25) ? null : JsonSerializer.Deserialize(reader.GetString(25)), - CJsonStringOverride = reader.IsDBNull(26) ? null : reader.GetString(26), - CEnum = reader.IsDBNull(27) ? null : reader.GetString(27).ToMysqlTypesCEnum(), - CSet = reader.IsDBNull(28) ? null : reader.GetString(28).ToMysqlTypesCSetArr(), - CYear = reader.IsDBNull(29) ? null : reader.GetInt16(29), - CDate = reader.IsDBNull(30) ? null : reader.GetDateTime(30), - CDatetime = reader.IsDBNull(31) ? null : reader.GetDateTime(31), - CTimestamp = reader.IsDBNull(32) ? null : reader.GetDateTime(32), - CBinary = reader.IsDBNull(33) ? null : reader.GetFieldValue(33), - CVarbinary = reader.IsDBNull(34) ? null : reader.GetFieldValue(34), - CTinyblob = reader.IsDBNull(35) ? null : reader.GetFieldValue(35), - CBlob = reader.IsDBNull(36) ? null : reader.GetFieldValue(36), - CMediumblob = reader.IsDBNull(37) ? null : reader.GetFieldValue(37), - CLongblob = reader.IsDBNull(38) ? null : reader.GetFieldValue(38) + CTinyint = reader.IsDBNull(3) ? null : reader.GetInt16(3), + CSmallint = reader.IsDBNull(4) ? null : reader.GetInt16(4), + CMediumint = reader.IsDBNull(5) ? null : reader.GetInt32(5), + CInt = reader.IsDBNull(6) ? null : reader.GetInt32(6), + CInteger = reader.IsDBNull(7) ? null : reader.GetInt32(7), + CBigint = reader.IsDBNull(8) ? null : reader.GetInt64(8), + CFloat = reader.IsDBNull(9) ? null : reader.GetDouble(9), + CNumeric = reader.IsDBNull(10) ? null : reader.GetDecimal(10), + CDecimal = reader.IsDBNull(11) ? null : reader.GetDecimal(11), + CDec = reader.IsDBNull(12) ? null : reader.GetDecimal(12), + CFixed = reader.IsDBNull(13) ? null : reader.GetDecimal(13), + CDouble = reader.IsDBNull(14) ? null : reader.GetDouble(14), + CDoublePrecision = reader.IsDBNull(15) ? null : reader.GetDouble(15) }; } } @@ -1016,59 +979,33 @@ public async Task InsertMysqlTypesBatch(List args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = GetMysqlTypesCntSql; + command.CommandText = GetMysqlNumericTypesCntSql; command.Transaction = this.Transaction; using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetMysqlTypesCntRow + return new GetMysqlNumericTypesCntRow { Cnt = reader.GetInt64(0), CBool = reader.IsDBNull(1) ? null : reader.GetBoolean(1), CBoolean = reader.IsDBNull(2) ? null : reader.GetBoolean(2), - CBit = reader.IsDBNull(3) ? null : reader.GetFieldValue(3), - CTinyint = reader.IsDBNull(4) ? null : reader.GetInt16(4), - CSmallint = reader.IsDBNull(5) ? null : reader.GetInt16(5), - CMediumint = reader.IsDBNull(6) ? null : reader.GetInt32(6), - CInt = reader.IsDBNull(7) ? null : reader.GetInt32(7), - CInteger = reader.IsDBNull(8) ? null : reader.GetInt32(8), - CBigint = reader.IsDBNull(9) ? null : reader.GetInt64(9), - CFloat = reader.IsDBNull(10) ? null : reader.GetDouble(10), - CNumeric = reader.IsDBNull(11) ? null : reader.GetDecimal(11), - CDecimal = reader.IsDBNull(12) ? null : reader.GetDecimal(12), - CDec = reader.IsDBNull(13) ? null : reader.GetDecimal(13), - CFixed = reader.IsDBNull(14) ? null : reader.GetDecimal(14), - CDouble = reader.IsDBNull(15) ? null : reader.GetDouble(15), - CDoublePrecision = reader.IsDBNull(16) ? null : reader.GetDouble(16), - CChar = reader.IsDBNull(17) ? null : reader.GetString(17), - CNchar = reader.IsDBNull(18) ? null : reader.GetString(18), - CNationalChar = reader.IsDBNull(19) ? null : reader.GetString(19), - CVarchar = reader.IsDBNull(20) ? null : reader.GetString(20), - CTinytext = reader.IsDBNull(21) ? null : reader.GetString(21), - CMediumtext = reader.IsDBNull(22) ? null : reader.GetString(22), - CText = reader.IsDBNull(23) ? null : reader.GetString(23), - CLongtext = reader.IsDBNull(24) ? null : reader.GetString(24), - CJson = reader.IsDBNull(25) ? null : JsonSerializer.Deserialize(reader.GetString(25)), - CJsonStringOverride = reader.IsDBNull(26) ? null : reader.GetString(26), - CEnum = reader.IsDBNull(27) ? null : reader.GetString(27).ToMysqlTypesCEnum(), - CSet = reader.IsDBNull(28) ? null : reader.GetString(28).ToMysqlTypesCSetArr(), - CYear = reader.IsDBNull(29) ? null : reader.GetInt16(29), - CDate = reader.IsDBNull(30) ? null : reader.GetDateTime(30), - CDatetime = reader.IsDBNull(31) ? null : reader.GetDateTime(31), - CTimestamp = reader.IsDBNull(32) ? null : reader.GetDateTime(32), - CBinary = reader.IsDBNull(33) ? null : reader.GetFieldValue(33), - CVarbinary = reader.IsDBNull(34) ? null : reader.GetFieldValue(34), - CTinyblob = reader.IsDBNull(35) ? null : reader.GetFieldValue(35), - CBlob = reader.IsDBNull(36) ? null : reader.GetFieldValue(36), - CMediumblob = reader.IsDBNull(37) ? null : reader.GetFieldValue(37), - CLongblob = reader.IsDBNull(38) ? null : reader.GetFieldValue(38) + CTinyint = reader.IsDBNull(3) ? null : reader.GetInt16(3), + CSmallint = reader.IsDBNull(4) ? null : reader.GetInt16(4), + CMediumint = reader.IsDBNull(5) ? null : reader.GetInt32(5), + CInt = reader.IsDBNull(6) ? null : reader.GetInt32(6), + CInteger = reader.IsDBNull(7) ? null : reader.GetInt32(7), + CBigint = reader.IsDBNull(8) ? null : reader.GetInt64(8), + CFloat = reader.IsDBNull(9) ? null : reader.GetDouble(9), + CNumeric = reader.IsDBNull(10) ? null : reader.GetDecimal(10), + CDecimal = reader.IsDBNull(11) ? null : reader.GetDecimal(11), + CDec = reader.IsDBNull(12) ? null : reader.GetDecimal(12), + CFixed = reader.IsDBNull(13) ? null : reader.GetDecimal(13), + CDouble = reader.IsDBNull(14) ? null : reader.GetDouble(14), + CDoublePrecision = reader.IsDBNull(15) ? null : reader.GetDouble(15) }; } } @@ -1077,106 +1014,514 @@ public async Task InsertMysqlTypesBatch(List args) return null; } - 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_types "; - public readonly record struct GetMysqlFunctionsRow(int? MaxInt, string? MaxVarchar, DateTime MaxTimestamp); - public async Task GetMysqlFunctions() + private const string TruncateMysqlNumericTypesSql = "TRUNCATE TABLE mysql_numeric_types"; + public async Task TruncateMysqlNumericTypes() { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { await connection.OpenAsync(); - using (var command = new MySqlCommand(GetMysqlFunctionsSql, connection)) + using (var command = new MySqlCommand(TruncateMysqlNumericTypesSql, connection)) { - using (var reader = await command.ExecuteReaderAsync()) - { - if (await reader.ReadAsync()) - { - return new GetMysqlFunctionsRow - { - MaxInt = reader.IsDBNull(0) ? null : reader.GetInt32(0), - MaxVarchar = reader.IsDBNull(1) ? null : reader.GetString(1), - MaxTimestamp = reader.GetDateTime(2) - }; - } - } + await command.ExecuteNonQueryAsync(); } } - return null; + return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = GetMysqlFunctionsSql; + command.CommandText = TruncateMysqlNumericTypesSql; command.Transaction = this.Transaction; - using (var reader = await command.ExecuteReaderAsync()) - { - if (await reader.ReadAsync()) - { - return new GetMysqlFunctionsRow - { - MaxInt = reader.IsDBNull(0) ? null : reader.GetInt32(0), - MaxVarchar = reader.IsDBNull(1) ? null : reader.GetString(1), - MaxTimestamp = reader.GetDateTime(2) - }; - } - } + await command.ExecuteNonQueryAsync(); } - - return null; } - private const string TruncateMysqlTypesSql = "TRUNCATE TABLE mysql_types"; - public async Task TruncateMysqlTypes() + 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) { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { await connection.OpenAsync(); - using (var command = new MySqlCommand(TruncateMysqlTypesSql, connection)) + using (var command = new MySqlCommand(InsertMysqlStringTypesSql, connection)) { - await command.ExecuteNonQueryAsync(); - } - } - - return; - } + command.Parameters.AddWithValue("@c_char", args.CChar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_nchar", args.CNchar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_national_char", args.CNationalChar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_varchar", args.CVarchar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_tinytext", args.CTinytext ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_mediumtext", args.CMediumtext ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_text", args.CText ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_longtext", args.CLongtext ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_json", args.CJson?.GetRawText() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_json_string_override", args.CJsonStringOverride ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_enum", args.CEnum ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_set", args.CSet != null ? string.Join(",", args.CSet) : (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = InsertMysqlStringTypesSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@c_char", args.CChar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_nchar", args.CNchar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_national_char", args.CNationalChar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_varchar", args.CVarchar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_tinytext", args.CTinytext ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_mediumtext", args.CMediumtext ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_text", args.CText ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_longtext", args.CLongtext ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_json", args.CJson?.GetRawText() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_json_string_override", args.CJsonStringOverride ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_enum", args.CEnum ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_set", args.CSet != null ? string.Join(",", args.CSet) : (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + public readonly record struct InsertMysqlStringTypesBatchArgs(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 InsertMysqlStringTypesBatch(List args) + { + const string supportedDateTimeFormat = "yyyy-MM-dd H:mm:ss"; + var config = new CsvConfiguration(CultureInfo.CurrentCulture) + { + Delimiter = ",", + NewLine = "\n" + }; + var nullConverterFn = new Utils.NullToStringCsvConverter(); + using (var writer = new StreamWriter("input.csv", false, new UTF8Encoding(false))) + using (var csvWriter = new CsvWriter(writer, config)) + { + var options = new TypeConverterOptions + { + Formats = new[] + { + supportedDateTimeFormat + } + }; + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterCache.AddConverter>(new Utils.MysqlStringTypesCSetCsvConverter()); + csvWriter.Context.TypeConverterCache.AddConverter?>(new Utils.MysqlStringTypesCSetCsvConverter()); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + await csvWriter.WriteRecordsAsync(args); + } + + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + var loader = new MySqlBulkLoader(connection) + { + Local = true, + TableName = "mysql_string_types", + FileName = "input.csv", + FieldTerminator = ",", + FieldQuotationCharacter = '"', + FieldQuotationOptional = true, + NumberOfLinesToSkip = 1, + LineTerminator = "\n" + }; + loader.Columns.AddRange(new List { "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" }); + await loader.LoadAsync(); + await connection.CloseAsync(); + } + } + + private const string GetMysqlStringTypesSql = "SELECT 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 LIMIT 1"; + public readonly record struct GetMysqlStringTypesRow(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 GetMysqlStringTypes() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(GetMysqlStringTypesSql, connection)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlStringTypesRow + { + CChar = reader.IsDBNull(0) ? null : reader.GetString(0), + CNchar = reader.IsDBNull(1) ? null : reader.GetString(1), + CNationalChar = reader.IsDBNull(2) ? null : reader.GetString(2), + CVarchar = reader.IsDBNull(3) ? null : reader.GetString(3), + CTinytext = reader.IsDBNull(4) ? null : reader.GetString(4), + CMediumtext = reader.IsDBNull(5) ? null : reader.GetString(5), + CText = reader.IsDBNull(6) ? null : reader.GetString(6), + CLongtext = reader.IsDBNull(7) ? null : reader.GetString(7), + CJson = reader.IsDBNull(8) ? null : JsonSerializer.Deserialize(reader.GetString(8)), + CJsonStringOverride = reader.IsDBNull(9) ? null : reader.GetString(9), + CEnum = reader.IsDBNull(10) ? null : reader.GetString(10).ToMysqlStringTypesCEnum(), + CSet = reader.IsDBNull(11) ? null : reader.GetString(11).ToMysqlStringTypesCSetSet() + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetMysqlStringTypesSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlStringTypesRow + { + CChar = reader.IsDBNull(0) ? null : reader.GetString(0), + CNchar = reader.IsDBNull(1) ? null : reader.GetString(1), + CNationalChar = reader.IsDBNull(2) ? null : reader.GetString(2), + CVarchar = reader.IsDBNull(3) ? null : reader.GetString(3), + CTinytext = reader.IsDBNull(4) ? null : reader.GetString(4), + CMediumtext = reader.IsDBNull(5) ? null : reader.GetString(5), + CText = reader.IsDBNull(6) ? null : reader.GetString(6), + CLongtext = reader.IsDBNull(7) ? null : reader.GetString(7), + CJson = reader.IsDBNull(8) ? null : JsonSerializer.Deserialize(reader.GetString(8)), + CJsonStringOverride = reader.IsDBNull(9) ? null : reader.GetString(9), + CEnum = reader.IsDBNull(10) ? null : reader.GetString(10).ToMysqlStringTypesCEnum(), + CSet = reader.IsDBNull(11) ? null : reader.GetString(11).ToMysqlStringTypesCSetSet() + }; + } + } + } + + 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"; + public readonly record struct GetMysqlStringTypesCntRow(long Cnt, 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 GetMysqlStringTypesCnt() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(GetMysqlStringTypesCntSql, connection)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlStringTypesCntRow + { + Cnt = reader.GetInt64(0), + CChar = reader.IsDBNull(1) ? null : reader.GetString(1), + CNchar = reader.IsDBNull(2) ? null : reader.GetString(2), + CNationalChar = reader.IsDBNull(3) ? null : reader.GetString(3), + CVarchar = reader.IsDBNull(4) ? null : reader.GetString(4), + CTinytext = reader.IsDBNull(5) ? null : reader.GetString(5), + CMediumtext = reader.IsDBNull(6) ? null : reader.GetString(6), + CText = reader.IsDBNull(7) ? null : reader.GetString(7), + CLongtext = reader.IsDBNull(8) ? null : reader.GetString(8), + CJson = reader.IsDBNull(9) ? null : JsonSerializer.Deserialize(reader.GetString(9)), + CJsonStringOverride = reader.IsDBNull(10) ? null : reader.GetString(10), + CEnum = reader.IsDBNull(11) ? null : reader.GetString(11).ToMysqlStringTypesCEnum(), + CSet = reader.IsDBNull(12) ? null : reader.GetString(12).ToMysqlStringTypesCSetSet() + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetMysqlStringTypesCntSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlStringTypesCntRow + { + Cnt = reader.GetInt64(0), + CChar = reader.IsDBNull(1) ? null : reader.GetString(1), + CNchar = reader.IsDBNull(2) ? null : reader.GetString(2), + CNationalChar = reader.IsDBNull(3) ? null : reader.GetString(3), + CVarchar = reader.IsDBNull(4) ? null : reader.GetString(4), + CTinytext = reader.IsDBNull(5) ? null : reader.GetString(5), + CMediumtext = reader.IsDBNull(6) ? null : reader.GetString(6), + CText = reader.IsDBNull(7) ? null : reader.GetString(7), + CLongtext = reader.IsDBNull(8) ? null : reader.GetString(8), + CJson = reader.IsDBNull(9) ? null : JsonSerializer.Deserialize(reader.GetString(9)), + CJsonStringOverride = reader.IsDBNull(10) ? null : reader.GetString(10), + CEnum = reader.IsDBNull(11) ? null : reader.GetString(11).ToMysqlStringTypesCEnum(), + CSet = reader.IsDBNull(12) ? null : reader.GetString(12).ToMysqlStringTypesCSetSet() + }; + } + } + } + + return null; + } + + private const string TruncateMysqlStringTypesSql = "TRUNCATE TABLE mysql_string_types"; + public async Task TruncateMysqlStringTypes() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(TruncateMysqlStringTypesSql, connection)) + { + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncateMysqlStringTypesSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } + + private const string InsertMysqlDatetimeTypesSql = " INSERT INTO mysql_datetime_types ( c_year, c_date, c_datetime, c_timestamp, c_time ) VALUES (@c_year, @c_date, @c_datetime, @c_timestamp, @c_time)"; + public readonly record struct InsertMysqlDatetimeTypesArgs(short? CYear, DateTime? CDate, DateTime? CDatetime, DateTime? CTimestamp, TimeSpan? CTime); + public async Task InsertMysqlDatetimeTypes(InsertMysqlDatetimeTypesArgs args) + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(InsertMysqlDatetimeTypesSql, connection)) + { + command.Parameters.AddWithValue("@c_year", args.CYear ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_date", args.CDate ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_datetime", args.CDatetime ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_timestamp", args.CTimestamp ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_time", args.CTime ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = InsertMysqlDatetimeTypesSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@c_year", args.CYear ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_date", args.CDate ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_datetime", args.CDatetime ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_timestamp", args.CTimestamp ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_time", args.CTime ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + public readonly record struct InsertMysqlDatetimeTypesBatchArgs(short? CYear, DateTime? CDate, DateTime? CDatetime, DateTime? CTimestamp, TimeSpan? CTime); + public async Task InsertMysqlDatetimeTypesBatch(List args) + { + const string supportedDateTimeFormat = "yyyy-MM-dd H:mm:ss"; + var config = new CsvConfiguration(CultureInfo.CurrentCulture) + { + Delimiter = ",", + NewLine = "\n" + }; + var nullConverterFn = new Utils.NullToStringCsvConverter(); + using (var writer = new StreamWriter("input.csv", false, new UTF8Encoding(false))) + using (var csvWriter = new CsvWriter(writer, config)) + { + var options = new TypeConverterOptions + { + Formats = new[] + { + supportedDateTimeFormat + } + }; + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + await csvWriter.WriteRecordsAsync(args); + } + + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + var loader = new MySqlBulkLoader(connection) + { + Local = true, + TableName = "mysql_datetime_types", + FileName = "input.csv", + FieldTerminator = ",", + FieldQuotationCharacter = '"', + FieldQuotationOptional = true, + NumberOfLinesToSkip = 1, + LineTerminator = "\n" + }; + loader.Columns.AddRange(new List { "c_year", "c_date", "c_datetime", "c_timestamp", "c_time" }); + await loader.LoadAsync(); + await connection.CloseAsync(); + } + } + + private const string GetMysqlDatetimeTypesSql = "SELECT c_year, c_date, c_datetime, c_timestamp, c_time FROM mysql_datetime_types LIMIT 1"; + public readonly record struct GetMysqlDatetimeTypesRow(short? CYear, DateTime? CDate, DateTime? CDatetime, DateTime? CTimestamp, TimeSpan? CTime); + public async Task GetMysqlDatetimeTypes() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(GetMysqlDatetimeTypesSql, connection)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlDatetimeTypesRow + { + CYear = reader.IsDBNull(0) ? null : reader.GetInt16(0), + CDate = reader.IsDBNull(1) ? null : reader.GetDateTime(1), + CDatetime = reader.IsDBNull(2) ? null : reader.GetDateTime(2), + CTimestamp = reader.IsDBNull(3) ? null : reader.GetDateTime(3), + CTime = reader.IsDBNull(4) ? null : reader.GetFieldValue(4) + }; + } + } + } + } + + return null; + } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetMysqlDatetimeTypesSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlDatetimeTypesRow + { + CYear = reader.IsDBNull(0) ? null : reader.GetInt16(0), + CDate = reader.IsDBNull(1) ? null : reader.GetDateTime(1), + CDatetime = reader.IsDBNull(2) ? null : reader.GetDateTime(2), + CTimestamp = reader.IsDBNull(3) ? null : reader.GetDateTime(3), + CTime = reader.IsDBNull(4) ? null : reader.GetFieldValue(4) + }; + } + } + } + + 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"; + public readonly record struct GetMysqlDatetimeTypesCntRow(long Cnt, short? CYear, DateTime? CDate, DateTime? CDatetime, DateTime? CTimestamp, TimeSpan? CTime); + public async Task GetMysqlDatetimeTypesCnt() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(GetMysqlDatetimeTypesCntSql, connection)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlDatetimeTypesCntRow + { + Cnt = reader.GetInt64(0), + CYear = reader.IsDBNull(1) ? null : reader.GetInt16(1), + CDate = reader.IsDBNull(2) ? null : reader.GetDateTime(2), + CDatetime = reader.IsDBNull(3) ? null : reader.GetDateTime(3), + CTimestamp = reader.IsDBNull(4) ? null : reader.GetDateTime(4), + CTime = reader.IsDBNull(5) ? null : reader.GetFieldValue(5) + }; + } + } + } + } + + return null; } + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = TruncateMysqlTypesSql; + command.CommandText = GetMysqlDatetimeTypesCntSql; command.Transaction = this.Transaction; - await command.ExecuteNonQueryAsync(); + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlDatetimeTypesCntRow + { + Cnt = reader.GetInt64(0), + CYear = reader.IsDBNull(1) ? null : reader.GetInt16(1), + CDate = reader.IsDBNull(2) ? null : reader.GetDateTime(2), + CDatetime = reader.IsDBNull(3) ? null : reader.GetDateTime(3), + CTimestamp = reader.IsDBNull(4) ? null : reader.GetDateTime(4), + CTime = reader.IsDBNull(5) ? null : reader.GetFieldValue(5) + }; + } + } } + + return null; } - private const string CreateExtendedBioSql = "INSERT INTO extended.bios (author_name, name, bio_type, author_type) VALUES (@author_name, @name, @bio_type, @author_type)"; - public readonly record struct CreateExtendedBioArgs(string? AuthorName, string? Name, ExtendedBiosBioType? BioType, ExtendedBiosAuthorType[]? AuthorType); - public async Task CreateExtendedBio(CreateExtendedBioArgs args) + private const string TruncateMysqlDatetimeTypesSql = "TRUNCATE TABLE mysql_datetime_types"; + public async Task TruncateMysqlDatetimeTypes() { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { await connection.OpenAsync(); - using (var command = new MySqlCommand(CreateExtendedBioSql, connection)) + using (var command = new MySqlCommand(TruncateMysqlDatetimeTypesSql, connection)) { - command.Parameters.AddWithValue("@author_name", args.AuthorName ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@name", args.Name ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@bio_type", args.BioType ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@author_type", args.AuthorType != null ? string.Join(",", args.AuthorType) : (object)DBNull.Value); await command.ExecuteNonQueryAsync(); } } @@ -1185,45 +1530,130 @@ public async Task CreateExtendedBio(CreateExtendedBioArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncateMysqlDatetimeTypesSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } + + 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) + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(InsertMysqlBinaryTypesSql, connection)) + { + command.Parameters.AddWithValue("@c_bit", args.CBit ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_binary", args.CBinary ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_varbinary", args.CVarbinary ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_tinyblob", args.CTinyblob ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_blob", args.CBlob ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_mediumblob", args.CMediumblob ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_longblob", args.CLongblob ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + return; } + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = CreateExtendedBioSql; + command.CommandText = InsertMysqlBinaryTypesSql; command.Transaction = this.Transaction; - command.Parameters.AddWithValue("@author_name", args.AuthorName ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@name", args.Name ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@bio_type", args.BioType ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@author_type", args.AuthorType != null ? string.Join(",", args.AuthorType) : (object)DBNull.Value); + command.Parameters.AddWithValue("@c_bit", args.CBit ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_binary", args.CBinary ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_varbinary", args.CVarbinary ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_tinyblob", args.CTinyblob ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_blob", args.CBlob ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_mediumblob", args.CMediumblob ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_longblob", args.CLongblob ?? (object)DBNull.Value); await command.ExecuteNonQueryAsync(); } } - private const string GetFirstExtendedBioByTypeSql = "SELECT author_name, name, bio_type, author_type FROM extended.bios WHERE bio_type = @bio_type LIMIT 1"; - public readonly record struct GetFirstExtendedBioByTypeRow(string? AuthorName, string? Name, ExtendedBiosBioType? BioType, ExtendedBiosAuthorType[]? AuthorType); - public readonly record struct GetFirstExtendedBioByTypeArgs(ExtendedBiosBioType? BioType); - public async Task GetFirstExtendedBioByType(GetFirstExtendedBioByTypeArgs args) + public readonly record struct InsertMysqlBinaryTypesBatchArgs(byte? CBit, byte[]? CBinary, byte[]? CVarbinary, byte[]? CTinyblob, byte[]? CBlob, byte[]? CMediumblob, byte[]? CLongblob); + public async Task InsertMysqlBinaryTypesBatch(List args) + { + const string supportedDateTimeFormat = "yyyy-MM-dd H:mm:ss"; + var config = new CsvConfiguration(CultureInfo.CurrentCulture) + { + Delimiter = ",", + NewLine = "\n" + }; + var nullConverterFn = new Utils.NullToStringCsvConverter(); + using (var writer = new StreamWriter("input.csv", false, new UTF8Encoding(false))) + using (var csvWriter = new CsvWriter(writer, config)) + { + var options = new TypeConverterOptions + { + Formats = new[] + { + supportedDateTimeFormat + } + }; + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteCsvConverter()); + csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteCsvConverter()); + csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteArrayCsvConverter()); + csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteArrayCsvConverter()); + await csvWriter.WriteRecordsAsync(args); + } + + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + var loader = new MySqlBulkLoader(connection) + { + Local = true, + TableName = "mysql_binary_types", + FileName = "input.csv", + FieldTerminator = ",", + FieldQuotationCharacter = '"', + FieldQuotationOptional = true, + NumberOfLinesToSkip = 1, + LineTerminator = "\n" + }; + loader.Columns.AddRange(new List { "c_bit", "c_binary", "c_varbinary", "c_tinyblob", "c_blob", "c_mediumblob", "c_longblob" }); + await loader.LoadAsync(); + await connection.CloseAsync(); + } + } + + private const string GetMysqlBinaryTypesSql = "SELECT c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_binary_types LIMIT 1"; + public readonly record struct GetMysqlBinaryTypesRow(byte? CBit, byte[]? CBinary, byte[]? CVarbinary, byte[]? CTinyblob, byte[]? CBlob, byte[]? CMediumblob, byte[]? CLongblob); + public async Task GetMysqlBinaryTypes() { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { await connection.OpenAsync(); - using (var command = new MySqlCommand(GetFirstExtendedBioByTypeSql, connection)) + using (var command = new MySqlCommand(GetMysqlBinaryTypesSql, connection)) { - command.Parameters.AddWithValue("@bio_type", args.BioType ?? (object)DBNull.Value); using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetFirstExtendedBioByTypeRow + return new GetMysqlBinaryTypesRow { - AuthorName = reader.IsDBNull(0) ? null : reader.GetString(0), - Name = reader.IsDBNull(1) ? null : reader.GetString(1), - BioType = reader.IsDBNull(2) ? null : reader.GetString(2).ToExtendedBiosBioType(), - AuthorType = reader.IsDBNull(3) ? null : reader.GetString(3).ToExtendedBiosAuthorTypeArr() + CBit = reader.IsDBNull(0) ? null : reader.GetFieldValue(0), + CBinary = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CVarbinary = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + CTinyblob = reader.IsDBNull(3) ? null : reader.GetFieldValue(3), + CBlob = reader.IsDBNull(4) ? null : reader.GetFieldValue(4), + CMediumblob = reader.IsDBNull(5) ? null : reader.GetFieldValue(5), + CLongblob = reader.IsDBNull(6) ? null : reader.GetFieldValue(6) }; } } @@ -1234,25 +1664,86 @@ public async Task CreateExtendedBio(CreateExtendedBioArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetMysqlBinaryTypesSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlBinaryTypesRow + { + CBit = reader.IsDBNull(0) ? null : reader.GetFieldValue(0), + CBinary = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CVarbinary = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + CTinyblob = reader.IsDBNull(3) ? null : reader.GetFieldValue(3), + CBlob = reader.IsDBNull(4) ? null : reader.GetFieldValue(4), + CMediumblob = reader.IsDBNull(5) ? null : reader.GetFieldValue(5), + CLongblob = reader.IsDBNull(6) ? null : reader.GetFieldValue(6) + }; + } + } + } + + 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"; + public readonly record struct GetMysqlBinaryTypesCntRow(long Cnt, byte? CBit, byte[]? CBinary, byte[]? CVarbinary, byte[]? CTinyblob, byte[]? CBlob, byte[]? CMediumblob, byte[]? CLongblob); + public async Task GetMysqlBinaryTypesCnt() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(GetMysqlBinaryTypesCntSql, connection)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlBinaryTypesCntRow + { + Cnt = reader.GetInt64(0), + CBit = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CBinary = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + CVarbinary = reader.IsDBNull(3) ? null : reader.GetFieldValue(3), + CTinyblob = reader.IsDBNull(4) ? null : reader.GetFieldValue(4), + CBlob = reader.IsDBNull(5) ? null : reader.GetFieldValue(5), + CMediumblob = reader.IsDBNull(6) ? null : reader.GetFieldValue(6), + CLongblob = reader.IsDBNull(7) ? null : reader.GetFieldValue(7) + }; + } + } + } + } + + return null; } + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = GetFirstExtendedBioByTypeSql; + command.CommandText = GetMysqlBinaryTypesCntSql; command.Transaction = this.Transaction; - command.Parameters.AddWithValue("@bio_type", args.BioType ?? (object)DBNull.Value); using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetFirstExtendedBioByTypeRow + return new GetMysqlBinaryTypesCntRow { - AuthorName = reader.IsDBNull(0) ? null : reader.GetString(0), - Name = reader.IsDBNull(1) ? null : reader.GetString(1), - BioType = reader.IsDBNull(2) ? null : reader.GetString(2).ToExtendedBiosBioType(), - AuthorType = reader.IsDBNull(3) ? null : reader.GetString(3).ToExtendedBiosAuthorTypeArr() + Cnt = reader.GetInt64(0), + CBit = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CBinary = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + CVarbinary = reader.IsDBNull(3) ? null : reader.GetFieldValue(3), + CTinyblob = reader.IsDBNull(4) ? null : reader.GetFieldValue(4), + CBlob = reader.IsDBNull(5) ? null : reader.GetFieldValue(5), + CMediumblob = reader.IsDBNull(6) ? null : reader.GetFieldValue(6), + CLongblob = reader.IsDBNull(7) ? null : reader.GetFieldValue(7) }; } } @@ -1261,15 +1752,15 @@ public async Task CreateExtendedBio(CreateExtendedBioArgs args) return null; } - private const string TruncateExtendedBiosSql = "TRUNCATE TABLE extended.bios"; - public async Task TruncateExtendedBios() + private const string TruncateMysqlBinaryTypesSql = "TRUNCATE TABLE mysql_binary_types"; + public async Task TruncateMysqlBinaryTypes() { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { await connection.OpenAsync(); - using (var command = new MySqlCommand(TruncateExtendedBiosSql, connection)) + using (var command = new MySqlCommand(TruncateMysqlBinaryTypesSql, connection)) { await command.ExecuteNonQueryAsync(); } @@ -1279,15 +1770,64 @@ public async Task TruncateExtendedBios() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncateMysqlBinaryTypesSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } + + 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() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(GetMysqlFunctionsSql, connection)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlFunctionsRow + { + MaxInt = reader.IsDBNull(0) ? null : reader.GetInt32(0), + MaxVarchar = reader.IsDBNull(1) ? null : reader.GetString(1), + MaxTimestamp = reader.GetDateTime(2) + }; + } + } + } + } + + return null; } + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = TruncateExtendedBiosSql; + command.CommandText = GetMysqlFunctionsSql; command.Transaction = this.Transaction; - await command.ExecuteNonQueryAsync(); + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlFunctionsRow + { + MaxInt = reader.IsDBNull(0) ? null : reader.GetInt32(0), + MaxVarchar = reader.IsDBNull(1) ? null : reader.GetString(1), + MaxTimestamp = reader.GetDateTime(2) + }; + } + } } + + return null; } } \ No newline at end of file diff --git a/examples/MySqlConnectorExample/Utils.cs b/examples/MySqlConnectorExample/Utils.cs index 741d29f7..d16b3f61 100644 --- a/examples/MySqlConnectorExample/Utils.cs +++ b/examples/MySqlConnectorExample/Utils.cs @@ -2,6 +2,7 @@ using CsvHelper; using CsvHelper.Configuration; using CsvHelper.TypeConversion; +using System.Collections.Generic; using System.Linq; namespace MySqlConnectorExampleGen; @@ -13,14 +14,14 @@ public static string TransformQueryForSliceArgs(string originalSql, int sliceSiz return originalSql.Replace($"/*SLICE:{paramName}*/@{paramName}", string.Join(",", paramArgs)); } - public class MysqlTypesCSetCsvConverter : DefaultTypeConverter + public class MysqlStringTypesCSetCsvConverter : DefaultTypeConverter { public override string? ConvertToString(object? value, IWriterRow row, MemberMapData memberMapData) { if (value == null) return @"\N"; - if (value is MysqlTypesCSet[] arrVal) - return string.Join(",", arrVal); + if (value is HashSet setVal) + return string.Join(",", setVal); return base.ConvertToString(value, row, memberMapData); } } diff --git a/examples/MySqlConnectorExample/request.json b/examples/MySqlConnectorExample/request.json index 8097883f..cfae6b86 100644 --- a/examples/MySqlConnectorExample/request.json +++ b/examples/MySqlConnectorExample/request.json @@ -3,10 +3,12 @@ "version": "2", "engine": "mysql", "schema": [ - "examples/config/mysql/schema.sql" + "examples/config/mysql/authors/schema.sql", + "examples/config/mysql/types/schema.sql" ], "queries": [ - "examples/config/mysql/query.sql" + "examples/config/mysql/authors/query.sql", + "examples/config/mysql/types/query.sql" ], "codegen": { "out": "examples/MySqlConnectorExample", @@ -114,14 +116,14 @@ }, { "rel": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "columns": [ { "name": "c_bool", "length": 1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "tinyint" @@ -131,7 +133,7 @@ "name": "c_boolean", "length": 1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "tinyint" @@ -141,7 +143,7 @@ "name": "c_tinyint", "length": 3, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "tinyint" @@ -151,7 +153,7 @@ "name": "c_smallint", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "smallint" @@ -161,7 +163,7 @@ "name": "c_mediumint", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "mediumint" @@ -171,7 +173,7 @@ "name": "c_int", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "int" @@ -181,7 +183,7 @@ "name": "c_integer", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "int" @@ -191,7 +193,7 @@ "name": "c_bigint", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "bigint" @@ -201,7 +203,7 @@ "name": "c_float", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "float" @@ -211,7 +213,7 @@ "name": "c_decimal", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -221,7 +223,7 @@ "name": "c_dec", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -231,7 +233,7 @@ "name": "c_numeric", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -241,7 +243,7 @@ "name": "c_fixed", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -251,7 +253,7 @@ "name": "c_double", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "double" @@ -261,187 +263,208 @@ "name": "c_double_precision", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "double" } - }, + } + ] + }, + { + "rel": { + "name": "mysql_string_types" + }, + "columns": [ { - "name": "c_year", + "name": "c_char", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "year" + "name": "char" } }, { - "name": "c_date", + "name": "c_nchar", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "date" + "name": "char" } }, { - "name": "c_time", - "length": 10, + "name": "c_national_char", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "time" + "name": "char" } }, { - "name": "c_datetime", - "length": 19, + "name": "c_varchar", + "length": 100, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "datetime" + "name": "varchar" } }, { - "name": "c_timestamp", - "length": 19, + "name": "c_tinytext", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "timestamp" + "name": "tinytext" } }, { - "name": "c_char", + "name": "c_mediumtext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "char" + "name": "mediumtext" } }, { - "name": "c_nchar", + "name": "c_text", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "char" + "name": "text" } }, { - "name": "c_national_char", + "name": "c_longtext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "char" + "name": "longtext" } }, { - "name": "c_varchar", - "length": 100, + "name": "c_json", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "varchar" + "name": "json" } }, { - "name": "c_tinytext", + "name": "c_json_string_override", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "tinytext" + "name": "json" } }, { - "name": "c_mediumtext", - "length": -1, + "name": "c_enum", + "length": 6, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mediumtext" + "name": "mysql_string_types_c_enum" } }, { - "name": "c_text", - "length": -1, + "name": "c_set", + "length": 15, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "text" + "name": "mysql_string_types_c_set" } - }, + } + ] + }, + { + "rel": { + "name": "mysql_datetime_types" + }, + "columns": [ { - "name": "c_longtext", + "name": "c_year", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "longtext" + "name": "year" } }, { - "name": "c_json", + "name": "c_date", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "json" + "name": "date" } }, { - "name": "c_json_string_override", - "length": -1, + "name": "c_datetime", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "json" + "name": "datetime" } }, { - "name": "c_enum", - "length": 6, + "name": "c_timestamp", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "mysql_types_c_enum" + "name": "timestamp" } }, { - "name": "c_set", - "length": 15, + "name": "c_time", + "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "mysql_types_c_set" + "name": "time" } - }, + } + ] + }, + { + "rel": { + "name": "mysql_binary_types" + }, + "columns": [ { "name": "c_bit", "length": 8, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "bit" @@ -451,7 +474,7 @@ "name": "c_binary", "length": 3, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "binary" @@ -461,7 +484,7 @@ "name": "c_varbinary", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "varbinary" @@ -471,7 +494,7 @@ "name": "c_tinyblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "tinyblob" @@ -481,7 +504,7 @@ "name": "c_blob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "blob" @@ -491,7 +514,7 @@ "name": "c_mediumblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "mediumblob" @@ -501,7 +524,7 @@ "name": "c_longblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "longblob" @@ -511,22 +534,6 @@ } ], "enums": [ - { - "name": "mysql_types_c_enum", - "vals": [ - "small", - "medium", - "big" - ] - }, - { - "name": "mysql_types_c_set", - "vals": [ - "tea", - "coffee", - "milk" - ] - }, { "name": "bios_bio_type", "vals": [ @@ -542,6 +549,22 @@ "Editor", "Translator" ] + }, + { + "name": "mysql_string_types_c_enum", + "vals": [ + "small", + "medium", + "big" + ] + }, + { + "name": "mysql_string_types_c_set", + "vals": [ + "tea", + "coffee", + "milk" + ] } ] }, @@ -1306,93 +1329,229 @@ "filename": "query.sql" }, { - "text": "INSERT INTO mysql_types \n(c_bit, c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, \n c_decimal, c_dec, c_numeric, c_fixed, c_float, c_double, c_double_precision, \n c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, \n c_json, c_json_string_override, c_enum, c_set, c_year, c_date, c_datetime, c_timestamp, \n c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - "name": "InsertMysqlTypes", + "text": "INSERT INTO extended.bios (author_name, name, bio_type, author_type) VALUES (?, ?, ?, ?)", + "name": "CreateExtendedBio", "cmd": ":exec", "parameters": [ { "number": 1, "column": { - "name": "c_bit", - "length": 8, + "name": "author_name", + "length": 100, "table": { - "schema": "public", - "name": "mysql_types" + "schema": "extended", + "name": "bios" }, "type": { - "name": "bit" + "name": "varchar" }, - "originalName": "c_bit" + "originalName": "author_name" } }, { "number": 2, "column": { - "name": "c_bool", - "length": 1, + "name": "name", + "length": 100, "table": { - "schema": "public", - "name": "mysql_types" + "schema": "extended", + "name": "bios" }, "type": { - "name": "tinyint" + "name": "varchar" }, - "originalName": "c_bool" + "originalName": "name" } }, { "number": 3, "column": { - "name": "c_boolean", - "length": 1, + "name": "bio_type", + "length": 13, "table": { - "schema": "public", - "name": "mysql_types" + "schema": "extended", + "name": "bios" }, "type": { - "name": "tinyint" + "name": "bios_bio_type" }, - "originalName": "c_boolean" + "originalName": "bio_type" } }, { "number": 4, "column": { - "name": "c_tinyint", - "length": 3, + "name": "author_type", + "length": 24, "table": { - "schema": "public", - "name": "mysql_types" + "schema": "extended", + "name": "bios" }, "type": { - "name": "tinyint" + "name": "bios_author_type" }, - "originalName": "c_tinyint" + "originalName": "author_type" } + } + ], + "filename": "query.sql", + "insert_into_table": { + "schema": "extended", + "name": "bios" + } + }, + { + "text": "SELECT author_name, name, bio_type, author_type FROM extended.bios WHERE bio_type = ? LIMIT 1", + "name": "GetFirstExtendedBioByType", + "cmd": ":one", + "columns": [ + { + "name": "author_name", + "length": 100, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "varchar" + }, + "originalName": "author_name" }, { - "number": 5, + "name": "name", + "length": 100, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "varchar" + }, + "originalName": "name" + }, + { + "name": "bio_type", + "length": 13, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "bios_bio_type" + }, + "originalName": "bio_type" + }, + { + "name": "author_type", + "length": 24, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "bios_author_type" + }, + "originalName": "author_type" + } + ], + "parameters": [ + { + "number": 1, "column": { - "name": "c_smallint", - "length": -1, + "name": "bio_type", + "length": 13, "table": { - "schema": "public", - "name": "mysql_types" + "schema": "extended", + "name": "bios" }, "type": { - "name": "smallint" + "name": "bios_bio_type" }, - "originalName": "c_smallint" + "originalName": "bio_type" } - }, + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE extended.bios", + "name": "TruncateExtendedBios", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO mysql_numeric_types \n(\n c_bool,\n c_boolean,\n c_tinyint,\n c_smallint,\n c_mediumint,\n c_int,\n c_integer,\n c_bigint, \n c_decimal, \n c_dec, \n c_numeric, \n c_fixed, \n c_float, \n c_double, \n c_double_precision\n) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlNumericTypes", + "cmd": ":exec", + "parameters": [ { - "number": 6, + "number": 1, + "column": { + "name": "c_bool", + "length": 1, + "table": { + "schema": "public", + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_bool" + } + }, + { + "number": 2, + "column": { + "name": "c_boolean", + "length": 1, + "table": { + "schema": "public", + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_boolean" + } + }, + { + "number": 3, + "column": { + "name": "c_tinyint", + "length": 3, + "table": { + "schema": "public", + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_tinyint" + } + }, + { + "number": 4, + "column": { + "name": "c_smallint", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_numeric_types" + }, + "type": { + "name": "smallint" + }, + "originalName": "c_smallint" + } + }, + { + "number": 5, "column": { "name": "c_mediumint", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "mediumint" @@ -1401,13 +1560,13 @@ } }, { - "number": 7, + "number": 6, "column": { "name": "c_int", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "int" @@ -1416,13 +1575,13 @@ } }, { - "number": 8, + "number": 7, "column": { "name": "c_integer", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "int" @@ -1431,13 +1590,13 @@ } }, { - "number": 9, + "number": 8, "column": { "name": "c_bigint", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "bigint" @@ -1446,13 +1605,13 @@ } }, { - "number": 10, + "number": 9, "column": { "name": "c_decimal", "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -1461,13 +1620,13 @@ } }, { - "number": 11, + "number": 10, "column": { "name": "c_dec", "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -1476,13 +1635,13 @@ } }, { - "number": 12, + "number": 11, "column": { "name": "c_numeric", "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -1491,13 +1650,13 @@ } }, { - "number": 13, + "number": 12, "column": { "name": "c_fixed", "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -1506,13 +1665,13 @@ } }, { - "number": 14, + "number": 13, "column": { "name": "c_float", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "float" @@ -1521,13 +1680,13 @@ } }, { - "number": 15, + "number": 14, "column": { "name": "c_double", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "double" @@ -1536,609 +1695,639 @@ } }, { - "number": 16, + "number": 15, "column": { "name": "c_double_precision", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "double" }, "originalName": "c_double_precision" } - }, + } + ], + "comments": [ + " Numeric types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_numeric_types" + } + }, + { + "text": "INSERT INTO mysql_numeric_types \n(\n c_bool,\n c_boolean,\n c_tinyint,\n c_smallint,\n c_mediumint,\n c_int,\n c_integer,\n c_bigint, \n c_float, \n c_numeric, \n c_decimal, \n c_dec, \n c_fixed, \n c_double, \n c_double_precision\n) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlNumericTypesBatch", + "cmd": ":copyfrom", + "parameters": [ { - "number": 17, + "number": 1, "column": { - "name": "c_char", - "length": -1, + "name": "c_bool", + "length": 1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "char" + "name": "tinyint" }, - "originalName": "c_char" + "originalName": "c_bool" } }, { - "number": 18, + "number": 2, "column": { - "name": "c_nchar", - "length": -1, + "name": "c_boolean", + "length": 1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "char" + "name": "tinyint" }, - "originalName": "c_nchar" + "originalName": "c_boolean" } }, { - "number": 19, + "number": 3, "column": { - "name": "c_national_char", - "length": -1, + "name": "c_tinyint", + "length": 3, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "char" + "name": "tinyint" }, - "originalName": "c_national_char" + "originalName": "c_tinyint" } }, { - "number": 20, + "number": 4, "column": { - "name": "c_varchar", - "length": 100, + "name": "c_smallint", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "varchar" + "name": "smallint" }, - "originalName": "c_varchar" + "originalName": "c_smallint" } }, { - "number": 21, + "number": 5, "column": { - "name": "c_tinytext", + "name": "c_mediumint", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "tinytext" + "name": "mediumint" }, - "originalName": "c_tinytext" + "originalName": "c_mediumint" } }, { - "number": 22, + "number": 6, "column": { - "name": "c_mediumtext", + "name": "c_int", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "mediumtext" + "name": "int" }, - "originalName": "c_mediumtext" + "originalName": "c_int" } }, { - "number": 23, + "number": 7, "column": { - "name": "c_text", + "name": "c_integer", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "text" + "name": "int" }, - "originalName": "c_text" + "originalName": "c_integer" } }, { - "number": 24, + "number": 8, "column": { - "name": "c_longtext", + "name": "c_bigint", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "longtext" + "name": "bigint" }, - "originalName": "c_longtext" + "originalName": "c_bigint" } }, { - "number": 25, + "number": 9, "column": { - "name": "c_json", + "name": "c_float", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "json" + "name": "float" }, - "originalName": "c_json" + "originalName": "c_float" } }, { - "number": 26, + "number": 10, "column": { - "name": "c_json_string_override", - "length": -1, + "name": "c_numeric", + "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "json" + "name": "decimal" }, - "originalName": "c_json_string_override" + "originalName": "c_numeric" } }, { - "number": 27, + "number": 11, "column": { - "name": "c_enum", - "length": 6, + "name": "c_decimal", + "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "mysql_types_c_enum" + "name": "decimal" }, - "originalName": "c_enum" + "originalName": "c_decimal" } }, { - "number": 28, + "number": 12, "column": { - "name": "c_set", - "length": 15, + "name": "c_dec", + "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "mysql_types_c_set" + "name": "decimal" }, - "originalName": "c_set" + "originalName": "c_dec" } }, { - "number": 29, + "number": 13, "column": { - "name": "c_year", - "length": -1, + "name": "c_fixed", + "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "year" + "name": "decimal" }, - "originalName": "c_year" + "originalName": "c_fixed" } }, { - "number": 30, + "number": 14, "column": { - "name": "c_date", + "name": "c_double", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "date" + "name": "double" }, - "originalName": "c_date" + "originalName": "c_double" } }, { - "number": 31, + "number": 15, "column": { - "name": "c_datetime", - "length": 19, + "name": "c_double_precision", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "datetime" + "name": "double" }, - "originalName": "c_datetime" + "originalName": "c_double_precision" } - }, + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_numeric_types" + } + }, + { + "text": "SELECT c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_decimal, c_dec, c_numeric, c_fixed, c_double, c_double_precision FROM mysql_numeric_types LIMIT 1", + "name": "GetMysqlNumericTypes", + "cmd": ":one", + "columns": [ { - "number": 32, - "column": { - "name": "c_timestamp", - "length": 19, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "timestamp" - }, - "originalName": "c_timestamp" - } + "name": "c_bool", + "length": 1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_bool" }, { - "number": 33, - "column": { - "name": "c_binary", - "length": 3, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "binary" - }, - "originalName": "c_binary" - } + "name": "c_boolean", + "length": 1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_boolean" }, { - "number": 34, - "column": { - "name": "c_varbinary", - "length": 10, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "varbinary" - }, - "originalName": "c_varbinary" - } + "name": "c_tinyint", + "length": 3, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_tinyint" }, { - "number": 35, - "column": { - "name": "c_tinyblob", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "tinyblob" - }, - "originalName": "c_tinyblob" - } + "name": "c_smallint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "smallint" + }, + "originalName": "c_smallint" }, { - "number": 36, - "column": { - "name": "c_blob", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "blob" - }, - "originalName": "c_blob" - } + "name": "c_mediumint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "mediumint" + }, + "originalName": "c_mediumint" }, { - "number": 37, - "column": { - "name": "c_mediumblob", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "mediumblob" - }, - "originalName": "c_mediumblob" - } + "name": "c_int", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "int" + }, + "originalName": "c_int" }, { - "number": 38, - "column": { - "name": "c_longblob", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "longblob" - }, - "originalName": "c_longblob" - } + "name": "c_integer", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "int" + }, + "originalName": "c_integer" + }, + { + "name": "c_bigint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "bigint" + }, + "originalName": "c_bigint" + }, + { + "name": "c_float", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "float" + }, + "originalName": "c_float" + }, + { + "name": "c_decimal", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_decimal" + }, + { + "name": "c_dec", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_dec" + }, + { + "name": "c_numeric", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_numeric" + }, + { + "name": "c_fixed", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_fixed" + }, + { + "name": "c_double", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "double" + }, + "originalName": "c_double" + }, + { + "name": "c_double_precision", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "double" + }, + "originalName": "c_double_precision" } ], - "filename": "query.sql", - "insert_into_table": { - "name": "mysql_types" - } + "filename": "query.sql" }, { - "text": "INSERT INTO mysql_types \n(c_bit, c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, \n c_float, c_numeric, c_decimal, c_dec, c_fixed, c_double, c_double_precision, \n c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, \n c_json, c_json_string_override, c_enum, c_set, c_year, c_date, c_datetime, c_timestamp,\n c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - "name": "InsertMysqlTypesBatch", - "cmd": ":copyfrom", - "parameters": [ - { - "number": 1, - "column": { - "name": "c_bit", - "length": 8, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "bit" - }, - "originalName": "c_bit" - } - }, + "text": "SELECT\n COUNT(*) AS cnt,\n c_bool,\n c_boolean,\n c_tinyint,\n c_smallint,\n c_mediumint,\n c_int,\n c_integer,\n c_bigint,\n c_float,\n c_numeric,\n c_decimal,\n c_dec,\n c_fixed,\n c_double,\n c_double_precision\nFROM mysql_numeric_types\nGROUP BY\n c_bool,\n c_boolean,\n c_tinyint,\n c_smallint,\n c_mediumint,\n c_int,\n c_integer,\n c_bigint,\n c_float,\n c_numeric,\n c_decimal,\n c_dec,\n c_fixed,\n c_double,\n c_double_precision\nLIMIT 1", + "name": "GetMysqlNumericTypesCnt", + "cmd": ":one", + "columns": [ { - "number": 2, - "column": { - "name": "c_bool", - "length": 1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_bool" + "name": "cnt", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "bigint" } }, { - "number": 3, - "column": { - "name": "c_boolean", - "length": 1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_boolean" - } + "name": "c_bool", + "length": 1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_bool" }, { - "number": 4, - "column": { - "name": "c_tinyint", - "length": 3, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_tinyint" - } + "name": "c_boolean", + "length": 1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_boolean" }, { - "number": 5, - "column": { - "name": "c_smallint", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "smallint" - }, - "originalName": "c_smallint" - } + "name": "c_tinyint", + "length": 3, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_tinyint" }, { - "number": 6, - "column": { - "name": "c_mediumint", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "mediumint" - }, - "originalName": "c_mediumint" - } + "name": "c_smallint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "smallint" + }, + "originalName": "c_smallint" }, { - "number": 7, - "column": { - "name": "c_int", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "int" - }, - "originalName": "c_int" - } + "name": "c_mediumint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "mediumint" + }, + "originalName": "c_mediumint" }, { - "number": 8, - "column": { - "name": "c_integer", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "int" - }, - "originalName": "c_integer" - } + "name": "c_int", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "int" + }, + "originalName": "c_int" }, { - "number": 9, - "column": { - "name": "c_bigint", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "bigint" - }, - "originalName": "c_bigint" - } + "name": "c_integer", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "int" + }, + "originalName": "c_integer" }, { - "number": 10, - "column": { - "name": "c_float", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "float" - }, - "originalName": "c_float" - } + "name": "c_bigint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "bigint" + }, + "originalName": "c_bigint" }, { - "number": 11, - "column": { - "name": "c_numeric", - "length": 10, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_numeric" - } + "name": "c_float", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "float" + }, + "originalName": "c_float" }, { - "number": 12, - "column": { - "name": "c_decimal", - "length": 10, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_decimal" - } + "name": "c_numeric", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_numeric" }, { - "number": 13, - "column": { - "name": "c_dec", - "length": 10, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_dec" - } + "name": "c_decimal", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_decimal" }, { - "number": 14, - "column": { - "name": "c_fixed", - "length": 10, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_fixed" - } + "name": "c_dec", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_dec" }, { - "number": 15, - "column": { - "name": "c_double", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "double" - }, - "originalName": "c_double" - } + "name": "c_fixed", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_fixed" }, { - "number": 16, - "column": { - "name": "c_double_precision", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "double" - }, - "originalName": "c_double_precision" - } + "name": "c_double", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "double" + }, + "originalName": "c_double" }, { - "number": 17, + "name": "c_double_precision", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "double" + }, + "originalName": "c_double_precision" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE mysql_numeric_types", + "name": "TruncateMysqlNumericTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO mysql_string_types \n(\n c_char,\n c_nchar,\n c_national_char,\n c_varchar,\n c_tinytext,\n c_mediumtext,\n c_text,\n c_longtext, \n c_json,\n c_json_string_override,\n c_enum,\n c_set\n) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlStringTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, "column": { "name": "c_char", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2147,13 +2336,13 @@ } }, { - "number": 18, + "number": 2, "column": { "name": "c_nchar", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2162,13 +2351,13 @@ } }, { - "number": 19, + "number": 3, "column": { "name": "c_national_char", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2177,13 +2366,13 @@ } }, { - "number": 20, + "number": 4, "column": { "name": "c_varchar", "length": 100, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "varchar" @@ -2192,511 +2381,335 @@ } }, { - "number": 21, + "number": 5, "column": { "name": "c_tinytext", "length": -1, "table": { "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "tinytext" - }, - "originalName": "c_tinytext" - } - }, - { - "number": 22, - "column": { - "name": "c_mediumtext", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "mediumtext" - }, - "originalName": "c_mediumtext" - } - }, - { - "number": 23, - "column": { - "name": "c_text", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "text" - }, - "originalName": "c_text" - } - }, - { - "number": 24, - "column": { - "name": "c_longtext", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "longtext" - }, - "originalName": "c_longtext" - } - }, - { - "number": 25, - "column": { - "name": "c_json", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "json" - }, - "originalName": "c_json" - } - }, - { - "number": 26, - "column": { - "name": "c_json_string_override", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "json" + "name": "tinytext" }, - "originalName": "c_json_string_override" + "originalName": "c_tinytext" } }, { - "number": 27, + "number": 6, "column": { - "name": "c_enum", - "length": 6, + "name": "c_mediumtext", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mysql_types_c_enum" + "name": "mediumtext" }, - "originalName": "c_enum" + "originalName": "c_mediumtext" } }, { - "number": 28, + "number": 7, "column": { - "name": "c_set", - "length": 15, + "name": "c_text", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mysql_types_c_set" + "name": "text" }, - "originalName": "c_set" + "originalName": "c_text" } }, { - "number": 29, + "number": 8, "column": { - "name": "c_year", + "name": "c_longtext", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "year" + "name": "longtext" }, - "originalName": "c_year" + "originalName": "c_longtext" } }, { - "number": 30, + "number": 9, "column": { - "name": "c_date", + "name": "c_json", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "date" + "name": "json" }, - "originalName": "c_date" + "originalName": "c_json" } }, { - "number": 31, + "number": 10, "column": { - "name": "c_datetime", - "length": 19, + "name": "c_json_string_override", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "datetime" + "name": "json" }, - "originalName": "c_datetime" + "originalName": "c_json_string_override" } }, { - "number": 32, + "number": 11, "column": { - "name": "c_timestamp", - "length": 19, + "name": "c_enum", + "length": 6, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "timestamp" + "name": "mysql_string_types_c_enum" }, - "originalName": "c_timestamp" + "originalName": "c_enum" } }, { - "number": 33, + "number": 12, "column": { - "name": "c_binary", - "length": 3, + "name": "c_set", + "length": 15, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "binary" + "name": "mysql_string_types_c_set" }, - "originalName": "c_binary" + "originalName": "c_set" } - }, + } + ], + "comments": [ + " String types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_string_types" + } + }, + { + "text": "INSERT INTO mysql_string_types \n(\n c_char,\n c_nchar,\n c_national_char,\n c_varchar,\n c_tinytext,\n c_mediumtext,\n c_text,\n c_longtext, \n c_json,\n c_json_string_override,\n c_enum,\n c_set\n) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlStringTypesBatch", + "cmd": ":copyfrom", + "parameters": [ { - "number": 34, + "number": 1, "column": { - "name": "c_varbinary", - "length": 10, + "name": "c_char", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "varbinary" + "name": "char" }, - "originalName": "c_varbinary" + "originalName": "c_char" } }, { - "number": 35, + "number": 2, "column": { - "name": "c_tinyblob", + "name": "c_nchar", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "tinyblob" + "name": "char" }, - "originalName": "c_tinyblob" + "originalName": "c_nchar" } }, { - "number": 36, + "number": 3, "column": { - "name": "c_blob", + "name": "c_national_char", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "blob" + "name": "char" }, - "originalName": "c_blob" + "originalName": "c_national_char" } }, { - "number": 37, + "number": 4, "column": { - "name": "c_mediumblob", - "length": -1, + "name": "c_varchar", + "length": 100, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mediumblob" + "name": "varchar" }, - "originalName": "c_mediumblob" + "originalName": "c_varchar" } }, { - "number": 38, + "number": 5, "column": { - "name": "c_longblob", + "name": "c_tinytext", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "longblob" + "name": "tinytext" }, - "originalName": "c_longblob" + "originalName": "c_tinytext" } - } - ], - "filename": "query.sql", - "insert_into_table": { - "name": "mysql_types" - } - }, - { - "text": "SELECT c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_decimal, c_dec, c_numeric, c_fixed, c_double, c_double_precision, c_year, c_date, c_time, c_datetime, c_timestamp, 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, c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_types LIMIT 1", - "name": "GetMysqlTypes", - "cmd": ":one", - "columns": [ - { - "name": "c_bool", - "length": 1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_bool" - }, - { - "name": "c_boolean", - "length": 1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_boolean" - }, - { - "name": "c_tinyint", - "length": 3, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_tinyint" - }, - { - "name": "c_smallint", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "smallint" - }, - "originalName": "c_smallint" - }, - { - "name": "c_mediumint", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "mediumint" - }, - "originalName": "c_mediumint" - }, - { - "name": "c_int", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "int" - }, - "originalName": "c_int" - }, - { - "name": "c_integer", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "int" - }, - "originalName": "c_integer" - }, - { - "name": "c_bigint", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "bigint" - }, - "originalName": "c_bigint" - }, - { - "name": "c_float", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "float" - }, - "originalName": "c_float" - }, - { - "name": "c_decimal", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_decimal" - }, - { - "name": "c_dec", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_dec" - }, - { - "name": "c_numeric", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_numeric" - }, - { - "name": "c_fixed", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_fixed" - }, - { - "name": "c_double", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "double" - }, - "originalName": "c_double" }, { - "name": "c_double_precision", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "double" - }, - "originalName": "c_double_precision" + "number": 6, + "column": { + "name": "c_mediumtext", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "mediumtext" + }, + "originalName": "c_mediumtext" + } }, { - "name": "c_year", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "year" - }, - "originalName": "c_year" + "number": 7, + "column": { + "name": "c_text", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "text" + }, + "originalName": "c_text" + } }, { - "name": "c_date", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "date" - }, - "originalName": "c_date" + "number": 8, + "column": { + "name": "c_longtext", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "longtext" + }, + "originalName": "c_longtext" + } }, { - "name": "c_time", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "time" - }, - "originalName": "c_time" + "number": 9, + "column": { + "name": "c_json", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "json" + }, + "originalName": "c_json" + } }, { - "name": "c_datetime", - "length": 19, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "datetime" - }, - "originalName": "c_datetime" + "number": 10, + "column": { + "name": "c_json_string_override", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "json" + }, + "originalName": "c_json_string_override" + } }, { - "name": "c_timestamp", - "length": 19, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "timestamp" - }, - "originalName": "c_timestamp" + "number": 11, + "column": { + "name": "c_enum", + "length": 6, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "mysql_string_types_c_enum" + }, + "originalName": "c_enum" + } }, + { + "number": 12, + "column": { + "name": "c_set", + "length": 15, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "mysql_string_types_c_set" + }, + "originalName": "c_set" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_string_types" + } + }, + { + "text": "SELECT 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 LIMIT 1", + "name": "GetMysqlStringTypes", + "cmd": ":one", + "columns": [ { "name": "c_char", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2707,7 +2720,7 @@ "name": "c_nchar", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2718,7 +2731,7 @@ "name": "c_national_char", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2729,7 +2742,7 @@ "name": "c_varchar", "length": 100, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "varchar" @@ -2740,7 +2753,7 @@ "name": "c_tinytext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "tinytext" @@ -2751,7 +2764,7 @@ "name": "c_mediumtext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "mediumtext" @@ -2762,7 +2775,7 @@ "name": "c_text", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "text" @@ -2773,7 +2786,7 @@ "name": "c_longtext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "longtext" @@ -2784,7 +2797,7 @@ "name": "c_json", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "json" @@ -2795,7 +2808,7 @@ "name": "c_json_string_override", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "json" @@ -2806,10 +2819,10 @@ "name": "c_enum", "length": 6, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mysql_types_c_enum" + "name": "mysql_string_types_c_enum" }, "originalName": "c_enum" }, @@ -2817,96 +2830,19 @@ "name": "c_set", "length": 15, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mysql_types_c_set" + "name": "mysql_string_types_c_set" }, "originalName": "c_set" - }, - { - "name": "c_bit", - "length": 8, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "bit" - }, - "originalName": "c_bit" - }, - { - "name": "c_binary", - "length": 3, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "binary" - }, - "originalName": "c_binary" - }, - { - "name": "c_varbinary", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "varbinary" - }, - "originalName": "c_varbinary" - }, - { - "name": "c_tinyblob", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "tinyblob" - }, - "originalName": "c_tinyblob" - }, - { - "name": "c_blob", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "blob" - }, - "originalName": "c_blob" - }, - { - "name": "c_mediumblob", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "mediumblob" - }, - "originalName": "c_mediumblob" - }, - { - "name": "c_longblob", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "longblob" - }, - "originalName": "c_longblob" } ], "filename": "query.sql" }, { - "text": "SELECT COUNT(1) AS cnt, c_bool, c_boolean, c_bit, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, \n c_float, c_numeric, c_decimal, c_dec, c_fixed, c_double, c_double_precision, \n c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, \n c_json, c_json_string_override, c_enum, c_set, c_year, c_date, c_datetime, c_timestamp, \n c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob\nFROM mysql_types\nGROUP BY c_bool, c_boolean, c_bit, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, \n c_float, c_numeric, c_decimal, c_dec, c_fixed, c_double, c_double_precision, \n c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, \n c_json, c_json_string_override, c_enum, c_set, c_year, c_date, c_datetime, c_timestamp, \n c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob\nLIMIT 1", - "name": "GetMysqlTypesCnt", + "text": "SELECT\n COUNT(*) AS cnt,\n c_char,\n c_nchar,\n c_national_char,\n c_varchar,\n c_tinytext,\n c_mediumtext,\n c_text,\n c_longtext,\n c_json,\n c_json_string_override,\n c_enum,\n c_set\nFROM mysql_string_types\nGROUP BY\n c_char,\n c_nchar,\n c_national_char,\n c_varchar,\n c_tinytext,\n c_mediumtext,\n c_text,\n c_longtext,\n c_json,\n c_json_string_override,\n c_enum,\n c_set\nLIMIT 1", + "name": "GetMysqlStringTypesCnt", "cmd": ":one", "columns": [ { @@ -2919,362 +2855,812 @@ } }, { - "name": "c_bool", - "length": 1, + "name": "c_char", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "tinyint" + "name": "char" }, - "originalName": "c_bool" + "originalName": "c_char" }, { - "name": "c_boolean", - "length": 1, + "name": "c_nchar", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "tinyint" + "name": "char" }, - "originalName": "c_boolean" + "originalName": "c_nchar" }, { - "name": "c_bit", - "length": 8, + "name": "c_national_char", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "bit" + "name": "char" }, - "originalName": "c_bit" + "originalName": "c_national_char" }, { - "name": "c_tinyint", - "length": 3, + "name": "c_varchar", + "length": 100, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "tinyint" + "name": "varchar" }, - "originalName": "c_tinyint" + "originalName": "c_varchar" }, { - "name": "c_smallint", + "name": "c_tinytext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "smallint" + "name": "tinytext" + }, + "originalName": "c_tinytext" + }, + { + "name": "c_mediumtext", + "length": -1, + "table": { + "name": "mysql_string_types" + }, + "type": { + "name": "mediumtext" }, - "originalName": "c_smallint" + "originalName": "c_mediumtext" }, { - "name": "c_mediumint", + "name": "c_text", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mediumint" + "name": "text" }, - "originalName": "c_mediumint" + "originalName": "c_text" }, { - "name": "c_int", + "name": "c_longtext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "int" + "name": "longtext" }, - "originalName": "c_int" + "originalName": "c_longtext" }, { - "name": "c_integer", + "name": "c_json", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "int" + "name": "json" }, - "originalName": "c_integer" + "originalName": "c_json" }, { - "name": "c_bigint", + "name": "c_json_string_override", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "bigint" + "name": "json" }, - "originalName": "c_bigint" + "originalName": "c_json_string_override" }, { - "name": "c_float", - "length": -1, + "name": "c_enum", + "length": 6, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "float" + "name": "mysql_string_types_c_enum" }, - "originalName": "c_float" + "originalName": "c_enum" }, { - "name": "c_numeric", - "length": 10, + "name": "c_set", + "length": 15, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "decimal" + "name": "mysql_string_types_c_set" }, - "originalName": "c_numeric" + "originalName": "c_set" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE mysql_string_types", + "name": "TruncateMysqlStringTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO mysql_datetime_types \n(\n c_year,\n c_date,\n c_datetime,\n c_timestamp,\n c_time\n) \nVALUES (?, ?, ?, ?, ?)", + "name": "InsertMysqlDatetimeTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_year", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "year" + }, + "originalName": "c_year" + } }, { - "name": "c_decimal", - "length": 10, + "number": 2, + "column": { + "name": "c_date", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "date" + }, + "originalName": "c_date" + } + }, + { + "number": 3, + "column": { + "name": "c_datetime", + "length": 19, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "datetime" + }, + "originalName": "c_datetime" + } + }, + { + "number": 4, + "column": { + "name": "c_timestamp", + "length": 19, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "timestamp" + }, + "originalName": "c_timestamp" + } + }, + { + "number": 5, + "column": { + "name": "c_time", + "length": 10, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "time" + }, + "originalName": "c_time" + } + } + ], + "comments": [ + " Datetime types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_datetime_types" + } + }, + { + "text": "INSERT INTO mysql_datetime_types \n(\n c_year,\n c_date,\n c_datetime,\n c_timestamp,\n c_time\n) \nVALUES (?, ?, ?, ?, ?)", + "name": "InsertMysqlDatetimeTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_year", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "year" + }, + "originalName": "c_year" + } + }, + { + "number": 2, + "column": { + "name": "c_date", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "date" + }, + "originalName": "c_date" + } + }, + { + "number": 3, + "column": { + "name": "c_datetime", + "length": 19, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "datetime" + }, + "originalName": "c_datetime" + } + }, + { + "number": 4, + "column": { + "name": "c_timestamp", + "length": 19, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "timestamp" + }, + "originalName": "c_timestamp" + } + }, + { + "number": 5, + "column": { + "name": "c_time", + "length": 10, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "time" + }, + "originalName": "c_time" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_datetime_types" + } + }, + { + "text": "SELECT c_year, c_date, c_datetime, c_timestamp, c_time FROM mysql_datetime_types LIMIT 1", + "name": "GetMysqlDatetimeTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_year", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "decimal" + "name": "year" }, - "originalName": "c_decimal" + "originalName": "c_year" }, { - "name": "c_dec", - "length": 10, + "name": "c_date", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "decimal" + "name": "date" }, - "originalName": "c_dec" + "originalName": "c_date" }, { - "name": "c_fixed", - "length": 10, + "name": "c_datetime", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "decimal" + "name": "datetime" }, - "originalName": "c_fixed" + "originalName": "c_datetime" }, { - "name": "c_double", - "length": -1, + "name": "c_timestamp", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "double" + "name": "timestamp" }, - "originalName": "c_double" + "originalName": "c_timestamp" }, { - "name": "c_double_precision", - "length": -1, + "name": "c_time", + "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "double" + "name": "time" }, - "originalName": "c_double_precision" + "originalName": "c_time" + } + ], + "filename": "query.sql" + }, + { + "text": "SELECT\n COUNT(*) AS cnt,\n c_year,\n c_date,\n c_datetime,\n c_timestamp,\n c_time\nFROM mysql_datetime_types\nGROUP BY\n c_year,\n c_date,\n c_datetime,\n c_timestamp,\n c_time\nLIMIT 1", + "name": "GetMysqlDatetimeTypesCnt", + "cmd": ":one", + "columns": [ + { + "name": "cnt", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "bigint" + } }, { - "name": "c_char", + "name": "c_year", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "char" + "name": "year" }, - "originalName": "c_char" + "originalName": "c_year" }, { - "name": "c_nchar", + "name": "c_date", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "char" + "name": "date" }, - "originalName": "c_nchar" + "originalName": "c_date" }, { - "name": "c_national_char", - "length": -1, + "name": "c_datetime", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "char" + "name": "datetime" }, - "originalName": "c_national_char" + "originalName": "c_datetime" }, { - "name": "c_varchar", - "length": 100, + "name": "c_timestamp", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "varchar" + "name": "timestamp" }, - "originalName": "c_varchar" + "originalName": "c_timestamp" }, { - "name": "c_tinytext", - "length": -1, + "name": "c_time", + "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "tinytext" + "name": "time" }, - "originalName": "c_tinytext" + "originalName": "c_time" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE mysql_datetime_types", + "name": "TruncateMysqlDatetimeTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO mysql_binary_types \n(\n c_bit,\n c_binary, \n c_varbinary, \n c_tinyblob, \n c_blob, \n c_mediumblob, \n c_longblob\n) \nVALUES (?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlBinaryTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_bit", + "length": 8, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "bit" + }, + "originalName": "c_bit" + } + }, + { + "number": 2, + "column": { + "name": "c_binary", + "length": 3, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "binary" + }, + "originalName": "c_binary" + } + }, + { + "number": 3, + "column": { + "name": "c_varbinary", + "length": 10, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "varbinary" + }, + "originalName": "c_varbinary" + } + }, + { + "number": 4, + "column": { + "name": "c_tinyblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "tinyblob" + }, + "originalName": "c_tinyblob" + } + }, + { + "number": 5, + "column": { + "name": "c_blob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "blob" + }, + "originalName": "c_blob" + } + }, + { + "number": 6, + "column": { + "name": "c_mediumblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "mediumblob" + }, + "originalName": "c_mediumblob" + } + }, + { + "number": 7, + "column": { + "name": "c_longblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "longblob" + }, + "originalName": "c_longblob" + } + } + ], + "comments": [ + " Binary types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_binary_types" + } + }, + { + "text": "INSERT INTO mysql_binary_types \n(\n c_bit,\n c_binary, \n c_varbinary, \n c_tinyblob, \n c_blob, \n c_mediumblob, \n c_longblob\n) \nVALUES (?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlBinaryTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_bit", + "length": 8, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "bit" + }, + "originalName": "c_bit" + } + }, + { + "number": 2, + "column": { + "name": "c_binary", + "length": 3, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "binary" + }, + "originalName": "c_binary" + } + }, + { + "number": 3, + "column": { + "name": "c_varbinary", + "length": 10, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "varbinary" + }, + "originalName": "c_varbinary" + } + }, + { + "number": 4, + "column": { + "name": "c_tinyblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "tinyblob" + }, + "originalName": "c_tinyblob" + } + }, + { + "number": 5, + "column": { + "name": "c_blob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "blob" + }, + "originalName": "c_blob" + } + }, + { + "number": 6, + "column": { + "name": "c_mediumblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "mediumblob" + }, + "originalName": "c_mediumblob" + } }, { - "name": "c_mediumtext", - "length": -1, + "number": 7, + "column": { + "name": "c_longblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "longblob" + }, + "originalName": "c_longblob" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_binary_types" + } + }, + { + "text": "SELECT c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_binary_types LIMIT 1", + "name": "GetMysqlBinaryTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_bit", + "length": 8, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "mediumtext" + "name": "bit" }, - "originalName": "c_mediumtext" + "originalName": "c_bit" }, { - "name": "c_text", - "length": -1, + "name": "c_binary", + "length": 3, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "text" + "name": "binary" }, - "originalName": "c_text" + "originalName": "c_binary" }, { - "name": "c_longtext", - "length": -1, + "name": "c_varbinary", + "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "longtext" + "name": "varbinary" }, - "originalName": "c_longtext" + "originalName": "c_varbinary" }, { - "name": "c_json", + "name": "c_tinyblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "json" + "name": "tinyblob" }, - "originalName": "c_json" + "originalName": "c_tinyblob" }, { - "name": "c_json_string_override", + "name": "c_blob", "length": -1, "table": { - "name": "mysql_types" - }, - "type": { - "name": "json" - }, - "originalName": "c_json_string_override" - }, - { - "name": "c_enum", - "length": 6, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "mysql_types_c_enum" - }, - "originalName": "c_enum" - }, - { - "name": "c_set", - "length": 15, - "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "mysql_types_c_set" + "name": "blob" }, - "originalName": "c_set" + "originalName": "c_blob" }, { - "name": "c_year", + "name": "c_mediumblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "year" + "name": "mediumblob" }, - "originalName": "c_year" + "originalName": "c_mediumblob" }, { - "name": "c_date", + "name": "c_longblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "date" + "name": "longblob" }, - "originalName": "c_date" - }, + "originalName": "c_longblob" + } + ], + "filename": "query.sql" + }, + { + "text": "SELECT\n COUNT(*) AS cnt,\n c_bit,\n c_binary,\n c_varbinary,\n c_tinyblob,\n c_blob,\n c_mediumblob,\n c_longblob\nFROM mysql_binary_types\nGROUP BY\n c_bit,\n c_binary,\n c_varbinary,\n c_tinyblob,\n c_blob,\n c_mediumblob,\n c_longblob\nLIMIT 1", + "name": "GetMysqlBinaryTypesCnt", + "cmd": ":one", + "columns": [ { - "name": "c_datetime", - "length": 19, - "table": { - "name": "mysql_types" - }, + "name": "cnt", + "notNull": true, + "length": -1, + "isFuncCall": true, "type": { - "name": "datetime" - }, - "originalName": "c_datetime" + "name": "bigint" + } }, { - "name": "c_timestamp", - "length": 19, + "name": "c_bit", + "length": 8, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "timestamp" + "name": "bit" }, - "originalName": "c_timestamp" + "originalName": "c_bit" }, { "name": "c_binary", "length": 3, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "binary" @@ -3285,7 +3671,7 @@ "name": "c_varbinary", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "varbinary" @@ -3296,7 +3682,7 @@ "name": "c_tinyblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "tinyblob" @@ -3307,7 +3693,7 @@ "name": "c_blob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "blob" @@ -3318,7 +3704,7 @@ "name": "c_mediumblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "mediumblob" @@ -3329,7 +3715,7 @@ "name": "c_longblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "longblob" @@ -3340,7 +3726,13 @@ "filename": "query.sql" }, { - "text": "SELECT MAX(c_int) AS max_int, MAX(c_varchar) AS max_varchar, MAX(c_timestamp) AS max_timestamp\nFROM mysql_types", + "text": "TRUNCATE TABLE mysql_binary_types", + "name": "TruncateMysqlBinaryTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "\nSELECT\n MAX(c_int) AS max_int,\n MAX(c_varchar) AS max_varchar,\n MAX(c_timestamp) AS max_timestamp\nFROM mysql_numeric_types\nCROSS JOIN mysql_string_types\nCROSS JOIN mysql_datetime_types", "name": "GetMysqlFunctions", "cmd": ":one", "columns": [ @@ -3372,164 +3764,10 @@ } } ], - "filename": "query.sql" - }, - { - "text": "TRUNCATE TABLE mysql_types", - "name": "TruncateMysqlTypes", - "cmd": ":exec", - "filename": "query.sql" - }, - { - "text": "INSERT INTO extended.bios (author_name, name, bio_type, author_type) VALUES (?, ?, ?, ?)", - "name": "CreateExtendedBio", - "cmd": ":exec", - "parameters": [ - { - "number": 1, - "column": { - "name": "author_name", - "length": 100, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "varchar" - }, - "originalName": "author_name" - } - }, - { - "number": 2, - "column": { - "name": "name", - "length": 100, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "varchar" - }, - "originalName": "name" - } - }, - { - "number": 3, - "column": { - "name": "bio_type", - "length": 13, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "bios_bio_type" - }, - "originalName": "bio_type" - } - }, - { - "number": 4, - "column": { - "name": "author_type", - "length": 24, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "bios_author_type" - }, - "originalName": "author_type" - } - } - ], - "filename": "query.sql", - "insert_into_table": { - "schema": "extended", - "name": "bios" - } - }, - { - "text": "SELECT author_name, name, bio_type, author_type FROM extended.bios WHERE bio_type = ? LIMIT 1", - "name": "GetFirstExtendedBioByType", - "cmd": ":one", - "columns": [ - { - "name": "author_name", - "length": 100, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "varchar" - }, - "originalName": "author_name" - }, - { - "name": "name", - "length": 100, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "varchar" - }, - "originalName": "name" - }, - { - "name": "bio_type", - "length": 13, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "bios_bio_type" - }, - "originalName": "bio_type" - }, - { - "name": "author_type", - "length": 24, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "bios_author_type" - }, - "originalName": "author_type" - } - ], - "parameters": [ - { - "number": 1, - "column": { - "name": "bio_type", - "length": 13, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "bios_bio_type" - }, - "originalName": "bio_type" - } - } + "comments": [ + " Functions " ], "filename": "query.sql" - }, - { - "text": "TRUNCATE TABLE extended.bios", - "name": "TruncateExtendedBios", - "cmd": ":exec", - "filename": "query.sql" } ], "sqlc_version": "v1.27.0", diff --git a/examples/MySqlConnectorExample/request.message b/examples/MySqlConnectorExample/request.message index 603ba7f5..1d678969 100644 Binary files a/examples/MySqlConnectorExample/request.message and b/examples/MySqlConnectorExample/request.message differ diff --git a/examples/MySqlConnectorLegacyExample/Models.cs b/examples/MySqlConnectorLegacyExample/Models.cs index 83f58691..1abbf592 100644 --- a/examples/MySqlConnectorLegacyExample/Models.cs +++ b/examples/MySqlConnectorLegacyExample/Models.cs @@ -19,7 +19,7 @@ public class Book public long AuthorId { get; set; } public string Description { get; set; } }; - public class MysqlType + public class MysqlNumericType { public bool? CBool { get; set; } public bool? CBoolean { get; set; } @@ -36,11 +36,9 @@ public class MysqlType public decimal? CFixed { get; set; } public double? CDouble { get; set; } public double? CDoublePrecision { get; set; } - public short? CYear { get; set; } - public DateTime? CDate { get; set; } - public string CTime { get; set; } - public DateTime? CDatetime { get; set; } - public DateTime? CTimestamp { get; set; } + }; + public class MysqlStringType + { public string CChar { get; set; } public string CNchar { get; set; } public string CNationalChar { get; set; } @@ -51,8 +49,19 @@ public class MysqlType public string CLongtext { get; set; } public JsonElement? CJson { get; set; } public JsonElement? CJsonStringOverride { get; set; } - public MysqlTypesCEnum? CEnum { get; set; } - public MysqlTypesCSet[] CSet { get; set; } + public MysqlStringTypesCEnum? CEnum { get; set; } + public HashSet CSet { get; set; } + }; + public class MysqlDatetimeType + { + public short? CYear { get; set; } + public DateTime? CDate { get; set; } + public DateTime? CDatetime { get; set; } + public DateTime? CTimestamp { get; set; } + public TimeSpan? CTime { get; set; } + }; + public class MysqlBinaryType + { public byte? CBit { get; set; } public byte[] CBinary { get; set; } public byte[] CVarbinary { get; set; } @@ -65,118 +74,166 @@ public class ExtendedBio { public string AuthorName { get; set; } public string Name { get; set; } - public ExtendedBiosBioType? BioType { get; set; } - public ExtendedBiosAuthorType[] AuthorType { get; set; } + public BiosBioType? BioType { get; set; } + public HashSet AuthorType { get; set; } }; - public enum MysqlTypesCEnum + public enum BiosBioType { Invalid = 0, // reserved for invalid enum value - Small = 1, - Medium = 2, - Big = 3 + Autobiography = 1, + Biography = 2, + Memoir = 3 } - public static class MysqlTypesCEnumExtensions + public static class BiosBioTypeExtensions { - private static readonly Dictionary StringToEnum = new Dictionary() + private static readonly Dictionary StringToEnum = new Dictionary() + { + [string.Empty] = BiosBioType.Invalid, + ["Autobiography"] = BiosBioType.Autobiography, + ["Biography"] = BiosBioType.Biography, + ["Memoir"] = BiosBioType.Memoir + }; + private static readonly Dictionary EnumToString = new Dictionary() { - [string.Empty] = MysqlTypesCEnum.Invalid, - ["small"] = MysqlTypesCEnum.Small, - ["medium"] = MysqlTypesCEnum.Medium, - ["big"] = MysqlTypesCEnum.Big + [BiosBioType.Invalid] = string.Empty, + [BiosBioType.Autobiography] = "Autobiography", + [BiosBioType.Biography] = "Biography", + [BiosBioType.Memoir] = "Memoir" }; - public static MysqlTypesCEnum ToMysqlTypesCEnum(this string me) + public static BiosBioType ToBiosBioType(this string me) { return StringToEnum[me]; } - public static MysqlTypesCEnum[] ToMysqlTypesCEnumArr(this string me) + public static string Stringify(this BiosBioType me) { - return me.Split(',').ToList().Select(v => StringToEnum[v]).ToArray(); + return EnumToString[me]; + } + + public static HashSet ToBiosBioTypeSet(this string me) + { + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); } } - public enum MysqlTypesCSet + public enum BiosAuthorType { Invalid = 0, // reserved for invalid enum value - Tea = 1, - Coffee = 2, - Milk = 3 + Author = 1, + Editor = 2, + Translator = 3 } - public static class MysqlTypesCSetExtensions + public static class BiosAuthorTypeExtensions { - private static readonly Dictionary StringToEnum = new Dictionary() + private static readonly Dictionary StringToEnum = new Dictionary() + { + [string.Empty] = BiosAuthorType.Invalid, + ["Author"] = BiosAuthorType.Author, + ["Editor"] = BiosAuthorType.Editor, + ["Translator"] = BiosAuthorType.Translator + }; + private static readonly Dictionary EnumToString = new Dictionary() { - [string.Empty] = MysqlTypesCSet.Invalid, - ["tea"] = MysqlTypesCSet.Tea, - ["coffee"] = MysqlTypesCSet.Coffee, - ["milk"] = MysqlTypesCSet.Milk + [BiosAuthorType.Invalid] = string.Empty, + [BiosAuthorType.Author] = "Author", + [BiosAuthorType.Editor] = "Editor", + [BiosAuthorType.Translator] = "Translator" }; - public static MysqlTypesCSet ToMysqlTypesCSet(this string me) + public static BiosAuthorType ToBiosAuthorType(this string me) { return StringToEnum[me]; } - public static MysqlTypesCSet[] ToMysqlTypesCSetArr(this string me) + public static string Stringify(this BiosAuthorType me) { - return me.Split(',').ToList().Select(v => StringToEnum[v]).ToArray(); + return EnumToString[me]; + } + + public static HashSet ToBiosAuthorTypeSet(this string me) + { + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); } } - public enum ExtendedBiosBioType + public enum MysqlStringTypesCEnum { Invalid = 0, // reserved for invalid enum value - Autobiography = 1, - Biography = 2, - Memoir = 3 + Small = 1, + Medium = 2, + Big = 3 } - public static class ExtendedBiosBioTypeExtensions + public static class MysqlStringTypesCEnumExtensions { - private static readonly Dictionary StringToEnum = new Dictionary() + private static readonly Dictionary StringToEnum = new Dictionary() + { + [string.Empty] = MysqlStringTypesCEnum.Invalid, + ["small"] = MysqlStringTypesCEnum.Small, + ["medium"] = MysqlStringTypesCEnum.Medium, + ["big"] = MysqlStringTypesCEnum.Big + }; + private static readonly Dictionary EnumToString = new Dictionary() { - [string.Empty] = ExtendedBiosBioType.Invalid, - ["Autobiography"] = ExtendedBiosBioType.Autobiography, - ["Biography"] = ExtendedBiosBioType.Biography, - ["Memoir"] = ExtendedBiosBioType.Memoir + [MysqlStringTypesCEnum.Invalid] = string.Empty, + [MysqlStringTypesCEnum.Small] = "small", + [MysqlStringTypesCEnum.Medium] = "medium", + [MysqlStringTypesCEnum.Big] = "big" }; - public static ExtendedBiosBioType ToExtendedBiosBioType(this string me) + public static MysqlStringTypesCEnum ToMysqlStringTypesCEnum(this string me) { return StringToEnum[me]; } - public static ExtendedBiosBioType[] ToExtendedBiosBioTypeArr(this string me) + public static string Stringify(this MysqlStringTypesCEnum me) { - return me.Split(',').ToList().Select(v => StringToEnum[v]).ToArray(); + return EnumToString[me]; + } + + public static HashSet ToMysqlStringTypesCEnumSet(this string me) + { + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); } } - public enum ExtendedBiosAuthorType + public enum MysqlStringTypesCSet { Invalid = 0, // reserved for invalid enum value - Author = 1, - Editor = 2, - Translator = 3 + Tea = 1, + Coffee = 2, + Milk = 3 } - public static class ExtendedBiosAuthorTypeExtensions + public static class MysqlStringTypesCSetExtensions { - private static readonly Dictionary StringToEnum = new Dictionary() + private static readonly Dictionary StringToEnum = new Dictionary() + { + [string.Empty] = MysqlStringTypesCSet.Invalid, + ["tea"] = MysqlStringTypesCSet.Tea, + ["coffee"] = MysqlStringTypesCSet.Coffee, + ["milk"] = MysqlStringTypesCSet.Milk + }; + private static readonly Dictionary EnumToString = new Dictionary() { - [string.Empty] = ExtendedBiosAuthorType.Invalid, - ["Author"] = ExtendedBiosAuthorType.Author, - ["Editor"] = ExtendedBiosAuthorType.Editor, - ["Translator"] = ExtendedBiosAuthorType.Translator + [MysqlStringTypesCSet.Invalid] = string.Empty, + [MysqlStringTypesCSet.Tea] = "tea", + [MysqlStringTypesCSet.Coffee] = "coffee", + [MysqlStringTypesCSet.Milk] = "milk" }; - public static ExtendedBiosAuthorType ToExtendedBiosAuthorType(this string me) + public static MysqlStringTypesCSet ToMysqlStringTypesCSet(this string me) { return StringToEnum[me]; } - public static ExtendedBiosAuthorType[] ToExtendedBiosAuthorTypeArr(this string me) + public static string Stringify(this MysqlStringTypesCSet me) + { + return EnumToString[me]; + } + + public static HashSet ToMysqlStringTypesCSetSet(this string me) { - return me.Split(',').ToList().Select(v => StringToEnum[v]).ToArray(); + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); } } } \ No newline at end of file diff --git a/examples/MySqlConnectorLegacyExample/QuerySql.cs b/examples/MySqlConnectorLegacyExample/QuerySql.cs index 0357dd17..98a4ae16 100644 --- a/examples/MySqlConnectorLegacyExample/QuerySql.cs +++ b/examples/MySqlConnectorLegacyExample/QuerySql.cs @@ -82,10 +82,7 @@ public async Task GetAuthor(GetAuthorArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetAuthorSql; @@ -108,7 +105,7 @@ 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; } @@ -187,10 +184,7 @@ public async Task CreateAuthor(CreateAuthorArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = CreateAuthorSql; @@ -226,10 +220,7 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = CreateAuthorReturnIdSql; @@ -281,10 +272,7 @@ public async Task GetAuthorById(GetAuthorByIdArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetAuthorByIdSql; @@ -307,7 +295,7 @@ 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; } @@ -356,7 +344,7 @@ 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; } @@ -379,10 +367,7 @@ public async Task DeleteAuthor(DeleteAuthorArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = DeleteAuthorSql; @@ -410,10 +395,7 @@ public async Task DeleteAllAuthors() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = DeleteAllAuthorsSql; @@ -422,7 +404,7 @@ 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; } @@ -443,10 +425,7 @@ public async Task UpdateAuthors(UpdateAuthorsArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = UpdateAuthorsSql; @@ -592,10 +571,7 @@ public async Task CreateBook(CreateBookArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = CreateBookSql; @@ -607,7 +583,7 @@ 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; } @@ -649,7 +625,7 @@ 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; } @@ -691,7 +667,7 @@ 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; } @@ -741,10 +717,144 @@ public async Task> GetAuthorsByBookName(GetAuthors } } - private const string InsertMysqlTypesSql = "INSERT INTO mysql_types (c_bit, 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, 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, c_year, c_date, c_datetime, c_timestamp, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob) VALUES ( @c_bit, @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, @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, @c_year, @c_date, @c_datetime, @c_timestamp, @c_binary, @c_varbinary, @c_tinyblob, @c_blob, @c_mediumblob, @c_longblob ) "; - public class InsertMysqlTypesArgs + private const string CreateExtendedBioSql = "INSERT INTO extended.bios (author_name, name, bio_type, author_type) VALUES (@author_name, @name, @bio_type, @author_type)"; + public class CreateExtendedBioArgs + { + public string AuthorName { get; set; } + public string Name { get; set; } + public BiosBioType? BioType { get; set; } + public HashSet AuthorType { get; set; } + }; + public async Task CreateExtendedBio(CreateExtendedBioArgs args) + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(CreateExtendedBioSql, connection)) + { + command.Parameters.AddWithValue("@author_name", args.AuthorName ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@name", args.Name ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@bio_type", args.BioType ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@author_type", args.AuthorType != null ? string.Join(",", args.AuthorType) : (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = CreateExtendedBioSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@author_name", args.AuthorName ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@name", args.Name ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@bio_type", args.BioType ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@author_type", args.AuthorType != null ? string.Join(",", args.AuthorType) : (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + private const string GetFirstExtendedBioByTypeSql = "SELECT author_name, name, bio_type, author_type FROM extended.bios WHERE bio_type = @bio_type LIMIT 1"; + public class GetFirstExtendedBioByTypeRow + { + public string AuthorName { get; set; } + public string Name { get; set; } + public BiosBioType? BioType { get; set; } + public HashSet AuthorType { get; set; } + }; + public class GetFirstExtendedBioByTypeArgs + { + public BiosBioType? BioType { get; set; } + }; + public async Task GetFirstExtendedBioByType(GetFirstExtendedBioByTypeArgs args) + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(GetFirstExtendedBioByTypeSql, connection)) + { + command.Parameters.AddWithValue("@bio_type", args.BioType ?? (object)DBNull.Value); + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetFirstExtendedBioByTypeRow + { + AuthorName = reader.IsDBNull(0) ? null : reader.GetString(0), + Name = reader.IsDBNull(1) ? null : reader.GetString(1), + BioType = reader.IsDBNull(2) ? (BiosBioType? )null : reader.GetString(2).ToBiosBioType(), + AuthorType = reader.IsDBNull(3) ? null : reader.GetString(3).ToBiosAuthorTypeSet() + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetFirstExtendedBioByTypeSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@bio_type", args.BioType ?? (object)DBNull.Value); + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetFirstExtendedBioByTypeRow + { + AuthorName = reader.IsDBNull(0) ? null : reader.GetString(0), + Name = reader.IsDBNull(1) ? null : reader.GetString(1), + BioType = reader.IsDBNull(2) ? (BiosBioType? )null : reader.GetString(2).ToBiosBioType(), + AuthorType = reader.IsDBNull(3) ? null : reader.GetString(3).ToBiosAuthorTypeSet() + }; + } + } + } + + return null; + } + + private const string TruncateExtendedBiosSql = "TRUNCATE TABLE extended.bios"; + public async Task TruncateExtendedBios() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(TruncateExtendedBiosSql, connection)) + { + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncateExtendedBiosSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } + + 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 byte? CBit { get; set; } public bool? CBool { get; set; } public bool? CBoolean { get; set; } public short? CTinyint { get; set; } @@ -760,39 +870,16 @@ public class InsertMysqlTypesArgs public double? CFloat { get; set; } public double? CDouble { get; set; } public double? CDoublePrecision { get; set; } - public string CChar { get; set; } - public string CNchar { get; set; } - public string CNationalChar { get; set; } - public string CVarchar { get; set; } - public string CTinytext { get; set; } - public string CMediumtext { get; set; } - public string CText { get; set; } - public string CLongtext { get; set; } - public JsonElement? CJson { get; set; } - public string CJsonStringOverride { get; set; } - public MysqlTypesCEnum? CEnum { get; set; } - public MysqlTypesCSet[] CSet { get; set; } - public short? CYear { get; set; } - public DateTime? CDate { get; set; } - public DateTime? CDatetime { get; set; } - public DateTime? CTimestamp { get; set; } - public byte[] CBinary { get; set; } - public byte[] CVarbinary { get; set; } - public byte[] CTinyblob { get; set; } - public byte[] CBlob { get; set; } - public byte[] CMediumblob { get; set; } - public byte[] CLongblob { get; set; } }; - public async Task InsertMysqlTypes(InsertMysqlTypesArgs args) + public async Task InsertMysqlNumericTypes(InsertMysqlNumericTypesArgs args) { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { await connection.OpenAsync(); - using (var command = new MySqlCommand(InsertMysqlTypesSql, connection)) + using (var command = new MySqlCommand(InsertMysqlNumericTypesSql, connection)) { - command.Parameters.AddWithValue("@c_bit", args.CBit ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_bool", args.CBool ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_boolean", args.CBoolean ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_tinyint", args.CTinyint ?? (object)DBNull.Value); @@ -808,28 +895,6 @@ public async Task InsertMysqlTypes(InsertMysqlTypesArgs args) command.Parameters.AddWithValue("@c_float", args.CFloat ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_double", args.CDouble ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_double_precision", args.CDoublePrecision ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_char", args.CChar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_nchar", args.CNchar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_national_char", args.CNationalChar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_varchar", args.CVarchar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_tinytext", args.CTinytext ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_mediumtext", args.CMediumtext ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_text", args.CText ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_longtext", args.CLongtext ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_json", args.CJson?.GetRawText() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_json_string_override", args.CJsonStringOverride ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_enum", args.CEnum ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_set", args.CSet != null ? string.Join(",", args.CSet) : (object)DBNull.Value); - command.Parameters.AddWithValue("@c_year", args.CYear ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_date", args.CDate ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_datetime", args.CDatetime ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_timestamp", args.CTimestamp ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_binary", args.CBinary ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_varbinary", args.CVarbinary ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_tinyblob", args.CTinyblob ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_blob", args.CBlob ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_mediumblob", args.CMediumblob ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_longblob", args.CLongblob ?? (object)DBNull.Value); await command.ExecuteNonQueryAsync(); } } @@ -838,15 +903,11 @@ public async Task InsertMysqlTypes(InsertMysqlTypesArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = InsertMysqlTypesSql; + command.CommandText = InsertMysqlNumericTypesSql; command.Transaction = this.Transaction; - command.Parameters.AddWithValue("@c_bit", args.CBit ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_bool", args.CBool ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_boolean", args.CBoolean ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_tinyint", args.CTinyint ?? (object)DBNull.Value); @@ -862,35 +923,12 @@ public async Task InsertMysqlTypes(InsertMysqlTypesArgs args) command.Parameters.AddWithValue("@c_float", args.CFloat ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_double", args.CDouble ?? (object)DBNull.Value); command.Parameters.AddWithValue("@c_double_precision", args.CDoublePrecision ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_char", args.CChar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_nchar", args.CNchar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_national_char", args.CNationalChar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_varchar", args.CVarchar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_tinytext", args.CTinytext ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_mediumtext", args.CMediumtext ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_text", args.CText ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_longtext", args.CLongtext ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_json", args.CJson?.GetRawText() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_json_string_override", args.CJsonStringOverride ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_enum", args.CEnum ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_set", args.CSet != null ? string.Join(",", args.CSet) : (object)DBNull.Value); - command.Parameters.AddWithValue("@c_year", args.CYear ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_date", args.CDate ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_datetime", args.CDatetime ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_timestamp", args.CTimestamp ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_binary", args.CBinary ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_varbinary", args.CVarbinary ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_tinyblob", args.CTinyblob ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_blob", args.CBlob ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_mediumblob", args.CMediumblob ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_longblob", args.CLongblob ?? (object)DBNull.Value); await command.ExecuteNonQueryAsync(); } } - public class InsertMysqlTypesBatchArgs + public class InsertMysqlNumericTypesBatchArgs { - public byte? CBit { get; set; } public bool? CBool { get; set; } public bool? CBoolean { get; set; } public short? CTinyint { get; set; } @@ -906,30 +944,8 @@ public class InsertMysqlTypesBatchArgs public decimal? CFixed { get; set; } public double? CDouble { get; set; } public double? CDoublePrecision { get; set; } - public string CChar { get; set; } - public string CNchar { get; set; } - public string CNationalChar { get; set; } - public string CVarchar { get; set; } - public string CTinytext { get; set; } - public string CMediumtext { get; set; } - public string CText { get; set; } - public string CLongtext { get; set; } - public JsonElement? CJson { get; set; } - public string CJsonStringOverride { get; set; } - public MysqlTypesCEnum? CEnum { get; set; } - public MysqlTypesCSet[] CSet { get; set; } - public short? CYear { get; set; } - public DateTime? CDate { get; set; } - public DateTime? CDatetime { get; set; } - public DateTime? CTimestamp { get; set; } - public byte[] CBinary { get; set; } - public byte[] CVarbinary { get; set; } - public byte[] CTinyblob { get; set; } - public byte[] CBlob { get; set; } - public byte[] CMediumblob { get; set; } - public byte[] CLongblob { get; set; } }; - public async Task InsertMysqlTypesBatch(List args) + public async Task InsertMysqlNumericTypesBatch(List args) { const string supportedDateTimeFormat = "yyyy-MM-dd H:mm:ss"; var config = new CsvConfiguration(CultureInfo.CurrentCulture) @@ -952,19 +968,11 @@ public async Task InsertMysqlTypesBatch(List args) csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); csvWriter.Context.TypeConverterCache.AddConverter(new Utils.BoolToBitCsvConverter()); csvWriter.Context.TypeConverterCache.AddConverter(new Utils.BoolToBitCsvConverter()); - csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteCsvConverter()); - csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteCsvConverter()); - csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteArrayCsvConverter()); - csvWriter.Context.TypeConverterCache.AddConverter(new Utils.MysqlTypesCSetCsvConverter()); csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); - csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); - csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); - csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); - csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); await csvWriter.WriteRecordsAsync(args); } @@ -974,7 +982,7 @@ public async Task InsertMysqlTypesBatch(List args) var loader = new MySqlBulkLoader(connection) { Local = true, - TableName = "mysql_types", + TableName = "mysql_numeric_types", FileName = "input.csv", FieldTerminator = ",", FieldQuotationCharacter = '"', @@ -982,14 +990,14 @@ public async Task InsertMysqlTypesBatch(List args) NumberOfLinesToSkip = 1, LineTerminator = "\n" }; - loader.Columns.AddRange(new List { "c_bit", "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", "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", "c_year", "c_date", "c_datetime", "c_timestamp", "c_binary", "c_varbinary", "c_tinyblob", "c_blob", "c_mediumblob", "c_longblob" }); + loader.Columns.AddRange(new List { "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" }); await loader.LoadAsync(); await connection.CloseAsync(); } } - private const string GetMysqlTypesSql = "SELECT c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_decimal, c_dec, c_numeric, c_fixed, c_double, c_double_precision, c_year, c_date, c_time, c_datetime, c_timestamp, 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, c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_types LIMIT 1"; - public class GetMysqlTypesRow + private const string GetMysqlNumericTypesSql = "SELECT c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_decimal, c_dec, c_numeric, c_fixed, c_double, c_double_precision FROM mysql_numeric_types LIMIT 1"; + public class GetMysqlNumericTypesRow { public bool? CBool { get; set; } public bool? CBoolean { get; set; } @@ -1006,45 +1014,21 @@ public class GetMysqlTypesRow public decimal? CFixed { get; set; } public double? CDouble { get; set; } public double? CDoublePrecision { get; set; } - public short? CYear { get; set; } - public DateTime? CDate { get; set; } - public string CTime { get; set; } - public DateTime? CDatetime { get; set; } - public DateTime? CTimestamp { get; set; } - public string CChar { get; set; } - public string CNchar { get; set; } - public string CNationalChar { get; set; } - public string CVarchar { get; set; } - public string CTinytext { get; set; } - public string CMediumtext { get; set; } - public string CText { get; set; } - public string CLongtext { get; set; } - public JsonElement? CJson { get; set; } - public string CJsonStringOverride { get; set; } - public MysqlTypesCEnum? CEnum { get; set; } - public MysqlTypesCSet[] CSet { get; set; } - public byte? CBit { get; set; } - public byte[] CBinary { get; set; } - public byte[] CVarbinary { get; set; } - public byte[] CTinyblob { get; set; } - public byte[] CBlob { get; set; } - public byte[] CMediumblob { get; set; } - public byte[] CLongblob { get; set; } }; - public async Task GetMysqlTypes() + public async Task GetMysqlNumericTypes() { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { await connection.OpenAsync(); - using (var command = new MySqlCommand(GetMysqlTypesSql, connection)) + using (var command = new MySqlCommand(GetMysqlNumericTypesSql, connection)) { using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetMysqlTypesRow + return new GetMysqlNumericTypesRow { CBool = reader.IsDBNull(0) ? (bool? )null : reader.GetBoolean(0), CBoolean = reader.IsDBNull(1) ? (bool? )null : reader.GetBoolean(1), @@ -1060,31 +1044,7 @@ public async Task GetMysqlTypes() CNumeric = reader.IsDBNull(11) ? (decimal? )null : reader.GetDecimal(11), CFixed = reader.IsDBNull(12) ? (decimal? )null : reader.GetDecimal(12), CDouble = reader.IsDBNull(13) ? (double? )null : reader.GetDouble(13), - CDoublePrecision = reader.IsDBNull(14) ? (double? )null : reader.GetDouble(14), - CYear = reader.IsDBNull(15) ? (short? )null : reader.GetInt16(15), - CDate = reader.IsDBNull(16) ? (DateTime? )null : reader.GetDateTime(16), - CTime = reader.IsDBNull(17) ? null : reader.GetString(17), - CDatetime = reader.IsDBNull(18) ? (DateTime? )null : reader.GetDateTime(18), - CTimestamp = reader.IsDBNull(19) ? (DateTime? )null : reader.GetDateTime(19), - CChar = reader.IsDBNull(20) ? null : reader.GetString(20), - CNchar = reader.IsDBNull(21) ? null : reader.GetString(21), - CNationalChar = reader.IsDBNull(22) ? null : reader.GetString(22), - CVarchar = reader.IsDBNull(23) ? null : reader.GetString(23), - CTinytext = reader.IsDBNull(24) ? null : reader.GetString(24), - CMediumtext = reader.IsDBNull(25) ? null : reader.GetString(25), - CText = reader.IsDBNull(26) ? null : reader.GetString(26), - CLongtext = reader.IsDBNull(27) ? null : reader.GetString(27), - CJson = reader.IsDBNull(28) ? (JsonElement? )null : JsonSerializer.Deserialize(reader.GetString(28)), - CJsonStringOverride = reader.IsDBNull(29) ? null : reader.GetString(29), - CEnum = reader.IsDBNull(30) ? (MysqlTypesCEnum? )null : reader.GetString(30).ToMysqlTypesCEnum(), - CSet = reader.IsDBNull(31) ? null : reader.GetString(31).ToMysqlTypesCSetArr(), - CBit = reader.IsDBNull(32) ? (byte? )null : reader.GetFieldValue(32), - CBinary = reader.IsDBNull(33) ? null : reader.GetFieldValue(33), - CVarbinary = reader.IsDBNull(34) ? null : reader.GetFieldValue(34), - CTinyblob = reader.IsDBNull(35) ? null : reader.GetFieldValue(35), - CBlob = reader.IsDBNull(36) ? null : reader.GetFieldValue(36), - CMediumblob = reader.IsDBNull(37) ? null : reader.GetFieldValue(37), - CLongblob = reader.IsDBNull(38) ? null : reader.GetFieldValue(38) + CDoublePrecision = reader.IsDBNull(14) ? (double? )null : reader.GetDouble(14) }; } } @@ -1095,19 +1055,16 @@ public async Task GetMysqlTypes() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = GetMysqlTypesSql; + command.CommandText = GetMysqlNumericTypesSql; command.Transaction = this.Transaction; using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetMysqlTypesRow + return new GetMysqlNumericTypesRow { CBool = reader.IsDBNull(0) ? (bool? )null : reader.GetBoolean(0), CBoolean = reader.IsDBNull(1) ? (bool? )null : reader.GetBoolean(1), @@ -1123,31 +1080,7 @@ public async Task GetMysqlTypes() CNumeric = reader.IsDBNull(11) ? (decimal? )null : reader.GetDecimal(11), CFixed = reader.IsDBNull(12) ? (decimal? )null : reader.GetDecimal(12), CDouble = reader.IsDBNull(13) ? (double? )null : reader.GetDouble(13), - CDoublePrecision = reader.IsDBNull(14) ? (double? )null : reader.GetDouble(14), - CYear = reader.IsDBNull(15) ? (short? )null : reader.GetInt16(15), - CDate = reader.IsDBNull(16) ? (DateTime? )null : reader.GetDateTime(16), - CTime = reader.IsDBNull(17) ? null : reader.GetString(17), - CDatetime = reader.IsDBNull(18) ? (DateTime? )null : reader.GetDateTime(18), - CTimestamp = reader.IsDBNull(19) ? (DateTime? )null : reader.GetDateTime(19), - CChar = reader.IsDBNull(20) ? null : reader.GetString(20), - CNchar = reader.IsDBNull(21) ? null : reader.GetString(21), - CNationalChar = reader.IsDBNull(22) ? null : reader.GetString(22), - CVarchar = reader.IsDBNull(23) ? null : reader.GetString(23), - CTinytext = reader.IsDBNull(24) ? null : reader.GetString(24), - CMediumtext = reader.IsDBNull(25) ? null : reader.GetString(25), - CText = reader.IsDBNull(26) ? null : reader.GetString(26), - CLongtext = reader.IsDBNull(27) ? null : reader.GetString(27), - CJson = reader.IsDBNull(28) ? (JsonElement? )null : JsonSerializer.Deserialize(reader.GetString(28)), - CJsonStringOverride = reader.IsDBNull(29) ? null : reader.GetString(29), - CEnum = reader.IsDBNull(30) ? (MysqlTypesCEnum? )null : reader.GetString(30).ToMysqlTypesCEnum(), - CSet = reader.IsDBNull(31) ? null : reader.GetString(31).ToMysqlTypesCSetArr(), - CBit = reader.IsDBNull(32) ? (byte? )null : reader.GetFieldValue(32), - CBinary = reader.IsDBNull(33) ? null : reader.GetFieldValue(33), - CVarbinary = reader.IsDBNull(34) ? null : reader.GetFieldValue(34), - CTinyblob = reader.IsDBNull(35) ? null : reader.GetFieldValue(35), - CBlob = reader.IsDBNull(36) ? null : reader.GetFieldValue(36), - CMediumblob = reader.IsDBNull(37) ? null : reader.GetFieldValue(37), - CLongblob = reader.IsDBNull(38) ? null : reader.GetFieldValue(38) + CDoublePrecision = reader.IsDBNull(14) ? (double? )null : reader.GetDouble(14) }; } } @@ -1156,13 +1089,12 @@ public async Task GetMysqlTypes() return null; } - private const string GetMysqlTypesCntSql = "SELECT COUNT(1) AS cnt, c_bool, c_boolean, c_bit, 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, 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, c_year, c_date, c_datetime, c_timestamp, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_types GROUP BY c_bool , c_boolean, c_bit, 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, 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, c_year, c_date, c_datetime, c_timestamp, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob LIMIT 1 "; - public class GetMysqlTypesCntRow + 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; } public bool? CBool { get; set; } public bool? CBoolean { get; set; } - public byte? CBit { get; set; } public short? CTinyint { get; set; } public short? CSmallint { get; set; } public int? CMediumint { get; set; } @@ -1176,83 +1108,38 @@ public class GetMysqlTypesCntRow public decimal? CFixed { get; set; } public double? CDouble { get; set; } public double? CDoublePrecision { get; set; } - public string CChar { get; set; } - public string CNchar { get; set; } - public string CNationalChar { get; set; } - public string CVarchar { get; set; } - public string CTinytext { get; set; } - public string CMediumtext { get; set; } - public string CText { get; set; } - public string CLongtext { get; set; } - public JsonElement? CJson { get; set; } - public string CJsonStringOverride { get; set; } - public MysqlTypesCEnum? CEnum { get; set; } - public MysqlTypesCSet[] CSet { get; set; } - public short? CYear { get; set; } - public DateTime? CDate { get; set; } - public DateTime? CDatetime { get; set; } - public DateTime? CTimestamp { get; set; } - public byte[] CBinary { get; set; } - public byte[] CVarbinary { get; set; } - public byte[] CTinyblob { get; set; } - public byte[] CBlob { get; set; } - public byte[] CMediumblob { get; set; } - public byte[] CLongblob { get; set; } }; - public async Task GetMysqlTypesCnt() + public async Task GetMysqlNumericTypesCnt() { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { await connection.OpenAsync(); - using (var command = new MySqlCommand(GetMysqlTypesCntSql, connection)) + using (var command = new MySqlCommand(GetMysqlNumericTypesCntSql, connection)) { using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetMysqlTypesCntRow + return new GetMysqlNumericTypesCntRow { Cnt = reader.GetInt64(0), CBool = reader.IsDBNull(1) ? (bool? )null : reader.GetBoolean(1), CBoolean = reader.IsDBNull(2) ? (bool? )null : reader.GetBoolean(2), - CBit = reader.IsDBNull(3) ? (byte? )null : reader.GetFieldValue(3), - CTinyint = reader.IsDBNull(4) ? (short? )null : reader.GetInt16(4), - CSmallint = reader.IsDBNull(5) ? (short? )null : reader.GetInt16(5), - CMediumint = reader.IsDBNull(6) ? (int? )null : reader.GetInt32(6), - CInt = reader.IsDBNull(7) ? (int? )null : reader.GetInt32(7), - CInteger = reader.IsDBNull(8) ? (int? )null : reader.GetInt32(8), - CBigint = reader.IsDBNull(9) ? (long? )null : reader.GetInt64(9), - CFloat = reader.IsDBNull(10) ? (double? )null : reader.GetDouble(10), - CNumeric = reader.IsDBNull(11) ? (decimal? )null : reader.GetDecimal(11), - CDecimal = reader.IsDBNull(12) ? (decimal? )null : reader.GetDecimal(12), - CDec = reader.IsDBNull(13) ? (decimal? )null : reader.GetDecimal(13), - CFixed = reader.IsDBNull(14) ? (decimal? )null : reader.GetDecimal(14), - CDouble = reader.IsDBNull(15) ? (double? )null : reader.GetDouble(15), - CDoublePrecision = reader.IsDBNull(16) ? (double? )null : reader.GetDouble(16), - CChar = reader.IsDBNull(17) ? null : reader.GetString(17), - CNchar = reader.IsDBNull(18) ? null : reader.GetString(18), - CNationalChar = reader.IsDBNull(19) ? null : reader.GetString(19), - CVarchar = reader.IsDBNull(20) ? null : reader.GetString(20), - CTinytext = reader.IsDBNull(21) ? null : reader.GetString(21), - CMediumtext = reader.IsDBNull(22) ? null : reader.GetString(22), - CText = reader.IsDBNull(23) ? null : reader.GetString(23), - CLongtext = reader.IsDBNull(24) ? null : reader.GetString(24), - CJson = reader.IsDBNull(25) ? (JsonElement? )null : JsonSerializer.Deserialize(reader.GetString(25)), - CJsonStringOverride = reader.IsDBNull(26) ? null : reader.GetString(26), - CEnum = reader.IsDBNull(27) ? (MysqlTypesCEnum? )null : reader.GetString(27).ToMysqlTypesCEnum(), - CSet = reader.IsDBNull(28) ? null : reader.GetString(28).ToMysqlTypesCSetArr(), - CYear = reader.IsDBNull(29) ? (short? )null : reader.GetInt16(29), - CDate = reader.IsDBNull(30) ? (DateTime? )null : reader.GetDateTime(30), - CDatetime = reader.IsDBNull(31) ? (DateTime? )null : reader.GetDateTime(31), - CTimestamp = reader.IsDBNull(32) ? (DateTime? )null : reader.GetDateTime(32), - CBinary = reader.IsDBNull(33) ? null : reader.GetFieldValue(33), - CVarbinary = reader.IsDBNull(34) ? null : reader.GetFieldValue(34), - CTinyblob = reader.IsDBNull(35) ? null : reader.GetFieldValue(35), - CBlob = reader.IsDBNull(36) ? null : reader.GetFieldValue(36), - CMediumblob = reader.IsDBNull(37) ? null : reader.GetFieldValue(37), - CLongblob = reader.IsDBNull(38) ? null : reader.GetFieldValue(38) + CTinyint = reader.IsDBNull(3) ? (short? )null : reader.GetInt16(3), + CSmallint = reader.IsDBNull(4) ? (short? )null : reader.GetInt16(4), + CMediumint = reader.IsDBNull(5) ? (int? )null : reader.GetInt32(5), + CInt = reader.IsDBNull(6) ? (int? )null : reader.GetInt32(6), + CInteger = reader.IsDBNull(7) ? (int? )null : reader.GetInt32(7), + CBigint = reader.IsDBNull(8) ? (long? )null : reader.GetInt64(8), + CFloat = reader.IsDBNull(9) ? (double? )null : reader.GetDouble(9), + CNumeric = reader.IsDBNull(10) ? (decimal? )null : reader.GetDecimal(10), + CDecimal = reader.IsDBNull(11) ? (decimal? )null : reader.GetDecimal(11), + CDec = reader.IsDBNull(12) ? (decimal? )null : reader.GetDecimal(12), + CFixed = reader.IsDBNull(13) ? (decimal? )null : reader.GetDecimal(13), + CDouble = reader.IsDBNull(14) ? (double? )null : reader.GetDouble(14), + CDoublePrecision = reader.IsDBNull(15) ? (double? )null : reader.GetDouble(15) }; } } @@ -1263,59 +1150,33 @@ public async Task GetMysqlTypesCnt() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = GetMysqlTypesCntSql; + command.CommandText = GetMysqlNumericTypesCntSql; command.Transaction = this.Transaction; using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetMysqlTypesCntRow + return new GetMysqlNumericTypesCntRow { Cnt = reader.GetInt64(0), CBool = reader.IsDBNull(1) ? (bool? )null : reader.GetBoolean(1), CBoolean = reader.IsDBNull(2) ? (bool? )null : reader.GetBoolean(2), - CBit = reader.IsDBNull(3) ? (byte? )null : reader.GetFieldValue(3), - CTinyint = reader.IsDBNull(4) ? (short? )null : reader.GetInt16(4), - CSmallint = reader.IsDBNull(5) ? (short? )null : reader.GetInt16(5), - CMediumint = reader.IsDBNull(6) ? (int? )null : reader.GetInt32(6), - CInt = reader.IsDBNull(7) ? (int? )null : reader.GetInt32(7), - CInteger = reader.IsDBNull(8) ? (int? )null : reader.GetInt32(8), - CBigint = reader.IsDBNull(9) ? (long? )null : reader.GetInt64(9), - CFloat = reader.IsDBNull(10) ? (double? )null : reader.GetDouble(10), - CNumeric = reader.IsDBNull(11) ? (decimal? )null : reader.GetDecimal(11), - CDecimal = reader.IsDBNull(12) ? (decimal? )null : reader.GetDecimal(12), - CDec = reader.IsDBNull(13) ? (decimal? )null : reader.GetDecimal(13), - CFixed = reader.IsDBNull(14) ? (decimal? )null : reader.GetDecimal(14), - CDouble = reader.IsDBNull(15) ? (double? )null : reader.GetDouble(15), - CDoublePrecision = reader.IsDBNull(16) ? (double? )null : reader.GetDouble(16), - CChar = reader.IsDBNull(17) ? null : reader.GetString(17), - CNchar = reader.IsDBNull(18) ? null : reader.GetString(18), - CNationalChar = reader.IsDBNull(19) ? null : reader.GetString(19), - CVarchar = reader.IsDBNull(20) ? null : reader.GetString(20), - CTinytext = reader.IsDBNull(21) ? null : reader.GetString(21), - CMediumtext = reader.IsDBNull(22) ? null : reader.GetString(22), - CText = reader.IsDBNull(23) ? null : reader.GetString(23), - CLongtext = reader.IsDBNull(24) ? null : reader.GetString(24), - CJson = reader.IsDBNull(25) ? (JsonElement? )null : JsonSerializer.Deserialize(reader.GetString(25)), - CJsonStringOverride = reader.IsDBNull(26) ? null : reader.GetString(26), - CEnum = reader.IsDBNull(27) ? (MysqlTypesCEnum? )null : reader.GetString(27).ToMysqlTypesCEnum(), - CSet = reader.IsDBNull(28) ? null : reader.GetString(28).ToMysqlTypesCSetArr(), - CYear = reader.IsDBNull(29) ? (short? )null : reader.GetInt16(29), - CDate = reader.IsDBNull(30) ? (DateTime? )null : reader.GetDateTime(30), - CDatetime = reader.IsDBNull(31) ? (DateTime? )null : reader.GetDateTime(31), - CTimestamp = reader.IsDBNull(32) ? (DateTime? )null : reader.GetDateTime(32), - CBinary = reader.IsDBNull(33) ? null : reader.GetFieldValue(33), - CVarbinary = reader.IsDBNull(34) ? null : reader.GetFieldValue(34), - CTinyblob = reader.IsDBNull(35) ? null : reader.GetFieldValue(35), - CBlob = reader.IsDBNull(36) ? null : reader.GetFieldValue(36), - CMediumblob = reader.IsDBNull(37) ? null : reader.GetFieldValue(37), - CLongblob = reader.IsDBNull(38) ? null : reader.GetFieldValue(38) + CTinyint = reader.IsDBNull(3) ? (short? )null : reader.GetInt16(3), + CSmallint = reader.IsDBNull(4) ? (short? )null : reader.GetInt16(4), + CMediumint = reader.IsDBNull(5) ? (int? )null : reader.GetInt32(5), + CInt = reader.IsDBNull(6) ? (int? )null : reader.GetInt32(6), + CInteger = reader.IsDBNull(7) ? (int? )null : reader.GetInt32(7), + CBigint = reader.IsDBNull(8) ? (long? )null : reader.GetInt64(8), + CFloat = reader.IsDBNull(9) ? (double? )null : reader.GetDouble(9), + CNumeric = reader.IsDBNull(10) ? (decimal? )null : reader.GetDecimal(10), + CDecimal = reader.IsDBNull(11) ? (decimal? )null : reader.GetDecimal(11), + CDec = reader.IsDBNull(12) ? (decimal? )null : reader.GetDecimal(12), + CFixed = reader.IsDBNull(13) ? (decimal? )null : reader.GetDecimal(13), + CDouble = reader.IsDBNull(14) ? (double? )null : reader.GetDouble(14), + CDoublePrecision = reader.IsDBNull(15) ? (double? )null : reader.GetDouble(15) }; } } @@ -1324,76 +1185,70 @@ public async Task GetMysqlTypesCnt() return null; } - 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_types "; - public class GetMysqlFunctionsRow - { - public int? MaxInt { get; set; } - public string MaxVarchar { get; set; } - public DateTime MaxTimestamp { get; set; } - }; - public async Task GetMysqlFunctions() + private const string TruncateMysqlNumericTypesSql = "TRUNCATE TABLE mysql_numeric_types"; + public async Task TruncateMysqlNumericTypes() { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { await connection.OpenAsync(); - using (var command = new MySqlCommand(GetMysqlFunctionsSql, connection)) + using (var command = new MySqlCommand(TruncateMysqlNumericTypesSql, connection)) { - using (var reader = await command.ExecuteReaderAsync()) - { - if (await reader.ReadAsync()) - { - return new GetMysqlFunctionsRow - { - MaxInt = reader.IsDBNull(0) ? (int? )null : reader.GetInt32(0), - MaxVarchar = reader.IsDBNull(1) ? null : reader.GetString(1), - MaxTimestamp = reader.GetDateTime(2) - }; - } - } + await command.ExecuteNonQueryAsync(); } } - return null; + return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = GetMysqlFunctionsSql; + command.CommandText = TruncateMysqlNumericTypesSql; command.Transaction = this.Transaction; - using (var reader = await command.ExecuteReaderAsync()) - { - if (await reader.ReadAsync()) - { - return new GetMysqlFunctionsRow - { - MaxInt = reader.IsDBNull(0) ? (int? )null : reader.GetInt32(0), - MaxVarchar = reader.IsDBNull(1) ? null : reader.GetString(1), - MaxTimestamp = reader.GetDateTime(2) - }; - } - } + await command.ExecuteNonQueryAsync(); } - - return null; } - private const string TruncateMysqlTypesSql = "TRUNCATE TABLE mysql_types"; - public async Task TruncateMysqlTypes() + 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; } + public string CNchar { get; set; } + public string CNationalChar { get; set; } + public string CVarchar { get; set; } + public string CTinytext { get; set; } + public string CMediumtext { get; set; } + public string CText { get; set; } + public string CLongtext { get; set; } + public JsonElement? CJson { get; set; } + public string CJsonStringOverride { get; set; } + public MysqlStringTypesCEnum? CEnum { get; set; } + public HashSet CSet { get; set; } + }; + public async Task InsertMysqlStringTypes(InsertMysqlStringTypesArgs args) { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { await connection.OpenAsync(); - using (var command = new MySqlCommand(TruncateMysqlTypesSql, connection)) + using (var command = new MySqlCommand(InsertMysqlStringTypesSql, connection)) { + command.Parameters.AddWithValue("@c_char", args.CChar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_nchar", args.CNchar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_national_char", args.CNationalChar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_varchar", args.CVarchar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_tinytext", args.CTinytext ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_mediumtext", args.CMediumtext ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_text", args.CText ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_longtext", args.CLongtext ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_json", args.CJson?.GetRawText() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_json_string_override", args.CJsonStringOverride ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_enum", args.CEnum ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_set", args.CSet != null ? string.Join(",", args.CSet) : (object)DBNull.Value); await command.ExecuteNonQueryAsync(); } } @@ -1402,95 +1257,133 @@ public async Task TruncateMysqlTypes() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = TruncateMysqlTypesSql; + command.CommandText = InsertMysqlStringTypesSql; command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@c_char", args.CChar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_nchar", args.CNchar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_national_char", args.CNationalChar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_varchar", args.CVarchar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_tinytext", args.CTinytext ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_mediumtext", args.CMediumtext ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_text", args.CText ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_longtext", args.CLongtext ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_json", args.CJson?.GetRawText() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_json_string_override", args.CJsonStringOverride ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_enum", args.CEnum ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_set", args.CSet != null ? string.Join(",", args.CSet) : (object)DBNull.Value); await command.ExecuteNonQueryAsync(); } } - private const string CreateExtendedBioSql = "INSERT INTO extended.bios (author_name, name, bio_type, author_type) VALUES (@author_name, @name, @bio_type, @author_type)"; - public class CreateExtendedBioArgs + public class InsertMysqlStringTypesBatchArgs { - public string AuthorName { get; set; } - public string Name { get; set; } - public ExtendedBiosBioType? BioType { get; set; } - public ExtendedBiosAuthorType[] AuthorType { get; set; } + public string CChar { get; set; } + public string CNchar { get; set; } + public string CNationalChar { get; set; } + public string CVarchar { get; set; } + public string CTinytext { get; set; } + public string CMediumtext { get; set; } + public string CText { get; set; } + public string CLongtext { get; set; } + public JsonElement? CJson { get; set; } + public string CJsonStringOverride { get; set; } + public MysqlStringTypesCEnum? CEnum { get; set; } + public HashSet CSet { get; set; } }; - public async Task CreateExtendedBio(CreateExtendedBioArgs args) + public async Task InsertMysqlStringTypesBatch(List args) { - if (this.Transaction == null) + const string supportedDateTimeFormat = "yyyy-MM-dd H:mm:ss"; + var config = new CsvConfiguration(CultureInfo.CurrentCulture) { - using (var connection = new MySqlConnection(ConnectionString)) + Delimiter = ",", + NewLine = "\n" + }; + var nullConverterFn = new Utils.NullToStringCsvConverter(); + using (var writer = new StreamWriter("input.csv", false, new UTF8Encoding(false))) + using (var csvWriter = new CsvWriter(writer, config)) + { + var options = new TypeConverterOptions { - await connection.OpenAsync(); - using (var command = new MySqlCommand(CreateExtendedBioSql, connection)) + Formats = new[] { - command.Parameters.AddWithValue("@author_name", args.AuthorName ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@name", args.Name ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@bio_type", args.BioType ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@author_type", args.AuthorType != null ? string.Join(",", args.AuthorType) : (object)DBNull.Value); - await command.ExecuteNonQueryAsync(); + supportedDateTimeFormat } - } - - return; - } - - if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + }; + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterCache.AddConverter>(new Utils.MysqlStringTypesCSetCsvConverter()); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + await csvWriter.WriteRecordsAsync(args); } - using (var command = this.Transaction.Connection.CreateCommand()) + using (var connection = new MySqlConnection(ConnectionString)) { - command.CommandText = CreateExtendedBioSql; - command.Transaction = this.Transaction; - command.Parameters.AddWithValue("@author_name", args.AuthorName ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@name", args.Name ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@bio_type", args.BioType ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@author_type", args.AuthorType != null ? string.Join(",", args.AuthorType) : (object)DBNull.Value); - await command.ExecuteNonQueryAsync(); + await connection.OpenAsync(); + var loader = new MySqlBulkLoader(connection) + { + Local = true, + TableName = "mysql_string_types", + FileName = "input.csv", + FieldTerminator = ",", + FieldQuotationCharacter = '"', + FieldQuotationOptional = true, + NumberOfLinesToSkip = 1, + LineTerminator = "\n" + }; + loader.Columns.AddRange(new List { "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" }); + await loader.LoadAsync(); + await connection.CloseAsync(); } } - private const string GetFirstExtendedBioByTypeSql = "SELECT author_name, name, bio_type, author_type FROM extended.bios WHERE bio_type = @bio_type LIMIT 1"; - public class GetFirstExtendedBioByTypeRow + private const string GetMysqlStringTypesSql = "SELECT 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 LIMIT 1"; + public class GetMysqlStringTypesRow { - public string AuthorName { get; set; } - public string Name { get; set; } - public ExtendedBiosBioType? BioType { get; set; } - public ExtendedBiosAuthorType[] AuthorType { get; set; } - }; - public class GetFirstExtendedBioByTypeArgs - { - public ExtendedBiosBioType? BioType { get; set; } + public string CChar { get; set; } + public string CNchar { get; set; } + public string CNationalChar { get; set; } + public string CVarchar { get; set; } + public string CTinytext { get; set; } + public string CMediumtext { get; set; } + public string CText { get; set; } + public string CLongtext { get; set; } + public JsonElement? CJson { get; set; } + public string CJsonStringOverride { get; set; } + public MysqlStringTypesCEnum? CEnum { get; set; } + public HashSet CSet { get; set; } }; - public async Task GetFirstExtendedBioByType(GetFirstExtendedBioByTypeArgs args) + public async Task GetMysqlStringTypes() { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { await connection.OpenAsync(); - using (var command = new MySqlCommand(GetFirstExtendedBioByTypeSql, connection)) + using (var command = new MySqlCommand(GetMysqlStringTypesSql, connection)) { - command.Parameters.AddWithValue("@bio_type", args.BioType ?? (object)DBNull.Value); using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetFirstExtendedBioByTypeRow + return new GetMysqlStringTypesRow { - AuthorName = reader.IsDBNull(0) ? null : reader.GetString(0), - Name = reader.IsDBNull(1) ? null : reader.GetString(1), - BioType = reader.IsDBNull(2) ? (ExtendedBiosBioType? )null : reader.GetString(2).ToExtendedBiosBioType(), - AuthorType = reader.IsDBNull(3) ? null : reader.GetString(3).ToExtendedBiosAuthorTypeArr() + CChar = reader.IsDBNull(0) ? null : reader.GetString(0), + CNchar = reader.IsDBNull(1) ? null : reader.GetString(1), + CNationalChar = reader.IsDBNull(2) ? null : reader.GetString(2), + CVarchar = reader.IsDBNull(3) ? null : reader.GetString(3), + CTinytext = reader.IsDBNull(4) ? null : reader.GetString(4), + CMediumtext = reader.IsDBNull(5) ? null : reader.GetString(5), + CText = reader.IsDBNull(6) ? null : reader.GetString(6), + CLongtext = reader.IsDBNull(7) ? null : reader.GetString(7), + CJson = reader.IsDBNull(8) ? (JsonElement? )null : JsonSerializer.Deserialize(reader.GetString(8)), + CJsonStringOverride = reader.IsDBNull(9) ? null : reader.GetString(9), + CEnum = reader.IsDBNull(10) ? (MysqlStringTypesCEnum? )null : reader.GetString(10).ToMysqlStringTypesCEnum(), + CSet = reader.IsDBNull(11) ? null : reader.GetString(11).ToMysqlStringTypesCSetSet() }; } } @@ -1501,25 +1394,29 @@ public async Task GetFirstExtendedBioByType(GetFir } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = GetFirstExtendedBioByTypeSql; + command.CommandText = GetMysqlStringTypesSql; command.Transaction = this.Transaction; - command.Parameters.AddWithValue("@bio_type", args.BioType ?? (object)DBNull.Value); using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetFirstExtendedBioByTypeRow + return new GetMysqlStringTypesRow { - AuthorName = reader.IsDBNull(0) ? null : reader.GetString(0), - Name = reader.IsDBNull(1) ? null : reader.GetString(1), - BioType = reader.IsDBNull(2) ? (ExtendedBiosBioType? )null : reader.GetString(2).ToExtendedBiosBioType(), - AuthorType = reader.IsDBNull(3) ? null : reader.GetString(3).ToExtendedBiosAuthorTypeArr() + CChar = reader.IsDBNull(0) ? null : reader.GetString(0), + CNchar = reader.IsDBNull(1) ? null : reader.GetString(1), + CNationalChar = reader.IsDBNull(2) ? null : reader.GetString(2), + CVarchar = reader.IsDBNull(3) ? null : reader.GetString(3), + CTinytext = reader.IsDBNull(4) ? null : reader.GetString(4), + CMediumtext = reader.IsDBNull(5) ? null : reader.GetString(5), + CText = reader.IsDBNull(6) ? null : reader.GetString(6), + CLongtext = reader.IsDBNull(7) ? null : reader.GetString(7), + CJson = reader.IsDBNull(8) ? (JsonElement? )null : JsonSerializer.Deserialize(reader.GetString(8)), + CJsonStringOverride = reader.IsDBNull(9) ? null : reader.GetString(9), + CEnum = reader.IsDBNull(10) ? (MysqlStringTypesCEnum? )null : reader.GetString(10).ToMysqlStringTypesCEnum(), + CSet = reader.IsDBNull(11) ? null : reader.GetString(11).ToMysqlStringTypesCSetSet() }; } } @@ -1528,34 +1425,707 @@ public async Task GetFirstExtendedBioByType(GetFir return null; } - private const string TruncateExtendedBiosSql = "TRUNCATE TABLE extended.bios"; - public async Task TruncateExtendedBios() + 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; } + public string CChar { get; set; } + public string CNchar { get; set; } + public string CNationalChar { get; set; } + public string CVarchar { get; set; } + public string CTinytext { get; set; } + public string CMediumtext { get; set; } + public string CText { get; set; } + public string CLongtext { get; set; } + public JsonElement? CJson { get; set; } + public string CJsonStringOverride { get; set; } + public MysqlStringTypesCEnum? CEnum { get; set; } + public HashSet CSet { get; set; } + }; + public async Task GetMysqlStringTypesCnt() { if (this.Transaction == null) { using (var connection = new MySqlConnection(ConnectionString)) { await connection.OpenAsync(); - using (var command = new MySqlCommand(TruncateExtendedBiosSql, connection)) + using (var command = new MySqlCommand(GetMysqlStringTypesCntSql, connection)) { - await command.ExecuteNonQueryAsync(); - } + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlStringTypesCntRow + { + Cnt = reader.GetInt64(0), + CChar = reader.IsDBNull(1) ? null : reader.GetString(1), + CNchar = reader.IsDBNull(2) ? null : reader.GetString(2), + CNationalChar = reader.IsDBNull(3) ? null : reader.GetString(3), + CVarchar = reader.IsDBNull(4) ? null : reader.GetString(4), + CTinytext = reader.IsDBNull(5) ? null : reader.GetString(5), + CMediumtext = reader.IsDBNull(6) ? null : reader.GetString(6), + CText = reader.IsDBNull(7) ? null : reader.GetString(7), + CLongtext = reader.IsDBNull(8) ? null : reader.GetString(8), + CJson = reader.IsDBNull(9) ? (JsonElement? )null : JsonSerializer.Deserialize(reader.GetString(9)), + CJsonStringOverride = reader.IsDBNull(10) ? null : reader.GetString(10), + CEnum = reader.IsDBNull(11) ? (MysqlStringTypesCEnum? )null : reader.GetString(11).ToMysqlStringTypesCEnum(), + CSet = reader.IsDBNull(12) ? null : reader.GetString(12).ToMysqlStringTypesCSetSet() + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetMysqlStringTypesCntSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlStringTypesCntRow + { + Cnt = reader.GetInt64(0), + CChar = reader.IsDBNull(1) ? null : reader.GetString(1), + CNchar = reader.IsDBNull(2) ? null : reader.GetString(2), + CNationalChar = reader.IsDBNull(3) ? null : reader.GetString(3), + CVarchar = reader.IsDBNull(4) ? null : reader.GetString(4), + CTinytext = reader.IsDBNull(5) ? null : reader.GetString(5), + CMediumtext = reader.IsDBNull(6) ? null : reader.GetString(6), + CText = reader.IsDBNull(7) ? null : reader.GetString(7), + CLongtext = reader.IsDBNull(8) ? null : reader.GetString(8), + CJson = reader.IsDBNull(9) ? (JsonElement? )null : JsonSerializer.Deserialize(reader.GetString(9)), + CJsonStringOverride = reader.IsDBNull(10) ? null : reader.GetString(10), + CEnum = reader.IsDBNull(11) ? (MysqlStringTypesCEnum? )null : reader.GetString(11).ToMysqlStringTypesCEnum(), + CSet = reader.IsDBNull(12) ? null : reader.GetString(12).ToMysqlStringTypesCSetSet() + }; + } + } + } + + return null; + } + + private const string TruncateMysqlStringTypesSql = "TRUNCATE TABLE mysql_string_types"; + public async Task TruncateMysqlStringTypes() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(TruncateMysqlStringTypesSql, connection)) + { + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncateMysqlStringTypesSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } + + private const string InsertMysqlDatetimeTypesSql = " INSERT INTO mysql_datetime_types ( c_year, c_date, c_datetime, c_timestamp, c_time ) VALUES (@c_year, @c_date, @c_datetime, @c_timestamp, @c_time)"; + public class InsertMysqlDatetimeTypesArgs + { + public short? CYear { get; set; } + public DateTime? CDate { get; set; } + public DateTime? CDatetime { get; set; } + public DateTime? CTimestamp { get; set; } + public TimeSpan? CTime { get; set; } + }; + public async Task InsertMysqlDatetimeTypes(InsertMysqlDatetimeTypesArgs args) + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(InsertMysqlDatetimeTypesSql, connection)) + { + command.Parameters.AddWithValue("@c_year", args.CYear ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_date", args.CDate ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_datetime", args.CDatetime ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_timestamp", args.CTimestamp ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_time", args.CTime ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = InsertMysqlDatetimeTypesSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@c_year", args.CYear ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_date", args.CDate ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_datetime", args.CDatetime ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_timestamp", args.CTimestamp ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_time", args.CTime ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + public class InsertMysqlDatetimeTypesBatchArgs + { + public short? CYear { get; set; } + public DateTime? CDate { get; set; } + public DateTime? CDatetime { get; set; } + public DateTime? CTimestamp { get; set; } + public TimeSpan? CTime { get; set; } + }; + public async Task InsertMysqlDatetimeTypesBatch(List args) + { + const string supportedDateTimeFormat = "yyyy-MM-dd H:mm:ss"; + var config = new CsvConfiguration(CultureInfo.CurrentCulture) + { + Delimiter = ",", + NewLine = "\n" + }; + var nullConverterFn = new Utils.NullToStringCsvConverter(); + using (var writer = new StreamWriter("input.csv", false, new UTF8Encoding(false))) + using (var csvWriter = new CsvWriter(writer, config)) + { + var options = new TypeConverterOptions + { + Formats = new[] + { + supportedDateTimeFormat + } + }; + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + csvWriter.Context.TypeConverterCache.AddConverter(nullConverterFn); + await csvWriter.WriteRecordsAsync(args); + } + + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + var loader = new MySqlBulkLoader(connection) + { + Local = true, + TableName = "mysql_datetime_types", + FileName = "input.csv", + FieldTerminator = ",", + FieldQuotationCharacter = '"', + FieldQuotationOptional = true, + NumberOfLinesToSkip = 1, + LineTerminator = "\n" + }; + loader.Columns.AddRange(new List { "c_year", "c_date", "c_datetime", "c_timestamp", "c_time" }); + await loader.LoadAsync(); + await connection.CloseAsync(); + } + } + + private const string GetMysqlDatetimeTypesSql = "SELECT c_year, c_date, c_datetime, c_timestamp, c_time FROM mysql_datetime_types LIMIT 1"; + public class GetMysqlDatetimeTypesRow + { + public short? CYear { get; set; } + public DateTime? CDate { get; set; } + public DateTime? CDatetime { get; set; } + public DateTime? CTimestamp { get; set; } + public TimeSpan? CTime { get; set; } + }; + public async Task GetMysqlDatetimeTypes() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(GetMysqlDatetimeTypesSql, connection)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlDatetimeTypesRow + { + CYear = reader.IsDBNull(0) ? (short? )null : reader.GetInt16(0), + CDate = reader.IsDBNull(1) ? (DateTime? )null : reader.GetDateTime(1), + CDatetime = reader.IsDBNull(2) ? (DateTime? )null : reader.GetDateTime(2), + CTimestamp = reader.IsDBNull(3) ? (DateTime? )null : reader.GetDateTime(3), + CTime = reader.IsDBNull(4) ? (TimeSpan? )null : reader.GetFieldValue(4) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetMysqlDatetimeTypesSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlDatetimeTypesRow + { + CYear = reader.IsDBNull(0) ? (short? )null : reader.GetInt16(0), + CDate = reader.IsDBNull(1) ? (DateTime? )null : reader.GetDateTime(1), + CDatetime = reader.IsDBNull(2) ? (DateTime? )null : reader.GetDateTime(2), + CTimestamp = reader.IsDBNull(3) ? (DateTime? )null : reader.GetDateTime(3), + CTime = reader.IsDBNull(4) ? (TimeSpan? )null : reader.GetFieldValue(4) + }; + } + } + } + + 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"; + public class GetMysqlDatetimeTypesCntRow + { + public long Cnt { get; set; } + public short? CYear { get; set; } + public DateTime? CDate { get; set; } + public DateTime? CDatetime { get; set; } + public DateTime? CTimestamp { get; set; } + public TimeSpan? CTime { get; set; } + }; + public async Task GetMysqlDatetimeTypesCnt() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(GetMysqlDatetimeTypesCntSql, connection)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlDatetimeTypesCntRow + { + Cnt = reader.GetInt64(0), + CYear = reader.IsDBNull(1) ? (short? )null : reader.GetInt16(1), + CDate = reader.IsDBNull(2) ? (DateTime? )null : reader.GetDateTime(2), + CDatetime = reader.IsDBNull(3) ? (DateTime? )null : reader.GetDateTime(3), + CTimestamp = reader.IsDBNull(4) ? (DateTime? )null : reader.GetDateTime(4), + CTime = reader.IsDBNull(5) ? (TimeSpan? )null : reader.GetFieldValue(5) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetMysqlDatetimeTypesCntSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlDatetimeTypesCntRow + { + Cnt = reader.GetInt64(0), + CYear = reader.IsDBNull(1) ? (short? )null : reader.GetInt16(1), + CDate = reader.IsDBNull(2) ? (DateTime? )null : reader.GetDateTime(2), + CDatetime = reader.IsDBNull(3) ? (DateTime? )null : reader.GetDateTime(3), + CTimestamp = reader.IsDBNull(4) ? (DateTime? )null : reader.GetDateTime(4), + CTime = reader.IsDBNull(5) ? (TimeSpan? )null : reader.GetFieldValue(5) + }; + } + } + } + + return null; + } + + private const string TruncateMysqlDatetimeTypesSql = "TRUNCATE TABLE mysql_datetime_types"; + public async Task TruncateMysqlDatetimeTypes() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(TruncateMysqlDatetimeTypesSql, connection)) + { + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncateMysqlDatetimeTypesSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } + + 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; } + public byte[] CBinary { get; set; } + public byte[] CVarbinary { get; set; } + public byte[] CTinyblob { get; set; } + public byte[] CBlob { get; set; } + public byte[] CMediumblob { get; set; } + public byte[] CLongblob { get; set; } + }; + public async Task InsertMysqlBinaryTypes(InsertMysqlBinaryTypesArgs args) + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(InsertMysqlBinaryTypesSql, connection)) + { + command.Parameters.AddWithValue("@c_bit", args.CBit ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_binary", args.CBinary ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_varbinary", args.CVarbinary ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_tinyblob", args.CTinyblob ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_blob", args.CBlob ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_mediumblob", args.CMediumblob ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_longblob", args.CLongblob ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } } return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = InsertMysqlBinaryTypesSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@c_bit", args.CBit ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_binary", args.CBinary ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_varbinary", args.CVarbinary ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_tinyblob", args.CTinyblob ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_blob", args.CBlob ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_mediumblob", args.CMediumblob ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_longblob", args.CLongblob ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + public class InsertMysqlBinaryTypesBatchArgs + { + public byte? CBit { get; set; } + public byte[] CBinary { get; set; } + public byte[] CVarbinary { get; set; } + public byte[] CTinyblob { get; set; } + public byte[] CBlob { get; set; } + public byte[] CMediumblob { get; set; } + public byte[] CLongblob { get; set; } + }; + public async Task InsertMysqlBinaryTypesBatch(List args) + { + const string supportedDateTimeFormat = "yyyy-MM-dd H:mm:ss"; + var config = new CsvConfiguration(CultureInfo.CurrentCulture) + { + Delimiter = ",", + NewLine = "\n" + }; + var nullConverterFn = new Utils.NullToStringCsvConverter(); + using (var writer = new StreamWriter("input.csv", false, new UTF8Encoding(false))) + using (var csvWriter = new CsvWriter(writer, config)) + { + var options = new TypeConverterOptions + { + Formats = new[] + { + supportedDateTimeFormat + } + }; + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterOptionsCache.AddOptions(options); + csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteCsvConverter()); + csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteCsvConverter()); + csvWriter.Context.TypeConverterCache.AddConverter(new Utils.ByteArrayCsvConverter()); + await csvWriter.WriteRecordsAsync(args); + } + + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + var loader = new MySqlBulkLoader(connection) + { + Local = true, + TableName = "mysql_binary_types", + FileName = "input.csv", + FieldTerminator = ",", + FieldQuotationCharacter = '"', + FieldQuotationOptional = true, + NumberOfLinesToSkip = 1, + LineTerminator = "\n" + }; + loader.Columns.AddRange(new List { "c_bit", "c_binary", "c_varbinary", "c_tinyblob", "c_blob", "c_mediumblob", "c_longblob" }); + await loader.LoadAsync(); + await connection.CloseAsync(); + } + } + + private const string GetMysqlBinaryTypesSql = "SELECT c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_binary_types LIMIT 1"; + public class GetMysqlBinaryTypesRow + { + public byte? CBit { get; set; } + public byte[] CBinary { get; set; } + public byte[] CVarbinary { get; set; } + public byte[] CTinyblob { get; set; } + public byte[] CBlob { get; set; } + public byte[] CMediumblob { get; set; } + public byte[] CLongblob { get; set; } + }; + public async Task GetMysqlBinaryTypes() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(GetMysqlBinaryTypesSql, connection)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlBinaryTypesRow + { + CBit = reader.IsDBNull(0) ? (byte? )null : reader.GetFieldValue(0), + CBinary = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CVarbinary = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + CTinyblob = reader.IsDBNull(3) ? null : reader.GetFieldValue(3), + CBlob = reader.IsDBNull(4) ? null : reader.GetFieldValue(4), + CMediumblob = reader.IsDBNull(5) ? null : reader.GetFieldValue(5), + CLongblob = reader.IsDBNull(6) ? null : reader.GetFieldValue(6) + }; + } + } + } + } + + return null; } + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = TruncateExtendedBiosSql; + command.CommandText = GetMysqlBinaryTypesSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlBinaryTypesRow + { + CBit = reader.IsDBNull(0) ? (byte? )null : reader.GetFieldValue(0), + CBinary = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CVarbinary = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + CTinyblob = reader.IsDBNull(3) ? null : reader.GetFieldValue(3), + CBlob = reader.IsDBNull(4) ? null : reader.GetFieldValue(4), + CMediumblob = reader.IsDBNull(5) ? null : reader.GetFieldValue(5), + CLongblob = reader.IsDBNull(6) ? null : reader.GetFieldValue(6) + }; + } + } + } + + 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"; + public class GetMysqlBinaryTypesCntRow + { + public long Cnt { get; set; } + public byte? CBit { get; set; } + public byte[] CBinary { get; set; } + public byte[] CVarbinary { get; set; } + public byte[] CTinyblob { get; set; } + public byte[] CBlob { get; set; } + public byte[] CMediumblob { get; set; } + public byte[] CLongblob { get; set; } + }; + public async Task GetMysqlBinaryTypesCnt() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(GetMysqlBinaryTypesCntSql, connection)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlBinaryTypesCntRow + { + Cnt = reader.GetInt64(0), + CBit = reader.IsDBNull(1) ? (byte? )null : reader.GetFieldValue(1), + CBinary = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + CVarbinary = reader.IsDBNull(3) ? null : reader.GetFieldValue(3), + CTinyblob = reader.IsDBNull(4) ? null : reader.GetFieldValue(4), + CBlob = reader.IsDBNull(5) ? null : reader.GetFieldValue(5), + CMediumblob = reader.IsDBNull(6) ? null : reader.GetFieldValue(6), + CLongblob = reader.IsDBNull(7) ? null : reader.GetFieldValue(7) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetMysqlBinaryTypesCntSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlBinaryTypesCntRow + { + Cnt = reader.GetInt64(0), + CBit = reader.IsDBNull(1) ? (byte? )null : reader.GetFieldValue(1), + CBinary = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + CVarbinary = reader.IsDBNull(3) ? null : reader.GetFieldValue(3), + CTinyblob = reader.IsDBNull(4) ? null : reader.GetFieldValue(4), + CBlob = reader.IsDBNull(5) ? null : reader.GetFieldValue(5), + CMediumblob = reader.IsDBNull(6) ? null : reader.GetFieldValue(6), + CLongblob = reader.IsDBNull(7) ? null : reader.GetFieldValue(7) + }; + } + } + } + + return null; + } + + private const string TruncateMysqlBinaryTypesSql = "TRUNCATE TABLE mysql_binary_types"; + public async Task TruncateMysqlBinaryTypes() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(TruncateMysqlBinaryTypesSql, connection)) + { + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncateMysqlBinaryTypesSql; command.Transaction = this.Transaction; await command.ExecuteNonQueryAsync(); } } + + 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; } + public string MaxVarchar { get; set; } + public DateTime MaxTimestamp { get; set; } + }; + public async Task GetMysqlFunctions() + { + if (this.Transaction == null) + { + using (var connection = new MySqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var command = new MySqlCommand(GetMysqlFunctionsSql, connection)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlFunctionsRow + { + MaxInt = reader.IsDBNull(0) ? (int? )null : reader.GetInt32(0), + MaxVarchar = reader.IsDBNull(1) ? null : reader.GetString(1), + MaxTimestamp = reader.GetDateTime(2) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetMysqlFunctionsSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetMysqlFunctionsRow + { + MaxInt = reader.IsDBNull(0) ? (int? )null : reader.GetInt32(0), + MaxVarchar = reader.IsDBNull(1) ? null : reader.GetString(1), + MaxTimestamp = reader.GetDateTime(2) + }; + } + } + } + + return null; + } } } \ No newline at end of file diff --git a/examples/MySqlConnectorLegacyExample/Utils.cs b/examples/MySqlConnectorLegacyExample/Utils.cs index 2912c7ea..93f3b167 100644 --- a/examples/MySqlConnectorLegacyExample/Utils.cs +++ b/examples/MySqlConnectorLegacyExample/Utils.cs @@ -4,6 +4,7 @@ namespace MySqlConnectorLegacyExampleGen using CsvHelper; using CsvHelper.Configuration; using CsvHelper.TypeConversion; + using System.Collections.Generic; using System.Linq; public static class Utils @@ -14,14 +15,14 @@ public static string TransformQueryForSliceArgs(string originalSql, int sliceSiz return originalSql.Replace($"/*SLICE:{paramName}*/@{paramName}", string.Join(",", paramArgs)); } - public class MysqlTypesCSetCsvConverter : DefaultTypeConverter + public class MysqlStringTypesCSetCsvConverter : DefaultTypeConverter { public override string ConvertToString(object value, IWriterRow row, MemberMapData memberMapData) { if (value == null) return @"\N"; - if (value is MysqlTypesCSet[] arrVal) - return string.Join(",", arrVal); + if (value is HashSet setVal) + return string.Join(",", setVal); return base.ConvertToString(value, row, memberMapData); } } diff --git a/examples/MySqlConnectorLegacyExample/request.json b/examples/MySqlConnectorLegacyExample/request.json index 7c97aba4..350da4df 100644 --- a/examples/MySqlConnectorLegacyExample/request.json +++ b/examples/MySqlConnectorLegacyExample/request.json @@ -3,10 +3,12 @@ "version": "2", "engine": "mysql", "schema": [ - "examples/config/mysql/schema.sql" + "examples/config/mysql/authors/schema.sql", + "examples/config/mysql/types/schema.sql" ], "queries": [ - "examples/config/mysql/query.sql" + "examples/config/mysql/authors/query.sql", + "examples/config/mysql/types/query.sql" ], "codegen": { "out": "examples/MySqlConnectorLegacyExample", @@ -114,14 +116,14 @@ }, { "rel": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "columns": [ { "name": "c_bool", "length": 1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "tinyint" @@ -131,7 +133,7 @@ "name": "c_boolean", "length": 1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "tinyint" @@ -141,7 +143,7 @@ "name": "c_tinyint", "length": 3, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "tinyint" @@ -151,7 +153,7 @@ "name": "c_smallint", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "smallint" @@ -161,7 +163,7 @@ "name": "c_mediumint", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "mediumint" @@ -171,7 +173,7 @@ "name": "c_int", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "int" @@ -181,7 +183,7 @@ "name": "c_integer", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "int" @@ -191,7 +193,7 @@ "name": "c_bigint", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "bigint" @@ -201,7 +203,7 @@ "name": "c_float", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "float" @@ -211,7 +213,7 @@ "name": "c_decimal", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -221,7 +223,7 @@ "name": "c_dec", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -231,7 +233,7 @@ "name": "c_numeric", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -241,7 +243,7 @@ "name": "c_fixed", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -251,7 +253,7 @@ "name": "c_double", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "double" @@ -261,187 +263,208 @@ "name": "c_double_precision", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "double" } - }, + } + ] + }, + { + "rel": { + "name": "mysql_string_types" + }, + "columns": [ { - "name": "c_year", + "name": "c_char", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "year" + "name": "char" } }, { - "name": "c_date", + "name": "c_nchar", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "date" + "name": "char" } }, { - "name": "c_time", - "length": 10, + "name": "c_national_char", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "time" + "name": "char" } }, { - "name": "c_datetime", - "length": 19, + "name": "c_varchar", + "length": 100, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "datetime" + "name": "varchar" } }, { - "name": "c_timestamp", - "length": 19, + "name": "c_tinytext", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "timestamp" + "name": "tinytext" } }, { - "name": "c_char", + "name": "c_mediumtext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "char" + "name": "mediumtext" } }, { - "name": "c_nchar", + "name": "c_text", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "char" + "name": "text" } }, { - "name": "c_national_char", + "name": "c_longtext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "char" + "name": "longtext" } }, { - "name": "c_varchar", - "length": 100, + "name": "c_json", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "varchar" + "name": "json" } }, { - "name": "c_tinytext", + "name": "c_json_string_override", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "tinytext" + "name": "json" } }, { - "name": "c_mediumtext", - "length": -1, + "name": "c_enum", + "length": 6, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mediumtext" + "name": "mysql_string_types_c_enum" } }, { - "name": "c_text", - "length": -1, + "name": "c_set", + "length": 15, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "text" + "name": "mysql_string_types_c_set" } - }, + } + ] + }, + { + "rel": { + "name": "mysql_datetime_types" + }, + "columns": [ { - "name": "c_longtext", + "name": "c_year", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "longtext" + "name": "year" } }, { - "name": "c_json", + "name": "c_date", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "json" + "name": "date" } }, { - "name": "c_json_string_override", - "length": -1, + "name": "c_datetime", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "json" + "name": "datetime" } }, { - "name": "c_enum", - "length": 6, + "name": "c_timestamp", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "mysql_types_c_enum" + "name": "timestamp" } }, { - "name": "c_set", - "length": 15, + "name": "c_time", + "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "mysql_types_c_set" + "name": "time" } - }, + } + ] + }, + { + "rel": { + "name": "mysql_binary_types" + }, + "columns": [ { "name": "c_bit", "length": 8, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "bit" @@ -451,7 +474,7 @@ "name": "c_binary", "length": 3, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "binary" @@ -461,7 +484,7 @@ "name": "c_varbinary", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "varbinary" @@ -471,7 +494,7 @@ "name": "c_tinyblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "tinyblob" @@ -481,7 +504,7 @@ "name": "c_blob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "blob" @@ -491,7 +514,7 @@ "name": "c_mediumblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "mediumblob" @@ -501,7 +524,7 @@ "name": "c_longblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "longblob" @@ -511,22 +534,6 @@ } ], "enums": [ - { - "name": "mysql_types_c_enum", - "vals": [ - "small", - "medium", - "big" - ] - }, - { - "name": "mysql_types_c_set", - "vals": [ - "tea", - "coffee", - "milk" - ] - }, { "name": "bios_bio_type", "vals": [ @@ -542,6 +549,22 @@ "Editor", "Translator" ] + }, + { + "name": "mysql_string_types_c_enum", + "vals": [ + "small", + "medium", + "big" + ] + }, + { + "name": "mysql_string_types_c_set", + "vals": [ + "tea", + "coffee", + "milk" + ] } ] }, @@ -1306,93 +1329,229 @@ "filename": "query.sql" }, { - "text": "INSERT INTO mysql_types \n(c_bit, c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, \n c_decimal, c_dec, c_numeric, c_fixed, c_float, c_double, c_double_precision, \n c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, \n c_json, c_json_string_override, c_enum, c_set, c_year, c_date, c_datetime, c_timestamp, \n c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - "name": "InsertMysqlTypes", + "text": "INSERT INTO extended.bios (author_name, name, bio_type, author_type) VALUES (?, ?, ?, ?)", + "name": "CreateExtendedBio", "cmd": ":exec", "parameters": [ { "number": 1, "column": { - "name": "c_bit", - "length": 8, + "name": "author_name", + "length": 100, "table": { - "schema": "public", - "name": "mysql_types" + "schema": "extended", + "name": "bios" }, "type": { - "name": "bit" + "name": "varchar" }, - "originalName": "c_bit" + "originalName": "author_name" } }, { "number": 2, "column": { - "name": "c_bool", - "length": 1, + "name": "name", + "length": 100, "table": { - "schema": "public", - "name": "mysql_types" + "schema": "extended", + "name": "bios" }, "type": { - "name": "tinyint" + "name": "varchar" }, - "originalName": "c_bool" + "originalName": "name" } }, { "number": 3, "column": { - "name": "c_boolean", - "length": 1, + "name": "bio_type", + "length": 13, "table": { - "schema": "public", - "name": "mysql_types" + "schema": "extended", + "name": "bios" }, "type": { - "name": "tinyint" + "name": "bios_bio_type" }, - "originalName": "c_boolean" + "originalName": "bio_type" } }, { "number": 4, "column": { - "name": "c_tinyint", - "length": 3, + "name": "author_type", + "length": 24, "table": { - "schema": "public", - "name": "mysql_types" + "schema": "extended", + "name": "bios" }, "type": { - "name": "tinyint" + "name": "bios_author_type" }, - "originalName": "c_tinyint" + "originalName": "author_type" } + } + ], + "filename": "query.sql", + "insert_into_table": { + "schema": "extended", + "name": "bios" + } + }, + { + "text": "SELECT author_name, name, bio_type, author_type FROM extended.bios WHERE bio_type = ? LIMIT 1", + "name": "GetFirstExtendedBioByType", + "cmd": ":one", + "columns": [ + { + "name": "author_name", + "length": 100, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "varchar" + }, + "originalName": "author_name" }, { - "number": 5, + "name": "name", + "length": 100, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "varchar" + }, + "originalName": "name" + }, + { + "name": "bio_type", + "length": 13, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "bios_bio_type" + }, + "originalName": "bio_type" + }, + { + "name": "author_type", + "length": 24, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "bios_author_type" + }, + "originalName": "author_type" + } + ], + "parameters": [ + { + "number": 1, "column": { - "name": "c_smallint", - "length": -1, + "name": "bio_type", + "length": 13, "table": { - "schema": "public", - "name": "mysql_types" + "schema": "extended", + "name": "bios" }, "type": { - "name": "smallint" + "name": "bios_bio_type" }, - "originalName": "c_smallint" + "originalName": "bio_type" } - }, + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE extended.bios", + "name": "TruncateExtendedBios", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO mysql_numeric_types \n(\n c_bool,\n c_boolean,\n c_tinyint,\n c_smallint,\n c_mediumint,\n c_int,\n c_integer,\n c_bigint, \n c_decimal, \n c_dec, \n c_numeric, \n c_fixed, \n c_float, \n c_double, \n c_double_precision\n) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlNumericTypes", + "cmd": ":exec", + "parameters": [ { - "number": 6, + "number": 1, + "column": { + "name": "c_bool", + "length": 1, + "table": { + "schema": "public", + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_bool" + } + }, + { + "number": 2, + "column": { + "name": "c_boolean", + "length": 1, + "table": { + "schema": "public", + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_boolean" + } + }, + { + "number": 3, + "column": { + "name": "c_tinyint", + "length": 3, + "table": { + "schema": "public", + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_tinyint" + } + }, + { + "number": 4, + "column": { + "name": "c_smallint", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_numeric_types" + }, + "type": { + "name": "smallint" + }, + "originalName": "c_smallint" + } + }, + { + "number": 5, "column": { "name": "c_mediumint", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "mediumint" @@ -1401,13 +1560,13 @@ } }, { - "number": 7, + "number": 6, "column": { "name": "c_int", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "int" @@ -1416,13 +1575,13 @@ } }, { - "number": 8, + "number": 7, "column": { "name": "c_integer", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "int" @@ -1431,13 +1590,13 @@ } }, { - "number": 9, + "number": 8, "column": { "name": "c_bigint", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "bigint" @@ -1446,13 +1605,13 @@ } }, { - "number": 10, + "number": 9, "column": { "name": "c_decimal", "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -1461,13 +1620,13 @@ } }, { - "number": 11, + "number": 10, "column": { "name": "c_dec", "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -1476,13 +1635,13 @@ } }, { - "number": 12, + "number": 11, "column": { "name": "c_numeric", "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -1491,13 +1650,13 @@ } }, { - "number": 13, + "number": 12, "column": { "name": "c_fixed", "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "decimal" @@ -1506,13 +1665,13 @@ } }, { - "number": 14, + "number": 13, "column": { "name": "c_float", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "float" @@ -1521,13 +1680,13 @@ } }, { - "number": 15, + "number": 14, "column": { "name": "c_double", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "double" @@ -1536,609 +1695,639 @@ } }, { - "number": 16, + "number": 15, "column": { "name": "c_double_precision", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { "name": "double" }, "originalName": "c_double_precision" } - }, + } + ], + "comments": [ + " Numeric types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_numeric_types" + } + }, + { + "text": "INSERT INTO mysql_numeric_types \n(\n c_bool,\n c_boolean,\n c_tinyint,\n c_smallint,\n c_mediumint,\n c_int,\n c_integer,\n c_bigint, \n c_float, \n c_numeric, \n c_decimal, \n c_dec, \n c_fixed, \n c_double, \n c_double_precision\n) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlNumericTypesBatch", + "cmd": ":copyfrom", + "parameters": [ { - "number": 17, + "number": 1, "column": { - "name": "c_char", - "length": -1, + "name": "c_bool", + "length": 1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "char" + "name": "tinyint" }, - "originalName": "c_char" + "originalName": "c_bool" } }, { - "number": 18, + "number": 2, "column": { - "name": "c_nchar", - "length": -1, + "name": "c_boolean", + "length": 1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "char" + "name": "tinyint" }, - "originalName": "c_nchar" + "originalName": "c_boolean" } }, { - "number": 19, + "number": 3, "column": { - "name": "c_national_char", - "length": -1, + "name": "c_tinyint", + "length": 3, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "char" + "name": "tinyint" }, - "originalName": "c_national_char" + "originalName": "c_tinyint" } }, { - "number": 20, + "number": 4, "column": { - "name": "c_varchar", - "length": 100, + "name": "c_smallint", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "varchar" + "name": "smallint" }, - "originalName": "c_varchar" + "originalName": "c_smallint" } }, { - "number": 21, + "number": 5, "column": { - "name": "c_tinytext", + "name": "c_mediumint", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "tinytext" + "name": "mediumint" }, - "originalName": "c_tinytext" + "originalName": "c_mediumint" } }, { - "number": 22, + "number": 6, "column": { - "name": "c_mediumtext", + "name": "c_int", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "mediumtext" + "name": "int" }, - "originalName": "c_mediumtext" + "originalName": "c_int" } }, { - "number": 23, + "number": 7, "column": { - "name": "c_text", + "name": "c_integer", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "text" + "name": "int" }, - "originalName": "c_text" + "originalName": "c_integer" } }, { - "number": 24, + "number": 8, "column": { - "name": "c_longtext", + "name": "c_bigint", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "longtext" + "name": "bigint" }, - "originalName": "c_longtext" + "originalName": "c_bigint" } }, { - "number": 25, + "number": 9, "column": { - "name": "c_json", + "name": "c_float", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "json" + "name": "float" }, - "originalName": "c_json" + "originalName": "c_float" } }, { - "number": 26, + "number": 10, "column": { - "name": "c_json_string_override", - "length": -1, + "name": "c_numeric", + "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "json" + "name": "decimal" }, - "originalName": "c_json_string_override" + "originalName": "c_numeric" } }, { - "number": 27, + "number": 11, "column": { - "name": "c_enum", - "length": 6, + "name": "c_decimal", + "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "mysql_types_c_enum" + "name": "decimal" }, - "originalName": "c_enum" + "originalName": "c_decimal" } }, { - "number": 28, + "number": 12, "column": { - "name": "c_set", - "length": 15, + "name": "c_dec", + "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "mysql_types_c_set" + "name": "decimal" }, - "originalName": "c_set" + "originalName": "c_dec" } }, { - "number": 29, + "number": 13, "column": { - "name": "c_year", - "length": -1, + "name": "c_fixed", + "length": 10, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "year" + "name": "decimal" }, - "originalName": "c_year" + "originalName": "c_fixed" } }, { - "number": 30, + "number": 14, "column": { - "name": "c_date", + "name": "c_double", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "date" + "name": "double" }, - "originalName": "c_date" + "originalName": "c_double" } }, { - "number": 31, + "number": 15, "column": { - "name": "c_datetime", - "length": 19, + "name": "c_double_precision", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_numeric_types" }, "type": { - "name": "datetime" + "name": "double" }, - "originalName": "c_datetime" + "originalName": "c_double_precision" } - }, + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_numeric_types" + } + }, + { + "text": "SELECT c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_decimal, c_dec, c_numeric, c_fixed, c_double, c_double_precision FROM mysql_numeric_types LIMIT 1", + "name": "GetMysqlNumericTypes", + "cmd": ":one", + "columns": [ { - "number": 32, - "column": { - "name": "c_timestamp", - "length": 19, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "timestamp" - }, - "originalName": "c_timestamp" - } + "name": "c_bool", + "length": 1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_bool" }, { - "number": 33, - "column": { - "name": "c_binary", - "length": 3, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "binary" - }, - "originalName": "c_binary" - } + "name": "c_boolean", + "length": 1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_boolean" }, { - "number": 34, - "column": { - "name": "c_varbinary", - "length": 10, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "varbinary" - }, - "originalName": "c_varbinary" - } + "name": "c_tinyint", + "length": 3, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_tinyint" }, { - "number": 35, - "column": { - "name": "c_tinyblob", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "tinyblob" - }, - "originalName": "c_tinyblob" - } + "name": "c_smallint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "smallint" + }, + "originalName": "c_smallint" }, { - "number": 36, - "column": { - "name": "c_blob", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "blob" - }, - "originalName": "c_blob" - } + "name": "c_mediumint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "mediumint" + }, + "originalName": "c_mediumint" }, { - "number": 37, - "column": { - "name": "c_mediumblob", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "mediumblob" - }, - "originalName": "c_mediumblob" - } + "name": "c_int", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "int" + }, + "originalName": "c_int" }, { - "number": 38, - "column": { - "name": "c_longblob", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "longblob" - }, - "originalName": "c_longblob" - } + "name": "c_integer", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "int" + }, + "originalName": "c_integer" + }, + { + "name": "c_bigint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "bigint" + }, + "originalName": "c_bigint" + }, + { + "name": "c_float", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "float" + }, + "originalName": "c_float" + }, + { + "name": "c_decimal", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_decimal" + }, + { + "name": "c_dec", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_dec" + }, + { + "name": "c_numeric", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_numeric" + }, + { + "name": "c_fixed", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_fixed" + }, + { + "name": "c_double", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "double" + }, + "originalName": "c_double" + }, + { + "name": "c_double_precision", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "double" + }, + "originalName": "c_double_precision" } ], - "filename": "query.sql", - "insert_into_table": { - "name": "mysql_types" - } + "filename": "query.sql" }, { - "text": "INSERT INTO mysql_types \n(c_bit, c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, \n c_float, c_numeric, c_decimal, c_dec, c_fixed, c_double, c_double_precision, \n c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, \n c_json, c_json_string_override, c_enum, c_set, c_year, c_date, c_datetime, c_timestamp,\n c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - "name": "InsertMysqlTypesBatch", - "cmd": ":copyfrom", - "parameters": [ - { - "number": 1, - "column": { - "name": "c_bit", - "length": 8, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "bit" - }, - "originalName": "c_bit" - } - }, + "text": "SELECT\n COUNT(*) AS cnt,\n c_bool,\n c_boolean,\n c_tinyint,\n c_smallint,\n c_mediumint,\n c_int,\n c_integer,\n c_bigint,\n c_float,\n c_numeric,\n c_decimal,\n c_dec,\n c_fixed,\n c_double,\n c_double_precision\nFROM mysql_numeric_types\nGROUP BY\n c_bool,\n c_boolean,\n c_tinyint,\n c_smallint,\n c_mediumint,\n c_int,\n c_integer,\n c_bigint,\n c_float,\n c_numeric,\n c_decimal,\n c_dec,\n c_fixed,\n c_double,\n c_double_precision\nLIMIT 1", + "name": "GetMysqlNumericTypesCnt", + "cmd": ":one", + "columns": [ { - "number": 2, - "column": { - "name": "c_bool", - "length": 1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_bool" + "name": "cnt", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "bigint" } }, { - "number": 3, - "column": { - "name": "c_boolean", - "length": 1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_boolean" - } + "name": "c_bool", + "length": 1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_bool" }, { - "number": 4, - "column": { - "name": "c_tinyint", - "length": 3, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_tinyint" - } + "name": "c_boolean", + "length": 1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_boolean" }, { - "number": 5, - "column": { - "name": "c_smallint", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "smallint" - }, - "originalName": "c_smallint" - } + "name": "c_tinyint", + "length": 3, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "tinyint" + }, + "originalName": "c_tinyint" }, { - "number": 6, - "column": { - "name": "c_mediumint", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "mediumint" - }, - "originalName": "c_mediumint" - } + "name": "c_smallint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "smallint" + }, + "originalName": "c_smallint" }, { - "number": 7, - "column": { - "name": "c_int", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "int" - }, - "originalName": "c_int" - } + "name": "c_mediumint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "mediumint" + }, + "originalName": "c_mediumint" }, { - "number": 8, - "column": { - "name": "c_integer", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "int" - }, - "originalName": "c_integer" - } + "name": "c_int", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "int" + }, + "originalName": "c_int" }, { - "number": 9, - "column": { - "name": "c_bigint", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "bigint" - }, - "originalName": "c_bigint" - } + "name": "c_integer", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "int" + }, + "originalName": "c_integer" }, { - "number": 10, - "column": { - "name": "c_float", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "float" - }, - "originalName": "c_float" - } + "name": "c_bigint", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "bigint" + }, + "originalName": "c_bigint" }, { - "number": 11, - "column": { - "name": "c_numeric", - "length": 10, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_numeric" - } + "name": "c_float", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "float" + }, + "originalName": "c_float" }, { - "number": 12, - "column": { - "name": "c_decimal", - "length": 10, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_decimal" - } + "name": "c_numeric", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_numeric" }, { - "number": 13, - "column": { - "name": "c_dec", - "length": 10, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_dec" - } + "name": "c_decimal", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_decimal" }, { - "number": 14, - "column": { - "name": "c_fixed", - "length": 10, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_fixed" - } + "name": "c_dec", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_dec" }, { - "number": 15, - "column": { - "name": "c_double", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "double" - }, - "originalName": "c_double" - } + "name": "c_fixed", + "length": 10, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "decimal" + }, + "originalName": "c_fixed" }, { - "number": 16, - "column": { - "name": "c_double_precision", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "double" - }, - "originalName": "c_double_precision" - } + "name": "c_double", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "double" + }, + "originalName": "c_double" }, { - "number": 17, + "name": "c_double_precision", + "length": -1, + "table": { + "name": "mysql_numeric_types" + }, + "type": { + "name": "double" + }, + "originalName": "c_double_precision" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE mysql_numeric_types", + "name": "TruncateMysqlNumericTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO mysql_string_types \n(\n c_char,\n c_nchar,\n c_national_char,\n c_varchar,\n c_tinytext,\n c_mediumtext,\n c_text,\n c_longtext, \n c_json,\n c_json_string_override,\n c_enum,\n c_set\n) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlStringTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, "column": { "name": "c_char", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2147,13 +2336,13 @@ } }, { - "number": 18, + "number": 2, "column": { "name": "c_nchar", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2162,13 +2351,13 @@ } }, { - "number": 19, + "number": 3, "column": { "name": "c_national_char", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2177,13 +2366,13 @@ } }, { - "number": 20, + "number": 4, "column": { "name": "c_varchar", "length": 100, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "varchar" @@ -2192,511 +2381,335 @@ } }, { - "number": 21, + "number": 5, "column": { "name": "c_tinytext", "length": -1, "table": { "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "tinytext" - }, - "originalName": "c_tinytext" - } - }, - { - "number": 22, - "column": { - "name": "c_mediumtext", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "mediumtext" - }, - "originalName": "c_mediumtext" - } - }, - { - "number": 23, - "column": { - "name": "c_text", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "text" - }, - "originalName": "c_text" - } - }, - { - "number": 24, - "column": { - "name": "c_longtext", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "longtext" - }, - "originalName": "c_longtext" - } - }, - { - "number": 25, - "column": { - "name": "c_json", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" - }, - "type": { - "name": "json" - }, - "originalName": "c_json" - } - }, - { - "number": 26, - "column": { - "name": "c_json_string_override", - "length": -1, - "table": { - "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "json" + "name": "tinytext" }, - "originalName": "c_json_string_override" + "originalName": "c_tinytext" } }, { - "number": 27, + "number": 6, "column": { - "name": "c_enum", - "length": 6, + "name": "c_mediumtext", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mysql_types_c_enum" + "name": "mediumtext" }, - "originalName": "c_enum" + "originalName": "c_mediumtext" } }, { - "number": 28, + "number": 7, "column": { - "name": "c_set", - "length": 15, + "name": "c_text", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mysql_types_c_set" + "name": "text" }, - "originalName": "c_set" + "originalName": "c_text" } }, { - "number": 29, + "number": 8, "column": { - "name": "c_year", + "name": "c_longtext", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "year" + "name": "longtext" }, - "originalName": "c_year" + "originalName": "c_longtext" } }, { - "number": 30, + "number": 9, "column": { - "name": "c_date", + "name": "c_json", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "date" + "name": "json" }, - "originalName": "c_date" + "originalName": "c_json" } }, { - "number": 31, + "number": 10, "column": { - "name": "c_datetime", - "length": 19, + "name": "c_json_string_override", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "datetime" + "name": "json" }, - "originalName": "c_datetime" + "originalName": "c_json_string_override" } }, { - "number": 32, + "number": 11, "column": { - "name": "c_timestamp", - "length": 19, + "name": "c_enum", + "length": 6, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "timestamp" + "name": "mysql_string_types_c_enum" }, - "originalName": "c_timestamp" + "originalName": "c_enum" } }, { - "number": 33, + "number": 12, "column": { - "name": "c_binary", - "length": 3, + "name": "c_set", + "length": 15, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "binary" + "name": "mysql_string_types_c_set" }, - "originalName": "c_binary" + "originalName": "c_set" } - }, + } + ], + "comments": [ + " String types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_string_types" + } + }, + { + "text": "INSERT INTO mysql_string_types \n(\n c_char,\n c_nchar,\n c_national_char,\n c_varchar,\n c_tinytext,\n c_mediumtext,\n c_text,\n c_longtext, \n c_json,\n c_json_string_override,\n c_enum,\n c_set\n) \nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlStringTypesBatch", + "cmd": ":copyfrom", + "parameters": [ { - "number": 34, + "number": 1, "column": { - "name": "c_varbinary", - "length": 10, + "name": "c_char", + "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "varbinary" + "name": "char" }, - "originalName": "c_varbinary" + "originalName": "c_char" } }, { - "number": 35, + "number": 2, "column": { - "name": "c_tinyblob", + "name": "c_nchar", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "tinyblob" + "name": "char" }, - "originalName": "c_tinyblob" + "originalName": "c_nchar" } }, { - "number": 36, + "number": 3, "column": { - "name": "c_blob", + "name": "c_national_char", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "blob" + "name": "char" }, - "originalName": "c_blob" + "originalName": "c_national_char" } }, { - "number": 37, + "number": 4, "column": { - "name": "c_mediumblob", - "length": -1, + "name": "c_varchar", + "length": 100, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mediumblob" + "name": "varchar" }, - "originalName": "c_mediumblob" + "originalName": "c_varchar" } }, { - "number": 38, + "number": 5, "column": { - "name": "c_longblob", + "name": "c_tinytext", "length": -1, "table": { "schema": "public", - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "longblob" + "name": "tinytext" }, - "originalName": "c_longblob" + "originalName": "c_tinytext" } - } - ], - "filename": "query.sql", - "insert_into_table": { - "name": "mysql_types" - } - }, - { - "text": "SELECT c_bool, c_boolean, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_float, c_decimal, c_dec, c_numeric, c_fixed, c_double, c_double_precision, c_year, c_date, c_time, c_datetime, c_timestamp, 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, c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_types LIMIT 1", - "name": "GetMysqlTypes", - "cmd": ":one", - "columns": [ - { - "name": "c_bool", - "length": 1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_bool" - }, - { - "name": "c_boolean", - "length": 1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_boolean" - }, - { - "name": "c_tinyint", - "length": 3, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "tinyint" - }, - "originalName": "c_tinyint" - }, - { - "name": "c_smallint", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "smallint" - }, - "originalName": "c_smallint" - }, - { - "name": "c_mediumint", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "mediumint" - }, - "originalName": "c_mediumint" - }, - { - "name": "c_int", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "int" - }, - "originalName": "c_int" - }, - { - "name": "c_integer", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "int" - }, - "originalName": "c_integer" - }, - { - "name": "c_bigint", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "bigint" - }, - "originalName": "c_bigint" - }, - { - "name": "c_float", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "float" - }, - "originalName": "c_float" - }, - { - "name": "c_decimal", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_decimal" - }, - { - "name": "c_dec", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_dec" - }, - { - "name": "c_numeric", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_numeric" - }, - { - "name": "c_fixed", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "decimal" - }, - "originalName": "c_fixed" - }, - { - "name": "c_double", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "double" - }, - "originalName": "c_double" }, { - "name": "c_double_precision", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "double" - }, - "originalName": "c_double_precision" + "number": 6, + "column": { + "name": "c_mediumtext", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "mediumtext" + }, + "originalName": "c_mediumtext" + } }, { - "name": "c_year", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "year" - }, - "originalName": "c_year" + "number": 7, + "column": { + "name": "c_text", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "text" + }, + "originalName": "c_text" + } }, { - "name": "c_date", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "date" - }, - "originalName": "c_date" + "number": 8, + "column": { + "name": "c_longtext", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "longtext" + }, + "originalName": "c_longtext" + } }, { - "name": "c_time", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "time" - }, - "originalName": "c_time" + "number": 9, + "column": { + "name": "c_json", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "json" + }, + "originalName": "c_json" + } }, { - "name": "c_datetime", - "length": 19, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "datetime" - }, - "originalName": "c_datetime" + "number": 10, + "column": { + "name": "c_json_string_override", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "json" + }, + "originalName": "c_json_string_override" + } }, { - "name": "c_timestamp", - "length": 19, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "timestamp" - }, - "originalName": "c_timestamp" + "number": 11, + "column": { + "name": "c_enum", + "length": 6, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "mysql_string_types_c_enum" + }, + "originalName": "c_enum" + } }, + { + "number": 12, + "column": { + "name": "c_set", + "length": 15, + "table": { + "schema": "public", + "name": "mysql_string_types" + }, + "type": { + "name": "mysql_string_types_c_set" + }, + "originalName": "c_set" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_string_types" + } + }, + { + "text": "SELECT 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 LIMIT 1", + "name": "GetMysqlStringTypes", + "cmd": ":one", + "columns": [ { "name": "c_char", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2707,7 +2720,7 @@ "name": "c_nchar", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2718,7 +2731,7 @@ "name": "c_national_char", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "char" @@ -2729,7 +2742,7 @@ "name": "c_varchar", "length": 100, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "varchar" @@ -2740,7 +2753,7 @@ "name": "c_tinytext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "tinytext" @@ -2751,7 +2764,7 @@ "name": "c_mediumtext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "mediumtext" @@ -2762,7 +2775,7 @@ "name": "c_text", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "text" @@ -2773,7 +2786,7 @@ "name": "c_longtext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "longtext" @@ -2784,7 +2797,7 @@ "name": "c_json", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "json" @@ -2795,7 +2808,7 @@ "name": "c_json_string_override", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { "name": "json" @@ -2806,10 +2819,10 @@ "name": "c_enum", "length": 6, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mysql_types_c_enum" + "name": "mysql_string_types_c_enum" }, "originalName": "c_enum" }, @@ -2817,96 +2830,19 @@ "name": "c_set", "length": 15, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mysql_types_c_set" + "name": "mysql_string_types_c_set" }, "originalName": "c_set" - }, - { - "name": "c_bit", - "length": 8, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "bit" - }, - "originalName": "c_bit" - }, - { - "name": "c_binary", - "length": 3, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "binary" - }, - "originalName": "c_binary" - }, - { - "name": "c_varbinary", - "length": 10, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "varbinary" - }, - "originalName": "c_varbinary" - }, - { - "name": "c_tinyblob", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "tinyblob" - }, - "originalName": "c_tinyblob" - }, - { - "name": "c_blob", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "blob" - }, - "originalName": "c_blob" - }, - { - "name": "c_mediumblob", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "mediumblob" - }, - "originalName": "c_mediumblob" - }, - { - "name": "c_longblob", - "length": -1, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "longblob" - }, - "originalName": "c_longblob" } ], "filename": "query.sql" }, { - "text": "SELECT COUNT(1) AS cnt, c_bool, c_boolean, c_bit, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, \n c_float, c_numeric, c_decimal, c_dec, c_fixed, c_double, c_double_precision, \n c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, \n c_json, c_json_string_override, c_enum, c_set, c_year, c_date, c_datetime, c_timestamp, \n c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob\nFROM mysql_types\nGROUP BY c_bool, c_boolean, c_bit, c_tinyint, c_smallint, c_mediumint, c_int, c_integer, c_bigint, \n c_float, c_numeric, c_decimal, c_dec, c_fixed, c_double, c_double_precision, \n c_char, c_nchar, c_national_char, c_varchar, c_tinytext, c_mediumtext, c_text, c_longtext, \n c_json, c_json_string_override, c_enum, c_set, c_year, c_date, c_datetime, c_timestamp, \n c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob\nLIMIT 1", - "name": "GetMysqlTypesCnt", + "text": "SELECT\n COUNT(*) AS cnt,\n c_char,\n c_nchar,\n c_national_char,\n c_varchar,\n c_tinytext,\n c_mediumtext,\n c_text,\n c_longtext,\n c_json,\n c_json_string_override,\n c_enum,\n c_set\nFROM mysql_string_types\nGROUP BY\n c_char,\n c_nchar,\n c_national_char,\n c_varchar,\n c_tinytext,\n c_mediumtext,\n c_text,\n c_longtext,\n c_json,\n c_json_string_override,\n c_enum,\n c_set\nLIMIT 1", + "name": "GetMysqlStringTypesCnt", "cmd": ":one", "columns": [ { @@ -2919,362 +2855,812 @@ } }, { - "name": "c_bool", - "length": 1, + "name": "c_char", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "tinyint" + "name": "char" }, - "originalName": "c_bool" + "originalName": "c_char" }, { - "name": "c_boolean", - "length": 1, + "name": "c_nchar", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "tinyint" + "name": "char" }, - "originalName": "c_boolean" + "originalName": "c_nchar" }, { - "name": "c_bit", - "length": 8, + "name": "c_national_char", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "bit" + "name": "char" }, - "originalName": "c_bit" + "originalName": "c_national_char" }, { - "name": "c_tinyint", - "length": 3, + "name": "c_varchar", + "length": 100, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "tinyint" + "name": "varchar" }, - "originalName": "c_tinyint" + "originalName": "c_varchar" }, { - "name": "c_smallint", + "name": "c_tinytext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "smallint" + "name": "tinytext" + }, + "originalName": "c_tinytext" + }, + { + "name": "c_mediumtext", + "length": -1, + "table": { + "name": "mysql_string_types" + }, + "type": { + "name": "mediumtext" }, - "originalName": "c_smallint" + "originalName": "c_mediumtext" }, { - "name": "c_mediumint", + "name": "c_text", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "mediumint" + "name": "text" }, - "originalName": "c_mediumint" + "originalName": "c_text" }, { - "name": "c_int", + "name": "c_longtext", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "int" + "name": "longtext" }, - "originalName": "c_int" + "originalName": "c_longtext" }, { - "name": "c_integer", + "name": "c_json", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "int" + "name": "json" }, - "originalName": "c_integer" + "originalName": "c_json" }, { - "name": "c_bigint", + "name": "c_json_string_override", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "bigint" + "name": "json" }, - "originalName": "c_bigint" + "originalName": "c_json_string_override" }, { - "name": "c_float", - "length": -1, + "name": "c_enum", + "length": 6, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "float" + "name": "mysql_string_types_c_enum" }, - "originalName": "c_float" + "originalName": "c_enum" }, { - "name": "c_numeric", - "length": 10, + "name": "c_set", + "length": 15, "table": { - "name": "mysql_types" + "name": "mysql_string_types" }, "type": { - "name": "decimal" + "name": "mysql_string_types_c_set" }, - "originalName": "c_numeric" + "originalName": "c_set" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE mysql_string_types", + "name": "TruncateMysqlStringTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO mysql_datetime_types \n(\n c_year,\n c_date,\n c_datetime,\n c_timestamp,\n c_time\n) \nVALUES (?, ?, ?, ?, ?)", + "name": "InsertMysqlDatetimeTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_year", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "year" + }, + "originalName": "c_year" + } }, { - "name": "c_decimal", - "length": 10, + "number": 2, + "column": { + "name": "c_date", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "date" + }, + "originalName": "c_date" + } + }, + { + "number": 3, + "column": { + "name": "c_datetime", + "length": 19, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "datetime" + }, + "originalName": "c_datetime" + } + }, + { + "number": 4, + "column": { + "name": "c_timestamp", + "length": 19, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "timestamp" + }, + "originalName": "c_timestamp" + } + }, + { + "number": 5, + "column": { + "name": "c_time", + "length": 10, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "time" + }, + "originalName": "c_time" + } + } + ], + "comments": [ + " Datetime types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_datetime_types" + } + }, + { + "text": "INSERT INTO mysql_datetime_types \n(\n c_year,\n c_date,\n c_datetime,\n c_timestamp,\n c_time\n) \nVALUES (?, ?, ?, ?, ?)", + "name": "InsertMysqlDatetimeTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_year", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "year" + }, + "originalName": "c_year" + } + }, + { + "number": 2, + "column": { + "name": "c_date", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "date" + }, + "originalName": "c_date" + } + }, + { + "number": 3, + "column": { + "name": "c_datetime", + "length": 19, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "datetime" + }, + "originalName": "c_datetime" + } + }, + { + "number": 4, + "column": { + "name": "c_timestamp", + "length": 19, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "timestamp" + }, + "originalName": "c_timestamp" + } + }, + { + "number": 5, + "column": { + "name": "c_time", + "length": 10, + "table": { + "schema": "public", + "name": "mysql_datetime_types" + }, + "type": { + "name": "time" + }, + "originalName": "c_time" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_datetime_types" + } + }, + { + "text": "SELECT c_year, c_date, c_datetime, c_timestamp, c_time FROM mysql_datetime_types LIMIT 1", + "name": "GetMysqlDatetimeTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_year", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "decimal" + "name": "year" }, - "originalName": "c_decimal" + "originalName": "c_year" }, { - "name": "c_dec", - "length": 10, + "name": "c_date", + "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "decimal" + "name": "date" }, - "originalName": "c_dec" + "originalName": "c_date" }, { - "name": "c_fixed", - "length": 10, + "name": "c_datetime", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "decimal" + "name": "datetime" }, - "originalName": "c_fixed" + "originalName": "c_datetime" }, { - "name": "c_double", - "length": -1, + "name": "c_timestamp", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "double" + "name": "timestamp" }, - "originalName": "c_double" + "originalName": "c_timestamp" }, { - "name": "c_double_precision", - "length": -1, + "name": "c_time", + "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "double" + "name": "time" }, - "originalName": "c_double_precision" + "originalName": "c_time" + } + ], + "filename": "query.sql" + }, + { + "text": "SELECT\n COUNT(*) AS cnt,\n c_year,\n c_date,\n c_datetime,\n c_timestamp,\n c_time\nFROM mysql_datetime_types\nGROUP BY\n c_year,\n c_date,\n c_datetime,\n c_timestamp,\n c_time\nLIMIT 1", + "name": "GetMysqlDatetimeTypesCnt", + "cmd": ":one", + "columns": [ + { + "name": "cnt", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "bigint" + } }, { - "name": "c_char", + "name": "c_year", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "char" + "name": "year" }, - "originalName": "c_char" + "originalName": "c_year" }, { - "name": "c_nchar", + "name": "c_date", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "char" + "name": "date" }, - "originalName": "c_nchar" + "originalName": "c_date" }, { - "name": "c_national_char", - "length": -1, + "name": "c_datetime", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "char" + "name": "datetime" }, - "originalName": "c_national_char" + "originalName": "c_datetime" }, { - "name": "c_varchar", - "length": 100, + "name": "c_timestamp", + "length": 19, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "varchar" + "name": "timestamp" }, - "originalName": "c_varchar" + "originalName": "c_timestamp" }, { - "name": "c_tinytext", - "length": -1, + "name": "c_time", + "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_datetime_types" }, "type": { - "name": "tinytext" + "name": "time" }, - "originalName": "c_tinytext" + "originalName": "c_time" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE mysql_datetime_types", + "name": "TruncateMysqlDatetimeTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO mysql_binary_types \n(\n c_bit,\n c_binary, \n c_varbinary, \n c_tinyblob, \n c_blob, \n c_mediumblob, \n c_longblob\n) \nVALUES (?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlBinaryTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_bit", + "length": 8, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "bit" + }, + "originalName": "c_bit" + } + }, + { + "number": 2, + "column": { + "name": "c_binary", + "length": 3, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "binary" + }, + "originalName": "c_binary" + } + }, + { + "number": 3, + "column": { + "name": "c_varbinary", + "length": 10, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "varbinary" + }, + "originalName": "c_varbinary" + } + }, + { + "number": 4, + "column": { + "name": "c_tinyblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "tinyblob" + }, + "originalName": "c_tinyblob" + } + }, + { + "number": 5, + "column": { + "name": "c_blob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "blob" + }, + "originalName": "c_blob" + } + }, + { + "number": 6, + "column": { + "name": "c_mediumblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "mediumblob" + }, + "originalName": "c_mediumblob" + } + }, + { + "number": 7, + "column": { + "name": "c_longblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "longblob" + }, + "originalName": "c_longblob" + } + } + ], + "comments": [ + " Binary types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_binary_types" + } + }, + { + "text": "INSERT INTO mysql_binary_types \n(\n c_bit,\n c_binary, \n c_varbinary, \n c_tinyblob, \n c_blob, \n c_mediumblob, \n c_longblob\n) \nVALUES (?, ?, ?, ?, ?, ?, ?)", + "name": "InsertMysqlBinaryTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_bit", + "length": 8, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "bit" + }, + "originalName": "c_bit" + } + }, + { + "number": 2, + "column": { + "name": "c_binary", + "length": 3, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "binary" + }, + "originalName": "c_binary" + } + }, + { + "number": 3, + "column": { + "name": "c_varbinary", + "length": 10, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "varbinary" + }, + "originalName": "c_varbinary" + } + }, + { + "number": 4, + "column": { + "name": "c_tinyblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "tinyblob" + }, + "originalName": "c_tinyblob" + } + }, + { + "number": 5, + "column": { + "name": "c_blob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "blob" + }, + "originalName": "c_blob" + } + }, + { + "number": 6, + "column": { + "name": "c_mediumblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "mediumblob" + }, + "originalName": "c_mediumblob" + } }, { - "name": "c_mediumtext", - "length": -1, + "number": 7, + "column": { + "name": "c_longblob", + "length": -1, + "table": { + "schema": "public", + "name": "mysql_binary_types" + }, + "type": { + "name": "longblob" + }, + "originalName": "c_longblob" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "mysql_binary_types" + } + }, + { + "text": "SELECT c_bit, c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob FROM mysql_binary_types LIMIT 1", + "name": "GetMysqlBinaryTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_bit", + "length": 8, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "mediumtext" + "name": "bit" }, - "originalName": "c_mediumtext" + "originalName": "c_bit" }, { - "name": "c_text", - "length": -1, + "name": "c_binary", + "length": 3, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "text" + "name": "binary" }, - "originalName": "c_text" + "originalName": "c_binary" }, { - "name": "c_longtext", - "length": -1, + "name": "c_varbinary", + "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "longtext" + "name": "varbinary" }, - "originalName": "c_longtext" + "originalName": "c_varbinary" }, { - "name": "c_json", + "name": "c_tinyblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "json" + "name": "tinyblob" }, - "originalName": "c_json" + "originalName": "c_tinyblob" }, { - "name": "c_json_string_override", + "name": "c_blob", "length": -1, "table": { - "name": "mysql_types" - }, - "type": { - "name": "json" - }, - "originalName": "c_json_string_override" - }, - { - "name": "c_enum", - "length": 6, - "table": { - "name": "mysql_types" - }, - "type": { - "name": "mysql_types_c_enum" - }, - "originalName": "c_enum" - }, - { - "name": "c_set", - "length": 15, - "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "mysql_types_c_set" + "name": "blob" }, - "originalName": "c_set" + "originalName": "c_blob" }, { - "name": "c_year", + "name": "c_mediumblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "year" + "name": "mediumblob" }, - "originalName": "c_year" + "originalName": "c_mediumblob" }, { - "name": "c_date", + "name": "c_longblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "date" + "name": "longblob" }, - "originalName": "c_date" - }, + "originalName": "c_longblob" + } + ], + "filename": "query.sql" + }, + { + "text": "SELECT\n COUNT(*) AS cnt,\n c_bit,\n c_binary,\n c_varbinary,\n c_tinyblob,\n c_blob,\n c_mediumblob,\n c_longblob\nFROM mysql_binary_types\nGROUP BY\n c_bit,\n c_binary,\n c_varbinary,\n c_tinyblob,\n c_blob,\n c_mediumblob,\n c_longblob\nLIMIT 1", + "name": "GetMysqlBinaryTypesCnt", + "cmd": ":one", + "columns": [ { - "name": "c_datetime", - "length": 19, - "table": { - "name": "mysql_types" - }, + "name": "cnt", + "notNull": true, + "length": -1, + "isFuncCall": true, "type": { - "name": "datetime" - }, - "originalName": "c_datetime" + "name": "bigint" + } }, { - "name": "c_timestamp", - "length": 19, + "name": "c_bit", + "length": 8, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { - "name": "timestamp" + "name": "bit" }, - "originalName": "c_timestamp" + "originalName": "c_bit" }, { "name": "c_binary", "length": 3, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "binary" @@ -3285,7 +3671,7 @@ "name": "c_varbinary", "length": 10, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "varbinary" @@ -3296,7 +3682,7 @@ "name": "c_tinyblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "tinyblob" @@ -3307,7 +3693,7 @@ "name": "c_blob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "blob" @@ -3318,7 +3704,7 @@ "name": "c_mediumblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "mediumblob" @@ -3329,7 +3715,7 @@ "name": "c_longblob", "length": -1, "table": { - "name": "mysql_types" + "name": "mysql_binary_types" }, "type": { "name": "longblob" @@ -3340,7 +3726,13 @@ "filename": "query.sql" }, { - "text": "SELECT MAX(c_int) AS max_int, MAX(c_varchar) AS max_varchar, MAX(c_timestamp) AS max_timestamp\nFROM mysql_types", + "text": "TRUNCATE TABLE mysql_binary_types", + "name": "TruncateMysqlBinaryTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "\nSELECT\n MAX(c_int) AS max_int,\n MAX(c_varchar) AS max_varchar,\n MAX(c_timestamp) AS max_timestamp\nFROM mysql_numeric_types\nCROSS JOIN mysql_string_types\nCROSS JOIN mysql_datetime_types", "name": "GetMysqlFunctions", "cmd": ":one", "columns": [ @@ -3372,164 +3764,10 @@ } } ], - "filename": "query.sql" - }, - { - "text": "TRUNCATE TABLE mysql_types", - "name": "TruncateMysqlTypes", - "cmd": ":exec", - "filename": "query.sql" - }, - { - "text": "INSERT INTO extended.bios (author_name, name, bio_type, author_type) VALUES (?, ?, ?, ?)", - "name": "CreateExtendedBio", - "cmd": ":exec", - "parameters": [ - { - "number": 1, - "column": { - "name": "author_name", - "length": 100, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "varchar" - }, - "originalName": "author_name" - } - }, - { - "number": 2, - "column": { - "name": "name", - "length": 100, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "varchar" - }, - "originalName": "name" - } - }, - { - "number": 3, - "column": { - "name": "bio_type", - "length": 13, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "bios_bio_type" - }, - "originalName": "bio_type" - } - }, - { - "number": 4, - "column": { - "name": "author_type", - "length": 24, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "bios_author_type" - }, - "originalName": "author_type" - } - } - ], - "filename": "query.sql", - "insert_into_table": { - "schema": "extended", - "name": "bios" - } - }, - { - "text": "SELECT author_name, name, bio_type, author_type FROM extended.bios WHERE bio_type = ? LIMIT 1", - "name": "GetFirstExtendedBioByType", - "cmd": ":one", - "columns": [ - { - "name": "author_name", - "length": 100, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "varchar" - }, - "originalName": "author_name" - }, - { - "name": "name", - "length": 100, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "varchar" - }, - "originalName": "name" - }, - { - "name": "bio_type", - "length": 13, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "bios_bio_type" - }, - "originalName": "bio_type" - }, - { - "name": "author_type", - "length": 24, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "bios_author_type" - }, - "originalName": "author_type" - } - ], - "parameters": [ - { - "number": 1, - "column": { - "name": "bio_type", - "length": 13, - "table": { - "schema": "extended", - "name": "bios" - }, - "type": { - "name": "bios_bio_type" - }, - "originalName": "bio_type" - } - } + "comments": [ + " Functions " ], "filename": "query.sql" - }, - { - "text": "TRUNCATE TABLE extended.bios", - "name": "TruncateExtendedBios", - "cmd": ":exec", - "filename": "query.sql" } ], "sqlc_version": "v1.27.0", diff --git a/examples/MySqlConnectorLegacyExample/request.message b/examples/MySqlConnectorLegacyExample/request.message index 1fd01367..41fbe903 100644 Binary files a/examples/MySqlConnectorLegacyExample/request.message and b/examples/MySqlConnectorLegacyExample/request.message differ diff --git a/examples/NpgsqlDapperExample/Models.cs b/examples/NpgsqlDapperExample/Models.cs index 17307005..923b9b7a 100644 --- a/examples/NpgsqlDapperExample/Models.cs +++ b/examples/NpgsqlDapperExample/Models.cs @@ -1,6 +1,7 @@ // auto-generated by sqlc - do not edit using NpgsqlTypes; using System; +using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.NetworkInformation; @@ -21,7 +22,7 @@ public class Book public required long AuthorId { get; init; } public string? Description { get; init; } }; -public class PostgresType +public class PostgresNumericType { public bool? CBoolean { get; init; } public byte[]? CBit { get; init; } @@ -33,26 +34,39 @@ public class PostgresType public float? CReal { get; init; } public double? CDoublePrecision { get; init; } public decimal? CMoney { get; init; } - public DateTime? CDate { get; init; } - public TimeSpan? CTime { get; init; } - public DateTime? CTimestamp { get; init; } - public DateTime? CTimestampWithTz { get; init; } - public TimeSpan? CInterval { get; init; } +}; +public class PostgresStringType +{ public string? CChar { get; init; } public string? CVarchar { get; init; } public string? CCharacterVarying { get; init; } public string? CBpchar { get; init; } public string? CText { get; init; } - public JsonElement? CJson { get; init; } - public JsonElement? CJsonStringOverride { get; init; } - public JsonElement? CJsonb { get; init; } - public string? CJsonpath { get; init; } - public XmlDocument? CXml { get; init; } +}; +public class PostgresDatetimeType +{ + public DateTime? CDate { get; init; } + public TimeSpan? CTime { get; init; } + public DateTime? CTimestamp { get; init; } + public DateTime? CTimestampWithTz { get; init; } + public TimeSpan? CInterval { get; init; } +}; +public class PostgresNetworkType +{ public NpgsqlCidr? CCidr { get; init; } public IPAddress? CInet { get; init; } public PhysicalAddress? CMacaddr { get; init; } public string? CMacaddr8 { get; init; } - public Guid? CUuid { get; init; } +}; +public class PostgresArrayType +{ + public byte[]? CBytea { get; init; } + public bool[]? CBooleanArray { get; init; } + public string[]? CTextArray { get; init; } + public int[]? CIntegerArray { get; init; } + public decimal[]? CDecimalArray { get; init; } + public DateTime[]? CDateArray { get; init; } + public DateTime[]? CTimestampArray { get; init; } }; public class PostgresGeometricType { @@ -64,13 +78,99 @@ public class PostgresGeometricType public NpgsqlPolygon? CPolygon { get; init; } public NpgsqlCircle? CCircle { get; init; } }; -public class PostgresArrayType +public class PostgresSpecialType { - public byte[]? CBytea { get; init; } - public bool[]? CBooleanArray { get; init; } - public string[]? CTextArray { get; init; } - public int[]? CIntegerArray { get; init; } - public decimal[]? CDecimalArray { get; init; } - public DateTime[]? CDateArray { get; init; } - public DateTime[]? CTimestampArray { get; init; } -}; \ No newline at end of file + public Guid? CUuid { get; init; } + public CEnum? CEnum { get; init; } + public JsonElement? CJson { get; init; } + public JsonElement? CJsonStringOverride { get; init; } + public JsonElement? CJsonb { get; init; } + public string? CJsonpath { get; init; } + public XmlDocument? CXml { get; init; } + public XmlDocument? CXmlStringOverride { get; init; } +}; +public class ExtendedBio +{ + public required string AuthorName { get; init; } + public required string Name { get; init; } + public ExtendedBioType? BioType { get; init; } +}; +public enum CEnum +{ + Invalid = 0, // reserved for invalid enum value + Small = 1, + Medium = 2, + Big = 3 +} + +public static class CEnumExtensions +{ + private static readonly Dictionary StringToEnum = new Dictionary() + { + [string.Empty] = CEnum.Invalid, + ["small"] = CEnum.Small, + ["medium"] = CEnum.Medium, + ["big"] = CEnum.Big + }; + private static readonly Dictionary EnumToString = new Dictionary() + { + [CEnum.Invalid] = string.Empty, + [CEnum.Small] = "small", + [CEnum.Medium] = "medium", + [CEnum.Big] = "big" + }; + public static CEnum ToCEnum(this string me) + { + return StringToEnum[me]; + } + + public static string Stringify(this CEnum me) + { + return EnumToString[me]; + } + + public static HashSet ToCEnumSet(this string me) + { + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); + } +} + +public enum ExtendedBioType +{ + Invalid = 0, // reserved for invalid enum value + Autobiography = 1, + Biography = 2, + Memoir = 3 +} + +public static class ExtendedBioTypeExtensions +{ + private static readonly Dictionary StringToEnum = new Dictionary() + { + [string.Empty] = ExtendedBioType.Invalid, + ["Autobiography"] = ExtendedBioType.Autobiography, + ["Biography"] = ExtendedBioType.Biography, + ["Memoir"] = ExtendedBioType.Memoir + }; + private static readonly Dictionary EnumToString = new Dictionary() + { + [ExtendedBioType.Invalid] = string.Empty, + [ExtendedBioType.Autobiography] = "Autobiography", + [ExtendedBioType.Biography] = "Biography", + [ExtendedBioType.Memoir] = "Memoir" + }; + public static ExtendedBioType ToExtendedBioType(this string me) + { + return StringToEnum[me]; + } + + public static string Stringify(this ExtendedBioType me) + { + return EnumToString[me]; + } + + public static HashSet ToExtendedBioTypeSet(this string me) + { + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); + } +} \ No newline at end of file diff --git a/examples/NpgsqlDapperExample/QuerySql.cs b/examples/NpgsqlDapperExample/QuerySql.cs index 9aa99e01..69d2337f 100644 --- a/examples/NpgsqlDapperExample/QuerySql.cs +++ b/examples/NpgsqlDapperExample/QuerySql.cs @@ -43,7 +43,7 @@ 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; } @@ -68,14 +68,11 @@ public class GetAuthorArgs } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -135,10 +132,7 @@ public class CreateAuthorArgs } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); return await this.Transaction.Connection.QueryFirstOrDefaultAsync(CreateAuthorSql, queryParams, transaction: this.Transaction); } @@ -160,20 +154,15 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) - { return await connection.QuerySingleAsync(CreateAuthorReturnIdSql, queryParams); - } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -198,14 +187,11 @@ public class GetAuthorByIdArgs } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -234,7 +220,7 @@ 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; } @@ -246,18 +232,12 @@ public async Task DeleteAuthor(DeleteAuthorArgs args) if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) - { await connection.ExecuteAsync(DeleteAuthorSql, queryParams); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); await this.Transaction.Connection.ExecuteAsync(DeleteAuthorSql, queryParams, transaction: this.Transaction); } @@ -267,22 +247,16 @@ public async Task TruncateAuthors() if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) - { await connection.ExecuteAsync(TruncateAuthorsSql); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -294,20 +268,15 @@ public async Task UpdateAuthors(UpdateAuthorsArgs args) if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) - { return await connection.ExecuteAsync(UpdateAuthorsSql, queryParams); - } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -336,7 +305,7 @@ 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; } @@ -385,20 +354,15 @@ public async Task CreateBook(CreateBookArgs args) if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) - { return await connection.QuerySingleAsync(CreateBookSql, queryParams); - } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -408,7 +372,7 @@ public async Task> ListAllAuthorsBooks() { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(ListAllAuthorsBooksSql)) { @@ -439,7 +403,7 @@ 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; } @@ -449,7 +413,7 @@ public async Task> GetDuplicateAuthors() { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(GetDuplicateAuthorsSql)) { @@ -480,7 +444,7 @@ 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; } @@ -496,7 +460,7 @@ public async Task> GetAuthorsByBookName(GetAuthors { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(GetAuthorsByBookNameSql)) { @@ -529,41 +493,113 @@ public async Task> GetAuthorsByBookName(GetAuthors } } - private const string InsertPostgresTypesSql = "INSERT INTO postgres_types(c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_real, c_numeric, c_decimal, c_double_precision, c_money, c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_char, c_varchar, c_character_varying, c_bpchar, c_text, c_uuid, c_json, c_json_string_override, c_jsonb, c_jsonpath, c_xml, c_cidr, c_inet, c_macaddr, c_macaddr8) VALUES ( @c_boolean, @c_bit, @c_smallint, @c_integer, @c_bigint, @c_real, @c_numeric, @c_decimal, @c_double_precision, @c_money, @c_date, @c_time, @c_timestamp, @c_timestamp_with_tz, @c_interval, @c_char, @c_varchar, @c_character_varying, @c_bpchar, @c_text, @c_uuid, @c_json :: json, @c_json_string_override :: json, @c_jsonb :: jsonb, @c_jsonpath :: jsonpath, @c_xml :: xml, @c_cidr, @c_inet, @c_macaddr :: macaddr, @c_macaddr8 :: macaddr8 ) "; - public class InsertPostgresTypesArgs + private const string CreateExtendedBioSql = "INSERT INTO extended.bios (author_name, name, bio_type) VALUES (@author_name, @name, @bio_type)"; + public class CreateExtendedBioArgs + { + public required string AuthorName { get; init; } + public required string Name { get; init; } + public ExtendedBioType? BioType { get; init; } + }; + public async Task CreateExtendedBio(CreateExtendedBioArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("author_name", args.AuthorName); + queryParams.Add("name", args.Name); + queryParams.Add("bio_type", args.BioType != null ? args.BioType.Value.Stringify() : null); + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(CreateExtendedBioSql, queryParams); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(CreateExtendedBioSql, queryParams, transaction: this.Transaction); + } + + private const string GetFirstExtendedBioByTypeSql = "SELECT author_name, name, bio_type FROM extended.bios WHERE bio_type = @bio_type LIMIT 1"; + public class GetFirstExtendedBioByTypeRow + { + public required string AuthorName { get; init; } + public required string Name { get; init; } + public ExtendedBioType? BioType { get; init; } + }; + public class GetFirstExtendedBioByTypeArgs + { + public ExtendedBioType? BioType { get; init; } + }; + public async Task GetFirstExtendedBioByType(GetFirstExtendedBioByTypeArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("bio_type", args.BioType != null ? args.BioType.Value.Stringify() : null); + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetFirstExtendedBioByTypeSql, queryParams); + return result; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetFirstExtendedBioByTypeSql, queryParams, transaction: this.Transaction); + } + + private const string TruncateExtendedBiosSql = "TRUNCATE TABLE extended.bios"; + public async Task TruncateExtendedBios() + { + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncateExtendedBiosSql); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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"; + public class GetPostgresFunctionsRow + { + public int? MaxInteger { get; init; } + public string? MaxVarchar { get; init; } + public required DateTime MaxTimestamp { get; init; } + }; + public async Task GetPostgresFunctions() + { + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresFunctionsSql); + return result; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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)"; + public class InsertPostgresNumericTypesArgs { public bool? CBoolean { get; init; } public byte[]? CBit { get; init; } public short? CSmallint { get; init; } public int? CInteger { get; init; } public long? CBigint { get; init; } - public float? CReal { get; init; } - public decimal? CNumeric { get; init; } public decimal? CDecimal { get; init; } + public decimal? CNumeric { get; init; } + public float? CReal { get; init; } public double? CDoublePrecision { get; init; } public decimal? CMoney { get; init; } - public DateTime? CDate { get; init; } - public TimeSpan? CTime { get; init; } - public DateTime? CTimestamp { get; init; } - public DateTime? CTimestampWithTz { get; init; } - public TimeSpan? CInterval { get; init; } - public string? CChar { get; init; } - public string? CVarchar { get; init; } - public string? CCharacterVarying { get; init; } - public string? CBpchar { get; init; } - public string? CText { get; init; } - public Guid? CUuid { get; init; } - public JsonElement? CJson { get; init; } - public string? CJsonStringOverride { get; init; } - public JsonElement? CJsonb { get; init; } - public string? CJsonpath { get; init; } - public XmlDocument? CXml { get; init; } - public NpgsqlCidr? CCidr { get; init; } - public IPAddress? CInet { get; init; } - public PhysicalAddress? CMacaddr { get; init; } - public string? CMacaddr8 { get; init; } }; - public async Task InsertPostgresTypes(InsertPostgresTypesArgs args) + public async Task InsertPostgresNumericTypes(InsertPostgresNumericTypesArgs args) { var queryParams = new Dictionary(); queryParams.Add("c_boolean", args.CBoolean); @@ -571,109 +607,133 @@ public async Task InsertPostgresTypes(InsertPostgresTypesArgs args) queryParams.Add("c_smallint", args.CSmallint); queryParams.Add("c_integer", args.CInteger); queryParams.Add("c_bigint", args.CBigint); - queryParams.Add("c_real", args.CReal); - queryParams.Add("c_numeric", args.CNumeric); queryParams.Add("c_decimal", args.CDecimal); + queryParams.Add("c_numeric", args.CNumeric); + queryParams.Add("c_real", args.CReal); queryParams.Add("c_double_precision", args.CDoublePrecision); queryParams.Add("c_money", args.CMoney); - queryParams.Add("c_date", args.CDate); - queryParams.Add("c_time", args.CTime); - queryParams.Add("c_timestamp", args.CTimestamp); - queryParams.Add("c_timestamp_with_tz", args.CTimestampWithTz); - queryParams.Add("c_interval", args.CInterval); - queryParams.Add("c_char", args.CChar); - queryParams.Add("c_varchar", args.CVarchar); - queryParams.Add("c_character_varying", args.CCharacterVarying); - queryParams.Add("c_bpchar", args.CBpchar); - queryParams.Add("c_text", args.CText); - queryParams.Add("c_uuid", args.CUuid); - queryParams.Add("c_json", args.CJson.HasValue ? args.CJson.Value.GetRawText() : null); - queryParams.Add("c_json_string_override", args.CJsonStringOverride); - queryParams.Add("c_jsonb", args.CJsonb.HasValue ? args.CJsonb.Value.GetRawText() : null); - queryParams.Add("c_jsonpath", args.CJsonpath); - queryParams.Add("c_xml", args.CXml != null ? args.CXml.OuterXml : null); - queryParams.Add("c_cidr", args.CCidr); - queryParams.Add("c_inet", args.CInet); - queryParams.Add("c_macaddr", args.CMacaddr); - queryParams.Add("c_macaddr8", args.CMacaddr8); + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(InsertPostgresNumericTypesSql, queryParams); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertPostgresNumericTypesSql, queryParams, transaction: this.Transaction); + } + + private const string GetPostgresNumericTypesSql = "SELECT c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money FROM postgres_numeric_types LIMIT 1"; + public class GetPostgresNumericTypesRow + { + public bool? CBoolean { get; init; } + public byte[]? CBit { get; init; } + public short? CSmallint { get; init; } + public int? CInteger { get; init; } + public long? CBigint { get; init; } + public decimal? CDecimal { get; init; } + public decimal? CNumeric { get; init; } + public float? CReal { get; init; } + public double? CDoublePrecision { get; init; } + public decimal? CMoney { get; init; } + }; + public async Task GetPostgresNumericTypes() + { if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) { - await connection.ExecuteAsync(InsertPostgresTypesSql, queryParams); + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresNumericTypesSql); + return result; } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresNumericTypesSql, transaction: this.Transaction); + } + private const string TruncatePostgresNumericTypesSql = "TRUNCATE TABLE postgres_numeric_types"; + public async Task TruncatePostgresNumericTypes() + { + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncatePostgresNumericTypesSql); return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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"; + public class GetPostgresNumericTypesCntRow + { + public bool? CBoolean { get; init; } + public byte[]? CBit { get; init; } + public short? CSmallint { get; init; } + public int? CInteger { get; init; } + public long? CBigint { get; init; } + public decimal? CDecimal { get; init; } + public decimal? CNumeric { get; init; } + public float? CReal { get; init; } + public double? CDoublePrecision { get; init; } + public decimal? CMoney { get; init; } + public required long Cnt { get; init; } + }; + public async Task GetPostgresNumericTypesCnt() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new NpgsqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresNumericTypesCntSql); + return result; + } } - await this.Transaction.Connection.ExecuteAsync(InsertPostgresTypesSql, queryParams, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresNumericTypesCntSql, transaction: this.Transaction); } - private const string InsertPostgresTypesBatchSql = "COPY postgres_types (c_boolean, c_smallint, c_integer, c_bigint, c_real, c_numeric, c_decimal, c_double_precision, c_money, c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_char, c_varchar, c_character_varying, c_bpchar, c_text, c_uuid, c_cidr, c_inet, c_macaddr) FROM STDIN (FORMAT BINARY)"; - public class InsertPostgresTypesBatchArgs + private const string InsertPostgresNumericTypesBatchSql = "COPY postgres_numeric_types (c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money) FROM STDIN (FORMAT BINARY)"; + public class InsertPostgresNumericTypesBatchArgs { public bool? CBoolean { get; init; } + public byte[]? CBit { get; init; } public short? CSmallint { get; init; } public int? CInteger { get; init; } public long? CBigint { get; init; } - public float? CReal { get; init; } - public decimal? CNumeric { get; init; } public decimal? CDecimal { get; init; } + public decimal? CNumeric { get; init; } + public float? CReal { get; init; } public double? CDoublePrecision { get; init; } public decimal? CMoney { get; init; } - public DateTime? CDate { get; init; } - public TimeSpan? CTime { get; init; } - public DateTime? CTimestamp { get; init; } - public DateTime? CTimestampWithTz { get; init; } - public TimeSpan? CInterval { get; init; } - public string? CChar { get; init; } - public string? CVarchar { get; init; } - public string? CCharacterVarying { get; init; } - public string? CBpchar { get; init; } - public string? CText { get; init; } - public Guid? CUuid { get; init; } - public NpgsqlCidr? CCidr { get; init; } - public IPAddress? CInet { get; init; } - public PhysicalAddress? CMacaddr { get; init; } }; - public async Task InsertPostgresTypesBatch(List args) + public async Task InsertPostgresNumericTypesBatch(List args) { using (var connection = new NpgsqlConnection(ConnectionString)) { await connection.OpenAsync(); - using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresTypesBatchSql)) + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresNumericTypesBatchSql)) { foreach (var row in args) { await writer.StartRowAsync(); await writer.WriteAsync(row.CBoolean); + await writer.WriteAsync(row.CBit); await writer.WriteAsync(row.CSmallint); await writer.WriteAsync(row.CInteger); await writer.WriteAsync(row.CBigint); - await writer.WriteAsync(row.CReal); - await writer.WriteAsync(row.CNumeric); await writer.WriteAsync(row.CDecimal); + await writer.WriteAsync(row.CNumeric); + await writer.WriteAsync(row.CReal); await writer.WriteAsync(row.CDoublePrecision); await writer.WriteAsync(row.CMoney, NpgsqlDbType.Money); - await writer.WriteAsync(row.CDate, NpgsqlDbType.Date); - await writer.WriteAsync(row.CTime, NpgsqlDbType.Time); - await writer.WriteAsync(row.CTimestamp); - await writer.WriteAsync(row.CTimestampWithTz); - await writer.WriteAsync(row.CInterval, NpgsqlDbType.Interval); - await writer.WriteAsync(row.CChar); - await writer.WriteAsync(row.CVarchar); - await writer.WriteAsync(row.CCharacterVarying); - await writer.WriteAsync(row.CBpchar); - await writer.WriteAsync(row.CText); - await writer.WriteAsync(row.CUuid); - await writer.WriteAsync(row.CCidr); - await writer.WriteAsync(row.CInet); - await writer.WriteAsync(row.CMacaddr); } await writer.CompleteAsync(); @@ -683,199 +743,402 @@ public async Task InsertPostgresTypesBatch(List ar } } - private const string GetPostgresTypesSql = "SELECT c_boolean , c_bit, c_smallint, c_integer, c_bigint, c_real, c_numeric, c_decimal, c_double_precision, c_money, c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_char, c_varchar, c_character_varying, c_bpchar, c_text, c_uuid, c_json, c_json_string_override, c_jsonb, c_jsonpath, c_xml, c_cidr, c_inet, c_macaddr, c_macaddr8 :: TEXT AS c_macaddr8 FROM postgres_types LIMIT 1 "; - public class GetPostgresTypesRow + private const string InsertPostgresStringTypesSql = " INSERT INTO postgres_string_types ( c_char, c_varchar, c_character_varying, c_bpchar, c_text ) VALUES (@c_char, @c_varchar, @c_character_varying, @c_bpchar, @c_text)"; + public class InsertPostgresStringTypesArgs + { + public string? CChar { get; init; } + public string? CVarchar { get; init; } + public string? CCharacterVarying { get; init; } + public string? CBpchar { get; init; } + public string? CText { get; init; } + }; + public async Task InsertPostgresStringTypes(InsertPostgresStringTypesArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("c_char", args.CChar); + queryParams.Add("c_varchar", args.CVarchar); + queryParams.Add("c_character_varying", args.CCharacterVarying); + queryParams.Add("c_bpchar", args.CBpchar); + queryParams.Add("c_text", args.CText); + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(InsertPostgresStringTypesSql, queryParams); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertPostgresStringTypesSql, queryParams, transaction: this.Transaction); + } + + private const string InsertPostgresStringTypesBatchSql = "COPY postgres_string_types (c_char, c_varchar, c_character_varying, c_bpchar, c_text) FROM STDIN (FORMAT BINARY)"; + public class InsertPostgresStringTypesBatchArgs + { + public string? CChar { get; init; } + public string? CVarchar { get; init; } + public string? CCharacterVarying { get; init; } + public string? CBpchar { get; init; } + public string? CText { get; init; } + }; + public async Task InsertPostgresStringTypesBatch(List args) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresStringTypesBatchSql)) + { + foreach (var row in args) + { + await writer.StartRowAsync(); + await writer.WriteAsync(row.CChar); + await writer.WriteAsync(row.CVarchar); + await writer.WriteAsync(row.CCharacterVarying); + await writer.WriteAsync(row.CBpchar); + await writer.WriteAsync(row.CText); + } + + await writer.CompleteAsync(); + } + + await connection.CloseAsync(); + } + } + + private const string GetPostgresStringTypesSql = "SELECT c_char, c_varchar, c_character_varying, c_bpchar, c_text FROM postgres_string_types LIMIT 1"; + public class GetPostgresStringTypesRow { - public bool? CBoolean { get; init; } - public byte[]? CBit { get; init; } - public short? CSmallint { get; init; } - public int? CInteger { get; init; } - public long? CBigint { get; init; } - public float? CReal { get; init; } - public decimal? CNumeric { get; init; } - public decimal? CDecimal { get; init; } - public double? CDoublePrecision { get; init; } - public decimal? CMoney { get; init; } - public DateTime? CDate { get; init; } - public TimeSpan? CTime { get; init; } - public DateTime? CTimestamp { get; init; } - public DateTime? CTimestampWithTz { get; init; } - public TimeSpan? CInterval { get; init; } public string? CChar { get; init; } public string? CVarchar { get; init; } public string? CCharacterVarying { get; init; } public string? CBpchar { get; init; } public string? CText { get; init; } - public Guid? CUuid { get; init; } - public JsonElement? CJson { get; init; } - public string? CJsonStringOverride { get; init; } - public JsonElement? CJsonb { get; init; } - public string? CJsonpath { get; init; } - public XmlDocument? CXml { get; init; } - public NpgsqlCidr? CCidr { get; init; } - public IPAddress? CInet { get; init; } - public PhysicalAddress? CMacaddr { get; init; } - public string? CMacaddr8 { get; init; } }; - public async Task GetPostgresTypes() + public async Task GetPostgresStringTypes() { if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) { - var result = await connection.QueryFirstOrDefaultAsync(GetPostgresTypesSql); + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresStringTypesSql); return result; } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresStringTypesSql, transaction: this.Transaction); + } + + private const string TruncatePostgresStringTypesSql = "TRUNCATE TABLE postgres_string_types"; + public async Task TruncatePostgresStringTypes() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncatePostgresStringTypesSql); + return; } - return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresTypesSql, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncatePostgresStringTypesSql, transaction: this.Transaction); } - private const string GetPostgresTypesCntSql = "SELECT c_smallint , c_boolean, c_integer, c_bigint, c_real, c_numeric, c_decimal, c_double_precision, c_money, c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_char, c_varchar, c_character_varying, c_bpchar, c_text, c_uuid, c_cidr, c_inet, c_macaddr, COUNT (* ) AS cnt FROM postgres_types GROUP BY c_smallint, c_boolean, c_integer, c_bigint, c_real, c_numeric, c_decimal, c_double_precision, c_money, c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_char, c_varchar, c_character_varying, c_bpchar, c_text, c_uuid, c_cidr, c_inet, c_macaddr LIMIT 1 "; - public class GetPostgresTypesCntRow + private const string GetPostgresStringTypesCntSql = "SELECT c_char, c_varchar, c_character_varying, c_bpchar, c_text, COUNT(*) AS cnt FROM postgres_string_types GROUP BY c_char, c_varchar, c_character_varying, c_bpchar, c_text LIMIT 1"; + public class GetPostgresStringTypesCntRow { - public short? CSmallint { get; init; } - public bool? CBoolean { get; init; } - public int? CInteger { get; init; } - public long? CBigint { get; init; } - public float? CReal { get; init; } - public decimal? CNumeric { get; init; } - public decimal? CDecimal { get; init; } - public double? CDoublePrecision { get; init; } - public decimal? CMoney { get; init; } - public DateTime? CDate { get; init; } - public TimeSpan? CTime { get; init; } - public DateTime? CTimestamp { get; init; } - public DateTime? CTimestampWithTz { get; init; } - public TimeSpan? CInterval { get; init; } public string? CChar { get; init; } public string? CVarchar { get; init; } public string? CCharacterVarying { get; init; } public string? CBpchar { get; init; } public string? CText { get; init; } - public Guid? CUuid { get; init; } - public NpgsqlCidr? CCidr { get; init; } - public IPAddress? CInet { get; init; } - public PhysicalAddress? CMacaddr { get; init; } public required long Cnt { get; init; } }; - public async Task GetPostgresTypesCnt() + public async Task GetPostgresStringTypesCnt() { if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) { - var result = await connection.QueryFirstOrDefaultAsync(GetPostgresTypesCntSql); + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresStringTypesCntSql); return result; } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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"; + public class GetPostgresStringTypesTextSearchRow + { + public string? CText { get; init; } + public required NpgsqlTsQuery Query { get; init; } + public required NpgsqlTsVector Tsv { get; init; } + public required float Rnk { get; init; } + }; + public class GetPostgresStringTypesTextSearchArgs + { + public required string ToTsquery { get; init; } + }; + public async Task GetPostgresStringTypesTextSearch(GetPostgresStringTypesTextSearchArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("to_tsquery", args.ToTsquery); + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new NpgsqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresStringTypesTextSearchSql, queryParams); + return result; + } } - return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresTypesCntSql, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresStringTypesTextSearchSql, queryParams, 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_types "; - public class GetPostgresFunctionsRow + private const string InsertPostgresDateTimeTypesSql = " INSERT INTO postgres_datetime_types ( c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval ) VALUES (@c_date, @c_time, @c_timestamp, @c_timestamp_with_tz, @c_interval)"; + public class InsertPostgresDateTimeTypesArgs { - public int? MaxInteger { get; init; } - public string? MaxVarchar { get; init; } - public required DateTime MaxTimestamp { get; init; } + public DateTime? CDate { get; init; } + public TimeSpan? CTime { get; init; } + public DateTime? CTimestamp { get; init; } + public DateTime? CTimestampWithTz { get; init; } + public TimeSpan? CInterval { get; init; } }; - public async Task GetPostgresFunctions() + public async Task InsertPostgresDateTimeTypes(InsertPostgresDateTimeTypesArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("c_date", args.CDate); + queryParams.Add("c_time", args.CTime); + queryParams.Add("c_timestamp", args.CTimestamp); + queryParams.Add("c_timestamp_with_tz", args.CTimestampWithTz); + queryParams.Add("c_interval", args.CInterval); + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(InsertPostgresDateTimeTypesSql, queryParams); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertPostgresDateTimeTypesSql, queryParams, transaction: this.Transaction); + } + + private const string GetPostgresDateTimeTypesSql = "SELECT c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval FROM postgres_datetime_types LIMIT 1"; + public class GetPostgresDateTimeTypesRow + { + public DateTime? CDate { get; init; } + public TimeSpan? CTime { get; init; } + public DateTime? CTimestamp { get; init; } + public DateTime? CTimestampWithTz { get; init; } + public TimeSpan? CInterval { get; init; } + }; + public async Task GetPostgresDateTimeTypes() { if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) { - var result = await connection.QueryFirstOrDefaultAsync(GetPostgresFunctionsSql); + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresDateTimeTypesSql); return result; } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresDateTimeTypesSql, transaction: this.Transaction); + } + + private const string TruncatePostgresDateTimeTypesSql = "TRUNCATE TABLE postgres_datetime_types"; + public async Task TruncatePostgresDateTimeTypes() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncatePostgresDateTimeTypesSql); + return; } - return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresFunctionsSql, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncatePostgresDateTimeTypesSql, transaction: this.Transaction); } - 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 class InsertPostgresGeoTypesArgs + 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 NpgsqlPoint? CPoint { get; init; } - public NpgsqlLine? CLine { get; init; } - public NpgsqlLSeg? CLseg { get; init; } - public NpgsqlBox? CBox { get; init; } - public NpgsqlPath? CPath { get; init; } - public NpgsqlPolygon? CPolygon { get; init; } - public NpgsqlCircle? CCircle { get; init; } + public DateTime? CDate { get; init; } + public TimeSpan? CTime { get; init; } + public DateTime? CTimestamp { get; init; } + public DateTime? CTimestampWithTz { get; init; } + public TimeSpan? CInterval { get; init; } + public required long Cnt { get; init; } }; - public async Task InsertPostgresGeoTypes(InsertPostgresGeoTypesArgs args) + public async Task GetPostgresDateTimeTypesCnt() + { + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresDateTimeTypesCntSql); + return result; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresDateTimeTypesCntSql, transaction: this.Transaction); + } + + private const string InsertPostgresDateTimeTypesBatchSql = "COPY postgres_datetime_types (c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval) FROM STDIN (FORMAT BINARY)"; + public class InsertPostgresDateTimeTypesBatchArgs + { + public DateTime? CDate { get; init; } + public TimeSpan? CTime { get; init; } + public DateTime? CTimestamp { get; init; } + public DateTime? CTimestampWithTz { get; init; } + public TimeSpan? CInterval { get; init; } + }; + public async Task InsertPostgresDateTimeTypesBatch(List args) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresDateTimeTypesBatchSql)) + { + foreach (var row in args) + { + await writer.StartRowAsync(); + await writer.WriteAsync(row.CDate, NpgsqlDbType.Date); + await writer.WriteAsync(row.CTime, NpgsqlDbType.Time); + await writer.WriteAsync(row.CTimestamp); + await writer.WriteAsync(row.CTimestampWithTz); + await writer.WriteAsync(row.CInterval, NpgsqlDbType.Interval); + } + + await writer.CompleteAsync(); + } + + await connection.CloseAsync(); + } + } + + private const string InsertPostgresNetworkTypesSql = " INSERT INTO postgres_network_types ( c_cidr, c_inet, c_macaddr, c_macaddr8 ) VALUES ( @c_cidr, @c_inet, @c_macaddr, @c_macaddr8::macaddr8 )"; + public class InsertPostgresNetworkTypesArgs + { + public NpgsqlCidr? CCidr { get; init; } + public IPAddress? CInet { get; init; } + public PhysicalAddress? CMacaddr { get; init; } + public string? CMacaddr8 { get; init; } + }; + public async Task InsertPostgresNetworkTypes(InsertPostgresNetworkTypesArgs args) { var queryParams = new Dictionary(); - queryParams.Add("c_point", args.CPoint); - queryParams.Add("c_line", args.CLine); - queryParams.Add("c_lseg", args.CLseg); - queryParams.Add("c_box", args.CBox); - queryParams.Add("c_path", args.CPath); - queryParams.Add("c_polygon", args.CPolygon); - queryParams.Add("c_circle", args.CCircle); + queryParams.Add("c_cidr", args.CCidr); + queryParams.Add("c_inet", args.CInet); + queryParams.Add("c_macaddr", args.CMacaddr); + queryParams.Add("c_macaddr8", args.CMacaddr8); + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(InsertPostgresNetworkTypesSql, queryParams); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertPostgresNetworkTypesSql, queryParams, transaction: this.Transaction); + } + + private const string GetPostgresNetworkTypesSql = "SELECT c_cidr, c_inet, c_macaddr, c_macaddr8::TEXT AS c_macaddr8 FROM postgres_network_types LIMIT 1"; + public class GetPostgresNetworkTypesRow + { + public NpgsqlCidr? CCidr { get; init; } + public IPAddress? CInet { get; init; } + public PhysicalAddress? CMacaddr { get; init; } + public string? CMacaddr8 { get; init; } + }; + public async Task GetPostgresNetworkTypes() + { if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) { - await connection.ExecuteAsync(InsertPostgresGeoTypesSql, queryParams); + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresNetworkTypesSql); + return result; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresNetworkTypesSql, transaction: this.Transaction); + } + + private const string TruncatePostgresNetworkTypesSql = "TRUNCATE TABLE postgres_network_types"; + public async Task TruncatePostgresNetworkTypes() + { + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncatePostgresNetworkTypesSql); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncatePostgresNetworkTypesSql, transaction: this.Transaction); + } + + 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 class GetPostgresNetworkTypesCntRow + { + public NpgsqlCidr? CCidr { get; init; } + public IPAddress? CInet { get; init; } + public PhysicalAddress? CMacaddr { get; init; } + public required long Cnt { get; init; } + }; + public async Task GetPostgresNetworkTypesCnt() + { + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresNetworkTypesCntSql); + return result; } - - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - - await this.Transaction.Connection.ExecuteAsync(InsertPostgresGeoTypesSql, queryParams, transaction: this.Transaction); + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresNetworkTypesCntSql, transaction: this.Transaction); } - private const string InsertPostgresGeoTypesBatchSql = "COPY postgres_geometric_types (c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle) FROM STDIN (FORMAT BINARY)"; - public class InsertPostgresGeoTypesBatchArgs + private const string InsertPostgresNetworkTypesBatchSql = "COPY postgres_network_types (c_cidr, c_inet, c_macaddr) FROM STDIN (FORMAT BINARY)"; + public class InsertPostgresNetworkTypesBatchArgs { - public NpgsqlPoint? CPoint { get; init; } - public NpgsqlLine? CLine { get; init; } - public NpgsqlLSeg? CLseg { get; init; } - public NpgsqlBox? CBox { get; init; } - public NpgsqlPath? CPath { get; init; } - public NpgsqlPolygon? CPolygon { get; init; } - public NpgsqlCircle? CCircle { get; init; } + public NpgsqlCidr? CCidr { get; init; } + public IPAddress? CInet { get; init; } + public PhysicalAddress? CMacaddr { get; init; } }; - public async Task InsertPostgresGeoTypesBatch(List args) + public async Task InsertPostgresNetworkTypesBatch(List args) { using (var connection = new NpgsqlConnection(ConnectionString)) { await connection.OpenAsync(); - using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresGeoTypesBatchSql)) + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresNetworkTypesBatchSql)) { foreach (var row in args) { await writer.StartRowAsync(); - await writer.WriteAsync(row.CPoint); - await writer.WriteAsync(row.CLine); - await writer.WriteAsync(row.CLseg); - await writer.WriteAsync(row.CBox); - await writer.WriteAsync(row.CPath); - await writer.WriteAsync(row.CPolygon); - await writer.WriteAsync(row.CCircle); + await writer.WriteAsync(row.CCidr); + await writer.WriteAsync(row.CInet); + await writer.WriteAsync(row.CMacaddr); } await writer.CompleteAsync(); @@ -885,79 +1148,132 @@ public async Task InsertPostgresGeoTypesBatch(List GetPostgresGeoTypes() + public async Task InsertPostgresSpecialTypes(InsertPostgresSpecialTypesArgs args) { + var queryParams = new Dictionary(); + queryParams.Add("c_json", args.CJson.HasValue ? args.CJson.Value.GetRawText() : null); + queryParams.Add("c_json_string_override", args.CJsonStringOverride); + queryParams.Add("c_jsonb", args.CJsonb.HasValue ? args.CJsonb.Value.GetRawText() : null); + queryParams.Add("c_jsonpath", args.CJsonpath); + queryParams.Add("c_xml", args.CXml != null ? args.CXml.OuterXml : null); + queryParams.Add("c_xml_string_override", args.CXmlStringOverride); + queryParams.Add("c_uuid", args.CUuid); + queryParams.Add("c_enum", args.CEnum != null ? args.CEnum.Value.Stringify() : null); if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) - { - var result = await connection.QueryFirstOrDefaultAsync(GetPostgresGeoTypesSql); - return result; - } + await connection.ExecuteAsync(InsertPostgresSpecialTypesSql, queryParams); + return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - - return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresGeoTypesSql, transaction: this.Transaction); + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertPostgresSpecialTypesSql, queryParams, transaction: this.Transaction); } - private const string TruncatePostgresTypesSql = "TRUNCATE TABLE postgres_types"; - public async Task TruncatePostgresTypes() + 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 class GetPostgresSpecialTypesRow + { + public JsonElement? CJson { get; init; } + public string? CJsonStringOverride { get; init; } + public JsonElement? CJsonb { get; init; } + public string? CJsonpath { get; init; } + public XmlDocument? CXml { get; init; } + public string? CXmlStringOverride { get; init; } + public Guid? CUuid { get; init; } + public CEnum? CEnum { get; init; } + }; + public async Task GetPostgresSpecialTypes() { if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) { - await connection.ExecuteAsync(TruncatePostgresTypesSql); + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresSpecialTypesSql); + return result; } - - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresSpecialTypesSql, transaction: this.Transaction); + } + + private const string TruncatePostgresSpecialTypesSql = "TRUNCATE TABLE postgres_special_types"; + public async Task TruncatePostgresSpecialTypes() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncatePostgresSpecialTypesSql); + return; } - await this.Transaction.Connection.ExecuteAsync(TruncatePostgresTypesSql, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncatePostgresSpecialTypesSql, transaction: this.Transaction); } - private const string TruncatePostgresGeoTypesSql = "TRUNCATE TABLE postgres_geometric_types"; - public async Task TruncatePostgresGeoTypes() + private const string InsertPostgresSpecialTypesBatchSql = "COPY postgres_special_types (c_uuid) FROM STDIN (FORMAT BINARY)"; + public class InsertPostgresSpecialTypesBatchArgs { - if (this.Transaction == null) + public Guid? CUuid { get; init; } + }; + public async Task InsertPostgresSpecialTypesBatch(List args) + { + using (var connection = new NpgsqlConnection(ConnectionString)) { - using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.OpenAsync(); + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresSpecialTypesBatchSql)) { - await connection.ExecuteAsync(TruncatePostgresGeoTypesSql); + foreach (var row in args) + { + await writer.StartRowAsync(); + await writer.WriteAsync(row.CUuid); + } + + await writer.CompleteAsync(); } - return; + await connection.CloseAsync(); } + } - if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + private const string GetPostgresSpecialTypesCntSql = "SELECT c_uuid, COUNT(*) AS cnt FROM postgres_special_types GROUP BY c_uuid LIMIT 1"; + public class GetPostgresSpecialTypesCntRow + { + public Guid? CUuid { get; init; } + public required long Cnt { get; init; } + }; + public async Task GetPostgresSpecialTypesCnt() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new NpgsqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresSpecialTypesCntSql); + return result; + } } - await this.Transaction.Connection.ExecuteAsync(TruncatePostgresGeoTypesSql, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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; init; } @@ -981,18 +1297,12 @@ public async Task InsertPostgresArrayTypes(InsertPostgresArrayTypesArgs args) if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) - { await connection.ExecuteAsync(InsertPostgresArrayTypesSql, queryParams); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); await this.Transaction.Connection.ExecuteAsync(InsertPostgresArrayTypesSql, queryParams, transaction: this.Transaction); } @@ -1019,17 +1329,19 @@ public class GetPostgresArrayTypesRow } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresArrayTypesSql, transaction: this.Transaction); } - private const string InsertPostgresArrayTypesBatchSql = "COPY postgres_array_types (c_bytea) FROM STDIN (FORMAT BINARY)"; + private const string InsertPostgresArrayTypesBatchSql = "COPY postgres_array_types (c_bytea, c_boolean_array, c_text_array, c_integer_array, c_decimal_array, c_timestamp_array) FROM STDIN (FORMAT BINARY)"; public class InsertPostgresArrayTypesBatchArgs { public byte[]? CBytea { get; init; } + public bool[]? CBooleanArray { get; init; } + public string[]? CTextArray { get; init; } + public int[]? CIntegerArray { get; init; } + public decimal[]? CDecimalArray { get; init; } + public DateTime[]? CTimestampArray { get; init; } }; public async Task InsertPostgresArrayTypesBatch(List args) { @@ -1042,6 +1354,11 @@ public async Task InsertPostgresArrayTypesBatch(List GetPostgresArrayTypesCnt() @@ -1069,10 +1391,7 @@ public class GetPostgresArrayTypesCntRow } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresArrayTypesCntSql, transaction: this.Transaction); } @@ -1082,18 +1401,124 @@ public async Task TruncatePostgresArrayTypes() if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) - { await connection.ExecuteAsync(TruncatePostgresArrayTypesSql); - } + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncatePostgresArrayTypesSql, transaction: this.Transaction); + } + 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 class InsertPostgresGeoTypesArgs + { + public NpgsqlPoint? CPoint { get; init; } + public NpgsqlLine? CLine { get; init; } + public NpgsqlLSeg? CLseg { get; init; } + public NpgsqlBox? CBox { get; init; } + public NpgsqlPath? CPath { get; init; } + public NpgsqlPolygon? CPolygon { get; init; } + public NpgsqlCircle? CCircle { get; init; } + }; + public async Task InsertPostgresGeoTypes(InsertPostgresGeoTypesArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("c_point", args.CPoint); + queryParams.Add("c_line", args.CLine); + queryParams.Add("c_lseg", args.CLseg); + queryParams.Add("c_box", args.CBox); + queryParams.Add("c_path", args.CPath); + queryParams.Add("c_polygon", args.CPolygon); + queryParams.Add("c_circle", args.CCircle); + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(InsertPostgresGeoTypesSql, queryParams); return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertPostgresGeoTypesSql, queryParams, transaction: this.Transaction); + } + + private const string InsertPostgresGeoTypesBatchSql = "COPY postgres_geometric_types (c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle) FROM STDIN (FORMAT BINARY)"; + public class InsertPostgresGeoTypesBatchArgs + { + public NpgsqlPoint? CPoint { get; init; } + public NpgsqlLine? CLine { get; init; } + public NpgsqlLSeg? CLseg { get; init; } + public NpgsqlBox? CBox { get; init; } + public NpgsqlPath? CPath { get; init; } + public NpgsqlPolygon? CPolygon { get; init; } + public NpgsqlCircle? CCircle { get; init; } + }; + public async Task InsertPostgresGeoTypesBatch(List args) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresGeoTypesBatchSql)) + { + foreach (var row in args) + { + await writer.StartRowAsync(); + await writer.WriteAsync(row.CPoint); + await writer.WriteAsync(row.CLine); + await writer.WriteAsync(row.CLseg); + await writer.WriteAsync(row.CBox); + await writer.WriteAsync(row.CPath); + await writer.WriteAsync(row.CPolygon); + await writer.WriteAsync(row.CCircle); + } + + await writer.CompleteAsync(); + } + + await connection.CloseAsync(); + } + } + + private const string GetPostgresGeoTypesSql = "SELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgres_geometric_types LIMIT 1"; + public class GetPostgresGeoTypesRow + { + public NpgsqlPoint? CPoint { get; init; } + public NpgsqlLine? CLine { get; init; } + public NpgsqlLSeg? CLseg { get; init; } + public NpgsqlBox? CBox { get; init; } + public NpgsqlPath? CPath { get; init; } + public NpgsqlPolygon? CPolygon { get; init; } + public NpgsqlCircle? CCircle { get; init; } + }; + public async Task GetPostgresGeoTypes() + { + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresGeoTypesSql); + return result; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresGeoTypesSql, transaction: this.Transaction); + } + + private const string TruncatePostgresGeoTypesSql = "TRUNCATE TABLE postgres_geometric_types"; + public async Task TruncatePostgresGeoTypes() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncatePostgresGeoTypesSql); + return; } - await this.Transaction.Connection.ExecuteAsync(TruncatePostgresArrayTypesSql, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncatePostgresGeoTypesSql, transaction: this.Transaction); } } \ No newline at end of file diff --git a/examples/NpgsqlDapperExample/Utils.cs b/examples/NpgsqlDapperExample/Utils.cs index 0c800aac..b44b6de3 100644 --- a/examples/NpgsqlDapperExample/Utils.cs +++ b/examples/NpgsqlDapperExample/Utils.cs @@ -50,16 +50,18 @@ public static void ConfigureSqlMapper() { SqlMapper.AddTypeHandler(typeof(JsonElement), new JsonElementTypeHandler()); SqlMapper.AddTypeHandler(typeof(XmlDocument), new XmlDocumentTypeHandler()); - RegisterNpgsqlTypeHandler(); - RegisterNpgsqlTypeHandler(); - RegisterNpgsqlTypeHandler(); - RegisterNpgsqlTypeHandler(); - RegisterNpgsqlTypeHandler(); - RegisterNpgsqlTypeHandler(); - RegisterNpgsqlTypeHandler(); - RegisterNpgsqlTypeHandler(); - RegisterNpgsqlTypeHandler(); - RegisterNpgsqlTypeHandler(); + SqlMapper.AddTypeHandler(typeof(NpgsqlPoint), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(NpgsqlLine), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(NpgsqlLSeg), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(NpgsqlBox), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(NpgsqlPath), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(NpgsqlPolygon), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(NpgsqlCircle), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(NpgsqlCidr), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(IPAddress), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(PhysicalAddress), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(NpgsqlTsQuery), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(NpgsqlTsVector), new NpgsqlTypeHandler()); } private class NpgsqlTypeHandler : SqlMapper.TypeHandler where T : notnull @@ -74,10 +76,4 @@ public override void SetValue(IDbDataParameter parameter, T? value) parameter.Value = value; } } - - private static void RegisterNpgsqlTypeHandler() - where T : notnull - { - SqlMapper.AddTypeHandler(typeof(T), new NpgsqlTypeHandler()); - } } \ No newline at end of file diff --git a/examples/NpgsqlDapperExample/request.json b/examples/NpgsqlDapperExample/request.json index c7520d91..5b1759e1 100644 --- a/examples/NpgsqlDapperExample/request.json +++ b/examples/NpgsqlDapperExample/request.json @@ -3,15 +3,17 @@ "version": "2", "engine": "postgresql", "schema": [ - "examples/config/postgresql/schema.sql" + "examples/config/postgresql/authors/schema.sql", + "examples/config/postgresql/types/schema.sql" ], "queries": [ - "examples/config/postgresql/query.sql" + "examples/config/postgresql/authors/query.sql", + "examples/config/postgresql/types/query.sql" ], "codegen": { "out": "examples/NpgsqlDapperExample", "plugin": "csharp", - "options": "eyJkZWJ1Z1JlcXVlc3QiOnRydWUsImdlbmVyYXRlQ3Nwcm9qIjp0cnVlLCJuYW1lc3BhY2VOYW1lIjoiTnBnc3FsRGFwcGVyRXhhbXBsZUdlbiIsIm92ZXJyaWRlcyI6W3siY29sdW1uIjoiR2V0UG9zdGdyZXNGdW5jdGlvbnM6bWF4X2ludGVnZXIiLCJjc2hhcnBfdHlwZSI6eyJub3ROdWxsIjpmYWxzZSwidHlwZSI6ImludCJ9fSx7ImNvbHVtbiI6IkdldFBvc3RncmVzRnVuY3Rpb25zOm1heF92YXJjaGFyIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6ZmFsc2UsInR5cGUiOiJzdHJpbmcifX0seyJjb2x1bW4iOiJHZXRQb3N0Z3Jlc0Z1bmN0aW9uczptYXhfdGltZXN0YW1wIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6dHJ1ZSwidHlwZSI6IkRhdGVUaW1lIn19LHsiY29sdW1uIjoiKjpjX2pzb25fc3RyaW5nX292ZXJyaWRlIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6ZmFsc2UsInR5cGUiOiJzdHJpbmcifX0seyJjb2x1bW4iOiIqOmNfbWFjYWRkcjgiLCJjc2hhcnBfdHlwZSI6eyJub3ROdWxsIjpmYWxzZSwidHlwZSI6InN0cmluZyJ9fV0sInRhcmdldEZyYW1ld29yayI6Im5ldDguMCIsInVzZURhcHBlciI6dHJ1ZX0=", + "options": "eyJkZWJ1Z1JlcXVlc3QiOnRydWUsImdlbmVyYXRlQ3Nwcm9qIjp0cnVlLCJuYW1lc3BhY2VOYW1lIjoiTnBnc3FsRGFwcGVyRXhhbXBsZUdlbiIsIm92ZXJyaWRlcyI6W3siY29sdW1uIjoiR2V0UG9zdGdyZXNGdW5jdGlvbnM6bWF4X2ludGVnZXIiLCJjc2hhcnBfdHlwZSI6eyJub3ROdWxsIjpmYWxzZSwidHlwZSI6ImludCJ9fSx7ImNvbHVtbiI6IkdldFBvc3RncmVzRnVuY3Rpb25zOm1heF92YXJjaGFyIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6ZmFsc2UsInR5cGUiOiJzdHJpbmcifX0seyJjb2x1bW4iOiJHZXRQb3N0Z3Jlc0Z1bmN0aW9uczptYXhfdGltZXN0YW1wIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6dHJ1ZSwidHlwZSI6IkRhdGVUaW1lIn19LHsiY29sdW1uIjoiKjpjX2pzb25fc3RyaW5nX292ZXJyaWRlIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6ZmFsc2UsInR5cGUiOiJzdHJpbmcifX0seyJjb2x1bW4iOiIqOmNfeG1sX3N0cmluZ19vdmVycmlkZSIsImNzaGFycF90eXBlIjp7Im5vdE51bGwiOmZhbHNlLCJ0eXBlIjoic3RyaW5nIn19LHsiY29sdW1uIjoiKjpjX21hY2FkZHI4IiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6ZmFsc2UsInR5cGUiOiJzdHJpbmcifX1dLCJ0YXJnZXRGcmFtZXdvcmsiOiJuZXQ4LjAiLCJ1c2VEYXBwZXIiOnRydWV9", "process": { "cmd": "./dist/LocalRunner" } @@ -115,14 +117,14 @@ }, { "rel": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "columns": [ { "name": "c_boolean", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -133,7 +135,7 @@ "name": "c_bit", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -144,7 +146,7 @@ "name": "c_smallint", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -155,7 +157,7 @@ "name": "c_integer", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -166,7 +168,7 @@ "name": "c_bigint", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -177,7 +179,7 @@ "name": "c_decimal", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -188,7 +190,7 @@ "name": "c_numeric", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -199,7 +201,7 @@ "name": "c_real", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -210,7 +212,7 @@ "name": "c_double_precision", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -221,218 +223,272 @@ "name": "c_money", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "money" } - }, + } + ] + }, + { + "rel": { + "name": "postgres_string_types" + }, + "columns": [ { - "name": "c_date", + "name": "c_char", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "date" + "schema": "pg_catalog", + "name": "bpchar" } }, { - "name": "c_time", + "name": "c_varchar", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { "schema": "pg_catalog", - "name": "time" + "name": "varchar" } }, { - "name": "c_timestamp", + "name": "c_character_varying", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { "schema": "pg_catalog", - "name": "timestamp" + "name": "varchar" } }, { - "name": "c_timestamp_with_tz", + "name": "c_bpchar", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "schema": "pg_catalog", - "name": "timestamptz" + "name": "bpchar" } }, { - "name": "c_interval", + "name": "c_text", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "schema": "pg_catalog", - "name": "interval" + "name": "text" + } + } + ] + }, + { + "rel": { + "name": "postgres_datetime_types" + }, + "columns": [ + { + "name": "c_date", + "length": -1, + "table": { + "name": "postgres_datetime_types" + }, + "type": { + "name": "date" } }, { - "name": "c_char", + "name": "c_time", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "bpchar" + "name": "time" } }, { - "name": "c_varchar", + "name": "c_timestamp", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "varchar" + "name": "timestamp" } }, { - "name": "c_character_varying", + "name": "c_timestamp_with_tz", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "varchar" + "name": "timestamptz" } }, { - "name": "c_bpchar", + "name": "c_interval", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "bpchar" + "schema": "pg_catalog", + "name": "interval" } - }, + } + ] + }, + { + "rel": { + "name": "postgres_network_types" + }, + "columns": [ { - "name": "c_text", + "name": "c_cidr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "text" + "name": "cidr" } }, { - "name": "c_json", + "name": "c_inet", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "json" + "name": "inet" } }, { - "name": "c_json_string_override", + "name": "c_macaddr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "json" + "name": "macaddr" } }, { - "name": "c_jsonb", + "name": "c_macaddr8", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "jsonb" + "name": "macaddr8" } - }, + } + ] + }, + { + "rel": { + "name": "postgres_array_types" + }, + "columns": [ { - "name": "c_jsonpath", + "name": "c_bytea", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "jsonpath" + "name": "bytea" } }, { - "name": "c_xml", + "name": "c_boolean_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "xml" - } + "schema": "pg_catalog", + "name": "bool" + }, + "arrayDims": 1 }, { - "name": "c_cidr", + "name": "c_text_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "cidr" - } + "name": "text" + }, + "arrayDims": 1 }, { - "name": "c_inet", + "name": "c_integer_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "inet" - } + "schema": "pg_catalog", + "name": "int4" + }, + "arrayDims": 1 }, { - "name": "c_macaddr", + "name": "c_decimal_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "macaddr" - } + "schema": "pg_catalog", + "name": "numeric" + }, + "arrayDims": 1 }, { - "name": "c_macaddr8", + "name": "c_date_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "macaddr8" - } + "name": "date" + }, + "arrayDims": 1 }, { - "name": "c_uuid", + "name": "c_timestamp_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "uuid" - } + "schema": "pg_catalog", + "name": "timestamp" + }, + "arrayDims": 1 } ] }, @@ -515,97 +571,101 @@ }, { "rel": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "columns": [ { - "name": "c_bytea", + "name": "c_uuid", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "name": "bytea" + "name": "uuid" } }, { - "name": "c_boolean_array", - "isArray": true, + "name": "c_enum", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "schema": "pg_catalog", - "name": "bool" - }, - "arrayDims": 1 + "name": "c_enum" + } }, { - "name": "c_text_array", - "isArray": true, + "name": "c_json", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "name": "text" - }, - "arrayDims": 1 + "name": "json" + } }, { - "name": "c_integer_array", - "isArray": true, + "name": "c_json_string_override", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "schema": "pg_catalog", - "name": "int4" - }, - "arrayDims": 1 + "name": "json" + } }, { - "name": "c_decimal_array", - "isArray": true, + "name": "c_jsonb", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "schema": "pg_catalog", - "name": "numeric" - }, - "arrayDims": 1 + "name": "jsonb" + } }, { - "name": "c_date_array", - "isArray": true, + "name": "c_jsonpath", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "name": "date" - }, - "arrayDims": 1 + "name": "jsonpath" + } }, { - "name": "c_timestamp_array", - "isArray": true, + "name": "c_xml", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "schema": "pg_catalog", - "name": "timestamp" + "name": "xml" + } + }, + { + "name": "c_xml_string_override", + "length": -1, + "table": { + "name": "postgres_special_types" }, - "arrayDims": 1 + "type": { + "name": "xml" + } } ] } + ], + "enums": [ + { + "name": "c_enum", + "vals": [ + "small", + "medium", + "big" + ] + } ] }, { @@ -32449,6 +32509,67 @@ ] } ] + }, + { + "name": "extended", + "tables": [ + { + "rel": { + "schema": "extended", + "name": "bios" + }, + "columns": [ + { + "name": "author_name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + } + }, + { + "name": "name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + } + }, + { + "name": "bio_type", + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "extended", + "name": "bio_type" + } + } + ] + } + ], + "enums": [ + { + "name": "bio_type", + "vals": [ + "Autobiography", + "Biography", + "Memoir" + ] + } + ] } ] }, @@ -33207,8 +33328,174 @@ "filename": "query.sql" }, { - "text": "INSERT INTO postgres_types\n(\n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_real,\n c_numeric,\n c_decimal,\n c_double_precision,\n c_money,\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n c_uuid,\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_cidr,\n c_inet,\n c_macaddr,\n c_macaddr8\n)\nVALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6,\n $7,\n $8,\n $9,\n $10,\n $11,\n $12,\n $13,\n $14,\n $15,\n $16,\n $17,\n $18,\n $19,\n $20,\n $21,\n $22::json, \n $23::json, \n $24::jsonb,\n $25::jsonpath,\n $26::xml,\n $27,\n $28,\n $29::macaddr,\n $30::macaddr8\n)", - "name": "InsertPostgresTypes", + "text": "INSERT INTO extended.bios (author_name, name, bio_type) VALUES ($1, $2, $3)", + "name": "CreateExtendedBio", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "author_name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "pg_catalog.varchar" + }, + "originalName": "author_name" + } + }, + { + "number": 2, + "column": { + "name": "name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "pg_catalog.varchar" + }, + "originalName": "name" + } + }, + { + "number": 3, + "column": { + "name": "bio_type", + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "extended.bio_type" + }, + "originalName": "bio_type" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "schema": "extended", + "name": "bios" + } + }, + { + "text": "SELECT author_name, name, bio_type FROM extended.bios WHERE bio_type = $1 LIMIT 1", + "name": "GetFirstExtendedBioByType", + "cmd": ":one", + "columns": [ + { + "name": "author_name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "author_name" + }, + { + "name": "name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "name" + }, + { + "name": "bio_type", + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "extended", + "name": "bio_type" + }, + "originalName": "bio_type" + } + ], + "parameters": [ + { + "number": 1, + "column": { + "name": "bio_type", + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "extended.bio_type" + }, + "originalName": "bio_type" + } + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE extended.bios", + "name": "TruncateExtendedBios", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "SELECT\n MAX(c_integer) AS max_integer,\n MAX(c_varchar) AS max_varchar,\n MAX(c_timestamp) AS max_timestamp\nFROM postgres_datetime_types\nCROSS JOIN postgres_numeric_types\nCROSS JOIN postgres_string_types", + "name": "GetPostgresFunctions", + "cmd": ":one", + "columns": [ + { + "name": "max_integer", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "anyarray" + } + }, + { + "name": "max_varchar", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "anyarray" + } + }, + { + "name": "max_timestamp", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "anyarray" + } + } + ], + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO postgres_numeric_types\n(\n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_decimal,\n c_numeric,\n c_real,\n c_double_precision,\n c_money\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", + "name": "InsertPostgresNumericTypes", "cmd": ":exec", "parameters": [ { @@ -33216,10 +33503,9 @@ "column": { "name": "c_boolean", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.bool" @@ -33232,10 +33518,9 @@ "column": { "name": "c_bit", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.bit" @@ -33248,10 +33533,9 @@ "column": { "name": "c_smallint", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.int2" @@ -33264,10 +33548,9 @@ "column": { "name": "c_integer", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.int4" @@ -33280,10 +33563,9 @@ "column": { "name": "c_bigint", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.int8" @@ -33294,17 +33576,16 @@ { "number": 6, "column": { - "name": "c_real", + "name": "c_decimal", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.float4" + "name": "pg_catalog.numeric" }, - "originalName": "c_real" + "originalName": "c_decimal" } }, { @@ -33312,10 +33593,9 @@ "column": { "name": "c_numeric", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.numeric" @@ -33326,17 +33606,16 @@ { "number": 8, "column": { - "name": "c_decimal", + "name": "c_real", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.numeric" + "name": "pg_catalog.float4" }, - "originalName": "c_decimal" + "originalName": "c_real" } }, { @@ -33344,10 +33623,9 @@ "column": { "name": "c_double_precision", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.float8" @@ -33360,914 +33638,1509 @@ "column": { "name": "c_money", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "money" }, "originalName": "c_money" } + } + ], + "comments": [ + " Numeric types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_numeric_types" + } + }, + { + "text": "SELECT c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money FROM postgres_numeric_types LIMIT 1", + "name": "GetPostgresNumericTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_boolean", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bool" + }, + "originalName": "c_boolean" + }, + { + "name": "c_bit", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bit" + }, + "originalName": "c_bit" + }, + { + "name": "c_smallint", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int2" + }, + "originalName": "c_smallint" + }, + { + "name": "c_integer", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int4" + }, + "originalName": "c_integer" + }, + { + "name": "c_bigint", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int8" + }, + "originalName": "c_bigint" + }, + { + "name": "c_decimal", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "numeric" + }, + "originalName": "c_decimal" + }, + { + "name": "c_numeric", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "numeric" + }, + "originalName": "c_numeric" + }, + { + "name": "c_real", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "float4" + }, + "originalName": "c_real" + }, + { + "name": "c_double_precision", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "float8" + }, + "originalName": "c_double_precision" + }, + { + "name": "c_money", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "name": "money" + }, + "originalName": "c_money" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_numeric_types", + "name": "TruncatePostgresNumericTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "SELECT\n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_decimal,\n c_numeric,\n c_real,\n c_double_precision,\n c_money,\n COUNT(*) AS cnt\nFROM postgres_numeric_types\nGROUP BY\n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_decimal,\n c_numeric,\n c_real,\n c_double_precision,\n c_money\nLIMIT 1", + "name": "GetPostgresNumericTypesCnt", + "cmd": ":one", + "columns": [ + { + "name": "c_boolean", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bool" + }, + "originalName": "c_boolean" + }, + { + "name": "c_bit", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bit" + }, + "originalName": "c_bit" + }, + { + "name": "c_smallint", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int2" + }, + "originalName": "c_smallint" + }, + { + "name": "c_integer", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int4" + }, + "originalName": "c_integer" + }, + { + "name": "c_bigint", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int8" + }, + "originalName": "c_bigint" + }, + { + "name": "c_decimal", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "numeric" + }, + "originalName": "c_decimal" + }, + { + "name": "c_numeric", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "numeric" + }, + "originalName": "c_numeric" + }, + { + "name": "c_real", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "float4" + }, + "originalName": "c_real" + }, + { + "name": "c_double_precision", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "float8" + }, + "originalName": "c_double_precision" + }, + { + "name": "c_money", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "name": "money" + }, + "originalName": "c_money" }, { - "number": 11, + "name": "cnt", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "bigint" + } + } + ], + "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_numeric_types\n(\n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_decimal,\n c_numeric,\n c_real,\n c_double_precision,\n c_money\n) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", + "name": "InsertPostgresNumericTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, "column": { - "name": "c_date", + "name": "c_boolean", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "date" + "name": "pg_catalog.bool" }, - "originalName": "c_date" + "originalName": "c_boolean" } }, { - "number": 12, + "number": 2, "column": { - "name": "c_time", + "name": "c_bit", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.time" + "name": "pg_catalog.bit" }, - "originalName": "c_time" + "originalName": "c_bit" } }, { - "number": 13, + "number": 3, "column": { - "name": "c_timestamp", + "name": "c_smallint", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.timestamp" + "name": "pg_catalog.int2" }, - "originalName": "c_timestamp" + "originalName": "c_smallint" } }, { - "number": 14, + "number": 4, "column": { - "name": "c_timestamp_with_tz", + "name": "c_integer", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.timestamptz" + "name": "pg_catalog.int4" }, - "originalName": "c_timestamp_with_tz" + "originalName": "c_integer" } }, { - "number": 15, + "number": 5, "column": { - "name": "c_interval", + "name": "c_bigint", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.interval" + "name": "pg_catalog.int8" }, - "originalName": "c_interval" + "originalName": "c_bigint" } }, { - "number": 16, + "number": 6, "column": { - "name": "c_char", + "name": "c_decimal", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.bpchar" + "name": "pg_catalog.numeric" }, - "originalName": "c_char" + "originalName": "c_decimal" } }, { - "number": 17, + "number": 7, "column": { - "name": "c_varchar", + "name": "c_numeric", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.varchar" + "name": "pg_catalog.numeric" }, - "originalName": "c_varchar" + "originalName": "c_numeric" } }, { - "number": 18, + "number": 8, "column": { - "name": "c_character_varying", + "name": "c_real", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.varchar" + "name": "pg_catalog.float4" }, - "originalName": "c_character_varying" + "originalName": "c_real" } }, { - "number": 19, + "number": 9, "column": { - "name": "c_bpchar", + "name": "c_double_precision", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "bpchar" + "name": "pg_catalog.float8" }, - "originalName": "c_bpchar" + "originalName": "c_double_precision" } }, { - "number": 20, + "number": 10, "column": { - "name": "c_text", + "name": "c_money", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "text" + "name": "money" }, - "originalName": "c_text" + "originalName": "c_money" } - }, + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_numeric_types" + } + }, + { + "text": "\nINSERT INTO postgres_string_types\n(\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text\n)\nVALUES ($1, $2, $3, $4, $5)", + "name": "InsertPostgresStringTypes", + "cmd": ":exec", + "parameters": [ { - "number": 21, + "number": 1, "column": { - "name": "c_uuid", + "name": "c_char", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "uuid" + "name": "pg_catalog.bpchar" }, - "originalName": "c_uuid" + "originalName": "c_char" } }, { - "number": 22, + "number": 2, "column": { - "name": "c_json", + "name": "c_varchar", "length": -1, + "table": { + "schema": "public", + "name": "postgres_string_types" + }, "type": { - "name": "json" - } + "name": "pg_catalog.varchar" + }, + "originalName": "c_varchar" } }, { - "number": 23, - "column": { - "name": "c_json_string_override", - "length": -1, - "type": { - "name": "json" - } - } - }, - { - "number": 24, - "column": { - "name": "c_jsonb", - "length": -1, - "type": { - "name": "jsonb" - } - } - }, - { - "number": 25, - "column": { - "name": "c_jsonpath", - "length": -1, - "type": { - "name": "jsonpath" - } - } - }, - { - "number": 26, - "column": { - "name": "c_xml", - "length": -1, - "type": { - "name": "xml" - } - } - }, - { - "number": 27, + "number": 3, "column": { - "name": "c_cidr", + "name": "c_character_varying", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "cidr" + "name": "pg_catalog.varchar" }, - "originalName": "c_cidr" + "originalName": "c_character_varying" } }, { - "number": 28, + "number": 4, "column": { - "name": "c_inet", + "name": "c_bpchar", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "inet" + "name": "bpchar" }, - "originalName": "c_inet" - } - }, - { - "number": 29, - "column": { - "name": "c_macaddr", - "length": -1, - "type": { - "name": "macaddr" - } + "originalName": "c_bpchar" } }, { - "number": 30, + "number": 5, "column": { - "name": "c_macaddr8", + "name": "c_text", "length": -1, + "table": { + "schema": "public", + "name": "postgres_string_types" + }, "type": { - "name": "macaddr8" - } + "name": "text" + }, + "originalName": "c_text" } } ], + "comments": [ + " String types " + ], "filename": "query.sql", "insert_into_table": { - "name": "postgres_types" + "name": "postgres_string_types" } }, { - "text": "INSERT INTO postgres_types\n(\n c_boolean,\n c_smallint,\n c_integer,\n c_bigint,\n c_real,\n c_numeric,\n c_decimal,\n c_double_precision,\n c_money,\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n c_uuid,\n c_cidr,\n c_inet,\n c_macaddr\n)\nVALUES (\n $1, \n $2, \n $3, \n $4, \n $5, \n $6, \n $7, \n $8, \n $9, \n $10, \n $11, \n $12, \n $13, \n $14, \n $15, \n $16, \n $17, \n $18,\n $19,\n $20,\n $21,\n $22,\n $23\n)", - "name": "InsertPostgresTypesBatch", + "text": "INSERT INTO postgres_string_types \n(\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text\n) VALUES ($1, $2, $3, $4, $5)", + "name": "InsertPostgresStringTypesBatch", "cmd": ":copyfrom", "parameters": [ { "number": 1, "column": { - "name": "c_boolean", + "name": "c_char", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "pg_catalog.bool" + "name": "pg_catalog.bpchar" }, - "originalName": "c_boolean" + "originalName": "c_char" } }, { "number": 2, "column": { - "name": "c_smallint", + "name": "c_varchar", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "pg_catalog.int2" + "name": "pg_catalog.varchar" }, - "originalName": "c_smallint" + "originalName": "c_varchar" } }, { "number": 3, "column": { - "name": "c_integer", + "name": "c_character_varying", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "pg_catalog.int4" + "name": "pg_catalog.varchar" }, - "originalName": "c_integer" + "originalName": "c_character_varying" } }, { "number": 4, "column": { - "name": "c_bigint", + "name": "c_bpchar", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "pg_catalog.int8" + "name": "bpchar" }, - "originalName": "c_bigint" + "originalName": "c_bpchar" } }, { "number": 5, "column": { - "name": "c_real", + "name": "c_text", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "pg_catalog.float4" + "name": "text" }, - "originalName": "c_real" + "originalName": "c_text" } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_string_types" + } + }, + { + "text": "SELECT c_char, c_varchar, c_character_varying, c_bpchar, c_text FROM postgres_string_types LIMIT 1", + "name": "GetPostgresStringTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_char", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bpchar" + }, + "originalName": "c_char" }, { - "number": 6, - "column": { - "name": "c_numeric", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.numeric" - }, - "originalName": "c_numeric" - } + "name": "c_varchar", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "c_varchar" }, { - "number": 7, - "column": { - "name": "c_decimal", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.numeric" - }, - "originalName": "c_decimal" - } + "name": "c_character_varying", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "c_character_varying" }, { - "number": 8, - "column": { - "name": "c_double_precision", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.float8" - }, - "originalName": "c_double_precision" - } + "name": "c_bpchar", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "name": "bpchar" + }, + "originalName": "c_bpchar" }, { - "number": 9, - "column": { - "name": "c_money", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "money" - }, - "originalName": "c_money" - } + "name": "c_text", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "name": "text" + }, + "originalName": "c_text" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_string_types", + "name": "TruncatePostgresStringTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "SELECT\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n COUNT(*) AS cnt\nFROM postgres_string_types\nGROUP BY\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text\nLIMIT 1", + "name": "GetPostgresStringTypesCnt", + "cmd": ":one", + "columns": [ + { + "name": "c_char", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bpchar" + }, + "originalName": "c_char" }, { - "number": 10, - "column": { - "name": "c_date", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "date" - }, - "originalName": "c_date" - } + "name": "c_varchar", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "c_varchar" }, { - "number": 11, - "column": { - "name": "c_time", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.time" - }, - "originalName": "c_time" - } + "name": "c_character_varying", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "c_character_varying" }, { - "number": 12, - "column": { - "name": "c_timestamp", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.timestamp" - }, - "originalName": "c_timestamp" - } + "name": "c_bpchar", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "name": "bpchar" + }, + "originalName": "c_bpchar" }, { - "number": 13, - "column": { - "name": "c_timestamp_with_tz", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.timestamptz" - }, - "originalName": "c_timestamp_with_tz" - } + "name": "c_text", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "name": "text" + }, + "originalName": "c_text" }, { - "number": 14, - "column": { - "name": "c_interval", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.interval" - }, - "originalName": "c_interval" + "name": "cnt", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "bigint" } + } + ], + "filename": "query.sql" + }, + { + "text": "WITH txt_query AS (\n SELECT \n c_text, \n to_tsquery('english', $1) AS query,\n to_tsvector('english', c_text) AS tsv\n FROM postgres_string_types \n WHERE c_text @@ to_tsquery('english', $1)\n)\n\nSELECT txt_query.c_text, txt_query.query, txt_query.tsv, ts_rank(tsv, query) AS rnk\nFROM txt_query\nORDER BY rnk DESC\nLIMIT 1", + "name": "GetPostgresStringTypesTextSearch", + "cmd": ":one", + "columns": [ + { + "name": "c_text", + "length": -1, + "table": { + "name": "txt_query" + }, + "type": { + "name": "text" + }, + "originalName": "c_text" }, { - "number": 15, - "column": { - "name": "c_char", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.bpchar" - }, - "originalName": "c_char" - } + "name": "query", + "notNull": true, + "length": -1, + "table": { + "name": "txt_query" + }, + "type": { + "name": "tsquery" + }, + "originalName": "query" }, { - "number": 16, - "column": { - "name": "c_varchar", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.varchar" - }, - "originalName": "c_varchar" - } + "name": "tsv", + "notNull": true, + "length": -1, + "table": { + "name": "txt_query" + }, + "type": { + "name": "tsvector" + }, + "originalName": "tsv" }, { - "number": 17, - "column": { - "name": "c_character_varying", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.varchar" - }, - "originalName": "c_character_varying" + "name": "rnk", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "real" } - }, + } + ], + "parameters": [ { - "number": 18, + "number": 1, "column": { - "name": "c_bpchar", + "name": "to_tsquery", + "notNull": true, "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, "type": { - "name": "bpchar" - }, - "originalName": "c_bpchar" + "name": "text" + } } - }, + } + ], + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO postgres_datetime_types\n(\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval\n) VALUES ($1, $2, $3, $4, $5)", + "name": "InsertPostgresDateTimeTypes", + "cmd": ":exec", + "parameters": [ { - "number": 19, + "number": 1, "column": { - "name": "c_text", + "name": "c_date", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "text" + "name": "date" }, - "originalName": "c_text" + "originalName": "c_date" } }, { - "number": 20, + "number": 2, "column": { - "name": "c_uuid", + "name": "c_time", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "uuid" + "name": "pg_catalog.time" }, - "originalName": "c_uuid" + "originalName": "c_time" } }, { - "number": 21, + "number": 3, "column": { - "name": "c_cidr", + "name": "c_timestamp", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "cidr" + "name": "pg_catalog.timestamp" }, - "originalName": "c_cidr" + "originalName": "c_timestamp" } }, { - "number": 22, + "number": 4, "column": { - "name": "c_inet", + "name": "c_timestamp_with_tz", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "inet" + "name": "pg_catalog.timestamptz" }, - "originalName": "c_inet" + "originalName": "c_timestamp_with_tz" } }, { - "number": 23, + "number": 5, "column": { - "name": "c_macaddr", + "name": "c_interval", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "macaddr" + "name": "pg_catalog.interval" }, - "originalName": "c_macaddr" + "originalName": "c_interval" } } ], + "comments": [ + " DateTime types " + ], "filename": "query.sql", "insert_into_table": { - "name": "postgres_types" + "name": "postgres_datetime_types" } }, { - "text": "SELECT \n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_real,\n c_numeric,\n c_decimal,\n c_double_precision,\n c_money,\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n c_uuid,\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_cidr,\n c_inet,\n c_macaddr,\n c_macaddr8::TEXT AS c_macaddr8\nFROM postgres_types \nLIMIT 1", - "name": "GetPostgresTypes", + "text": "SELECT c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval FROM postgres_datetime_types LIMIT 1", + "name": "GetPostgresDateTimeTypes", "cmd": ":one", "columns": [ { - "name": "c_boolean", + "name": "c_date", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "schema": "pg_catalog", - "name": "bool" + "name": "date" }, - "originalName": "c_boolean" + "originalName": "c_date" }, { - "name": "c_bit", + "name": "c_time", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "bit" + "name": "time" }, - "originalName": "c_bit" + "originalName": "c_time" }, { - "name": "c_smallint", + "name": "c_timestamp", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "int2" + "name": "timestamp" }, - "originalName": "c_smallint" + "originalName": "c_timestamp" }, { - "name": "c_integer", + "name": "c_timestamp_with_tz", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "int4" + "name": "timestamptz" }, - "originalName": "c_integer" + "originalName": "c_timestamp_with_tz" }, { - "name": "c_bigint", + "name": "c_interval", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "int8" + "name": "interval" }, - "originalName": "c_bigint" - }, + "originalName": "c_interval" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_datetime_types", + "name": "TruncatePostgresDateTimeTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "SELECT\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n COUNT(*) AS cnt\nFROM postgres_datetime_types\nGROUP BY\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval\nLIMIT 1", + "name": "GetPostgresDateTimeTypesCnt", + "cmd": ":one", + "columns": [ { - "name": "c_real", + "name": "c_date", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "schema": "pg_catalog", - "name": "float4" + "name": "date" }, - "originalName": "c_real" + "originalName": "c_date" }, { - "name": "c_numeric", + "name": "c_time", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "numeric" + "name": "time" }, - "originalName": "c_numeric" + "originalName": "c_time" }, { - "name": "c_decimal", + "name": "c_timestamp", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "numeric" + "name": "timestamp" }, - "originalName": "c_decimal" + "originalName": "c_timestamp" }, { - "name": "c_double_precision", + "name": "c_timestamp_with_tz", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "float8" + "name": "timestamptz" }, - "originalName": "c_double_precision" + "originalName": "c_timestamp_with_tz" }, { - "name": "c_money", + "name": "c_interval", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "money" + "schema": "pg_catalog", + "name": "interval" }, - "originalName": "c_money" + "originalName": "c_interval" }, { - "name": "c_date", + "name": "cnt", + "notNull": true, "length": -1, - "table": { - "name": "postgres_types" - }, + "isFuncCall": true, "type": { - "name": "date" - }, - "originalName": "c_date" + "name": "bigint" + } + } + ], + "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_datetime_types\n(\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval\n) VALUES ($1, $2, $3, $4, $5)", + "name": "InsertPostgresDateTimeTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_date", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_datetime_types" + }, + "type": { + "name": "date" + }, + "originalName": "c_date" + } }, { - "name": "c_time", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "time" - }, - "originalName": "c_time" + "number": 2, + "column": { + "name": "c_time", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_datetime_types" + }, + "type": { + "name": "pg_catalog.time" + }, + "originalName": "c_time" + } }, { - "name": "c_timestamp", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "timestamp" - }, - "originalName": "c_timestamp" + "number": 3, + "column": { + "name": "c_timestamp", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_datetime_types" + }, + "type": { + "name": "pg_catalog.timestamp" + }, + "originalName": "c_timestamp" + } }, { - "name": "c_timestamp_with_tz", + "number": 4, + "column": { + "name": "c_timestamp_with_tz", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_datetime_types" + }, + "type": { + "name": "pg_catalog.timestamptz" + }, + "originalName": "c_timestamp_with_tz" + } + }, + { + "number": 5, + "column": { + "name": "c_interval", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_datetime_types" + }, + "type": { + "name": "pg_catalog.interval" + }, + "originalName": "c_interval" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_datetime_types" + } + }, + { + "text": "\nINSERT INTO postgres_network_types\n(\n c_cidr,\n c_inet,\n c_macaddr,\n c_macaddr8\n) VALUES (\n $1, \n $2, \n $3, \n $4::macaddr8\n)", + "name": "InsertPostgresNetworkTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_cidr", + "length": -1, + "isNamedParam": true, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "cidr" + }, + "originalName": "c_cidr" + } + }, + { + "number": 2, + "column": { + "name": "c_inet", + "length": -1, + "isNamedParam": true, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "inet" + }, + "originalName": "c_inet" + } + }, + { + "number": 3, + "column": { + "name": "c_macaddr", + "length": -1, + "isNamedParam": true, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "macaddr" + }, + "originalName": "c_macaddr" + } + }, + { + "number": 4, + "column": { + "name": "c_macaddr8", + "length": -1, + "type": { + "name": "macaddr8" + } + } + } + ], + "comments": [ + " Network types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_network_types" + } + }, + { + "text": "SELECT\n c_cidr,\n c_inet,\n c_macaddr,\n c_macaddr8::TEXT AS c_macaddr8\nFROM postgres_network_types\nLIMIT 1", + "name": "GetPostgresNetworkTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_cidr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "schema": "pg_catalog", - "name": "timestamptz" + "name": "cidr" }, - "originalName": "c_timestamp_with_tz" + "originalName": "c_cidr" }, { - "name": "c_interval", + "name": "c_inet", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "schema": "pg_catalog", - "name": "interval" + "name": "inet" }, - "originalName": "c_interval" + "originalName": "c_inet" }, { - "name": "c_char", + "name": "c_macaddr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "schema": "pg_catalog", - "name": "bpchar" + "name": "macaddr" }, - "originalName": "c_char" + "originalName": "c_macaddr" }, { - "name": "c_varchar", + "name": "c_macaddr8", + "notNull": true, "length": -1, - "table": { - "name": "postgres_types" - }, "type": { - "schema": "pg_catalog", - "name": "varchar" - }, - "originalName": "c_varchar" - }, + "name": "text" + } + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_network_types", + "name": "TruncatePostgresNetworkTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "SELECT\n c_cidr,\n c_inet,\n c_macaddr,\n COUNT(*) AS cnt\nFROM postgres_network_types\nGROUP BY\n c_cidr,\n c_inet,\n c_macaddr\nLIMIT 1", + "name": "GetPostgresNetworkTypesCnt", + "cmd": ":one", + "columns": [ { - "name": "c_character_varying", + "name": "c_cidr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "schema": "pg_catalog", - "name": "varchar" + "name": "cidr" }, - "originalName": "c_character_varying" + "originalName": "c_cidr" }, { - "name": "c_bpchar", + "name": "c_inet", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "bpchar" + "name": "inet" }, - "originalName": "c_bpchar" + "originalName": "c_inet" }, { - "name": "c_text", + "name": "c_macaddr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "text" + "name": "macaddr" }, - "originalName": "c_text" + "originalName": "c_macaddr" }, { - "name": "c_uuid", + "name": "cnt", + "notNull": true, "length": -1, - "table": { - "name": "postgres_types" - }, + "isFuncCall": true, "type": { - "name": "uuid" - }, - "originalName": "c_uuid" + "name": "bigint" + } + } + ], + "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_network_types\n(\n c_cidr,\n c_inet,\n c_macaddr\n) VALUES ($1, $2, $3)", + "name": "InsertPostgresNetworkTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_cidr", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "cidr" + }, + "originalName": "c_cidr" + } + }, + { + "number": 2, + "column": { + "name": "c_inet", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "inet" + }, + "originalName": "c_inet" + } + }, + { + "number": 3, + "column": { + "name": "c_macaddr", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "macaddr" + }, + "originalName": "c_macaddr" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_network_types" + } + }, + { + "text": "\nINSERT INTO postgres_special_types\n(\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum\n)\nVALUES (\n $1::json, \n $2::json, \n $3::jsonb,\n $4::jsonpath,\n $5::xml,\n $6::xml,\n $7,\n $8::c_enum\n)", + "name": "InsertPostgresSpecialTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_json", + "length": -1, + "type": { + "name": "json" + } + } + }, + { + "number": 2, + "column": { + "name": "c_json_string_override", + "length": -1, + "type": { + "name": "json" + } + } + }, + { + "number": 3, + "column": { + "name": "c_jsonb", + "length": -1, + "type": { + "name": "jsonb" + } + } + }, + { + "number": 4, + "column": { + "name": "c_jsonpath", + "length": -1, + "type": { + "name": "jsonpath" + } + } + }, + { + "number": 5, + "column": { + "name": "c_xml", + "length": -1, + "type": { + "name": "xml" + } + } + }, + { + "number": 6, + "column": { + "name": "c_xml_string_override", + "length": -1, + "type": { + "name": "xml" + } + } }, + { + "number": 7, + "column": { + "name": "c_uuid", + "length": -1, + "isNamedParam": true, + "table": { + "schema": "public", + "name": "postgres_special_types" + }, + "type": { + "name": "uuid" + }, + "originalName": "c_uuid" + } + }, + { + "number": 8, + "column": { + "name": "c_enum", + "length": -1, + "type": { + "name": "c_enum" + } + } + } + ], + "comments": [ + " Special types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_special_types" + } + }, + { + "text": "SELECT\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum\nFROM postgres_special_types \nLIMIT 1", + "name": "GetPostgresSpecialTypes", + "cmd": ":one", + "columns": [ { "name": "c_json", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { "name": "json" @@ -34278,7 +35151,7 @@ "name": "c_json_string_override", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { "name": "json" @@ -34289,7 +35162,7 @@ "name": "c_jsonb", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { "name": "jsonb" @@ -34300,7 +35173,7 @@ "name": "c_jsonpath", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { "name": "jsonpath" @@ -34311,7 +35184,7 @@ "name": "c_xml", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { "name": "xml" @@ -34319,321 +35192,528 @@ "originalName": "c_xml" }, { - "name": "c_cidr", + "name": "c_xml_string_override", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { - "name": "cidr" + "name": "xml" }, - "originalName": "c_cidr" + "originalName": "c_xml_string_override" }, { - "name": "c_inet", + "name": "c_uuid", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { - "name": "inet" + "name": "uuid" }, - "originalName": "c_inet" + "originalName": "c_uuid" }, { - "name": "c_macaddr", + "name": "c_enum", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { - "name": "macaddr" + "name": "c_enum" }, - "originalName": "c_macaddr" - }, + "originalName": "c_enum" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_special_types", + "name": "TruncatePostgresSpecialTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_special_types\n(\n c_uuid\n)\nVALUES (\n $1\n)", + "name": "InsertPostgresSpecialTypesBatch", + "cmd": ":copyfrom", + "parameters": [ { - "name": "c_macaddr8", - "notNull": true, - "length": -1, - "type": { - "name": "text" + "number": 1, + "column": { + "name": "c_uuid", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_special_types" + }, + "type": { + "name": "uuid" + }, + "originalName": "c_uuid" } } ], - "filename": "query.sql" + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_special_types" + } }, { - "text": "SELECT\n c_smallint,\n c_boolean,\n c_integer,\n c_bigint,\n c_real,\n c_numeric,\n c_decimal,\n c_double_precision,\n c_money,\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n c_uuid,\n c_cidr,\n c_inet,\n c_macaddr,\n COUNT(*) AS cnt\nFROM postgres_types\nGROUP BY\n c_smallint,\n c_boolean,\n c_integer,\n c_bigint,\n c_real,\n c_numeric,\n c_decimal,\n c_double_precision,\n c_money,\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n c_uuid,\n c_cidr,\n c_inet,\n c_macaddr\nLIMIT 1", - "name": "GetPostgresTypesCnt", + "text": "SELECT\n c_uuid,\n COUNT(*) AS cnt\nFROM postgres_special_types\nGROUP BY\n c_uuid\nLIMIT 1", + "name": "GetPostgresSpecialTypesCnt", "cmd": ":one", "columns": [ { - "name": "c_smallint", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "int2" - }, - "originalName": "c_smallint" - }, - { - "name": "c_boolean", + "name": "c_uuid", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { - "schema": "pg_catalog", - "name": "bool" + "name": "uuid" }, - "originalName": "c_boolean" + "originalName": "c_uuid" }, { - "name": "c_integer", + "name": "cnt", + "notNull": true, "length": -1, - "table": { - "name": "postgres_types" - }, + "isFuncCall": true, "type": { - "schema": "pg_catalog", - "name": "int4" - }, - "originalName": "c_integer" - }, + "name": "bigint" + } + } + ], + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO postgres_array_types\n(\n c_bytea,\n c_boolean_array,\n c_text_array,\n c_integer_array,\n c_decimal_array,\n c_date_array,\n c_timestamp_array\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", + "name": "InsertPostgresArrayTypes", + "cmd": ":exec", + "parameters": [ { - "name": "c_bigint", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "int8" - }, - "originalName": "c_bigint" + "number": 1, + "column": { + "name": "c_bytea", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "bytea" + }, + "originalName": "c_bytea" + } }, { - "name": "c_real", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "float4" - }, - "originalName": "c_real" + "number": 2, + "column": { + "name": "c_boolean_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.bool" + }, + "originalName": "c_boolean_array", + "arrayDims": 1 + } }, { - "name": "c_numeric", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "numeric" - }, - "originalName": "c_numeric" + "number": 3, + "column": { + "name": "c_text_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "text" + }, + "originalName": "c_text_array", + "arrayDims": 1 + } }, { - "name": "c_decimal", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "numeric" - }, - "originalName": "c_decimal" + "number": 4, + "column": { + "name": "c_integer_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.int4" + }, + "originalName": "c_integer_array", + "arrayDims": 1 + } }, { - "name": "c_double_precision", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "float8" - }, - "originalName": "c_double_precision" + "number": 5, + "column": { + "name": "c_decimal_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.numeric" + }, + "originalName": "c_decimal_array", + "arrayDims": 1 + } }, { - "name": "c_money", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "name": "money" - }, - "originalName": "c_money" + "number": 6, + "column": { + "name": "c_date_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "date" + }, + "originalName": "c_date_array", + "arrayDims": 1 + } }, { - "name": "c_date", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "name": "date" - }, - "originalName": "c_date" - }, + "number": 7, + "column": { + "name": "c_timestamp_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.timestamp" + }, + "originalName": "c_timestamp_array", + "arrayDims": 1 + } + } + ], + "comments": [ + " Array types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_array_types" + } + }, + { + "text": "SELECT c_bytea, c_boolean_array, c_text_array, c_integer_array, c_decimal_array, c_date_array, c_timestamp_array FROM postgres_array_types LIMIT 1", + "name": "GetPostgresArrayTypes", + "cmd": ":one", + "columns": [ { - "name": "c_time", + "name": "c_bytea", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "schema": "pg_catalog", - "name": "time" + "name": "bytea" }, - "originalName": "c_time" + "originalName": "c_bytea" }, { - "name": "c_timestamp", + "name": "c_boolean_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { "schema": "pg_catalog", - "name": "timestamp" + "name": "bool" }, - "originalName": "c_timestamp" + "originalName": "c_boolean_array", + "arrayDims": 1 }, { - "name": "c_timestamp_with_tz", + "name": "c_text_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "schema": "pg_catalog", - "name": "timestamptz" + "name": "text" }, - "originalName": "c_timestamp_with_tz" + "originalName": "c_text_array", + "arrayDims": 1 }, { - "name": "c_interval", + "name": "c_integer_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { "schema": "pg_catalog", - "name": "interval" + "name": "int4" }, - "originalName": "c_interval" + "originalName": "c_integer_array", + "arrayDims": 1 }, { - "name": "c_char", + "name": "c_decimal_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { "schema": "pg_catalog", - "name": "bpchar" + "name": "numeric" }, - "originalName": "c_char" + "originalName": "c_decimal_array", + "arrayDims": 1 }, { - "name": "c_varchar", + "name": "c_date_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, - "type": { - "schema": "pg_catalog", - "name": "varchar" + "type": { + "name": "date" }, - "originalName": "c_varchar" + "originalName": "c_date_array", + "arrayDims": 1 }, { - "name": "c_character_varying", + "name": "c_timestamp_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { "schema": "pg_catalog", - "name": "varchar" + "name": "timestamp" }, - "originalName": "c_character_varying" + "originalName": "c_timestamp_array", + "arrayDims": 1 + } + ], + "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_array_types (\n c_bytea,\n c_boolean_array,\n c_text_array,\n c_integer_array,\n c_decimal_array,\n c_timestamp_array\n) \nVALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6\n)", + "name": "InsertPostgresArrayTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_bytea", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "bytea" + }, + "originalName": "c_bytea" + } }, { - "name": "c_bpchar", + "number": 2, + "column": { + "name": "c_boolean_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.bool" + }, + "originalName": "c_boolean_array", + "arrayDims": 1 + } + }, + { + "number": 3, + "column": { + "name": "c_text_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "text" + }, + "originalName": "c_text_array", + "arrayDims": 1 + } + }, + { + "number": 4, + "column": { + "name": "c_integer_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.int4" + }, + "originalName": "c_integer_array", + "arrayDims": 1 + } + }, + { + "number": 5, + "column": { + "name": "c_decimal_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.numeric" + }, + "originalName": "c_decimal_array", + "arrayDims": 1 + } + }, + { + "number": 6, + "column": { + "name": "c_timestamp_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.timestamp" + }, + "originalName": "c_timestamp_array", + "arrayDims": 1 + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_array_types" + } + }, + { + "text": "SELECT\n c_bytea,\n c_boolean_array,\n c_text_array,\n c_integer_array,\n c_decimal_array,\n c_timestamp_array,\n COUNT(*) AS cnt\nFROM postgres_array_types\nGROUP BY\n c_bytea,\n c_boolean_array,\n c_text_array,\n c_integer_array,\n c_decimal_array,\n c_timestamp_array\nLIMIT 1", + "name": "GetPostgresArrayTypesCnt", + "cmd": ":one", + "columns": [ + { + "name": "c_bytea", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "bpchar" + "name": "bytea" }, - "originalName": "c_bpchar" + "originalName": "c_bytea" }, { - "name": "c_text", + "name": "c_boolean_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "text" + "schema": "pg_catalog", + "name": "bool" }, - "originalName": "c_text" + "originalName": "c_boolean_array", + "arrayDims": 1 }, { - "name": "c_uuid", + "name": "c_text_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "uuid" + "name": "text" }, - "originalName": "c_uuid" + "originalName": "c_text_array", + "arrayDims": 1 }, { - "name": "c_cidr", + "name": "c_integer_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "cidr" + "schema": "pg_catalog", + "name": "int4" }, - "originalName": "c_cidr" + "originalName": "c_integer_array", + "arrayDims": 1 }, { - "name": "c_inet", + "name": "c_decimal_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "inet" + "schema": "pg_catalog", + "name": "numeric" }, - "originalName": "c_inet" + "originalName": "c_decimal_array", + "arrayDims": 1 }, { - "name": "c_macaddr", + "name": "c_timestamp_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "macaddr" + "schema": "pg_catalog", + "name": "timestamp" }, - "originalName": "c_macaddr" + "originalName": "c_timestamp_array", + "arrayDims": 1 }, { "name": "cnt", @@ -34648,42 +35728,13 @@ "filename": "query.sql" }, { - "text": "SELECT\n MAX(c_integer) AS max_integer,\n MAX(c_varchar) AS max_varchar,\n MAX(c_timestamp) AS max_timestamp\nFROM postgres_types", - "name": "GetPostgresFunctions", - "cmd": ":one", - "columns": [ - { - "name": "max_integer", - "notNull": true, - "length": -1, - "isFuncCall": true, - "type": { - "name": "anyarray" - } - }, - { - "name": "max_varchar", - "notNull": true, - "length": -1, - "isFuncCall": true, - "type": { - "name": "anyarray" - } - }, - { - "name": "max_timestamp", - "notNull": true, - "length": -1, - "isFuncCall": true, - "type": { - "name": "anyarray" - } - } - ], + "text": "TRUNCATE TABLE postgres_array_types", + "name": "TruncatePostgresArrayTypes", + "cmd": ":exec", "filename": "query.sql" }, { - "text": "INSERT INTO postgres_geometric_types (\n c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", + "text": "\nINSERT INTO postgres_geometric_types (\n c_point, \n c_line, \n c_lseg, \n c_box, \n c_path, \n c_polygon, \n c_circle\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", "name": "InsertPostgresGeoTypes", "cmd": ":exec", "parameters": [ @@ -34793,13 +35844,16 @@ } } ], + "comments": [ + " Geometric types " + ], "filename": "query.sql", "insert_into_table": { "name": "postgres_geometric_types" } }, { - "text": "INSERT INTO postgres_geometric_types (\n c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", + "text": "INSERT INTO postgres_geometric_types (\n c_point, \n c_line, \n c_lseg, \n c_box, \n c_path, \n c_polygon, \n c_circle\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", "name": "InsertPostgresGeoTypesBatch", "cmd": ":copyfrom", "parameters": [ @@ -34999,308 +36053,13 @@ ], "filename": "query.sql" }, - { - "text": "TRUNCATE TABLE postgres_types", - "name": "TruncatePostgresTypes", - "cmd": ":exec", - "filename": "query.sql" - }, { "text": "TRUNCATE TABLE postgres_geometric_types", "name": "TruncatePostgresGeoTypes", "cmd": ":exec", "filename": "query.sql" - }, - { - "text": "INSERT INTO postgres_array_types\n(\n c_bytea,\n c_boolean_array,\n c_text_array,\n c_integer_array,\n c_decimal_array,\n c_date_array,\n c_timestamp_array\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", - "name": "InsertPostgresArrayTypes", - "cmd": ":exec", - "parameters": [ - { - "number": 1, - "column": { - "name": "c_bytea", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "bytea" - }, - "originalName": "c_bytea" - } - }, - { - "number": 2, - "column": { - "name": "c_boolean_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "pg_catalog.bool" - }, - "originalName": "c_boolean_array", - "arrayDims": 1 - } - }, - { - "number": 3, - "column": { - "name": "c_text_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "text" - }, - "originalName": "c_text_array", - "arrayDims": 1 - } - }, - { - "number": 4, - "column": { - "name": "c_integer_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "pg_catalog.int4" - }, - "originalName": "c_integer_array", - "arrayDims": 1 - } - }, - { - "number": 5, - "column": { - "name": "c_decimal_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "pg_catalog.numeric" - }, - "originalName": "c_decimal_array", - "arrayDims": 1 - } - }, - { - "number": 6, - "column": { - "name": "c_date_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "date" - }, - "originalName": "c_date_array", - "arrayDims": 1 - } - }, - { - "number": 7, - "column": { - "name": "c_timestamp_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "pg_catalog.timestamp" - }, - "originalName": "c_timestamp_array", - "arrayDims": 1 - } - } - ], - "filename": "query.sql", - "insert_into_table": { - "name": "postgres_array_types" - } - }, - { - "text": "SELECT c_bytea, c_boolean_array, c_text_array, c_integer_array, c_decimal_array, c_date_array, c_timestamp_array FROM postgres_array_types LIMIT 1", - "name": "GetPostgresArrayTypes", - "cmd": ":one", - "columns": [ - { - "name": "c_bytea", - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "name": "bytea" - }, - "originalName": "c_bytea" - }, - { - "name": "c_boolean_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "schema": "pg_catalog", - "name": "bool" - }, - "originalName": "c_boolean_array", - "arrayDims": 1 - }, - { - "name": "c_text_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "name": "text" - }, - "originalName": "c_text_array", - "arrayDims": 1 - }, - { - "name": "c_integer_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "schema": "pg_catalog", - "name": "int4" - }, - "originalName": "c_integer_array", - "arrayDims": 1 - }, - { - "name": "c_decimal_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "schema": "pg_catalog", - "name": "numeric" - }, - "originalName": "c_decimal_array", - "arrayDims": 1 - }, - { - "name": "c_date_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "name": "date" - }, - "originalName": "c_date_array", - "arrayDims": 1 - }, - { - "name": "c_timestamp_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "schema": "pg_catalog", - "name": "timestamp" - }, - "originalName": "c_timestamp_array", - "arrayDims": 1 - } - ], - "filename": "query.sql" - }, - { - "text": "INSERT INTO postgres_array_types (c_bytea) VALUES ($1)", - "name": "InsertPostgresArrayTypesBatch", - "cmd": ":copyfrom", - "parameters": [ - { - "number": 1, - "column": { - "name": "c_bytea", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "bytea" - }, - "originalName": "c_bytea" - } - } - ], - "filename": "query.sql", - "insert_into_table": { - "name": "postgres_array_types" - } - }, - { - "text": "SELECT\n c_bytea,\n COUNT(*) AS cnt\nFROM postgres_array_types\nGROUP BY\n c_bytea\nLIMIT 1", - "name": "GetPostgresArrayTypesCnt", - "cmd": ":one", - "columns": [ - { - "name": "c_bytea", - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "name": "bytea" - }, - "originalName": "c_bytea" - }, - { - "name": "cnt", - "notNull": true, - "length": -1, - "isFuncCall": true, - "type": { - "name": "bigint" - } - } - ], - "filename": "query.sql" - }, - { - "text": "TRUNCATE TABLE postgres_array_types", - "name": "TruncatePostgresArrayTypes", - "cmd": ":exec", - "filename": "query.sql" } ], "sqlc_version": "v1.27.0", - "plugin_options": "eyJvdmVycmlkZURyaXZlclZlcnNpb24iOiIiLCJnZW5lcmF0ZUNzcHJvaiI6dHJ1ZSwidGFyZ2V0RnJhbWV3b3JrIjoibmV0OC4wIiwibmFtZXNwYWNlTmFtZSI6Ik5wZ3NxbERhcHBlckV4YW1wbGVHZW4iLCJ1c2VEYXBwZXIiOnRydWUsIm92ZXJyaWRlRGFwcGVyVmVyc2lvbiI6IiIsIm92ZXJyaWRlcyI6W3siY29sdW1uIjoiR2V0UG9zdGdyZXNGdW5jdGlvbnM6bWF4X2ludGVnZXIiLCJjc2hhcnBfdHlwZSI6eyJ0eXBlIjoiaW50Iiwibm90TnVsbCI6ZmFsc2V9fSx7ImNvbHVtbiI6IkdldFBvc3RncmVzRnVuY3Rpb25zOm1heF92YXJjaGFyIiwiY3NoYXJwX3R5cGUiOnsidHlwZSI6InN0cmluZyIsIm5vdE51bGwiOmZhbHNlfX0seyJjb2x1bW4iOiJHZXRQb3N0Z3Jlc0Z1bmN0aW9uczptYXhfdGltZXN0YW1wIiwiY3NoYXJwX3R5cGUiOnsidHlwZSI6IkRhdGVUaW1lIiwibm90TnVsbCI6dHJ1ZX19LHsiY29sdW1uIjoiKjpjX2pzb25fc3RyaW5nX292ZXJyaWRlIiwiY3NoYXJwX3R5cGUiOnsidHlwZSI6InN0cmluZyIsIm5vdE51bGwiOmZhbHNlfX0seyJjb2x1bW4iOiIqOmNfbWFjYWRkcjgiLCJjc2hhcnBfdHlwZSI6eyJ0eXBlIjoic3RyaW5nIiwibm90TnVsbCI6ZmFsc2V9fV0sImRlYnVnUmVxdWVzdCI6ZmFsc2V9" + "plugin_options": "eyJvdmVycmlkZURyaXZlclZlcnNpb24iOiIiLCJnZW5lcmF0ZUNzcHJvaiI6dHJ1ZSwidGFyZ2V0RnJhbWV3b3JrIjoibmV0OC4wIiwibmFtZXNwYWNlTmFtZSI6Ik5wZ3NxbERhcHBlckV4YW1wbGVHZW4iLCJ1c2VEYXBwZXIiOnRydWUsIm92ZXJyaWRlRGFwcGVyVmVyc2lvbiI6IiIsIm92ZXJyaWRlcyI6W3siY29sdW1uIjoiR2V0UG9zdGdyZXNGdW5jdGlvbnM6bWF4X2ludGVnZXIiLCJjc2hhcnBfdHlwZSI6eyJ0eXBlIjoiaW50Iiwibm90TnVsbCI6ZmFsc2V9fSx7ImNvbHVtbiI6IkdldFBvc3RncmVzRnVuY3Rpb25zOm1heF92YXJjaGFyIiwiY3NoYXJwX3R5cGUiOnsidHlwZSI6InN0cmluZyIsIm5vdE51bGwiOmZhbHNlfX0seyJjb2x1bW4iOiJHZXRQb3N0Z3Jlc0Z1bmN0aW9uczptYXhfdGltZXN0YW1wIiwiY3NoYXJwX3R5cGUiOnsidHlwZSI6IkRhdGVUaW1lIiwibm90TnVsbCI6dHJ1ZX19LHsiY29sdW1uIjoiKjpjX2pzb25fc3RyaW5nX292ZXJyaWRlIiwiY3NoYXJwX3R5cGUiOnsidHlwZSI6InN0cmluZyIsIm5vdE51bGwiOmZhbHNlfX0seyJjb2x1bW4iOiIqOmNfeG1sX3N0cmluZ19vdmVycmlkZSIsImNzaGFycF90eXBlIjp7InR5cGUiOiJzdHJpbmciLCJub3ROdWxsIjpmYWxzZX19LHsiY29sdW1uIjoiKjpjX21hY2FkZHI4IiwiY3NoYXJwX3R5cGUiOnsidHlwZSI6InN0cmluZyIsIm5vdE51bGwiOmZhbHNlfX1dLCJkZWJ1Z1JlcXVlc3QiOmZhbHNlfQ==" } \ No newline at end of file diff --git a/examples/NpgsqlDapperExample/request.message b/examples/NpgsqlDapperExample/request.message index 8b05217a..76a9fa7f 100644 --- a/examples/NpgsqlDapperExample/request.message +++ b/examples/NpgsqlDapperExample/request.message @@ -1,9 +1,9 @@ -æ +¤ 2 -postgresql%examples/config/postgresql/schema.sql"$examples/config/postgresql/query.sqlb‡ -examples/NpgsqlDapperExamplecsharpÈ{"debugRequest":true,"generateCsproj":true,"namespaceName":"NpgsqlDapperExampleGen","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"notNull":false,"type":"int"}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"notNull":false,"type":"string"}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"notNull":true,"type":"DateTime"}},{"column":"*:c_json_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_macaddr8","csharp_type":{"notNull":false,"type":"string"}}],"targetFramework":"net8.0","useDapper":true}* -./dist/LocalRunner©æ public"ýpublicƒ +postgresql-examples/config/postgresql/authors/schema.sql+examples/config/postgresql/types/schema.sql",examples/config/postgresql/authors/query.sql"*examples/config/postgresql/types/query.sqlbÜ +examples/NpgsqlDapperExamplecsharp{"debugRequest":true,"generateCsproj":true,"namespaceName":"NpgsqlDapperExampleGen","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"notNull":false,"type":"int"}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"notNull":false,"type":"string"}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"notNull":true,"type":"DateTime"}},{"column":"*:c_json_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_xml_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_macaddr8","csharp_type":{"notNull":false,"type":"string"}}],"targetFramework":"net8.0","useDapper":true}* +./dist/LocalRunnerÃì public"…publicƒ authors) id0ÿÿÿÿÿÿÿÿÿR authorsb  bigserial& name0ÿÿÿÿÿÿÿÿÿR authorsbtext# @@ -13,68 +13,55 @@ postgresql%examples/config/postgresql/schema.sql"$examples/config/postgresql/qu name0ÿÿÿÿÿÿÿÿÿRbooksbtext5 author_id0ÿÿÿÿÿÿÿÿÿRbooksb pg_catalogint8) - description0ÿÿÿÿÿÿÿÿÿRbooksbtextä -postgres_types< - c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbool7 -c_bit0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbit= - -c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint2< - c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint4; -c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint8? - c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumeric? - c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumeric; -c_real0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat4G -c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat8/ -c_money0ÿÿÿÿÿÿÿÿÿRpostgres_typesbmoney- -c_date0ÿÿÿÿÿÿÿÿÿRpostgres_typesbdate9 -c_time0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogtimeC - c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestampM -c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestamptzA - -c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_cataloginterval; -c_char0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbpchar? - c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarcharI -c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarchar1 -c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesbbpchar- -c_text0ÿÿÿÿÿÿÿÿÿRpostgres_typesbtext- -c_json0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjson= -c_json_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjson/ -c_jsonb0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjsonb5 - -c_jsonpath0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -jsonpath+ -c_xml0ÿÿÿÿÿÿÿÿÿRpostgres_typesbxml- -c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_typesbcidr- -c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_typesbinet3 - c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_typesb macaddr5 - -c_macaddr80ÿÿÿÿÿÿÿÿÿRpostgres_typesb -macaddr8- -c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_typesbuuidµ -postgres_geometric_types9 -c_point0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpoint7 -c_line0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbline7 -c_lseg0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblseg5 -c_box0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbbox7 -c_path0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpath= - c_polygon0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesb polygon; -c_circle0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbcircle• + description0ÿÿÿÿÿÿÿÿÿRbooksbtextÔ +postgres_numeric_typesD + c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogbool? +c_bit0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogbitE + +c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint2D + c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint4C +c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint8G + c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericG + c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericC +c_real0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat4O +c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat87 +c_money0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesbmoneyç +postgres_string_typesB +c_char0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogbpcharF + c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarcharP +c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarchar8 +c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbbpchar4 +c_text0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbtext‰ +postgres_datetime_types6 +c_date0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesbdateB +c_time0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalogtimeL + c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestampV +c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestamptzJ + +c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_cataloginterval„ +postgres_network_types5 +c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbcidr5 +c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbinet; + c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesb macaddr= + +c_macaddr80ÿÿÿÿÿÿÿÿÿRpostgres_network_typesb +macaddr8• postgres_array_types5 c_bytea0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbbyteaM c_boolean_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb @@ -86,7 +73,27 @@ pg_catalogint4 pg_catalognumericˆ> c_date_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbdateˆT c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb -pg_catalog timestampˆ" pg_temp"æ² +pg_catalog timestampˆµ +postgres_geometric_types9 +c_point0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpoint7 +c_line0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbline7 +c_lseg0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblseg5 +c_box0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbbox7 +c_path0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpath= + c_polygon0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesb polygon; +c_circle0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbcircleú +postgres_special_types5 +c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbuuid7 +c_enum0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbc_enum5 +c_json0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjsonE +c_json_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjson7 +c_jsonb0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjsonb= + +c_jsonpath0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesb +jsonpath3 +c_xml0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbxmlC +c_xml_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbxml" +c_enumsmallmediumbig" pg_temp"æ² pg_catalog‰ & @@ -10207,7 +10214,14 @@ pg_cataloginformation_schemaviewsb  yes_or_noW pg_cataloginformation_schemaviewsb  yes_or_no] is_trigger_insertable_into0ÿÿÿÿÿÿÿÿÿR' -pg_cataloginformation_schemaviewsb  yes_or_no +pg_cataloginformation_schemaviewsb  yes_or_no"extendedÔ +extendedbiosC + author_name0ÿÿÿÿÿÿÿÿÿRextendedbiosb +pg_catalogvarchar< +name0ÿÿÿÿÿÿÿÿÿRextendedbiosb +pg_catalogvarchar= +bio_type0ÿÿÿÿÿÿÿÿÿRextendedbiosbextendedbio_type", +bio_type Autobiography BiographyMemoir 9SELECT id, name, bio FROM authors WHERE name = $1 LIMIT 1 GetAuthor:one"- id0ÿÿÿÿÿÿÿÿÿR authorsb  bigserialzid", @@ -10298,415 +10312,439 @@ WHERE books.name = $1GetAuthorsByBookName:many"- name0ÿÿÿÿÿÿÿÿÿR authorsbtextzname"( bio0ÿÿÿÿÿÿÿÿÿR authorsbtextzbio" books0ÿÿÿÿÿÿÿÿÿbrbooks*.* -name0ÿÿÿÿÿÿÿÿÿRbooksbtextzname: query.sqlˆ -¬INSERT INTO postgres_types +name0ÿÿÿÿÿÿÿÿÿRbooksbtextzname: query.sqlì +KINSERT INTO extended.bios (author_name, name, bio_type) VALUES ($1, $2, $3)CreateExtendedBio:exec*SO + author_name0ÿÿÿÿÿÿÿÿÿRextendedbiosbpg_catalog.varcharz author_name*EA +name0ÿÿÿÿÿÿÿÿÿRextendedbiosbpg_catalog.varcharzname*JF +bio_type0ÿÿÿÿÿÿÿÿÿRextendedbiosbextended.bio_typezbio_type: query.sqlBextendedbiosª +QSELECT author_name, name, bio_type FROM extended.bios WHERE bio_type = $1 LIMIT 1GetFirstExtendedBioByType:one"P + author_name0ÿÿÿÿÿÿÿÿÿRextendedbiosb +pg_catalogvarcharz author_name"B +name0ÿÿÿÿÿÿÿÿÿRextendedbiosb +pg_catalogvarcharzname"G +bio_type0ÿÿÿÿÿÿÿÿÿRextendedbiosbextendedbio_typezbio_type*JF +bio_type0ÿÿÿÿÿÿÿÿÿRextendedbiosbextended.bio_typezbio_type: query.sqlF +TRUNCATE TABLE extended.biosTruncateExtendedBios:exec: query.sqlü +Ò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_typesGetPostgresFunctions:one"( + max_integer0ÿÿÿÿÿÿÿÿÿ@b +anyarray"( + max_varchar0ÿÿÿÿÿÿÿÿÿ@b +anyarray"* + max_timestamp0ÿÿÿÿÿÿÿÿÿ@b +anyarray: query.sqlà +í +INSERT INTO postgres_numeric_types ( c_boolean, c_bit, c_smallint, c_integer, c_bigint, - c_real, - c_numeric, c_decimal, + c_numeric, + c_real, c_double_precision, - c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, - c_json, - c_json_string_override, - c_jsonb, - c_jsonpath, - c_xml, - c_cidr, - c_inet, - c_macaddr, - c_macaddr8 + c_money ) -VALUES ( - $1, - $2, - $3, - $4, - $5, - $6, - $7, - $8, - $9, - $10, - $11, - $12, - $13, - $14, - $15, - $16, - $17, - $18, - $19, - $20, - $21, - $22::json, - $23::json, - $24::jsonb, - $25::jsonpath, - $26::xml, - $27, - $28, - $29::macaddr, - $30::macaddr8 -)InsertPostgresTypes:exec*TP - c_boolean0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.boolz c_boolean*KG -c_bit0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.bitzc_bit*VR - -c_smallint0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.int2z -c_smallint*TP - c_integer0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.int4z c_integer*RN -c_bigint0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.int8zc_bigint*PL -c_real0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.float4zc_real*WS - c_numeric0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.numericz c_numeric*WS - c_decimal0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.numericz c_decimal*h d -c_double_precision0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.float8zc_double_precision*F -B -c_money0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbmoneyzc_money*C ? -c_date0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbdatezc_date*N J -c_time0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.timezc_time*] Y - c_timestamp0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.timestampz c_timestamp*ok -c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.timestamptzzc_timestamp_with_tz*ZV - -c_interval0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.intervalz -c_interval*PL -c_char0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.bpcharzc_char*WS - c_varchar0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.varcharz c_varchar*kg -c_character_varying0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.varcharzc_character_varying*IE -c_bpchar0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbbpcharzc_bpchar*C? -c_text0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbtextzc_text*C? -c_uuid0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbuuidzc_uuid* -c_json0ÿÿÿÿÿÿÿÿÿbjson*/+ -c_json_string_override0ÿÿÿÿÿÿÿÿÿbjson*! -c_jsonb0ÿÿÿÿÿÿÿÿÿbjsonb*'# - -c_jsonpath0ÿÿÿÿÿÿÿÿÿb -jsonpath* -c_xml0ÿÿÿÿÿÿÿÿÿbxml*C? -c_cidr0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbcidrzc_cidr*C? -c_inet0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbinetzc_inet*%! - c_macaddr0ÿÿÿÿÿÿÿÿÿb macaddr*'# - -c_macaddr80ÿÿÿÿÿÿÿÿÿb -macaddr8: query.sqlBpostgres_types‡ -ÜINSERT INTO postgres_types -( +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)InsertPostgresNumericTypes:exec*ZV + c_boolean0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.boolz c_boolean*QM +c_bit0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.bitzc_bit*\X + +c_smallint0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int2z +c_smallint*ZV + c_integer0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int4z c_integer*XT +c_bigint0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int8zc_bigint*]Y + c_decimal0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.numericz c_decimal*]Y + c_numeric0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.numericz c_numeric*VR +c_real0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.float4zc_real*n j +c_double_precision0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.float8zc_double_precision*L +H +c_money0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbmoneyzc_money2 Numeric types : query.sqlBpostgres_numeric_typesì +—SELECT c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money FROM postgres_numeric_types LIMIT 1GetPostgresNumericTypes:one"O + c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogboolz c_boolean"F +c_bit0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogbitzc_bit"Q + +c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint2z +c_smallint"O + c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint4z c_integer"M +c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint8zc_bigint"R + c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericz c_decimal"R + c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericz c_numeric"K +c_real0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat4zc_real"c +c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat8zc_double_precision"@ +c_money0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesbmoneyzc_money: query.sqlW +%TRUNCATE TABLE postgres_numeric_typesTruncatePostgresNumericTypes:exec: query.sqlê +òSELECT c_boolean, + c_bit, c_smallint, c_integer, c_bigint, - c_real, - c_numeric, c_decimal, + c_numeric, + c_real, c_double_precision, c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, - c_cidr, - c_inet, - c_macaddr -) -VALUES ( - $1, - $2, - $3, - $4, - $5, - $6, - $7, - $8, - $9, - $10, - $11, - $12, - $13, - $14, - $15, - $16, - $17, - $18, - $19, - $20, - $21, - $22, - $23 -)InsertPostgresTypesBatch :copyfrom*RN - c_boolean0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.boolz c_boolean*TP - -c_smallint0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.int2z -c_smallint*RN - c_integer0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.int4z c_integer*PL -c_bigint0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.int8zc_bigint*NJ -c_real0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.float4zc_real*UQ - c_numeric0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.numericz c_numeric*UQ - c_decimal0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.numericz c_decimal*fb -c_double_precision0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.float8zc_double_precision*D @ -c_money0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbmoneyzc_money*A -= -c_date0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbdatezc_date*L H -c_time0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.timezc_time*[ W - c_timestamp0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.timestampz c_timestamp*m i -c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.timestamptzzc_timestamp_with_tz*XT - -c_interval0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.intervalz -c_interval*NJ -c_char0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.bpcharzc_char*UQ - c_varchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.varcharz c_varchar*ie -c_character_varying0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.varcharzc_character_varying*GC -c_bpchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbbpcharzc_bpchar*A= -c_text0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbtextzc_text*A= -c_uuid0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbuuidzc_uuid*A= -c_cidr0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbcidrzc_cidr*A= -c_inet0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbinetzc_inet*JF - c_macaddr0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesb macaddrz c_macaddr: query.sqlBpostgres_types­ -„SELECT + COUNT(*) AS cnt +FROM postgres_numeric_types +GROUP BY c_boolean, c_bit, c_smallint, c_integer, c_bigint, - c_real, - c_numeric, c_decimal, + c_numeric, + c_real, c_double_precision, - c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, - c_json, - c_json_string_override, - c_jsonb, - c_jsonpath, - c_xml, - c_cidr, - c_inet, - c_macaddr, - c_macaddr8::TEXT AS c_macaddr8 -FROM postgres_types -LIMIT 1GetPostgresTypes:one"G - c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogboolz c_boolean"> -c_bit0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbitzc_bit"I - -c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb + c_money +LIMIT 1GetPostgresNumericTypesCnt:one"O + c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogboolz c_boolean"F +c_bit0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogbitzc_bit"Q + +c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb pg_catalogint2z -c_smallint"G - c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint4z c_integer"E -c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint8zc_bigint"C -c_real0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat4zc_real"J - c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumericz c_numeric"J - c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumericz c_decimal"[ -c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat8zc_double_precision"8 -c_money0ÿÿÿÿÿÿÿÿÿRpostgres_typesbmoneyzc_money"5 -c_date0ÿÿÿÿÿÿÿÿÿRpostgres_typesbdatezc_date"A -c_time0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogtimezc_time"P - c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestampz c_timestamp"b -c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestamptzzc_timestamp_with_tz"M - -c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogintervalz -c_interval"C -c_char0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbpcharzc_char"J - c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarcharz c_varchar"^ -c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarcharzc_character_varying"; -c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesbbpcharzc_bpchar"5 -c_text0ÿÿÿÿÿÿÿÿÿRpostgres_typesbtextzc_text"5 -c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_typesbuuidzc_uuid"5 -c_json0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjsonzc_json"U -c_json_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjsonzc_json_string_override"8 -c_jsonb0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjsonbzc_jsonb"A - -c_jsonpath0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -jsonpathz -c_jsonpath"2 -c_xml0ÿÿÿÿÿÿÿÿÿRpostgres_typesbxmlzc_xml"5 -c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_typesbcidrzc_cidr"5 -c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_typesbinetzc_inet"> - c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_typesb macaddrz c_macaddr"! - -c_macaddr80ÿÿÿÿÿÿÿÿÿbtext: query.sql¤ -úSELECT - c_smallint, +c_smallint"O + c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint4z c_integer"M +c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint8zc_bigint"R + c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericz c_decimal"R + c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericz c_numeric"K +c_real0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat4zc_real"c +c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat8zc_double_precision"@ +c_money0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesbmoneyzc_money" +cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sql× +ìINSERT INTO postgres_numeric_types +( c_boolean, + c_bit, + c_smallint, c_integer, c_bigint, - c_real, - c_numeric, c_decimal, + c_numeric, + c_real, c_double_precision, - c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, + c_money +) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)InsertPostgresNumericTypesBatch :copyfrom*ZV + c_boolean0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.boolz c_boolean*QM +c_bit0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.bitzc_bit*\X + +c_smallint0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int2z +c_smallint*ZV + c_integer0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int4z c_integer*XT +c_bigint0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int8zc_bigint*]Y + c_decimal0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.numericz c_decimal*]Y + c_numeric0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.numericz c_numeric*VR +c_real0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.float4zc_real*n j +c_double_precision0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.float8zc_double_precision*L +H +c_money0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbmoneyzc_money: query.sqlBpostgres_numeric_types© + +INSERT INTO postgres_string_types +( + c_char, + c_varchar, + c_character_varying, + c_bpchar, + c_text +) +VALUES ($1, $2, $3, $4, $5)InsertPostgresStringTypes:exec*UQ +c_char0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.bpcharzc_char*\X + c_varchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.varcharz c_varchar*pl +c_character_varying0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.varcharzc_character_varying*NJ +c_bpchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbbpcharzc_bpchar*HD +c_text0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbtextzc_text2 String types : query.sqlBpostgres_string_types¢ +INSERT INTO postgres_string_types +( + c_char, + c_varchar, + c_character_varying, + c_bpchar, + c_text +) VALUES ($1, $2, $3, $4, $5)InsertPostgresStringTypesBatch :copyfrom*UQ +c_char0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.bpcharzc_char*\X + c_varchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.varcharz c_varchar*pl +c_character_varying0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.varcharzc_character_varying*NJ +c_bpchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbbpcharzc_bpchar*HD +c_text0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbtextzc_text: query.sqlBpostgres_string_types• +bSELECT c_char, c_varchar, c_character_varying, c_bpchar, c_text FROM postgres_string_types LIMIT 1GetPostgresStringTypes:one"J +c_char0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogbpcharzc_char"Q + c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarcharz c_varchar"e +c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarcharzc_character_varying"B +c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbbpcharzc_bpchar"< +c_text0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbtextzc_text: query.sqlU +$TRUNCATE TABLE postgres_string_typesTruncatePostgresStringTypes:exec: query.sql¸ +áSELECT c_char, c_varchar, c_character_varying, c_bpchar, c_text, - c_uuid, - c_cidr, - c_inet, - c_macaddr, COUNT(*) AS cnt -FROM postgres_types +FROM postgres_string_types GROUP BY - c_smallint, - c_boolean, - c_integer, - c_bigint, - c_real, - c_numeric, - c_decimal, - c_double_precision, - c_money, + c_char, + c_varchar, + c_character_varying, + c_bpchar, + c_text +LIMIT 1GetPostgresStringTypesCnt:one"J +c_char0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogbpcharzc_char"Q + c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarcharz c_varchar"e +c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarcharzc_character_varying"B +c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbbpcharzc_bpchar"< +c_text0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbtextzc_text" +cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sqlì +ØWITH txt_query AS ( + SELECT + c_text, + to_tsquery('english', $1) AS query, + to_tsvector('english', c_text) AS tsv + FROM postgres_string_types + WHERE c_text @@ to_tsquery('english', $1) +) + +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 GetPostgresStringTypesTextSearch:one"0 +c_text0ÿÿÿÿÿÿÿÿÿR  txt_querybtextzc_text"3 +query0ÿÿÿÿÿÿÿÿÿR  txt_queryb tsqueryzquery"0 +tsv0ÿÿÿÿÿÿÿÿÿR  txt_queryb +tsvectorztsv" +rnk0ÿÿÿÿÿÿÿÿÿ@breal*%! + +to_tsquery0ÿÿÿÿÿÿÿÿÿbtext: query.sqlØ +• +INSERT INTO postgres_datetime_types +( + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval +) VALUES ($1, $2, $3, $4, $5)InsertPostgresDateTimeTypes:exec*JF +c_date0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbdatezc_date*UQ +c_time0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timezc_time*d` + c_timestamp0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timestampz c_timestamp*vr +c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timestamptzzc_timestamp_with_tz*a] + +c_interval0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.intervalz +c_interval2 DateTime types : query.sqlBpostgres_datetime_typesÁ +hSELECT c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval FROM postgres_datetime_types LIMIT 1GetPostgresDateTimeTypes:one"> +c_date0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesbdatezc_date"J +c_time0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalogtimezc_time"Y + c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestampz c_timestamp"k +c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestamptzzc_timestamp_with_tz"V + +c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalogintervalz +c_interval: query.sqlY +&TRUNCATE TABLE postgres_datetime_typesTruncatePostgresDateTimeTypes:exec: query.sqlè +ëSELECT c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, + COUNT(*) AS cnt +FROM postgres_datetime_types +GROUP BY + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval +LIMIT 1GetPostgresDateTimeTypesCnt:one"> +c_date0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesbdatezc_date"J +c_time0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalogtimezc_time"Y + c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestampz c_timestamp"k +c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestamptzzc_timestamp_with_tz"V + +c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalogintervalz +c_interval" +cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sqlÎ +”INSERT INTO postgres_datetime_types +( + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval +) VALUES ($1, $2, $3, $4, $5) InsertPostgresDateTimeTypesBatch :copyfrom*JF +c_date0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbdatezc_date*UQ +c_time0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timezc_time*d` + c_timestamp0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timestampz c_timestamp*vr +c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timestamptzzc_timestamp_with_tz*a] + +c_interval0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.intervalz +c_interval: query.sqlBpostgres_datetime_types‰ +” +INSERT INTO postgres_network_types +( c_cidr, c_inet, - c_macaddr -LIMIT 1GetPostgresTypesCnt:one"I + c_macaddr, + c_macaddr8 +) VALUES ( + $1, + $2, + $3, + $4::macaddr8 +)InsertPostgresNetworkTypes:exec*KG +c_cidr0ÿÿÿÿÿÿÿÿÿ8R publicpostgres_network_typesbcidrzc_cidr*KG +c_inet0ÿÿÿÿÿÿÿÿÿ8R publicpostgres_network_typesbinetzc_inet*TP + c_macaddr0ÿÿÿÿÿÿÿÿÿ8R publicpostgres_network_typesb macaddrz c_macaddr*'# -c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint2z -c_smallint"G - c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogboolz c_boolean"G - c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint4z c_integer"E -c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint8zc_bigint"C -c_real0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat4zc_real"J - c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumericz c_numeric"J - c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumericz c_decimal"[ -c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat8zc_double_precision"8 -c_money0ÿÿÿÿÿÿÿÿÿRpostgres_typesbmoneyzc_money"5 -c_date0ÿÿÿÿÿÿÿÿÿRpostgres_typesbdatezc_date"A -c_time0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogtimezc_time"P - c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestampz c_timestamp"b -c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestamptzzc_timestamp_with_tz"M - -c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogintervalz -c_interval"C -c_char0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbpcharzc_char"J - c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarcharz c_varchar"^ -c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarcharzc_character_varying"; -c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesbbpcharzc_bpchar"5 -c_text0ÿÿÿÿÿÿÿÿÿRpostgres_typesbtextzc_text"5 -c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_typesbuuidzc_uuid"5 -c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_typesbcidrzc_cidr"5 -c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_typesbinetzc_inet"> - c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_typesb macaddrz c_macaddr" -cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sql° -†SELECT - MAX(c_integer) AS max_integer, - MAX(c_varchar) AS max_varchar, - MAX(c_timestamp) AS max_timestamp -FROM postgres_typesGetPostgresFunctions:one"( - max_integer0ÿÿÿÿÿÿÿÿÿ@b -anyarray"( - max_varchar0ÿÿÿÿÿÿÿÿÿ@b -anyarray"* - max_timestamp0ÿÿÿÿÿÿÿÿÿ@b -anyarray: query.sqlÿ -ŒINSERT INTO postgres_geometric_types ( - c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle +c_macaddr80ÿÿÿÿÿÿÿÿÿb +macaddr82 Network types : query.sqlBpostgres_network_types‰ +tSELECT + c_cidr, + c_inet, + c_macaddr, + c_macaddr8::TEXT AS c_macaddr8 +FROM postgres_network_types +LIMIT 1GetPostgresNetworkTypes:one"= +c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbcidrzc_cidr"= +c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbinetzc_inet"F + c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesb macaddrz c_macaddr"! + +c_macaddr80ÿÿÿÿÿÿÿÿÿbtext: query.sqlW +%TRUNCATE TABLE postgres_network_typesTruncatePostgresNetworkTypes:exec: query.sqlª +”SELECT + c_cidr, + c_inet, + c_macaddr, + COUNT(*) AS cnt +FROM postgres_network_types +GROUP BY + c_cidr, + c_inet, + c_macaddr +LIMIT 1GetPostgresNetworkTypesCnt:one"= +c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbcidrzc_cidr"= +c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbinetzc_inet"F + c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesb macaddrz c_macaddr" +cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sql +`INSERT INTO postgres_network_types +( + c_cidr, + c_inet, + c_macaddr +) VALUES ($1, $2, $3)InsertPostgresNetworkTypesBatch :copyfrom*IE +c_cidr0ÿÿÿÿÿÿÿÿÿR publicpostgres_network_typesbcidrzc_cidr*IE +c_inet0ÿÿÿÿÿÿÿÿÿR publicpostgres_network_typesbinetzc_inet*RN + c_macaddr0ÿÿÿÿÿÿÿÿÿR publicpostgres_network_typesb macaddrz c_macaddr: query.sqlBpostgres_network_typesÜ +¤ +INSERT INTO postgres_special_types +( + c_json, + c_json_string_override, + c_jsonb, + c_jsonpath, + c_xml, + c_xml_string_override, + c_uuid, + c_enum ) -VALUES ($1, $2, $3, $4, $5, $6, $7)InsertPostgresGeoTypes:exec*NJ -c_point0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpointzc_point*KG -c_line0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblinezc_line*KG -c_lseg0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblsegzc_lseg*HD -c_box0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbboxzc_box*KG -c_path0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpathzc_path*TP - c_polygon0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesb polygonz c_polygon*QM -c_circle0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbcirclezc_circle: query.sqlBpostgres_geometric_typesˆ -ŒINSERT INTO postgres_geometric_types ( - c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle +VALUES ( + $1::json, + $2::json, + $3::jsonb, + $4::jsonpath, + $5::xml, + $6::xml, + $7, + $8::c_enum +)InsertPostgresSpecialTypes:exec* +c_json0ÿÿÿÿÿÿÿÿÿbjson*/+ +c_json_string_override0ÿÿÿÿÿÿÿÿÿbjson*! +c_jsonb0ÿÿÿÿÿÿÿÿÿbjsonb*'# + +c_jsonpath0ÿÿÿÿÿÿÿÿÿb +jsonpath* +c_xml0ÿÿÿÿÿÿÿÿÿbxml*-) +c_xml_string_override0ÿÿÿÿÿÿÿÿÿbxml*KG +c_uuid0ÿÿÿÿÿÿÿÿÿ8R publicpostgres_special_typesbuuidzc_uuid*! +c_enum0ÿÿÿÿÿÿÿÿÿbc_enum2 Special types : query.sqlBpostgres_special_types +­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 1GetPostgresSpecialTypes:one"= +c_json0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjsonzc_json"] +c_json_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjsonzc_json_string_override"@ +c_jsonb0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjsonbzc_jsonb"I + +c_jsonpath0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesb +jsonpathz +c_jsonpath": +c_xml0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbxmlzc_xml"Z +c_xml_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbxmlzc_xml_string_override"= +c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbuuidzc_uuid"? +c_enum0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbc_enumzc_enum: query.sqlW +%TRUNCATE TABLE postgres_special_typesTruncatePostgresSpecialTypes:exec: query.sqlá +CINSERT INTO postgres_special_types +( + c_uuid ) -VALUES ($1, $2, $3, $4, $5, $6, $7)InsertPostgresGeoTypesBatch :copyfrom*NJ -c_point0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpointzc_point*KG -c_line0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblinezc_line*KG -c_lseg0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblsegzc_lseg*HD -c_box0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbboxzc_box*KG -c_path0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpathzc_path*TP - c_polygon0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesb polygonz c_polygon*QM -c_circle0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbcirclezc_circle: query.sqlBpostgres_geometric_typesæ -hSELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgres_geometric_types LIMIT 1GetPostgresGeoTypes:one"B -c_point0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpointzc_point"? -c_line0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblinezc_line"? -c_lseg0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblsegzc_lseg"< -c_box0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbboxzc_box"? -c_path0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpathzc_path"H - c_polygon0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesb polygonz c_polygon"E -c_circle0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbcirclezc_circle: query.sqlH -TRUNCATE TABLE postgres_typesTruncatePostgresTypes:exec: query.sqlU -'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sqlÍ -ÎINSERT INTO postgres_array_types +VALUES ( + $1 +)InsertPostgresSpecialTypesBatch :copyfrom*IE +c_uuid0ÿÿÿÿÿÿÿÿÿR publicpostgres_special_typesbuuidzc_uuid: query.sqlBpostgres_special_typesì +^SELECT + c_uuid, + COUNT(*) AS cnt +FROM postgres_special_types +GROUP BY + c_uuid +LIMIT 1GetPostgresSpecialTypesCnt:one"= +c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbuuidzc_uuid" +cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sqlÝ +Ï +INSERT INTO postgres_array_types ( c_bytea, c_boolean_array, @@ -10723,7 +10761,7 @@ VALUES ($1, $2, $3, $4, $5, $6, $7)InsertPostgresArrayTypes:exec*JF c_integer_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.int4zc_integer_arrayˆ*lh c_decimal_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.numericzc_decimal_arrayˆ*XT c_date_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbdatez c_date_arrayˆ*rn -c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.timestampzc_timestamp_arrayˆ: query.sqlBpostgres_array_types¥ +c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.timestampzc_timestamp_arrayˆ2 Array types : query.sqlBpostgres_array_types¥ ’SELECT c_bytea, c_boolean_array, c_text_array, c_integer_array, c_decimal_array, c_date_array, c_timestamp_array FROM postgres_array_types LIMIT 1GetPostgresArrayTypes:one"> c_bytea0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbbyteazc_bytea"^ c_boolean_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb @@ -10735,16 +10773,99 @@ pg_catalogint4zc_integer_array pg_catalognumericzc_decimal_arrayˆ"L c_date_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbdatez c_date_arrayˆ"g c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb -pg_catalog timestampzc_timestamp_arrayˆ: query.sqlÑ -6INSERT INTO postgres_array_types (c_bytea) VALUES ($1)InsertPostgresArrayTypesBatch :copyfrom*JF -c_bytea0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbbyteazc_bytea: query.sqlBpostgres_array_typesë -^SELECT +pg_catalog timestampzc_timestamp_arrayˆ: query.sql +ÓINSERT INTO postgres_array_types ( + c_bytea, + c_boolean_array, + c_text_array, + c_integer_array, + c_decimal_array, + c_timestamp_array +) +VALUES ( + $1, + $2, + $3, + $4, + $5, + $6 +)InsertPostgresArrayTypesBatch :copyfrom*JF +c_bytea0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbbyteazc_bytea*ie +c_boolean_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.boolzc_boolean_arrayˆ*XT + c_text_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbtextz c_text_arrayˆ*ie +c_integer_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.int4zc_integer_arrayˆ*lh +c_decimal_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.numericzc_decimal_arrayˆ*rn +c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.timestampzc_timestamp_arrayˆ: query.sqlBpostgres_array_types– +®SELECT c_bytea, + c_boolean_array, + c_text_array, + c_integer_array, + c_decimal_array, + c_timestamp_array, COUNT(*) AS cnt FROM postgres_array_types GROUP BY - c_bytea + c_bytea, + c_boolean_array, + c_text_array, + c_integer_array, + c_decimal_array, + c_timestamp_array LIMIT 1GetPostgresArrayTypesCnt:one"> -c_bytea0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbbyteazc_bytea" +c_bytea0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbbyteazc_bytea"^ +c_boolean_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb +pg_catalogboolzc_boolean_arrayˆ"L + c_text_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbtextz c_text_arrayˆ"^ +c_integer_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb +pg_catalogint4zc_integer_arrayˆ"a +c_decimal_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb +pg_catalognumericzc_decimal_arrayˆ"g +c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb +pg_catalog timestampzc_timestamp_arrayˆ" cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sqlS -#TRUNCATE TABLE postgres_array_typesTruncatePostgresArrayTypes:exec: query.sql"v1.27.0*ÿ{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"net8.0","namespaceName":"NpgsqlDapperExampleGen","useDapper":true,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}}],"debugRequest":false} \ No newline at end of file +#TRUNCATE TABLE postgres_array_typesTruncatePostgresArrayTypes:exec: query.sql± +« +INSERT INTO postgres_geometric_types ( + c_point, + c_line, + c_lseg, + c_box, + c_path, + c_polygon, + c_circle +) +VALUES ($1, $2, $3, $4, $5, $6, $7)InsertPostgresGeoTypes:exec*NJ +c_point0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpointzc_point*KG +c_line0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblinezc_line*KG +c_lseg0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblsegzc_lseg*HD +c_box0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbboxzc_box*KG +c_path0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpathzc_path*TP + c_polygon0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesb polygonz c_polygon*QM +c_circle0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbcirclezc_circle2 Geometric types : query.sqlBpostgres_geometric_types¦ +ªINSERT INTO postgres_geometric_types ( + c_point, + c_line, + c_lseg, + c_box, + c_path, + c_polygon, + c_circle +) +VALUES ($1, $2, $3, $4, $5, $6, $7)InsertPostgresGeoTypesBatch :copyfrom*NJ +c_point0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpointzc_point*KG +c_line0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblinezc_line*KG +c_lseg0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblsegzc_lseg*HD +c_box0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbboxzc_box*KG +c_path0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpathzc_path*TP + c_polygon0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesb polygonz c_polygon*QM +c_circle0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbcirclezc_circle: query.sqlBpostgres_geometric_typesæ +hSELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgres_geometric_types LIMIT 1GetPostgresGeoTypes:one"B +c_point0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpointzc_point"? +c_line0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblinezc_line"? +c_lseg0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblsegzc_lseg"< +c_box0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbboxzc_box"? +c_path0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpathzc_path"H + c_polygon0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesb polygonz c_polygon"E +c_circle0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbcirclezc_circle: query.sqlU +'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sql"v1.27.0*Ô{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"net8.0","namespaceName":"NpgsqlDapperExampleGen","useDapper":true,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_xml_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}}],"debugRequest":false} \ No newline at end of file diff --git a/examples/NpgsqlDapperLegacyExample/Models.cs b/examples/NpgsqlDapperLegacyExample/Models.cs index b495a364..31723a2e 100644 --- a/examples/NpgsqlDapperLegacyExample/Models.cs +++ b/examples/NpgsqlDapperLegacyExample/Models.cs @@ -3,6 +3,7 @@ namespace NpgsqlDapperLegacyExampleGen { using NpgsqlTypes; using System; + using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.NetworkInformation; @@ -22,7 +23,7 @@ public class Book public long AuthorId { get; set; } public string Description { get; set; } }; - public class PostgresType + public class PostgresNumericType { public bool? CBoolean { get; set; } public byte[] CBit { get; set; } @@ -34,26 +35,39 @@ public class PostgresType public float? CReal { get; set; } public double? CDoublePrecision { get; set; } public decimal? CMoney { get; set; } - public DateTime? CDate { get; set; } - public TimeSpan? CTime { get; set; } - public DateTime? CTimestamp { get; set; } - public DateTime? CTimestampWithTz { get; set; } - public TimeSpan? CInterval { get; set; } + }; + public class PostgresStringType + { public string CChar { get; set; } public string CVarchar { get; set; } public string CCharacterVarying { get; set; } public string CBpchar { get; set; } public string CText { get; set; } - public JsonElement? CJson { get; set; } - public JsonElement? CJsonStringOverride { get; set; } - public JsonElement? CJsonb { get; set; } - public string CJsonpath { get; set; } - public XmlDocument CXml { get; set; } + }; + public class PostgresDatetimeType + { + public DateTime? CDate { get; set; } + public TimeSpan? CTime { get; set; } + public DateTime? CTimestamp { get; set; } + public DateTime? CTimestampWithTz { get; set; } + public TimeSpan? CInterval { get; set; } + }; + public class PostgresNetworkType + { public NpgsqlCidr? CCidr { get; set; } public IPAddress CInet { get; set; } public PhysicalAddress CMacaddr { get; set; } public string CMacaddr8 { get; set; } - public Guid? CUuid { get; set; } + }; + public class PostgresArrayType + { + public byte[] CBytea { get; set; } + public bool[] CBooleanArray { get; set; } + public string[] CTextArray { get; set; } + public int[] CIntegerArray { get; set; } + public decimal[] CDecimalArray { get; set; } + public DateTime[] CDateArray { get; set; } + public DateTime[] CTimestampArray { get; set; } }; public class PostgresGeometricType { @@ -65,14 +79,100 @@ public class PostgresGeometricType public NpgsqlPolygon? CPolygon { get; set; } public NpgsqlCircle? CCircle { get; set; } }; - public class PostgresArrayType + public class PostgresSpecialType { - public byte[] CBytea { get; set; } - public bool[] CBooleanArray { get; set; } - public string[] CTextArray { get; set; } - public int[] CIntegerArray { get; set; } - public decimal[] CDecimalArray { get; set; } - public DateTime[] CDateArray { get; set; } - public DateTime[] CTimestampArray { get; set; } + public Guid? CUuid { get; set; } + public CEnum? CEnum { get; set; } + public JsonElement? CJson { get; set; } + public JsonElement? CJsonStringOverride { get; set; } + public JsonElement? CJsonb { get; set; } + public string CJsonpath { get; set; } + public XmlDocument CXml { get; set; } + public XmlDocument CXmlStringOverride { get; set; } + }; + public class ExtendedBio + { + public string AuthorName { get; set; } + public string Name { get; set; } + public ExtendedBioType? BioType { get; set; } }; + public enum CEnum + { + Invalid = 0, // reserved for invalid enum value + Small = 1, + Medium = 2, + Big = 3 + } + + public static class CEnumExtensions + { + private static readonly Dictionary StringToEnum = new Dictionary() + { + [string.Empty] = CEnum.Invalid, + ["small"] = CEnum.Small, + ["medium"] = CEnum.Medium, + ["big"] = CEnum.Big + }; + private static readonly Dictionary EnumToString = new Dictionary() + { + [CEnum.Invalid] = string.Empty, + [CEnum.Small] = "small", + [CEnum.Medium] = "medium", + [CEnum.Big] = "big" + }; + public static CEnum ToCEnum(this string me) + { + return StringToEnum[me]; + } + + public static string Stringify(this CEnum me) + { + return EnumToString[me]; + } + + public static HashSet ToCEnumSet(this string me) + { + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); + } + } + + public enum ExtendedBioType + { + Invalid = 0, // reserved for invalid enum value + Autobiography = 1, + Biography = 2, + Memoir = 3 + } + + public static class ExtendedBioTypeExtensions + { + private static readonly Dictionary StringToEnum = new Dictionary() + { + [string.Empty] = ExtendedBioType.Invalid, + ["Autobiography"] = ExtendedBioType.Autobiography, + ["Biography"] = ExtendedBioType.Biography, + ["Memoir"] = ExtendedBioType.Memoir + }; + private static readonly Dictionary EnumToString = new Dictionary() + { + [ExtendedBioType.Invalid] = string.Empty, + [ExtendedBioType.Autobiography] = "Autobiography", + [ExtendedBioType.Biography] = "Biography", + [ExtendedBioType.Memoir] = "Memoir" + }; + public static ExtendedBioType ToExtendedBioType(this string me) + { + return StringToEnum[me]; + } + + public static string Stringify(this ExtendedBioType me) + { + return EnumToString[me]; + } + + public static HashSet ToExtendedBioTypeSet(this string me) + { + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); + } + } } \ No newline at end of file diff --git a/examples/NpgsqlDapperLegacyExample/QuerySql.cs b/examples/NpgsqlDapperLegacyExample/QuerySql.cs index 782d4024..73dda028 100644 --- a/examples/NpgsqlDapperLegacyExample/QuerySql.cs +++ b/examples/NpgsqlDapperLegacyExample/QuerySql.cs @@ -44,7 +44,7 @@ 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; } @@ -69,14 +69,11 @@ public async Task GetAuthor(GetAuthorArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -136,10 +133,7 @@ public async Task CreateAuthor(CreateAuthorArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); return await this.Transaction.Connection.QueryFirstOrDefaultAsync(CreateAuthorSql, queryParams, transaction: this.Transaction); } @@ -161,20 +155,15 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) - { return await connection.QuerySingleAsync(CreateAuthorReturnIdSql, queryParams); - } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -199,14 +188,11 @@ public async Task GetAuthorById(GetAuthorByIdArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -235,7 +221,7 @@ 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; } @@ -247,18 +233,12 @@ public async Task DeleteAuthor(DeleteAuthorArgs args) if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) - { await connection.ExecuteAsync(DeleteAuthorSql, queryParams); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); await this.Transaction.Connection.ExecuteAsync(DeleteAuthorSql, queryParams, transaction: this.Transaction); } @@ -268,22 +248,16 @@ public async Task TruncateAuthors() if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) - { await connection.ExecuteAsync(TruncateAuthorsSql); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -295,20 +269,15 @@ public async Task UpdateAuthors(UpdateAuthorsArgs args) if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) - { return await connection.ExecuteAsync(UpdateAuthorsSql, queryParams); - } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -337,7 +306,7 @@ 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; } @@ -386,20 +355,15 @@ public async Task CreateBook(CreateBookArgs args) if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) - { return await connection.QuerySingleAsync(CreateBookSql, queryParams); - } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -440,7 +404,7 @@ 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; } @@ -481,7 +445,7 @@ 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; } @@ -530,41 +494,113 @@ public async Task> GetAuthorsByBookName(GetAuthors } } - private const string InsertPostgresTypesSql = "INSERT INTO postgres_types(c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_real, c_numeric, c_decimal, c_double_precision, c_money, c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_char, c_varchar, c_character_varying, c_bpchar, c_text, c_uuid, c_json, c_json_string_override, c_jsonb, c_jsonpath, c_xml, c_cidr, c_inet, c_macaddr, c_macaddr8) VALUES ( @c_boolean, @c_bit, @c_smallint, @c_integer, @c_bigint, @c_real, @c_numeric, @c_decimal, @c_double_precision, @c_money, @c_date, @c_time, @c_timestamp, @c_timestamp_with_tz, @c_interval, @c_char, @c_varchar, @c_character_varying, @c_bpchar, @c_text, @c_uuid, @c_json :: json, @c_json_string_override :: json, @c_jsonb :: jsonb, @c_jsonpath :: jsonpath, @c_xml :: xml, @c_cidr, @c_inet, @c_macaddr :: macaddr, @c_macaddr8 :: macaddr8 ) "; - public class InsertPostgresTypesArgs + private const string CreateExtendedBioSql = "INSERT INTO extended.bios (author_name, name, bio_type) VALUES (@author_name, @name, @bio_type)"; + public class CreateExtendedBioArgs + { + public string AuthorName { get; set; } + public string Name { get; set; } + public ExtendedBioType? BioType { get; set; } + }; + public async Task CreateExtendedBio(CreateExtendedBioArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("author_name", args.AuthorName); + queryParams.Add("name", args.Name); + queryParams.Add("bio_type", args.BioType != null ? args.BioType.Value.Stringify() : null); + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(CreateExtendedBioSql, queryParams); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(CreateExtendedBioSql, queryParams, transaction: this.Transaction); + } + + private const string GetFirstExtendedBioByTypeSql = "SELECT author_name, name, bio_type FROM extended.bios WHERE bio_type = @bio_type LIMIT 1"; + public class GetFirstExtendedBioByTypeRow + { + public string AuthorName { get; set; } + public string Name { get; set; } + public ExtendedBioType? BioType { get; set; } + }; + public class GetFirstExtendedBioByTypeArgs + { + public ExtendedBioType? BioType { get; set; } + }; + public async Task GetFirstExtendedBioByType(GetFirstExtendedBioByTypeArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("bio_type", args.BioType != null ? args.BioType.Value.Stringify() : null); + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetFirstExtendedBioByTypeSql, queryParams); + return result; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetFirstExtendedBioByTypeSql, queryParams, transaction: this.Transaction); + } + + private const string TruncateExtendedBiosSql = "TRUNCATE TABLE extended.bios"; + public async Task TruncateExtendedBios() + { + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncateExtendedBiosSql); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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"; + public class GetPostgresFunctionsRow + { + public int? MaxInteger { get; set; } + public string MaxVarchar { get; set; } + public DateTime MaxTimestamp { get; set; } + }; + public async Task GetPostgresFunctions() + { + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresFunctionsSql); + return result; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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)"; + public class InsertPostgresNumericTypesArgs { public bool? CBoolean { get; set; } public byte[] CBit { get; set; } public short? CSmallint { get; set; } public int? CInteger { get; set; } public long? CBigint { get; set; } - public float? CReal { get; set; } - public decimal? CNumeric { get; set; } public decimal? CDecimal { get; set; } + public decimal? CNumeric { get; set; } + public float? CReal { get; set; } public double? CDoublePrecision { get; set; } public decimal? CMoney { get; set; } - public DateTime? CDate { get; set; } - public TimeSpan? CTime { get; set; } - public DateTime? CTimestamp { get; set; } - public DateTime? CTimestampWithTz { get; set; } - public TimeSpan? CInterval { get; set; } - public string CChar { get; set; } - public string CVarchar { get; set; } - public string CCharacterVarying { get; set; } - public string CBpchar { get; set; } - public string CText { get; set; } - public Guid? CUuid { get; set; } - public JsonElement? CJson { get; set; } - public string CJsonStringOverride { get; set; } - public JsonElement? CJsonb { get; set; } - public string CJsonpath { get; set; } - public XmlDocument CXml { get; set; } - public NpgsqlCidr? CCidr { get; set; } - public IPAddress CInet { get; set; } - public PhysicalAddress CMacaddr { get; set; } - public string CMacaddr8 { get; set; } }; - public async Task InsertPostgresTypes(InsertPostgresTypesArgs args) + public async Task InsertPostgresNumericTypes(InsertPostgresNumericTypesArgs args) { var queryParams = new Dictionary(); queryParams.Add("c_boolean", args.CBoolean); @@ -572,109 +608,133 @@ public async Task InsertPostgresTypes(InsertPostgresTypesArgs args) queryParams.Add("c_smallint", args.CSmallint); queryParams.Add("c_integer", args.CInteger); queryParams.Add("c_bigint", args.CBigint); - queryParams.Add("c_real", args.CReal); - queryParams.Add("c_numeric", args.CNumeric); queryParams.Add("c_decimal", args.CDecimal); + queryParams.Add("c_numeric", args.CNumeric); + queryParams.Add("c_real", args.CReal); queryParams.Add("c_double_precision", args.CDoublePrecision); queryParams.Add("c_money", args.CMoney); - queryParams.Add("c_date", args.CDate); - queryParams.Add("c_time", args.CTime); - queryParams.Add("c_timestamp", args.CTimestamp); - queryParams.Add("c_timestamp_with_tz", args.CTimestampWithTz); - queryParams.Add("c_interval", args.CInterval); - queryParams.Add("c_char", args.CChar); - queryParams.Add("c_varchar", args.CVarchar); - queryParams.Add("c_character_varying", args.CCharacterVarying); - queryParams.Add("c_bpchar", args.CBpchar); - queryParams.Add("c_text", args.CText); - queryParams.Add("c_uuid", args.CUuid); - queryParams.Add("c_json", args.CJson.HasValue ? args.CJson.Value.GetRawText() : null); - queryParams.Add("c_json_string_override", args.CJsonStringOverride); - queryParams.Add("c_jsonb", args.CJsonb.HasValue ? args.CJsonb.Value.GetRawText() : null); - queryParams.Add("c_jsonpath", args.CJsonpath); - queryParams.Add("c_xml", args.CXml != null ? args.CXml.OuterXml : null); - queryParams.Add("c_cidr", args.CCidr); - queryParams.Add("c_inet", args.CInet); - queryParams.Add("c_macaddr", args.CMacaddr); - queryParams.Add("c_macaddr8", args.CMacaddr8); + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(InsertPostgresNumericTypesSql, queryParams); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertPostgresNumericTypesSql, queryParams, transaction: this.Transaction); + } + + private const string GetPostgresNumericTypesSql = "SELECT c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money FROM postgres_numeric_types LIMIT 1"; + public class GetPostgresNumericTypesRow + { + public bool? CBoolean { get; set; } + public byte[] CBit { get; set; } + public short? CSmallint { get; set; } + public int? CInteger { get; set; } + public long? CBigint { get; set; } + public decimal? CDecimal { get; set; } + public decimal? CNumeric { get; set; } + public float? CReal { get; set; } + public double? CDoublePrecision { get; set; } + public decimal? CMoney { get; set; } + }; + public async Task GetPostgresNumericTypes() + { if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) { - await connection.ExecuteAsync(InsertPostgresTypesSql, queryParams); + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresNumericTypesSql); + return result; } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresNumericTypesSql, transaction: this.Transaction); + } + private const string TruncatePostgresNumericTypesSql = "TRUNCATE TABLE postgres_numeric_types"; + public async Task TruncatePostgresNumericTypes() + { + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncatePostgresNumericTypesSql); return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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"; + public class GetPostgresNumericTypesCntRow + { + public bool? CBoolean { get; set; } + public byte[] CBit { get; set; } + public short? CSmallint { get; set; } + public int? CInteger { get; set; } + public long? CBigint { get; set; } + public decimal? CDecimal { get; set; } + public decimal? CNumeric { get; set; } + public float? CReal { get; set; } + public double? CDoublePrecision { get; set; } + public decimal? CMoney { get; set; } + public long Cnt { get; set; } + }; + public async Task GetPostgresNumericTypesCnt() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new NpgsqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresNumericTypesCntSql); + return result; + } } - await this.Transaction.Connection.ExecuteAsync(InsertPostgresTypesSql, queryParams, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresNumericTypesCntSql, transaction: this.Transaction); } - private const string InsertPostgresTypesBatchSql = "COPY postgres_types (c_boolean, c_smallint, c_integer, c_bigint, c_real, c_numeric, c_decimal, c_double_precision, c_money, c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_char, c_varchar, c_character_varying, c_bpchar, c_text, c_uuid, c_cidr, c_inet, c_macaddr) FROM STDIN (FORMAT BINARY)"; - public class InsertPostgresTypesBatchArgs + private const string InsertPostgresNumericTypesBatchSql = "COPY postgres_numeric_types (c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money) FROM STDIN (FORMAT BINARY)"; + public class InsertPostgresNumericTypesBatchArgs { public bool? CBoolean { get; set; } + public byte[] CBit { get; set; } public short? CSmallint { get; set; } public int? CInteger { get; set; } public long? CBigint { get; set; } - public float? CReal { get; set; } - public decimal? CNumeric { get; set; } public decimal? CDecimal { get; set; } + public decimal? CNumeric { get; set; } + public float? CReal { get; set; } public double? CDoublePrecision { get; set; } public decimal? CMoney { get; set; } - public DateTime? CDate { get; set; } - public TimeSpan? CTime { get; set; } - public DateTime? CTimestamp { get; set; } - public DateTime? CTimestampWithTz { get; set; } - public TimeSpan? CInterval { get; set; } - public string CChar { get; set; } - public string CVarchar { get; set; } - public string CCharacterVarying { get; set; } - public string CBpchar { get; set; } - public string CText { get; set; } - public Guid? CUuid { get; set; } - public NpgsqlCidr? CCidr { get; set; } - public IPAddress CInet { get; set; } - public PhysicalAddress CMacaddr { get; set; } }; - public async Task InsertPostgresTypesBatch(List args) + public async Task InsertPostgresNumericTypesBatch(List args) { using (var connection = new NpgsqlConnection(ConnectionString)) { await connection.OpenAsync(); - using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresTypesBatchSql)) + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresNumericTypesBatchSql)) { foreach (var row in args) { await writer.StartRowAsync(); await writer.WriteAsync(row.CBoolean); + await writer.WriteAsync(row.CBit); await writer.WriteAsync(row.CSmallint); await writer.WriteAsync(row.CInteger); await writer.WriteAsync(row.CBigint); - await writer.WriteAsync(row.CReal); - await writer.WriteAsync(row.CNumeric); await writer.WriteAsync(row.CDecimal); + await writer.WriteAsync(row.CNumeric); + await writer.WriteAsync(row.CReal); await writer.WriteAsync(row.CDoublePrecision); await writer.WriteAsync(row.CMoney, NpgsqlDbType.Money); - await writer.WriteAsync(row.CDate, NpgsqlDbType.Date); - await writer.WriteAsync(row.CTime, NpgsqlDbType.Time); - await writer.WriteAsync(row.CTimestamp); - await writer.WriteAsync(row.CTimestampWithTz); - await writer.WriteAsync(row.CInterval, NpgsqlDbType.Interval); - await writer.WriteAsync(row.CChar); - await writer.WriteAsync(row.CVarchar); - await writer.WriteAsync(row.CCharacterVarying); - await writer.WriteAsync(row.CBpchar); - await writer.WriteAsync(row.CText); - await writer.WriteAsync(row.CUuid); - await writer.WriteAsync(row.CCidr); - await writer.WriteAsync(row.CInet); - await writer.WriteAsync(row.CMacaddr); } await writer.CompleteAsync(); @@ -684,199 +744,402 @@ public async Task InsertPostgresTypesBatch(List ar } } - private const string GetPostgresTypesSql = "SELECT c_boolean , c_bit, c_smallint, c_integer, c_bigint, c_real, c_numeric, c_decimal, c_double_precision, c_money, c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_char, c_varchar, c_character_varying, c_bpchar, c_text, c_uuid, c_json, c_json_string_override, c_jsonb, c_jsonpath, c_xml, c_cidr, c_inet, c_macaddr, c_macaddr8 :: TEXT AS c_macaddr8 FROM postgres_types LIMIT 1 "; - public class GetPostgresTypesRow + private const string InsertPostgresStringTypesSql = " INSERT INTO postgres_string_types ( c_char, c_varchar, c_character_varying, c_bpchar, c_text ) VALUES (@c_char, @c_varchar, @c_character_varying, @c_bpchar, @c_text)"; + public class InsertPostgresStringTypesArgs + { + public string CChar { get; set; } + public string CVarchar { get; set; } + public string CCharacterVarying { get; set; } + public string CBpchar { get; set; } + public string CText { get; set; } + }; + public async Task InsertPostgresStringTypes(InsertPostgresStringTypesArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("c_char", args.CChar); + queryParams.Add("c_varchar", args.CVarchar); + queryParams.Add("c_character_varying", args.CCharacterVarying); + queryParams.Add("c_bpchar", args.CBpchar); + queryParams.Add("c_text", args.CText); + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(InsertPostgresStringTypesSql, queryParams); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertPostgresStringTypesSql, queryParams, transaction: this.Transaction); + } + + private const string InsertPostgresStringTypesBatchSql = "COPY postgres_string_types (c_char, c_varchar, c_character_varying, c_bpchar, c_text) FROM STDIN (FORMAT BINARY)"; + public class InsertPostgresStringTypesBatchArgs + { + public string CChar { get; set; } + public string CVarchar { get; set; } + public string CCharacterVarying { get; set; } + public string CBpchar { get; set; } + public string CText { get; set; } + }; + public async Task InsertPostgresStringTypesBatch(List args) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresStringTypesBatchSql)) + { + foreach (var row in args) + { + await writer.StartRowAsync(); + await writer.WriteAsync(row.CChar); + await writer.WriteAsync(row.CVarchar); + await writer.WriteAsync(row.CCharacterVarying); + await writer.WriteAsync(row.CBpchar); + await writer.WriteAsync(row.CText); + } + + await writer.CompleteAsync(); + } + + await connection.CloseAsync(); + } + } + + private const string GetPostgresStringTypesSql = "SELECT c_char, c_varchar, c_character_varying, c_bpchar, c_text FROM postgres_string_types LIMIT 1"; + public class GetPostgresStringTypesRow { - public bool? CBoolean { get; set; } - public byte[] CBit { get; set; } - public short? CSmallint { get; set; } - public int? CInteger { get; set; } - public long? CBigint { get; set; } - public float? CReal { get; set; } - public decimal? CNumeric { get; set; } - public decimal? CDecimal { get; set; } - public double? CDoublePrecision { get; set; } - public decimal? CMoney { get; set; } - public DateTime? CDate { get; set; } - public TimeSpan? CTime { get; set; } - public DateTime? CTimestamp { get; set; } - public DateTime? CTimestampWithTz { get; set; } - public TimeSpan? CInterval { get; set; } public string CChar { get; set; } public string CVarchar { get; set; } public string CCharacterVarying { get; set; } public string CBpchar { get; set; } public string CText { get; set; } - public Guid? CUuid { get; set; } - public JsonElement? CJson { get; set; } - public string CJsonStringOverride { get; set; } - public JsonElement? CJsonb { get; set; } - public string CJsonpath { get; set; } - public XmlDocument CXml { get; set; } - public NpgsqlCidr? CCidr { get; set; } - public IPAddress CInet { get; set; } - public PhysicalAddress CMacaddr { get; set; } - public string CMacaddr8 { get; set; } }; - public async Task GetPostgresTypes() + public async Task GetPostgresStringTypes() { if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) { - var result = await connection.QueryFirstOrDefaultAsync(GetPostgresTypesSql); + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresStringTypesSql); return result; } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresStringTypesSql, transaction: this.Transaction); + } + + private const string TruncatePostgresStringTypesSql = "TRUNCATE TABLE postgres_string_types"; + public async Task TruncatePostgresStringTypes() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncatePostgresStringTypesSql); + return; } - return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresTypesSql, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncatePostgresStringTypesSql, transaction: this.Transaction); } - private const string GetPostgresTypesCntSql = "SELECT c_smallint , c_boolean, c_integer, c_bigint, c_real, c_numeric, c_decimal, c_double_precision, c_money, c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_char, c_varchar, c_character_varying, c_bpchar, c_text, c_uuid, c_cidr, c_inet, c_macaddr, COUNT (* ) AS cnt FROM postgres_types GROUP BY c_smallint, c_boolean, c_integer, c_bigint, c_real, c_numeric, c_decimal, c_double_precision, c_money, c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_char, c_varchar, c_character_varying, c_bpchar, c_text, c_uuid, c_cidr, c_inet, c_macaddr LIMIT 1 "; - public class GetPostgresTypesCntRow + private const string GetPostgresStringTypesCntSql = "SELECT c_char, c_varchar, c_character_varying, c_bpchar, c_text, COUNT(*) AS cnt FROM postgres_string_types GROUP BY c_char, c_varchar, c_character_varying, c_bpchar, c_text LIMIT 1"; + public class GetPostgresStringTypesCntRow { - public short? CSmallint { get; set; } - public bool? CBoolean { get; set; } - public int? CInteger { get; set; } - public long? CBigint { get; set; } - public float? CReal { get; set; } - public decimal? CNumeric { get; set; } - public decimal? CDecimal { get; set; } - public double? CDoublePrecision { get; set; } - public decimal? CMoney { get; set; } - public DateTime? CDate { get; set; } - public TimeSpan? CTime { get; set; } - public DateTime? CTimestamp { get; set; } - public DateTime? CTimestampWithTz { get; set; } - public TimeSpan? CInterval { get; set; } public string CChar { get; set; } public string CVarchar { get; set; } public string CCharacterVarying { get; set; } public string CBpchar { get; set; } public string CText { get; set; } - public Guid? CUuid { get; set; } - public NpgsqlCidr? CCidr { get; set; } - public IPAddress CInet { get; set; } - public PhysicalAddress CMacaddr { get; set; } public long Cnt { get; set; } }; - public async Task GetPostgresTypesCnt() + public async Task GetPostgresStringTypesCnt() { if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) { - var result = await connection.QueryFirstOrDefaultAsync(GetPostgresTypesCntSql); + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresStringTypesCntSql); return result; } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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"; + public class GetPostgresStringTypesTextSearchRow + { + public string CText { get; set; } + public NpgsqlTsQuery Query { get; set; } + public NpgsqlTsVector Tsv { get; set; } + public float Rnk { get; set; } + }; + public class GetPostgresStringTypesTextSearchArgs + { + public string ToTsquery { get; set; } + }; + public async Task GetPostgresStringTypesTextSearch(GetPostgresStringTypesTextSearchArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("to_tsquery", args.ToTsquery); + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new NpgsqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresStringTypesTextSearchSql, queryParams); + return result; + } } - return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresTypesCntSql, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresStringTypesTextSearchSql, queryParams, 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_types "; - public class GetPostgresFunctionsRow + private const string InsertPostgresDateTimeTypesSql = " INSERT INTO postgres_datetime_types ( c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval ) VALUES (@c_date, @c_time, @c_timestamp, @c_timestamp_with_tz, @c_interval)"; + public class InsertPostgresDateTimeTypesArgs { - public int? MaxInteger { get; set; } - public string MaxVarchar { get; set; } - public DateTime MaxTimestamp { get; set; } + public DateTime? CDate { get; set; } + public TimeSpan? CTime { get; set; } + public DateTime? CTimestamp { get; set; } + public DateTime? CTimestampWithTz { get; set; } + public TimeSpan? CInterval { get; set; } }; - public async Task GetPostgresFunctions() + public async Task InsertPostgresDateTimeTypes(InsertPostgresDateTimeTypesArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("c_date", args.CDate); + queryParams.Add("c_time", args.CTime); + queryParams.Add("c_timestamp", args.CTimestamp); + queryParams.Add("c_timestamp_with_tz", args.CTimestampWithTz); + queryParams.Add("c_interval", args.CInterval); + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(InsertPostgresDateTimeTypesSql, queryParams); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertPostgresDateTimeTypesSql, queryParams, transaction: this.Transaction); + } + + private const string GetPostgresDateTimeTypesSql = "SELECT c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval FROM postgres_datetime_types LIMIT 1"; + public class GetPostgresDateTimeTypesRow + { + public DateTime? CDate { get; set; } + public TimeSpan? CTime { get; set; } + public DateTime? CTimestamp { get; set; } + public DateTime? CTimestampWithTz { get; set; } + public TimeSpan? CInterval { get; set; } + }; + public async Task GetPostgresDateTimeTypes() { if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) { - var result = await connection.QueryFirstOrDefaultAsync(GetPostgresFunctionsSql); + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresDateTimeTypesSql); return result; } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresDateTimeTypesSql, transaction: this.Transaction); + } + + private const string TruncatePostgresDateTimeTypesSql = "TRUNCATE TABLE postgres_datetime_types"; + public async Task TruncatePostgresDateTimeTypes() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncatePostgresDateTimeTypesSql); + return; } - return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresFunctionsSql, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncatePostgresDateTimeTypesSql, transaction: this.Transaction); } - 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 class InsertPostgresGeoTypesArgs + 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 NpgsqlPoint? CPoint { get; set; } - public NpgsqlLine? CLine { get; set; } - public NpgsqlLSeg? CLseg { get; set; } - public NpgsqlBox? CBox { get; set; } - public NpgsqlPath? CPath { get; set; } - public NpgsqlPolygon? CPolygon { get; set; } - public NpgsqlCircle? CCircle { get; set; } + public DateTime? CDate { get; set; } + public TimeSpan? CTime { get; set; } + public DateTime? CTimestamp { get; set; } + public DateTime? CTimestampWithTz { get; set; } + public TimeSpan? CInterval { get; set; } + public long Cnt { get; set; } }; - public async Task InsertPostgresGeoTypes(InsertPostgresGeoTypesArgs args) + public async Task GetPostgresDateTimeTypesCnt() + { + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresDateTimeTypesCntSql); + return result; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresDateTimeTypesCntSql, transaction: this.Transaction); + } + + private const string InsertPostgresDateTimeTypesBatchSql = "COPY postgres_datetime_types (c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval) FROM STDIN (FORMAT BINARY)"; + public class InsertPostgresDateTimeTypesBatchArgs + { + public DateTime? CDate { get; set; } + public TimeSpan? CTime { get; set; } + public DateTime? CTimestamp { get; set; } + public DateTime? CTimestampWithTz { get; set; } + public TimeSpan? CInterval { get; set; } + }; + public async Task InsertPostgresDateTimeTypesBatch(List args) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresDateTimeTypesBatchSql)) + { + foreach (var row in args) + { + await writer.StartRowAsync(); + await writer.WriteAsync(row.CDate, NpgsqlDbType.Date); + await writer.WriteAsync(row.CTime, NpgsqlDbType.Time); + await writer.WriteAsync(row.CTimestamp); + await writer.WriteAsync(row.CTimestampWithTz); + await writer.WriteAsync(row.CInterval, NpgsqlDbType.Interval); + } + + await writer.CompleteAsync(); + } + + await connection.CloseAsync(); + } + } + + private const string InsertPostgresNetworkTypesSql = " INSERT INTO postgres_network_types ( c_cidr, c_inet, c_macaddr, c_macaddr8 ) VALUES ( @c_cidr, @c_inet, @c_macaddr, @c_macaddr8::macaddr8 )"; + public class InsertPostgresNetworkTypesArgs + { + public NpgsqlCidr? CCidr { get; set; } + public IPAddress CInet { get; set; } + public PhysicalAddress CMacaddr { get; set; } + public string CMacaddr8 { get; set; } + }; + public async Task InsertPostgresNetworkTypes(InsertPostgresNetworkTypesArgs args) { var queryParams = new Dictionary(); - queryParams.Add("c_point", args.CPoint); - queryParams.Add("c_line", args.CLine); - queryParams.Add("c_lseg", args.CLseg); - queryParams.Add("c_box", args.CBox); - queryParams.Add("c_path", args.CPath); - queryParams.Add("c_polygon", args.CPolygon); - queryParams.Add("c_circle", args.CCircle); + queryParams.Add("c_cidr", args.CCidr); + queryParams.Add("c_inet", args.CInet); + queryParams.Add("c_macaddr", args.CMacaddr); + queryParams.Add("c_macaddr8", args.CMacaddr8); + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(InsertPostgresNetworkTypesSql, queryParams); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertPostgresNetworkTypesSql, queryParams, transaction: this.Transaction); + } + + private const string GetPostgresNetworkTypesSql = "SELECT c_cidr, c_inet, c_macaddr, c_macaddr8::TEXT AS c_macaddr8 FROM postgres_network_types LIMIT 1"; + public class GetPostgresNetworkTypesRow + { + public NpgsqlCidr? CCidr { get; set; } + public IPAddress CInet { get; set; } + public PhysicalAddress CMacaddr { get; set; } + public string CMacaddr8 { get; set; } + }; + public async Task GetPostgresNetworkTypes() + { if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) { - await connection.ExecuteAsync(InsertPostgresGeoTypesSql, queryParams); + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresNetworkTypesSql); + return result; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresNetworkTypesSql, transaction: this.Transaction); + } + + private const string TruncatePostgresNetworkTypesSql = "TRUNCATE TABLE postgres_network_types"; + public async Task TruncatePostgresNetworkTypes() + { + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncatePostgresNetworkTypesSql); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncatePostgresNetworkTypesSql, transaction: this.Transaction); + } + + 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 class GetPostgresNetworkTypesCntRow + { + public NpgsqlCidr? CCidr { get; set; } + public IPAddress CInet { get; set; } + public PhysicalAddress CMacaddr { get; set; } + public long Cnt { get; set; } + }; + public async Task GetPostgresNetworkTypesCnt() + { + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresNetworkTypesCntSql); + return result; } - - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - - await this.Transaction.Connection.ExecuteAsync(InsertPostgresGeoTypesSql, queryParams, transaction: this.Transaction); + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresNetworkTypesCntSql, transaction: this.Transaction); } - private const string InsertPostgresGeoTypesBatchSql = "COPY postgres_geometric_types (c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle) FROM STDIN (FORMAT BINARY)"; - public class InsertPostgresGeoTypesBatchArgs + private const string InsertPostgresNetworkTypesBatchSql = "COPY postgres_network_types (c_cidr, c_inet, c_macaddr) FROM STDIN (FORMAT BINARY)"; + public class InsertPostgresNetworkTypesBatchArgs { - public NpgsqlPoint? CPoint { get; set; } - public NpgsqlLine? CLine { get; set; } - public NpgsqlLSeg? CLseg { get; set; } - public NpgsqlBox? CBox { get; set; } - public NpgsqlPath? CPath { get; set; } - public NpgsqlPolygon? CPolygon { get; set; } - public NpgsqlCircle? CCircle { get; set; } + public NpgsqlCidr? CCidr { get; set; } + public IPAddress CInet { get; set; } + public PhysicalAddress CMacaddr { get; set; } }; - public async Task InsertPostgresGeoTypesBatch(List args) + public async Task InsertPostgresNetworkTypesBatch(List args) { using (var connection = new NpgsqlConnection(ConnectionString)) { await connection.OpenAsync(); - using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresGeoTypesBatchSql)) + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresNetworkTypesBatchSql)) { foreach (var row in args) { await writer.StartRowAsync(); - await writer.WriteAsync(row.CPoint); - await writer.WriteAsync(row.CLine); - await writer.WriteAsync(row.CLseg); - await writer.WriteAsync(row.CBox); - await writer.WriteAsync(row.CPath); - await writer.WriteAsync(row.CPolygon); - await writer.WriteAsync(row.CCircle); + await writer.WriteAsync(row.CCidr); + await writer.WriteAsync(row.CInet); + await writer.WriteAsync(row.CMacaddr); } await writer.CompleteAsync(); @@ -886,79 +1149,132 @@ public async Task InsertPostgresGeoTypesBatch(List GetPostgresGeoTypes() + public async Task InsertPostgresSpecialTypes(InsertPostgresSpecialTypesArgs args) { + var queryParams = new Dictionary(); + queryParams.Add("c_json", args.CJson.HasValue ? args.CJson.Value.GetRawText() : null); + queryParams.Add("c_json_string_override", args.CJsonStringOverride); + queryParams.Add("c_jsonb", args.CJsonb.HasValue ? args.CJsonb.Value.GetRawText() : null); + queryParams.Add("c_jsonpath", args.CJsonpath); + queryParams.Add("c_xml", args.CXml != null ? args.CXml.OuterXml : null); + queryParams.Add("c_xml_string_override", args.CXmlStringOverride); + queryParams.Add("c_uuid", args.CUuid); + queryParams.Add("c_enum", args.CEnum != null ? args.CEnum.Value.Stringify() : null); if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) - { - var result = await connection.QueryFirstOrDefaultAsync(GetPostgresGeoTypesSql); - return result; - } + await connection.ExecuteAsync(InsertPostgresSpecialTypesSql, queryParams); + return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - - return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresGeoTypesSql, transaction: this.Transaction); + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertPostgresSpecialTypesSql, queryParams, transaction: this.Transaction); } - private const string TruncatePostgresTypesSql = "TRUNCATE TABLE postgres_types"; - public async Task TruncatePostgresTypes() + 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 class GetPostgresSpecialTypesRow + { + public JsonElement? CJson { get; set; } + public string CJsonStringOverride { get; set; } + public JsonElement? CJsonb { get; set; } + public string CJsonpath { get; set; } + public XmlDocument CXml { get; set; } + public string CXmlStringOverride { get; set; } + public Guid? CUuid { get; set; } + public CEnum? CEnum { get; set; } + }; + public async Task GetPostgresSpecialTypes() { if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) { - await connection.ExecuteAsync(TruncatePostgresTypesSql); + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresSpecialTypesSql); + return result; } - - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresSpecialTypesSql, transaction: this.Transaction); + } + + private const string TruncatePostgresSpecialTypesSql = "TRUNCATE TABLE postgres_special_types"; + public async Task TruncatePostgresSpecialTypes() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncatePostgresSpecialTypesSql); + return; } - await this.Transaction.Connection.ExecuteAsync(TruncatePostgresTypesSql, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncatePostgresSpecialTypesSql, transaction: this.Transaction); } - private const string TruncatePostgresGeoTypesSql = "TRUNCATE TABLE postgres_geometric_types"; - public async Task TruncatePostgresGeoTypes() + private const string InsertPostgresSpecialTypesBatchSql = "COPY postgres_special_types (c_uuid) FROM STDIN (FORMAT BINARY)"; + public class InsertPostgresSpecialTypesBatchArgs { - if (this.Transaction == null) + public Guid? CUuid { get; set; } + }; + public async Task InsertPostgresSpecialTypesBatch(List args) + { + using (var connection = new NpgsqlConnection(ConnectionString)) { - using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.OpenAsync(); + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresSpecialTypesBatchSql)) { - await connection.ExecuteAsync(TruncatePostgresGeoTypesSql); + foreach (var row in args) + { + await writer.StartRowAsync(); + await writer.WriteAsync(row.CUuid); + } + + await writer.CompleteAsync(); } - return; + await connection.CloseAsync(); } + } - if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + private const string GetPostgresSpecialTypesCntSql = "SELECT c_uuid, COUNT(*) AS cnt FROM postgres_special_types GROUP BY c_uuid LIMIT 1"; + public class GetPostgresSpecialTypesCntRow + { + public Guid? CUuid { get; set; } + public long Cnt { get; set; } + }; + public async Task GetPostgresSpecialTypesCnt() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new NpgsqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresSpecialTypesCntSql); + return result; + } } - await this.Transaction.Connection.ExecuteAsync(TruncatePostgresGeoTypesSql, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + 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; } @@ -982,18 +1298,12 @@ public async Task InsertPostgresArrayTypes(InsertPostgresArrayTypesArgs args) if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) - { await connection.ExecuteAsync(InsertPostgresArrayTypesSql, queryParams); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); await this.Transaction.Connection.ExecuteAsync(InsertPostgresArrayTypesSql, queryParams, transaction: this.Transaction); } @@ -1020,17 +1330,19 @@ public async Task GetPostgresArrayTypes() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresArrayTypesSql, transaction: this.Transaction); } - private const string InsertPostgresArrayTypesBatchSql = "COPY postgres_array_types (c_bytea) FROM STDIN (FORMAT BINARY)"; + private const string InsertPostgresArrayTypesBatchSql = "COPY postgres_array_types (c_bytea, c_boolean_array, c_text_array, c_integer_array, c_decimal_array, c_timestamp_array) FROM STDIN (FORMAT BINARY)"; public class InsertPostgresArrayTypesBatchArgs { public byte[] CBytea { get; set; } + public bool[] CBooleanArray { get; set; } + public string[] CTextArray { get; set; } + public int[] CIntegerArray { get; set; } + public decimal[] CDecimalArray { get; set; } + public DateTime[] CTimestampArray { get; set; } }; public async Task InsertPostgresArrayTypesBatch(List args) { @@ -1043,6 +1355,11 @@ public async Task InsertPostgresArrayTypesBatch(List GetPostgresArrayTypesCnt() @@ -1070,10 +1392,7 @@ public async Task GetPostgresArrayTypesCnt() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresArrayTypesCntSql, transaction: this.Transaction); } @@ -1083,19 +1402,125 @@ public async Task TruncatePostgresArrayTypes() if (this.Transaction == null) { using (var connection = new NpgsqlConnection(ConnectionString)) - { await connection.ExecuteAsync(TruncatePostgresArrayTypesSql); - } + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncatePostgresArrayTypesSql, transaction: this.Transaction); + } + 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 class InsertPostgresGeoTypesArgs + { + public NpgsqlPoint? CPoint { get; set; } + public NpgsqlLine? CLine { get; set; } + public NpgsqlLSeg? CLseg { get; set; } + public NpgsqlBox? CBox { get; set; } + public NpgsqlPath? CPath { get; set; } + public NpgsqlPolygon? CPolygon { get; set; } + public NpgsqlCircle? CCircle { get; set; } + }; + public async Task InsertPostgresGeoTypes(InsertPostgresGeoTypesArgs args) + { + var queryParams = new Dictionary(); + queryParams.Add("c_point", args.CPoint); + queryParams.Add("c_line", args.CLine); + queryParams.Add("c_lseg", args.CLseg); + queryParams.Add("c_box", args.CBox); + queryParams.Add("c_path", args.CPath); + queryParams.Add("c_polygon", args.CPolygon); + queryParams.Add("c_circle", args.CCircle); + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(InsertPostgresGeoTypesSql, queryParams); return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(InsertPostgresGeoTypesSql, queryParams, transaction: this.Transaction); + } + + private const string InsertPostgresGeoTypesBatchSql = "COPY postgres_geometric_types (c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle) FROM STDIN (FORMAT BINARY)"; + public class InsertPostgresGeoTypesBatchArgs + { + public NpgsqlPoint? CPoint { get; set; } + public NpgsqlLine? CLine { get; set; } + public NpgsqlLSeg? CLseg { get; set; } + public NpgsqlBox? CBox { get; set; } + public NpgsqlPath? CPath { get; set; } + public NpgsqlPolygon? CPolygon { get; set; } + public NpgsqlCircle? CCircle { get; set; } + }; + public async Task InsertPostgresGeoTypesBatch(List args) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresGeoTypesBatchSql)) + { + foreach (var row in args) + { + await writer.StartRowAsync(); + await writer.WriteAsync(row.CPoint); + await writer.WriteAsync(row.CLine); + await writer.WriteAsync(row.CLseg); + await writer.WriteAsync(row.CBox); + await writer.WriteAsync(row.CPath); + await writer.WriteAsync(row.CPolygon); + await writer.WriteAsync(row.CCircle); + } + + await writer.CompleteAsync(); + } + + await connection.CloseAsync(); + } + } + + private const string GetPostgresGeoTypesSql = "SELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgres_geometric_types LIMIT 1"; + public class GetPostgresGeoTypesRow + { + public NpgsqlPoint? CPoint { get; set; } + public NpgsqlLine? CLine { get; set; } + public NpgsqlLSeg? CLseg { get; set; } + public NpgsqlBox? CBox { get; set; } + public NpgsqlPath? CPath { get; set; } + public NpgsqlPolygon? CPolygon { get; set; } + public NpgsqlCircle? CCircle { get; set; } + }; + public async Task GetPostgresGeoTypes() + { + if (this.Transaction == null) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + var result = await connection.QueryFirstOrDefaultAsync(GetPostgresGeoTypesSql); + return result; + } + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetPostgresGeoTypesSql, transaction: this.Transaction); + } + + private const string TruncatePostgresGeoTypesSql = "TRUNCATE TABLE postgres_geometric_types"; + public async Task TruncatePostgresGeoTypes() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = new NpgsqlConnection(ConnectionString)) + await connection.ExecuteAsync(TruncatePostgresGeoTypesSql); + return; } - await this.Transaction.Connection.ExecuteAsync(TruncatePostgresArrayTypesSql, transaction: this.Transaction); + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + await this.Transaction.Connection.ExecuteAsync(TruncatePostgresGeoTypesSql, transaction: this.Transaction); } } } \ No newline at end of file diff --git a/examples/NpgsqlDapperLegacyExample/Utils.cs b/examples/NpgsqlDapperLegacyExample/Utils.cs index 585d0584..5ec33447 100644 --- a/examples/NpgsqlDapperLegacyExample/Utils.cs +++ b/examples/NpgsqlDapperLegacyExample/Utils.cs @@ -51,16 +51,18 @@ public static void ConfigureSqlMapper() { SqlMapper.AddTypeHandler(typeof(JsonElement), new JsonElementTypeHandler()); SqlMapper.AddTypeHandler(typeof(XmlDocument), new XmlDocumentTypeHandler()); - RegisterNpgsqlTypeHandler(); - RegisterNpgsqlTypeHandler(); - RegisterNpgsqlTypeHandler(); - RegisterNpgsqlTypeHandler(); - RegisterNpgsqlTypeHandler(); - RegisterNpgsqlTypeHandler(); - RegisterNpgsqlTypeHandler(); - RegisterNpgsqlTypeHandler(); - RegisterNpgsqlTypeHandler(); - RegisterNpgsqlTypeHandler(); + SqlMapper.AddTypeHandler(typeof(NpgsqlPoint), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(NpgsqlLine), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(NpgsqlLSeg), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(NpgsqlBox), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(NpgsqlPath), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(NpgsqlPolygon), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(NpgsqlCircle), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(NpgsqlCidr), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(IPAddress), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(PhysicalAddress), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(NpgsqlTsQuery), new NpgsqlTypeHandler()); + SqlMapper.AddTypeHandler(typeof(NpgsqlTsVector), new NpgsqlTypeHandler()); } private class NpgsqlTypeHandler : SqlMapper.TypeHandler @@ -75,10 +77,5 @@ public override void SetValue(IDbDataParameter parameter, T value) parameter.Value = value; } } - - private static void RegisterNpgsqlTypeHandler() - { - SqlMapper.AddTypeHandler(typeof(T), new NpgsqlTypeHandler()); - } } } \ No newline at end of file diff --git a/examples/NpgsqlDapperLegacyExample/request.json b/examples/NpgsqlDapperLegacyExample/request.json index 3360c681..17f34e7c 100644 --- a/examples/NpgsqlDapperLegacyExample/request.json +++ b/examples/NpgsqlDapperLegacyExample/request.json @@ -3,15 +3,17 @@ "version": "2", "engine": "postgresql", "schema": [ - "examples/config/postgresql/schema.sql" + "examples/config/postgresql/authors/schema.sql", + "examples/config/postgresql/types/schema.sql" ], "queries": [ - "examples/config/postgresql/query.sql" + "examples/config/postgresql/authors/query.sql", + "examples/config/postgresql/types/query.sql" ], "codegen": { "out": "examples/NpgsqlDapperLegacyExample", "plugin": "csharp", - "options": "eyJkZWJ1Z1JlcXVlc3QiOnRydWUsImdlbmVyYXRlQ3Nwcm9qIjp0cnVlLCJuYW1lc3BhY2VOYW1lIjoiTnBnc3FsRGFwcGVyTGVnYWN5RXhhbXBsZUdlbiIsIm92ZXJyaWRlcyI6W3siY29sdW1uIjoiR2V0UG9zdGdyZXNGdW5jdGlvbnM6bWF4X2ludGVnZXIiLCJjc2hhcnBfdHlwZSI6eyJub3ROdWxsIjpmYWxzZSwidHlwZSI6ImludCJ9fSx7ImNvbHVtbiI6IkdldFBvc3RncmVzRnVuY3Rpb25zOm1heF92YXJjaGFyIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6ZmFsc2UsInR5cGUiOiJzdHJpbmcifX0seyJjb2x1bW4iOiJHZXRQb3N0Z3Jlc0Z1bmN0aW9uczptYXhfdGltZXN0YW1wIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6dHJ1ZSwidHlwZSI6IkRhdGVUaW1lIn19LHsiY29sdW1uIjoiKjpjX2pzb25fc3RyaW5nX292ZXJyaWRlIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6ZmFsc2UsInR5cGUiOiJzdHJpbmcifX0seyJjb2x1bW4iOiIqOmNfbWFjYWRkcjgiLCJjc2hhcnBfdHlwZSI6eyJub3ROdWxsIjpmYWxzZSwidHlwZSI6InN0cmluZyJ9fV0sInRhcmdldEZyYW1ld29yayI6Im5ldHN0YW5kYXJkMi4wIiwidXNlRGFwcGVyIjp0cnVlfQ==", + "options": "eyJkZWJ1Z1JlcXVlc3QiOnRydWUsImdlbmVyYXRlQ3Nwcm9qIjp0cnVlLCJuYW1lc3BhY2VOYW1lIjoiTnBnc3FsRGFwcGVyTGVnYWN5RXhhbXBsZUdlbiIsIm92ZXJyaWRlcyI6W3siY29sdW1uIjoiR2V0UG9zdGdyZXNGdW5jdGlvbnM6bWF4X2ludGVnZXIiLCJjc2hhcnBfdHlwZSI6eyJub3ROdWxsIjpmYWxzZSwidHlwZSI6ImludCJ9fSx7ImNvbHVtbiI6IkdldFBvc3RncmVzRnVuY3Rpb25zOm1heF92YXJjaGFyIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6ZmFsc2UsInR5cGUiOiJzdHJpbmcifX0seyJjb2x1bW4iOiJHZXRQb3N0Z3Jlc0Z1bmN0aW9uczptYXhfdGltZXN0YW1wIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6dHJ1ZSwidHlwZSI6IkRhdGVUaW1lIn19LHsiY29sdW1uIjoiKjpjX2pzb25fc3RyaW5nX292ZXJyaWRlIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6ZmFsc2UsInR5cGUiOiJzdHJpbmcifX0seyJjb2x1bW4iOiIqOmNfeG1sX3N0cmluZ19vdmVycmlkZSIsImNzaGFycF90eXBlIjp7Im5vdE51bGwiOmZhbHNlLCJ0eXBlIjoic3RyaW5nIn19LHsiY29sdW1uIjoiKjpjX21hY2FkZHI4IiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6ZmFsc2UsInR5cGUiOiJzdHJpbmcifX1dLCJ0YXJnZXRGcmFtZXdvcmsiOiJuZXRzdGFuZGFyZDIuMCIsInVzZURhcHBlciI6dHJ1ZX0=", "process": { "cmd": "./dist/LocalRunner" } @@ -115,14 +117,14 @@ }, { "rel": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "columns": [ { "name": "c_boolean", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -133,7 +135,7 @@ "name": "c_bit", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -144,7 +146,7 @@ "name": "c_smallint", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -155,7 +157,7 @@ "name": "c_integer", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -166,7 +168,7 @@ "name": "c_bigint", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -177,7 +179,7 @@ "name": "c_decimal", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -188,7 +190,7 @@ "name": "c_numeric", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -199,7 +201,7 @@ "name": "c_real", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -210,7 +212,7 @@ "name": "c_double_precision", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -221,218 +223,272 @@ "name": "c_money", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "money" } - }, + } + ] + }, + { + "rel": { + "name": "postgres_string_types" + }, + "columns": [ { - "name": "c_date", + "name": "c_char", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "date" + "schema": "pg_catalog", + "name": "bpchar" } }, { - "name": "c_time", + "name": "c_varchar", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { "schema": "pg_catalog", - "name": "time" + "name": "varchar" } }, { - "name": "c_timestamp", + "name": "c_character_varying", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { "schema": "pg_catalog", - "name": "timestamp" + "name": "varchar" } }, { - "name": "c_timestamp_with_tz", + "name": "c_bpchar", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "schema": "pg_catalog", - "name": "timestamptz" + "name": "bpchar" } }, { - "name": "c_interval", + "name": "c_text", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "schema": "pg_catalog", - "name": "interval" + "name": "text" + } + } + ] + }, + { + "rel": { + "name": "postgres_datetime_types" + }, + "columns": [ + { + "name": "c_date", + "length": -1, + "table": { + "name": "postgres_datetime_types" + }, + "type": { + "name": "date" } }, { - "name": "c_char", + "name": "c_time", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "bpchar" + "name": "time" } }, { - "name": "c_varchar", + "name": "c_timestamp", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "varchar" + "name": "timestamp" } }, { - "name": "c_character_varying", + "name": "c_timestamp_with_tz", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "varchar" + "name": "timestamptz" } }, { - "name": "c_bpchar", + "name": "c_interval", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "bpchar" + "schema": "pg_catalog", + "name": "interval" } - }, + } + ] + }, + { + "rel": { + "name": "postgres_network_types" + }, + "columns": [ { - "name": "c_text", + "name": "c_cidr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "text" + "name": "cidr" } }, { - "name": "c_json", + "name": "c_inet", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "json" + "name": "inet" } }, { - "name": "c_json_string_override", + "name": "c_macaddr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "json" + "name": "macaddr" } }, { - "name": "c_jsonb", + "name": "c_macaddr8", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "jsonb" + "name": "macaddr8" } - }, + } + ] + }, + { + "rel": { + "name": "postgres_array_types" + }, + "columns": [ { - "name": "c_jsonpath", + "name": "c_bytea", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "jsonpath" + "name": "bytea" } }, { - "name": "c_xml", + "name": "c_boolean_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "xml" - } + "schema": "pg_catalog", + "name": "bool" + }, + "arrayDims": 1 }, { - "name": "c_cidr", + "name": "c_text_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "cidr" - } + "name": "text" + }, + "arrayDims": 1 }, { - "name": "c_inet", + "name": "c_integer_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "inet" - } + "schema": "pg_catalog", + "name": "int4" + }, + "arrayDims": 1 }, { - "name": "c_macaddr", + "name": "c_decimal_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "macaddr" - } + "schema": "pg_catalog", + "name": "numeric" + }, + "arrayDims": 1 }, { - "name": "c_macaddr8", + "name": "c_date_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "macaddr8" - } + "name": "date" + }, + "arrayDims": 1 }, { - "name": "c_uuid", + "name": "c_timestamp_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "uuid" - } + "schema": "pg_catalog", + "name": "timestamp" + }, + "arrayDims": 1 } ] }, @@ -515,97 +571,101 @@ }, { "rel": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "columns": [ { - "name": "c_bytea", + "name": "c_uuid", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "name": "bytea" + "name": "uuid" } }, { - "name": "c_boolean_array", - "isArray": true, + "name": "c_enum", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "schema": "pg_catalog", - "name": "bool" - }, - "arrayDims": 1 + "name": "c_enum" + } }, { - "name": "c_text_array", - "isArray": true, + "name": "c_json", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "name": "text" - }, - "arrayDims": 1 + "name": "json" + } }, { - "name": "c_integer_array", - "isArray": true, + "name": "c_json_string_override", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "schema": "pg_catalog", - "name": "int4" - }, - "arrayDims": 1 + "name": "json" + } }, { - "name": "c_decimal_array", - "isArray": true, + "name": "c_jsonb", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "schema": "pg_catalog", - "name": "numeric" - }, - "arrayDims": 1 + "name": "jsonb" + } }, { - "name": "c_date_array", - "isArray": true, + "name": "c_jsonpath", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "name": "date" - }, - "arrayDims": 1 + "name": "jsonpath" + } }, { - "name": "c_timestamp_array", - "isArray": true, + "name": "c_xml", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "schema": "pg_catalog", - "name": "timestamp" + "name": "xml" + } + }, + { + "name": "c_xml_string_override", + "length": -1, + "table": { + "name": "postgres_special_types" }, - "arrayDims": 1 + "type": { + "name": "xml" + } } ] } + ], + "enums": [ + { + "name": "c_enum", + "vals": [ + "small", + "medium", + "big" + ] + } ] }, { @@ -32449,6 +32509,67 @@ ] } ] + }, + { + "name": "extended", + "tables": [ + { + "rel": { + "schema": "extended", + "name": "bios" + }, + "columns": [ + { + "name": "author_name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + } + }, + { + "name": "name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + } + }, + { + "name": "bio_type", + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "extended", + "name": "bio_type" + } + } + ] + } + ], + "enums": [ + { + "name": "bio_type", + "vals": [ + "Autobiography", + "Biography", + "Memoir" + ] + } + ] } ] }, @@ -33207,8 +33328,174 @@ "filename": "query.sql" }, { - "text": "INSERT INTO postgres_types\n(\n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_real,\n c_numeric,\n c_decimal,\n c_double_precision,\n c_money,\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n c_uuid,\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_cidr,\n c_inet,\n c_macaddr,\n c_macaddr8\n)\nVALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6,\n $7,\n $8,\n $9,\n $10,\n $11,\n $12,\n $13,\n $14,\n $15,\n $16,\n $17,\n $18,\n $19,\n $20,\n $21,\n $22::json, \n $23::json, \n $24::jsonb,\n $25::jsonpath,\n $26::xml,\n $27,\n $28,\n $29::macaddr,\n $30::macaddr8\n)", - "name": "InsertPostgresTypes", + "text": "INSERT INTO extended.bios (author_name, name, bio_type) VALUES ($1, $2, $3)", + "name": "CreateExtendedBio", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "author_name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "pg_catalog.varchar" + }, + "originalName": "author_name" + } + }, + { + "number": 2, + "column": { + "name": "name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "pg_catalog.varchar" + }, + "originalName": "name" + } + }, + { + "number": 3, + "column": { + "name": "bio_type", + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "extended.bio_type" + }, + "originalName": "bio_type" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "schema": "extended", + "name": "bios" + } + }, + { + "text": "SELECT author_name, name, bio_type FROM extended.bios WHERE bio_type = $1 LIMIT 1", + "name": "GetFirstExtendedBioByType", + "cmd": ":one", + "columns": [ + { + "name": "author_name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "author_name" + }, + { + "name": "name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "name" + }, + { + "name": "bio_type", + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "extended", + "name": "bio_type" + }, + "originalName": "bio_type" + } + ], + "parameters": [ + { + "number": 1, + "column": { + "name": "bio_type", + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "extended.bio_type" + }, + "originalName": "bio_type" + } + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE extended.bios", + "name": "TruncateExtendedBios", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "SELECT\n MAX(c_integer) AS max_integer,\n MAX(c_varchar) AS max_varchar,\n MAX(c_timestamp) AS max_timestamp\nFROM postgres_datetime_types\nCROSS JOIN postgres_numeric_types\nCROSS JOIN postgres_string_types", + "name": "GetPostgresFunctions", + "cmd": ":one", + "columns": [ + { + "name": "max_integer", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "anyarray" + } + }, + { + "name": "max_varchar", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "anyarray" + } + }, + { + "name": "max_timestamp", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "anyarray" + } + } + ], + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO postgres_numeric_types\n(\n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_decimal,\n c_numeric,\n c_real,\n c_double_precision,\n c_money\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", + "name": "InsertPostgresNumericTypes", "cmd": ":exec", "parameters": [ { @@ -33216,10 +33503,9 @@ "column": { "name": "c_boolean", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.bool" @@ -33232,10 +33518,9 @@ "column": { "name": "c_bit", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.bit" @@ -33248,10 +33533,9 @@ "column": { "name": "c_smallint", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.int2" @@ -33264,10 +33548,9 @@ "column": { "name": "c_integer", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.int4" @@ -33280,10 +33563,9 @@ "column": { "name": "c_bigint", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.int8" @@ -33294,17 +33576,16 @@ { "number": 6, "column": { - "name": "c_real", + "name": "c_decimal", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.float4" + "name": "pg_catalog.numeric" }, - "originalName": "c_real" + "originalName": "c_decimal" } }, { @@ -33312,10 +33593,9 @@ "column": { "name": "c_numeric", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.numeric" @@ -33326,17 +33606,16 @@ { "number": 8, "column": { - "name": "c_decimal", + "name": "c_real", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.numeric" + "name": "pg_catalog.float4" }, - "originalName": "c_decimal" + "originalName": "c_real" } }, { @@ -33344,10 +33623,9 @@ "column": { "name": "c_double_precision", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.float8" @@ -33360,914 +33638,1509 @@ "column": { "name": "c_money", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "money" }, "originalName": "c_money" } + } + ], + "comments": [ + " Numeric types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_numeric_types" + } + }, + { + "text": "SELECT c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money FROM postgres_numeric_types LIMIT 1", + "name": "GetPostgresNumericTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_boolean", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bool" + }, + "originalName": "c_boolean" + }, + { + "name": "c_bit", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bit" + }, + "originalName": "c_bit" + }, + { + "name": "c_smallint", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int2" + }, + "originalName": "c_smallint" + }, + { + "name": "c_integer", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int4" + }, + "originalName": "c_integer" + }, + { + "name": "c_bigint", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int8" + }, + "originalName": "c_bigint" + }, + { + "name": "c_decimal", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "numeric" + }, + "originalName": "c_decimal" + }, + { + "name": "c_numeric", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "numeric" + }, + "originalName": "c_numeric" + }, + { + "name": "c_real", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "float4" + }, + "originalName": "c_real" + }, + { + "name": "c_double_precision", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "float8" + }, + "originalName": "c_double_precision" + }, + { + "name": "c_money", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "name": "money" + }, + "originalName": "c_money" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_numeric_types", + "name": "TruncatePostgresNumericTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "SELECT\n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_decimal,\n c_numeric,\n c_real,\n c_double_precision,\n c_money,\n COUNT(*) AS cnt\nFROM postgres_numeric_types\nGROUP BY\n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_decimal,\n c_numeric,\n c_real,\n c_double_precision,\n c_money\nLIMIT 1", + "name": "GetPostgresNumericTypesCnt", + "cmd": ":one", + "columns": [ + { + "name": "c_boolean", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bool" + }, + "originalName": "c_boolean" + }, + { + "name": "c_bit", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bit" + }, + "originalName": "c_bit" + }, + { + "name": "c_smallint", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int2" + }, + "originalName": "c_smallint" + }, + { + "name": "c_integer", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int4" + }, + "originalName": "c_integer" + }, + { + "name": "c_bigint", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int8" + }, + "originalName": "c_bigint" + }, + { + "name": "c_decimal", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "numeric" + }, + "originalName": "c_decimal" + }, + { + "name": "c_numeric", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "numeric" + }, + "originalName": "c_numeric" + }, + { + "name": "c_real", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "float4" + }, + "originalName": "c_real" + }, + { + "name": "c_double_precision", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "float8" + }, + "originalName": "c_double_precision" + }, + { + "name": "c_money", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "name": "money" + }, + "originalName": "c_money" }, { - "number": 11, + "name": "cnt", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "bigint" + } + } + ], + "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_numeric_types\n(\n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_decimal,\n c_numeric,\n c_real,\n c_double_precision,\n c_money\n) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", + "name": "InsertPostgresNumericTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, "column": { - "name": "c_date", + "name": "c_boolean", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "date" + "name": "pg_catalog.bool" }, - "originalName": "c_date" + "originalName": "c_boolean" } }, { - "number": 12, + "number": 2, "column": { - "name": "c_time", + "name": "c_bit", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.time" + "name": "pg_catalog.bit" }, - "originalName": "c_time" + "originalName": "c_bit" } }, { - "number": 13, + "number": 3, "column": { - "name": "c_timestamp", + "name": "c_smallint", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.timestamp" + "name": "pg_catalog.int2" }, - "originalName": "c_timestamp" + "originalName": "c_smallint" } }, { - "number": 14, + "number": 4, "column": { - "name": "c_timestamp_with_tz", + "name": "c_integer", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.timestamptz" + "name": "pg_catalog.int4" }, - "originalName": "c_timestamp_with_tz" + "originalName": "c_integer" } }, { - "number": 15, + "number": 5, "column": { - "name": "c_interval", + "name": "c_bigint", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.interval" + "name": "pg_catalog.int8" }, - "originalName": "c_interval" + "originalName": "c_bigint" } }, { - "number": 16, + "number": 6, "column": { - "name": "c_char", + "name": "c_decimal", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.bpchar" + "name": "pg_catalog.numeric" }, - "originalName": "c_char" + "originalName": "c_decimal" } }, { - "number": 17, + "number": 7, "column": { - "name": "c_varchar", + "name": "c_numeric", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.varchar" + "name": "pg_catalog.numeric" }, - "originalName": "c_varchar" + "originalName": "c_numeric" } }, { - "number": 18, + "number": 8, "column": { - "name": "c_character_varying", + "name": "c_real", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.varchar" + "name": "pg_catalog.float4" }, - "originalName": "c_character_varying" + "originalName": "c_real" } }, { - "number": 19, + "number": 9, "column": { - "name": "c_bpchar", + "name": "c_double_precision", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "bpchar" + "name": "pg_catalog.float8" }, - "originalName": "c_bpchar" + "originalName": "c_double_precision" } }, { - "number": 20, + "number": 10, "column": { - "name": "c_text", + "name": "c_money", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "text" + "name": "money" }, - "originalName": "c_text" + "originalName": "c_money" } - }, + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_numeric_types" + } + }, + { + "text": "\nINSERT INTO postgres_string_types\n(\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text\n)\nVALUES ($1, $2, $3, $4, $5)", + "name": "InsertPostgresStringTypes", + "cmd": ":exec", + "parameters": [ { - "number": 21, + "number": 1, "column": { - "name": "c_uuid", + "name": "c_char", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "uuid" + "name": "pg_catalog.bpchar" }, - "originalName": "c_uuid" + "originalName": "c_char" } }, { - "number": 22, + "number": 2, "column": { - "name": "c_json", + "name": "c_varchar", "length": -1, + "table": { + "schema": "public", + "name": "postgres_string_types" + }, "type": { - "name": "json" - } + "name": "pg_catalog.varchar" + }, + "originalName": "c_varchar" } }, { - "number": 23, - "column": { - "name": "c_json_string_override", - "length": -1, - "type": { - "name": "json" - } - } - }, - { - "number": 24, - "column": { - "name": "c_jsonb", - "length": -1, - "type": { - "name": "jsonb" - } - } - }, - { - "number": 25, - "column": { - "name": "c_jsonpath", - "length": -1, - "type": { - "name": "jsonpath" - } - } - }, - { - "number": 26, - "column": { - "name": "c_xml", - "length": -1, - "type": { - "name": "xml" - } - } - }, - { - "number": 27, + "number": 3, "column": { - "name": "c_cidr", + "name": "c_character_varying", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "cidr" + "name": "pg_catalog.varchar" }, - "originalName": "c_cidr" + "originalName": "c_character_varying" } }, { - "number": 28, + "number": 4, "column": { - "name": "c_inet", + "name": "c_bpchar", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "inet" + "name": "bpchar" }, - "originalName": "c_inet" - } - }, - { - "number": 29, - "column": { - "name": "c_macaddr", - "length": -1, - "type": { - "name": "macaddr" - } + "originalName": "c_bpchar" } }, { - "number": 30, + "number": 5, "column": { - "name": "c_macaddr8", + "name": "c_text", "length": -1, + "table": { + "schema": "public", + "name": "postgres_string_types" + }, "type": { - "name": "macaddr8" - } + "name": "text" + }, + "originalName": "c_text" } } ], + "comments": [ + " String types " + ], "filename": "query.sql", "insert_into_table": { - "name": "postgres_types" + "name": "postgres_string_types" } }, { - "text": "INSERT INTO postgres_types\n(\n c_boolean,\n c_smallint,\n c_integer,\n c_bigint,\n c_real,\n c_numeric,\n c_decimal,\n c_double_precision,\n c_money,\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n c_uuid,\n c_cidr,\n c_inet,\n c_macaddr\n)\nVALUES (\n $1, \n $2, \n $3, \n $4, \n $5, \n $6, \n $7, \n $8, \n $9, \n $10, \n $11, \n $12, \n $13, \n $14, \n $15, \n $16, \n $17, \n $18,\n $19,\n $20,\n $21,\n $22,\n $23\n)", - "name": "InsertPostgresTypesBatch", + "text": "INSERT INTO postgres_string_types \n(\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text\n) VALUES ($1, $2, $3, $4, $5)", + "name": "InsertPostgresStringTypesBatch", "cmd": ":copyfrom", "parameters": [ { "number": 1, "column": { - "name": "c_boolean", + "name": "c_char", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "pg_catalog.bool" + "name": "pg_catalog.bpchar" }, - "originalName": "c_boolean" + "originalName": "c_char" } }, { "number": 2, "column": { - "name": "c_smallint", + "name": "c_varchar", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "pg_catalog.int2" + "name": "pg_catalog.varchar" }, - "originalName": "c_smallint" + "originalName": "c_varchar" } }, { "number": 3, "column": { - "name": "c_integer", + "name": "c_character_varying", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "pg_catalog.int4" + "name": "pg_catalog.varchar" }, - "originalName": "c_integer" + "originalName": "c_character_varying" } }, { "number": 4, "column": { - "name": "c_bigint", + "name": "c_bpchar", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "pg_catalog.int8" + "name": "bpchar" }, - "originalName": "c_bigint" + "originalName": "c_bpchar" } }, { "number": 5, "column": { - "name": "c_real", + "name": "c_text", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "pg_catalog.float4" + "name": "text" }, - "originalName": "c_real" + "originalName": "c_text" } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_string_types" + } + }, + { + "text": "SELECT c_char, c_varchar, c_character_varying, c_bpchar, c_text FROM postgres_string_types LIMIT 1", + "name": "GetPostgresStringTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_char", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bpchar" + }, + "originalName": "c_char" }, { - "number": 6, - "column": { - "name": "c_numeric", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.numeric" - }, - "originalName": "c_numeric" - } + "name": "c_varchar", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "c_varchar" }, { - "number": 7, - "column": { - "name": "c_decimal", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.numeric" - }, - "originalName": "c_decimal" - } + "name": "c_character_varying", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "c_character_varying" }, { - "number": 8, - "column": { - "name": "c_double_precision", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.float8" - }, - "originalName": "c_double_precision" - } + "name": "c_bpchar", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "name": "bpchar" + }, + "originalName": "c_bpchar" }, { - "number": 9, - "column": { - "name": "c_money", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "money" - }, - "originalName": "c_money" - } + "name": "c_text", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "name": "text" + }, + "originalName": "c_text" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_string_types", + "name": "TruncatePostgresStringTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "SELECT\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n COUNT(*) AS cnt\nFROM postgres_string_types\nGROUP BY\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text\nLIMIT 1", + "name": "GetPostgresStringTypesCnt", + "cmd": ":one", + "columns": [ + { + "name": "c_char", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bpchar" + }, + "originalName": "c_char" }, { - "number": 10, - "column": { - "name": "c_date", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "date" - }, - "originalName": "c_date" - } + "name": "c_varchar", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "c_varchar" }, { - "number": 11, - "column": { - "name": "c_time", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.time" - }, - "originalName": "c_time" - } + "name": "c_character_varying", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "c_character_varying" }, { - "number": 12, - "column": { - "name": "c_timestamp", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.timestamp" - }, - "originalName": "c_timestamp" - } + "name": "c_bpchar", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "name": "bpchar" + }, + "originalName": "c_bpchar" }, { - "number": 13, - "column": { - "name": "c_timestamp_with_tz", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.timestamptz" - }, - "originalName": "c_timestamp_with_tz" - } + "name": "c_text", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "name": "text" + }, + "originalName": "c_text" }, { - "number": 14, - "column": { - "name": "c_interval", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.interval" - }, - "originalName": "c_interval" + "name": "cnt", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "bigint" } + } + ], + "filename": "query.sql" + }, + { + "text": "WITH txt_query AS (\n SELECT \n c_text, \n to_tsquery('english', $1) AS query,\n to_tsvector('english', c_text) AS tsv\n FROM postgres_string_types \n WHERE c_text @@ to_tsquery('english', $1)\n)\n\nSELECT txt_query.c_text, txt_query.query, txt_query.tsv, ts_rank(tsv, query) AS rnk\nFROM txt_query\nORDER BY rnk DESC\nLIMIT 1", + "name": "GetPostgresStringTypesTextSearch", + "cmd": ":one", + "columns": [ + { + "name": "c_text", + "length": -1, + "table": { + "name": "txt_query" + }, + "type": { + "name": "text" + }, + "originalName": "c_text" }, { - "number": 15, - "column": { - "name": "c_char", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.bpchar" - }, - "originalName": "c_char" - } + "name": "query", + "notNull": true, + "length": -1, + "table": { + "name": "txt_query" + }, + "type": { + "name": "tsquery" + }, + "originalName": "query" }, { - "number": 16, - "column": { - "name": "c_varchar", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.varchar" - }, - "originalName": "c_varchar" - } + "name": "tsv", + "notNull": true, + "length": -1, + "table": { + "name": "txt_query" + }, + "type": { + "name": "tsvector" + }, + "originalName": "tsv" }, { - "number": 17, - "column": { - "name": "c_character_varying", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.varchar" - }, - "originalName": "c_character_varying" + "name": "rnk", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "real" } - }, + } + ], + "parameters": [ { - "number": 18, + "number": 1, "column": { - "name": "c_bpchar", + "name": "to_tsquery", + "notNull": true, "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, "type": { - "name": "bpchar" - }, - "originalName": "c_bpchar" + "name": "text" + } } - }, + } + ], + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO postgres_datetime_types\n(\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval\n) VALUES ($1, $2, $3, $4, $5)", + "name": "InsertPostgresDateTimeTypes", + "cmd": ":exec", + "parameters": [ { - "number": 19, + "number": 1, "column": { - "name": "c_text", + "name": "c_date", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "text" + "name": "date" }, - "originalName": "c_text" + "originalName": "c_date" } }, { - "number": 20, + "number": 2, "column": { - "name": "c_uuid", + "name": "c_time", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "uuid" + "name": "pg_catalog.time" }, - "originalName": "c_uuid" + "originalName": "c_time" } }, { - "number": 21, + "number": 3, "column": { - "name": "c_cidr", + "name": "c_timestamp", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "cidr" + "name": "pg_catalog.timestamp" }, - "originalName": "c_cidr" + "originalName": "c_timestamp" } }, { - "number": 22, + "number": 4, "column": { - "name": "c_inet", + "name": "c_timestamp_with_tz", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "inet" + "name": "pg_catalog.timestamptz" }, - "originalName": "c_inet" + "originalName": "c_timestamp_with_tz" } }, { - "number": 23, + "number": 5, "column": { - "name": "c_macaddr", + "name": "c_interval", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "macaddr" + "name": "pg_catalog.interval" }, - "originalName": "c_macaddr" + "originalName": "c_interval" } } ], + "comments": [ + " DateTime types " + ], "filename": "query.sql", "insert_into_table": { - "name": "postgres_types" + "name": "postgres_datetime_types" } }, { - "text": "SELECT \n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_real,\n c_numeric,\n c_decimal,\n c_double_precision,\n c_money,\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n c_uuid,\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_cidr,\n c_inet,\n c_macaddr,\n c_macaddr8::TEXT AS c_macaddr8\nFROM postgres_types \nLIMIT 1", - "name": "GetPostgresTypes", + "text": "SELECT c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval FROM postgres_datetime_types LIMIT 1", + "name": "GetPostgresDateTimeTypes", "cmd": ":one", "columns": [ { - "name": "c_boolean", + "name": "c_date", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "schema": "pg_catalog", - "name": "bool" + "name": "date" }, - "originalName": "c_boolean" + "originalName": "c_date" }, { - "name": "c_bit", + "name": "c_time", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "bit" + "name": "time" }, - "originalName": "c_bit" + "originalName": "c_time" }, { - "name": "c_smallint", + "name": "c_timestamp", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "int2" + "name": "timestamp" }, - "originalName": "c_smallint" + "originalName": "c_timestamp" }, { - "name": "c_integer", + "name": "c_timestamp_with_tz", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "int4" + "name": "timestamptz" }, - "originalName": "c_integer" + "originalName": "c_timestamp_with_tz" }, { - "name": "c_bigint", + "name": "c_interval", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "int8" + "name": "interval" }, - "originalName": "c_bigint" - }, + "originalName": "c_interval" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_datetime_types", + "name": "TruncatePostgresDateTimeTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "SELECT\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n COUNT(*) AS cnt\nFROM postgres_datetime_types\nGROUP BY\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval\nLIMIT 1", + "name": "GetPostgresDateTimeTypesCnt", + "cmd": ":one", + "columns": [ { - "name": "c_real", + "name": "c_date", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "schema": "pg_catalog", - "name": "float4" + "name": "date" }, - "originalName": "c_real" + "originalName": "c_date" }, { - "name": "c_numeric", + "name": "c_time", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "numeric" + "name": "time" }, - "originalName": "c_numeric" + "originalName": "c_time" }, { - "name": "c_decimal", + "name": "c_timestamp", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "numeric" + "name": "timestamp" }, - "originalName": "c_decimal" + "originalName": "c_timestamp" }, { - "name": "c_double_precision", + "name": "c_timestamp_with_tz", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "float8" + "name": "timestamptz" }, - "originalName": "c_double_precision" + "originalName": "c_timestamp_with_tz" }, { - "name": "c_money", + "name": "c_interval", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "money" + "schema": "pg_catalog", + "name": "interval" }, - "originalName": "c_money" + "originalName": "c_interval" }, { - "name": "c_date", + "name": "cnt", + "notNull": true, "length": -1, - "table": { - "name": "postgres_types" - }, + "isFuncCall": true, "type": { - "name": "date" - }, - "originalName": "c_date" + "name": "bigint" + } + } + ], + "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_datetime_types\n(\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval\n) VALUES ($1, $2, $3, $4, $5)", + "name": "InsertPostgresDateTimeTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_date", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_datetime_types" + }, + "type": { + "name": "date" + }, + "originalName": "c_date" + } }, { - "name": "c_time", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "time" - }, - "originalName": "c_time" + "number": 2, + "column": { + "name": "c_time", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_datetime_types" + }, + "type": { + "name": "pg_catalog.time" + }, + "originalName": "c_time" + } }, { - "name": "c_timestamp", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "timestamp" - }, - "originalName": "c_timestamp" + "number": 3, + "column": { + "name": "c_timestamp", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_datetime_types" + }, + "type": { + "name": "pg_catalog.timestamp" + }, + "originalName": "c_timestamp" + } }, { - "name": "c_timestamp_with_tz", + "number": 4, + "column": { + "name": "c_timestamp_with_tz", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_datetime_types" + }, + "type": { + "name": "pg_catalog.timestamptz" + }, + "originalName": "c_timestamp_with_tz" + } + }, + { + "number": 5, + "column": { + "name": "c_interval", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_datetime_types" + }, + "type": { + "name": "pg_catalog.interval" + }, + "originalName": "c_interval" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_datetime_types" + } + }, + { + "text": "\nINSERT INTO postgres_network_types\n(\n c_cidr,\n c_inet,\n c_macaddr,\n c_macaddr8\n) VALUES (\n $1, \n $2, \n $3, \n $4::macaddr8\n)", + "name": "InsertPostgresNetworkTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_cidr", + "length": -1, + "isNamedParam": true, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "cidr" + }, + "originalName": "c_cidr" + } + }, + { + "number": 2, + "column": { + "name": "c_inet", + "length": -1, + "isNamedParam": true, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "inet" + }, + "originalName": "c_inet" + } + }, + { + "number": 3, + "column": { + "name": "c_macaddr", + "length": -1, + "isNamedParam": true, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "macaddr" + }, + "originalName": "c_macaddr" + } + }, + { + "number": 4, + "column": { + "name": "c_macaddr8", + "length": -1, + "type": { + "name": "macaddr8" + } + } + } + ], + "comments": [ + " Network types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_network_types" + } + }, + { + "text": "SELECT\n c_cidr,\n c_inet,\n c_macaddr,\n c_macaddr8::TEXT AS c_macaddr8\nFROM postgres_network_types\nLIMIT 1", + "name": "GetPostgresNetworkTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_cidr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "schema": "pg_catalog", - "name": "timestamptz" + "name": "cidr" }, - "originalName": "c_timestamp_with_tz" + "originalName": "c_cidr" }, { - "name": "c_interval", + "name": "c_inet", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "schema": "pg_catalog", - "name": "interval" + "name": "inet" }, - "originalName": "c_interval" + "originalName": "c_inet" }, { - "name": "c_char", + "name": "c_macaddr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "schema": "pg_catalog", - "name": "bpchar" + "name": "macaddr" }, - "originalName": "c_char" + "originalName": "c_macaddr" }, { - "name": "c_varchar", + "name": "c_macaddr8", + "notNull": true, "length": -1, - "table": { - "name": "postgres_types" - }, "type": { - "schema": "pg_catalog", - "name": "varchar" - }, - "originalName": "c_varchar" - }, + "name": "text" + } + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_network_types", + "name": "TruncatePostgresNetworkTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "SELECT\n c_cidr,\n c_inet,\n c_macaddr,\n COUNT(*) AS cnt\nFROM postgres_network_types\nGROUP BY\n c_cidr,\n c_inet,\n c_macaddr\nLIMIT 1", + "name": "GetPostgresNetworkTypesCnt", + "cmd": ":one", + "columns": [ { - "name": "c_character_varying", + "name": "c_cidr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "schema": "pg_catalog", - "name": "varchar" + "name": "cidr" }, - "originalName": "c_character_varying" + "originalName": "c_cidr" }, { - "name": "c_bpchar", + "name": "c_inet", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "bpchar" + "name": "inet" }, - "originalName": "c_bpchar" + "originalName": "c_inet" }, { - "name": "c_text", + "name": "c_macaddr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "text" + "name": "macaddr" }, - "originalName": "c_text" + "originalName": "c_macaddr" }, { - "name": "c_uuid", + "name": "cnt", + "notNull": true, "length": -1, - "table": { - "name": "postgres_types" - }, + "isFuncCall": true, "type": { - "name": "uuid" - }, - "originalName": "c_uuid" + "name": "bigint" + } + } + ], + "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_network_types\n(\n c_cidr,\n c_inet,\n c_macaddr\n) VALUES ($1, $2, $3)", + "name": "InsertPostgresNetworkTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_cidr", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "cidr" + }, + "originalName": "c_cidr" + } + }, + { + "number": 2, + "column": { + "name": "c_inet", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "inet" + }, + "originalName": "c_inet" + } + }, + { + "number": 3, + "column": { + "name": "c_macaddr", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "macaddr" + }, + "originalName": "c_macaddr" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_network_types" + } + }, + { + "text": "\nINSERT INTO postgres_special_types\n(\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum\n)\nVALUES (\n $1::json, \n $2::json, \n $3::jsonb,\n $4::jsonpath,\n $5::xml,\n $6::xml,\n $7,\n $8::c_enum\n)", + "name": "InsertPostgresSpecialTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_json", + "length": -1, + "type": { + "name": "json" + } + } + }, + { + "number": 2, + "column": { + "name": "c_json_string_override", + "length": -1, + "type": { + "name": "json" + } + } + }, + { + "number": 3, + "column": { + "name": "c_jsonb", + "length": -1, + "type": { + "name": "jsonb" + } + } + }, + { + "number": 4, + "column": { + "name": "c_jsonpath", + "length": -1, + "type": { + "name": "jsonpath" + } + } + }, + { + "number": 5, + "column": { + "name": "c_xml", + "length": -1, + "type": { + "name": "xml" + } + } + }, + { + "number": 6, + "column": { + "name": "c_xml_string_override", + "length": -1, + "type": { + "name": "xml" + } + } }, + { + "number": 7, + "column": { + "name": "c_uuid", + "length": -1, + "isNamedParam": true, + "table": { + "schema": "public", + "name": "postgres_special_types" + }, + "type": { + "name": "uuid" + }, + "originalName": "c_uuid" + } + }, + { + "number": 8, + "column": { + "name": "c_enum", + "length": -1, + "type": { + "name": "c_enum" + } + } + } + ], + "comments": [ + " Special types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_special_types" + } + }, + { + "text": "SELECT\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum\nFROM postgres_special_types \nLIMIT 1", + "name": "GetPostgresSpecialTypes", + "cmd": ":one", + "columns": [ { "name": "c_json", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { "name": "json" @@ -34278,7 +35151,7 @@ "name": "c_json_string_override", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { "name": "json" @@ -34289,7 +35162,7 @@ "name": "c_jsonb", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { "name": "jsonb" @@ -34300,7 +35173,7 @@ "name": "c_jsonpath", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { "name": "jsonpath" @@ -34311,7 +35184,7 @@ "name": "c_xml", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { "name": "xml" @@ -34319,321 +35192,528 @@ "originalName": "c_xml" }, { - "name": "c_cidr", + "name": "c_xml_string_override", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { - "name": "cidr" + "name": "xml" }, - "originalName": "c_cidr" + "originalName": "c_xml_string_override" }, { - "name": "c_inet", + "name": "c_uuid", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { - "name": "inet" + "name": "uuid" }, - "originalName": "c_inet" + "originalName": "c_uuid" }, { - "name": "c_macaddr", + "name": "c_enum", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { - "name": "macaddr" + "name": "c_enum" }, - "originalName": "c_macaddr" - }, + "originalName": "c_enum" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_special_types", + "name": "TruncatePostgresSpecialTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_special_types\n(\n c_uuid\n)\nVALUES (\n $1\n)", + "name": "InsertPostgresSpecialTypesBatch", + "cmd": ":copyfrom", + "parameters": [ { - "name": "c_macaddr8", - "notNull": true, - "length": -1, - "type": { - "name": "text" + "number": 1, + "column": { + "name": "c_uuid", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_special_types" + }, + "type": { + "name": "uuid" + }, + "originalName": "c_uuid" } } ], - "filename": "query.sql" + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_special_types" + } }, { - "text": "SELECT\n c_smallint,\n c_boolean,\n c_integer,\n c_bigint,\n c_real,\n c_numeric,\n c_decimal,\n c_double_precision,\n c_money,\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n c_uuid,\n c_cidr,\n c_inet,\n c_macaddr,\n COUNT(*) AS cnt\nFROM postgres_types\nGROUP BY\n c_smallint,\n c_boolean,\n c_integer,\n c_bigint,\n c_real,\n c_numeric,\n c_decimal,\n c_double_precision,\n c_money,\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n c_uuid,\n c_cidr,\n c_inet,\n c_macaddr\nLIMIT 1", - "name": "GetPostgresTypesCnt", + "text": "SELECT\n c_uuid,\n COUNT(*) AS cnt\nFROM postgres_special_types\nGROUP BY\n c_uuid\nLIMIT 1", + "name": "GetPostgresSpecialTypesCnt", "cmd": ":one", "columns": [ { - "name": "c_smallint", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "int2" - }, - "originalName": "c_smallint" - }, - { - "name": "c_boolean", + "name": "c_uuid", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { - "schema": "pg_catalog", - "name": "bool" + "name": "uuid" }, - "originalName": "c_boolean" + "originalName": "c_uuid" }, { - "name": "c_integer", + "name": "cnt", + "notNull": true, "length": -1, - "table": { - "name": "postgres_types" - }, + "isFuncCall": true, "type": { - "schema": "pg_catalog", - "name": "int4" - }, - "originalName": "c_integer" - }, + "name": "bigint" + } + } + ], + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO postgres_array_types\n(\n c_bytea,\n c_boolean_array,\n c_text_array,\n c_integer_array,\n c_decimal_array,\n c_date_array,\n c_timestamp_array\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", + "name": "InsertPostgresArrayTypes", + "cmd": ":exec", + "parameters": [ { - "name": "c_bigint", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "int8" - }, - "originalName": "c_bigint" + "number": 1, + "column": { + "name": "c_bytea", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "bytea" + }, + "originalName": "c_bytea" + } }, { - "name": "c_real", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "float4" - }, - "originalName": "c_real" + "number": 2, + "column": { + "name": "c_boolean_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.bool" + }, + "originalName": "c_boolean_array", + "arrayDims": 1 + } }, { - "name": "c_numeric", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "numeric" - }, - "originalName": "c_numeric" + "number": 3, + "column": { + "name": "c_text_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "text" + }, + "originalName": "c_text_array", + "arrayDims": 1 + } }, { - "name": "c_decimal", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "numeric" - }, - "originalName": "c_decimal" + "number": 4, + "column": { + "name": "c_integer_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.int4" + }, + "originalName": "c_integer_array", + "arrayDims": 1 + } }, { - "name": "c_double_precision", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "float8" - }, - "originalName": "c_double_precision" + "number": 5, + "column": { + "name": "c_decimal_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.numeric" + }, + "originalName": "c_decimal_array", + "arrayDims": 1 + } }, { - "name": "c_money", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "name": "money" - }, - "originalName": "c_money" + "number": 6, + "column": { + "name": "c_date_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "date" + }, + "originalName": "c_date_array", + "arrayDims": 1 + } }, { - "name": "c_date", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "name": "date" - }, - "originalName": "c_date" - }, + "number": 7, + "column": { + "name": "c_timestamp_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.timestamp" + }, + "originalName": "c_timestamp_array", + "arrayDims": 1 + } + } + ], + "comments": [ + " Array types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_array_types" + } + }, + { + "text": "SELECT c_bytea, c_boolean_array, c_text_array, c_integer_array, c_decimal_array, c_date_array, c_timestamp_array FROM postgres_array_types LIMIT 1", + "name": "GetPostgresArrayTypes", + "cmd": ":one", + "columns": [ { - "name": "c_time", + "name": "c_bytea", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "schema": "pg_catalog", - "name": "time" + "name": "bytea" }, - "originalName": "c_time" + "originalName": "c_bytea" }, { - "name": "c_timestamp", + "name": "c_boolean_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { "schema": "pg_catalog", - "name": "timestamp" + "name": "bool" }, - "originalName": "c_timestamp" + "originalName": "c_boolean_array", + "arrayDims": 1 }, { - "name": "c_timestamp_with_tz", + "name": "c_text_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "schema": "pg_catalog", - "name": "timestamptz" + "name": "text" }, - "originalName": "c_timestamp_with_tz" + "originalName": "c_text_array", + "arrayDims": 1 }, { - "name": "c_interval", + "name": "c_integer_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { "schema": "pg_catalog", - "name": "interval" + "name": "int4" }, - "originalName": "c_interval" + "originalName": "c_integer_array", + "arrayDims": 1 }, { - "name": "c_char", + "name": "c_decimal_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { "schema": "pg_catalog", - "name": "bpchar" + "name": "numeric" }, - "originalName": "c_char" + "originalName": "c_decimal_array", + "arrayDims": 1 }, { - "name": "c_varchar", + "name": "c_date_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, - "type": { - "schema": "pg_catalog", - "name": "varchar" + "type": { + "name": "date" }, - "originalName": "c_varchar" + "originalName": "c_date_array", + "arrayDims": 1 }, { - "name": "c_character_varying", + "name": "c_timestamp_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { "schema": "pg_catalog", - "name": "varchar" + "name": "timestamp" }, - "originalName": "c_character_varying" + "originalName": "c_timestamp_array", + "arrayDims": 1 + } + ], + "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_array_types (\n c_bytea,\n c_boolean_array,\n c_text_array,\n c_integer_array,\n c_decimal_array,\n c_timestamp_array\n) \nVALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6\n)", + "name": "InsertPostgresArrayTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_bytea", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "bytea" + }, + "originalName": "c_bytea" + } }, { - "name": "c_bpchar", + "number": 2, + "column": { + "name": "c_boolean_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.bool" + }, + "originalName": "c_boolean_array", + "arrayDims": 1 + } + }, + { + "number": 3, + "column": { + "name": "c_text_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "text" + }, + "originalName": "c_text_array", + "arrayDims": 1 + } + }, + { + "number": 4, + "column": { + "name": "c_integer_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.int4" + }, + "originalName": "c_integer_array", + "arrayDims": 1 + } + }, + { + "number": 5, + "column": { + "name": "c_decimal_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.numeric" + }, + "originalName": "c_decimal_array", + "arrayDims": 1 + } + }, + { + "number": 6, + "column": { + "name": "c_timestamp_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.timestamp" + }, + "originalName": "c_timestamp_array", + "arrayDims": 1 + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_array_types" + } + }, + { + "text": "SELECT\n c_bytea,\n c_boolean_array,\n c_text_array,\n c_integer_array,\n c_decimal_array,\n c_timestamp_array,\n COUNT(*) AS cnt\nFROM postgres_array_types\nGROUP BY\n c_bytea,\n c_boolean_array,\n c_text_array,\n c_integer_array,\n c_decimal_array,\n c_timestamp_array\nLIMIT 1", + "name": "GetPostgresArrayTypesCnt", + "cmd": ":one", + "columns": [ + { + "name": "c_bytea", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "bpchar" + "name": "bytea" }, - "originalName": "c_bpchar" + "originalName": "c_bytea" }, { - "name": "c_text", + "name": "c_boolean_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "text" + "schema": "pg_catalog", + "name": "bool" }, - "originalName": "c_text" + "originalName": "c_boolean_array", + "arrayDims": 1 }, { - "name": "c_uuid", + "name": "c_text_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "uuid" + "name": "text" }, - "originalName": "c_uuid" + "originalName": "c_text_array", + "arrayDims": 1 }, { - "name": "c_cidr", + "name": "c_integer_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "cidr" + "schema": "pg_catalog", + "name": "int4" }, - "originalName": "c_cidr" + "originalName": "c_integer_array", + "arrayDims": 1 }, { - "name": "c_inet", + "name": "c_decimal_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "inet" + "schema": "pg_catalog", + "name": "numeric" }, - "originalName": "c_inet" + "originalName": "c_decimal_array", + "arrayDims": 1 }, { - "name": "c_macaddr", + "name": "c_timestamp_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "macaddr" + "schema": "pg_catalog", + "name": "timestamp" }, - "originalName": "c_macaddr" + "originalName": "c_timestamp_array", + "arrayDims": 1 }, { "name": "cnt", @@ -34648,42 +35728,13 @@ "filename": "query.sql" }, { - "text": "SELECT\n MAX(c_integer) AS max_integer,\n MAX(c_varchar) AS max_varchar,\n MAX(c_timestamp) AS max_timestamp\nFROM postgres_types", - "name": "GetPostgresFunctions", - "cmd": ":one", - "columns": [ - { - "name": "max_integer", - "notNull": true, - "length": -1, - "isFuncCall": true, - "type": { - "name": "anyarray" - } - }, - { - "name": "max_varchar", - "notNull": true, - "length": -1, - "isFuncCall": true, - "type": { - "name": "anyarray" - } - }, - { - "name": "max_timestamp", - "notNull": true, - "length": -1, - "isFuncCall": true, - "type": { - "name": "anyarray" - } - } - ], + "text": "TRUNCATE TABLE postgres_array_types", + "name": "TruncatePostgresArrayTypes", + "cmd": ":exec", "filename": "query.sql" }, { - "text": "INSERT INTO postgres_geometric_types (\n c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", + "text": "\nINSERT INTO postgres_geometric_types (\n c_point, \n c_line, \n c_lseg, \n c_box, \n c_path, \n c_polygon, \n c_circle\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", "name": "InsertPostgresGeoTypes", "cmd": ":exec", "parameters": [ @@ -34793,13 +35844,16 @@ } } ], + "comments": [ + " Geometric types " + ], "filename": "query.sql", "insert_into_table": { "name": "postgres_geometric_types" } }, { - "text": "INSERT INTO postgres_geometric_types (\n c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", + "text": "INSERT INTO postgres_geometric_types (\n c_point, \n c_line, \n c_lseg, \n c_box, \n c_path, \n c_polygon, \n c_circle\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", "name": "InsertPostgresGeoTypesBatch", "cmd": ":copyfrom", "parameters": [ @@ -34999,308 +36053,13 @@ ], "filename": "query.sql" }, - { - "text": "TRUNCATE TABLE postgres_types", - "name": "TruncatePostgresTypes", - "cmd": ":exec", - "filename": "query.sql" - }, { "text": "TRUNCATE TABLE postgres_geometric_types", "name": "TruncatePostgresGeoTypes", "cmd": ":exec", "filename": "query.sql" - }, - { - "text": "INSERT INTO postgres_array_types\n(\n c_bytea,\n c_boolean_array,\n c_text_array,\n c_integer_array,\n c_decimal_array,\n c_date_array,\n c_timestamp_array\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", - "name": "InsertPostgresArrayTypes", - "cmd": ":exec", - "parameters": [ - { - "number": 1, - "column": { - "name": "c_bytea", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "bytea" - }, - "originalName": "c_bytea" - } - }, - { - "number": 2, - "column": { - "name": "c_boolean_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "pg_catalog.bool" - }, - "originalName": "c_boolean_array", - "arrayDims": 1 - } - }, - { - "number": 3, - "column": { - "name": "c_text_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "text" - }, - "originalName": "c_text_array", - "arrayDims": 1 - } - }, - { - "number": 4, - "column": { - "name": "c_integer_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "pg_catalog.int4" - }, - "originalName": "c_integer_array", - "arrayDims": 1 - } - }, - { - "number": 5, - "column": { - "name": "c_decimal_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "pg_catalog.numeric" - }, - "originalName": "c_decimal_array", - "arrayDims": 1 - } - }, - { - "number": 6, - "column": { - "name": "c_date_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "date" - }, - "originalName": "c_date_array", - "arrayDims": 1 - } - }, - { - "number": 7, - "column": { - "name": "c_timestamp_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "pg_catalog.timestamp" - }, - "originalName": "c_timestamp_array", - "arrayDims": 1 - } - } - ], - "filename": "query.sql", - "insert_into_table": { - "name": "postgres_array_types" - } - }, - { - "text": "SELECT c_bytea, c_boolean_array, c_text_array, c_integer_array, c_decimal_array, c_date_array, c_timestamp_array FROM postgres_array_types LIMIT 1", - "name": "GetPostgresArrayTypes", - "cmd": ":one", - "columns": [ - { - "name": "c_bytea", - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "name": "bytea" - }, - "originalName": "c_bytea" - }, - { - "name": "c_boolean_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "schema": "pg_catalog", - "name": "bool" - }, - "originalName": "c_boolean_array", - "arrayDims": 1 - }, - { - "name": "c_text_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "name": "text" - }, - "originalName": "c_text_array", - "arrayDims": 1 - }, - { - "name": "c_integer_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "schema": "pg_catalog", - "name": "int4" - }, - "originalName": "c_integer_array", - "arrayDims": 1 - }, - { - "name": "c_decimal_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "schema": "pg_catalog", - "name": "numeric" - }, - "originalName": "c_decimal_array", - "arrayDims": 1 - }, - { - "name": "c_date_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "name": "date" - }, - "originalName": "c_date_array", - "arrayDims": 1 - }, - { - "name": "c_timestamp_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "schema": "pg_catalog", - "name": "timestamp" - }, - "originalName": "c_timestamp_array", - "arrayDims": 1 - } - ], - "filename": "query.sql" - }, - { - "text": "INSERT INTO postgres_array_types (c_bytea) VALUES ($1)", - "name": "InsertPostgresArrayTypesBatch", - "cmd": ":copyfrom", - "parameters": [ - { - "number": 1, - "column": { - "name": "c_bytea", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "bytea" - }, - "originalName": "c_bytea" - } - } - ], - "filename": "query.sql", - "insert_into_table": { - "name": "postgres_array_types" - } - }, - { - "text": "SELECT\n c_bytea,\n COUNT(*) AS cnt\nFROM postgres_array_types\nGROUP BY\n c_bytea\nLIMIT 1", - "name": "GetPostgresArrayTypesCnt", - "cmd": ":one", - "columns": [ - { - "name": "c_bytea", - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "name": "bytea" - }, - "originalName": "c_bytea" - }, - { - "name": "cnt", - "notNull": true, - "length": -1, - "isFuncCall": true, - "type": { - "name": "bigint" - } - } - ], - "filename": "query.sql" - }, - { - "text": "TRUNCATE TABLE postgres_array_types", - "name": "TruncatePostgresArrayTypes", - "cmd": ":exec", - "filename": "query.sql" } ], "sqlc_version": "v1.27.0", - "plugin_options": "eyJvdmVycmlkZURyaXZlclZlcnNpb24iOiIiLCJnZW5lcmF0ZUNzcHJvaiI6dHJ1ZSwidGFyZ2V0RnJhbWV3b3JrIjoibmV0c3RhbmRhcmQyLjAiLCJuYW1lc3BhY2VOYW1lIjoiTnBnc3FsRGFwcGVyTGVnYWN5RXhhbXBsZUdlbiIsInVzZURhcHBlciI6dHJ1ZSwib3ZlcnJpZGVEYXBwZXJWZXJzaW9uIjoiIiwib3ZlcnJpZGVzIjpbeyJjb2x1bW4iOiJHZXRQb3N0Z3Jlc0Z1bmN0aW9uczptYXhfaW50ZWdlciIsImNzaGFycF90eXBlIjp7InR5cGUiOiJpbnQiLCJub3ROdWxsIjpmYWxzZX19LHsiY29sdW1uIjoiR2V0UG9zdGdyZXNGdW5jdGlvbnM6bWF4X3ZhcmNoYXIiLCJjc2hhcnBfdHlwZSI6eyJ0eXBlIjoic3RyaW5nIiwibm90TnVsbCI6ZmFsc2V9fSx7ImNvbHVtbiI6IkdldFBvc3RncmVzRnVuY3Rpb25zOm1heF90aW1lc3RhbXAiLCJjc2hhcnBfdHlwZSI6eyJ0eXBlIjoiRGF0ZVRpbWUiLCJub3ROdWxsIjp0cnVlfX0seyJjb2x1bW4iOiIqOmNfanNvbl9zdHJpbmdfb3ZlcnJpZGUiLCJjc2hhcnBfdHlwZSI6eyJ0eXBlIjoic3RyaW5nIiwibm90TnVsbCI6ZmFsc2V9fSx7ImNvbHVtbiI6Iio6Y19tYWNhZGRyOCIsImNzaGFycF90eXBlIjp7InR5cGUiOiJzdHJpbmciLCJub3ROdWxsIjpmYWxzZX19XSwiZGVidWdSZXF1ZXN0IjpmYWxzZX0=" + "plugin_options": "eyJvdmVycmlkZURyaXZlclZlcnNpb24iOiIiLCJnZW5lcmF0ZUNzcHJvaiI6dHJ1ZSwidGFyZ2V0RnJhbWV3b3JrIjoibmV0c3RhbmRhcmQyLjAiLCJuYW1lc3BhY2VOYW1lIjoiTnBnc3FsRGFwcGVyTGVnYWN5RXhhbXBsZUdlbiIsInVzZURhcHBlciI6dHJ1ZSwib3ZlcnJpZGVEYXBwZXJWZXJzaW9uIjoiIiwib3ZlcnJpZGVzIjpbeyJjb2x1bW4iOiJHZXRQb3N0Z3Jlc0Z1bmN0aW9uczptYXhfaW50ZWdlciIsImNzaGFycF90eXBlIjp7InR5cGUiOiJpbnQiLCJub3ROdWxsIjpmYWxzZX19LHsiY29sdW1uIjoiR2V0UG9zdGdyZXNGdW5jdGlvbnM6bWF4X3ZhcmNoYXIiLCJjc2hhcnBfdHlwZSI6eyJ0eXBlIjoic3RyaW5nIiwibm90TnVsbCI6ZmFsc2V9fSx7ImNvbHVtbiI6IkdldFBvc3RncmVzRnVuY3Rpb25zOm1heF90aW1lc3RhbXAiLCJjc2hhcnBfdHlwZSI6eyJ0eXBlIjoiRGF0ZVRpbWUiLCJub3ROdWxsIjp0cnVlfX0seyJjb2x1bW4iOiIqOmNfanNvbl9zdHJpbmdfb3ZlcnJpZGUiLCJjc2hhcnBfdHlwZSI6eyJ0eXBlIjoic3RyaW5nIiwibm90TnVsbCI6ZmFsc2V9fSx7ImNvbHVtbiI6Iio6Y194bWxfc3RyaW5nX292ZXJyaWRlIiwiY3NoYXJwX3R5cGUiOnsidHlwZSI6InN0cmluZyIsIm5vdE51bGwiOmZhbHNlfX0seyJjb2x1bW4iOiIqOmNfbWFjYWRkcjgiLCJjc2hhcnBfdHlwZSI6eyJ0eXBlIjoic3RyaW5nIiwibm90TnVsbCI6ZmFsc2V9fV0sImRlYnVnUmVxdWVzdCI6ZmFsc2V9" } \ No newline at end of file diff --git a/examples/NpgsqlDapperLegacyExample/request.message b/examples/NpgsqlDapperLegacyExample/request.message index 0bf7eb12..44b9c189 100644 --- a/examples/NpgsqlDapperLegacyExample/request.message +++ b/examples/NpgsqlDapperLegacyExample/request.message @@ -1,9 +1,9 @@ -ú +¸ 2 -postgresql%examples/config/postgresql/schema.sql"$examples/config/postgresql/query.sqlb› -"examples/NpgsqlDapperLegacyExamplecsharpÖ{"debugRequest":true,"generateCsproj":true,"namespaceName":"NpgsqlDapperLegacyExampleGen","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"notNull":false,"type":"int"}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"notNull":false,"type":"string"}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"notNull":true,"type":"DateTime"}},{"column":"*:c_json_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_macaddr8","csharp_type":{"notNull":false,"type":"string"}}],"targetFramework":"netstandard2.0","useDapper":true}* -./dist/LocalRunner©æ public"ýpublicƒ +postgresql-examples/config/postgresql/authors/schema.sql+examples/config/postgresql/types/schema.sql",examples/config/postgresql/authors/query.sql"*examples/config/postgresql/types/query.sqlbð +"examples/NpgsqlDapperLegacyExamplecsharp«{"debugRequest":true,"generateCsproj":true,"namespaceName":"NpgsqlDapperLegacyExampleGen","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"notNull":false,"type":"int"}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"notNull":false,"type":"string"}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"notNull":true,"type":"DateTime"}},{"column":"*:c_json_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_xml_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_macaddr8","csharp_type":{"notNull":false,"type":"string"}}],"targetFramework":"netstandard2.0","useDapper":true}* +./dist/LocalRunnerÃì public"…publicƒ authors) id0ÿÿÿÿÿÿÿÿÿR authorsb  bigserial& name0ÿÿÿÿÿÿÿÿÿR authorsbtext# @@ -13,68 +13,55 @@ postgresql%examples/config/postgresql/schema.sql"$examples/config/postgresql/qu name0ÿÿÿÿÿÿÿÿÿRbooksbtext5 author_id0ÿÿÿÿÿÿÿÿÿRbooksb pg_catalogint8) - description0ÿÿÿÿÿÿÿÿÿRbooksbtextä -postgres_types< - c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbool7 -c_bit0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbit= - -c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint2< - c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint4; -c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint8? - c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumeric? - c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumeric; -c_real0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat4G -c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat8/ -c_money0ÿÿÿÿÿÿÿÿÿRpostgres_typesbmoney- -c_date0ÿÿÿÿÿÿÿÿÿRpostgres_typesbdate9 -c_time0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogtimeC - c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestampM -c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestamptzA - -c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_cataloginterval; -c_char0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbpchar? - c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarcharI -c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarchar1 -c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesbbpchar- -c_text0ÿÿÿÿÿÿÿÿÿRpostgres_typesbtext- -c_json0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjson= -c_json_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjson/ -c_jsonb0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjsonb5 - -c_jsonpath0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -jsonpath+ -c_xml0ÿÿÿÿÿÿÿÿÿRpostgres_typesbxml- -c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_typesbcidr- -c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_typesbinet3 - c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_typesb macaddr5 - -c_macaddr80ÿÿÿÿÿÿÿÿÿRpostgres_typesb -macaddr8- -c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_typesbuuidµ -postgres_geometric_types9 -c_point0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpoint7 -c_line0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbline7 -c_lseg0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblseg5 -c_box0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbbox7 -c_path0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpath= - c_polygon0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesb polygon; -c_circle0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbcircle• + description0ÿÿÿÿÿÿÿÿÿRbooksbtextÔ +postgres_numeric_typesD + c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogbool? +c_bit0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogbitE + +c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint2D + c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint4C +c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint8G + c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericG + c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericC +c_real0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat4O +c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat87 +c_money0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesbmoneyç +postgres_string_typesB +c_char0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogbpcharF + c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarcharP +c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarchar8 +c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbbpchar4 +c_text0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbtext‰ +postgres_datetime_types6 +c_date0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesbdateB +c_time0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalogtimeL + c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestampV +c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestamptzJ + +c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_cataloginterval„ +postgres_network_types5 +c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbcidr5 +c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbinet; + c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesb macaddr= + +c_macaddr80ÿÿÿÿÿÿÿÿÿRpostgres_network_typesb +macaddr8• postgres_array_types5 c_bytea0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbbyteaM c_boolean_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb @@ -86,7 +73,27 @@ pg_catalogint4 pg_catalognumericˆ> c_date_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbdateˆT c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb -pg_catalog timestampˆ" pg_temp"æ² +pg_catalog timestampˆµ +postgres_geometric_types9 +c_point0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpoint7 +c_line0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbline7 +c_lseg0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblseg5 +c_box0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbbox7 +c_path0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpath= + c_polygon0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesb polygon; +c_circle0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbcircleú +postgres_special_types5 +c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbuuid7 +c_enum0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbc_enum5 +c_json0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjsonE +c_json_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjson7 +c_jsonb0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjsonb= + +c_jsonpath0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesb +jsonpath3 +c_xml0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbxmlC +c_xml_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbxml" +c_enumsmallmediumbig" pg_temp"æ² pg_catalog‰ & @@ -10207,7 +10214,14 @@ pg_cataloginformation_schemaviewsb  yes_or_noW pg_cataloginformation_schemaviewsb  yes_or_no] is_trigger_insertable_into0ÿÿÿÿÿÿÿÿÿR' -pg_cataloginformation_schemaviewsb  yes_or_no +pg_cataloginformation_schemaviewsb  yes_or_no"extendedÔ +extendedbiosC + author_name0ÿÿÿÿÿÿÿÿÿRextendedbiosb +pg_catalogvarchar< +name0ÿÿÿÿÿÿÿÿÿRextendedbiosb +pg_catalogvarchar= +bio_type0ÿÿÿÿÿÿÿÿÿRextendedbiosbextendedbio_type", +bio_type Autobiography BiographyMemoir 9SELECT id, name, bio FROM authors WHERE name = $1 LIMIT 1 GetAuthor:one"- id0ÿÿÿÿÿÿÿÿÿR authorsb  bigserialzid", @@ -10298,415 +10312,439 @@ WHERE books.name = $1GetAuthorsByBookName:many"- name0ÿÿÿÿÿÿÿÿÿR authorsbtextzname"( bio0ÿÿÿÿÿÿÿÿÿR authorsbtextzbio" books0ÿÿÿÿÿÿÿÿÿbrbooks*.* -name0ÿÿÿÿÿÿÿÿÿRbooksbtextzname: query.sqlˆ -¬INSERT INTO postgres_types +name0ÿÿÿÿÿÿÿÿÿRbooksbtextzname: query.sqlì +KINSERT INTO extended.bios (author_name, name, bio_type) VALUES ($1, $2, $3)CreateExtendedBio:exec*SO + author_name0ÿÿÿÿÿÿÿÿÿRextendedbiosbpg_catalog.varcharz author_name*EA +name0ÿÿÿÿÿÿÿÿÿRextendedbiosbpg_catalog.varcharzname*JF +bio_type0ÿÿÿÿÿÿÿÿÿRextendedbiosbextended.bio_typezbio_type: query.sqlBextendedbiosª +QSELECT author_name, name, bio_type FROM extended.bios WHERE bio_type = $1 LIMIT 1GetFirstExtendedBioByType:one"P + author_name0ÿÿÿÿÿÿÿÿÿRextendedbiosb +pg_catalogvarcharz author_name"B +name0ÿÿÿÿÿÿÿÿÿRextendedbiosb +pg_catalogvarcharzname"G +bio_type0ÿÿÿÿÿÿÿÿÿRextendedbiosbextendedbio_typezbio_type*JF +bio_type0ÿÿÿÿÿÿÿÿÿRextendedbiosbextended.bio_typezbio_type: query.sqlF +TRUNCATE TABLE extended.biosTruncateExtendedBios:exec: query.sqlü +Ò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_typesGetPostgresFunctions:one"( + max_integer0ÿÿÿÿÿÿÿÿÿ@b +anyarray"( + max_varchar0ÿÿÿÿÿÿÿÿÿ@b +anyarray"* + max_timestamp0ÿÿÿÿÿÿÿÿÿ@b +anyarray: query.sqlà +í +INSERT INTO postgres_numeric_types ( c_boolean, c_bit, c_smallint, c_integer, c_bigint, - c_real, - c_numeric, c_decimal, + c_numeric, + c_real, c_double_precision, - c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, - c_json, - c_json_string_override, - c_jsonb, - c_jsonpath, - c_xml, - c_cidr, - c_inet, - c_macaddr, - c_macaddr8 + c_money ) -VALUES ( - $1, - $2, - $3, - $4, - $5, - $6, - $7, - $8, - $9, - $10, - $11, - $12, - $13, - $14, - $15, - $16, - $17, - $18, - $19, - $20, - $21, - $22::json, - $23::json, - $24::jsonb, - $25::jsonpath, - $26::xml, - $27, - $28, - $29::macaddr, - $30::macaddr8 -)InsertPostgresTypes:exec*TP - c_boolean0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.boolz c_boolean*KG -c_bit0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.bitzc_bit*VR - -c_smallint0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.int2z -c_smallint*TP - c_integer0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.int4z c_integer*RN -c_bigint0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.int8zc_bigint*PL -c_real0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.float4zc_real*WS - c_numeric0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.numericz c_numeric*WS - c_decimal0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.numericz c_decimal*h d -c_double_precision0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.float8zc_double_precision*F -B -c_money0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbmoneyzc_money*C ? -c_date0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbdatezc_date*N J -c_time0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.timezc_time*] Y - c_timestamp0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.timestampz c_timestamp*ok -c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.timestamptzzc_timestamp_with_tz*ZV - -c_interval0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.intervalz -c_interval*PL -c_char0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.bpcharzc_char*WS - c_varchar0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.varcharz c_varchar*kg -c_character_varying0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.varcharzc_character_varying*IE -c_bpchar0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbbpcharzc_bpchar*C? -c_text0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbtextzc_text*C? -c_uuid0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbuuidzc_uuid* -c_json0ÿÿÿÿÿÿÿÿÿbjson*/+ -c_json_string_override0ÿÿÿÿÿÿÿÿÿbjson*! -c_jsonb0ÿÿÿÿÿÿÿÿÿbjsonb*'# - -c_jsonpath0ÿÿÿÿÿÿÿÿÿb -jsonpath* -c_xml0ÿÿÿÿÿÿÿÿÿbxml*C? -c_cidr0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbcidrzc_cidr*C? -c_inet0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbinetzc_inet*%! - c_macaddr0ÿÿÿÿÿÿÿÿÿb macaddr*'# - -c_macaddr80ÿÿÿÿÿÿÿÿÿb -macaddr8: query.sqlBpostgres_types‡ -ÜINSERT INTO postgres_types -( +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)InsertPostgresNumericTypes:exec*ZV + c_boolean0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.boolz c_boolean*QM +c_bit0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.bitzc_bit*\X + +c_smallint0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int2z +c_smallint*ZV + c_integer0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int4z c_integer*XT +c_bigint0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int8zc_bigint*]Y + c_decimal0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.numericz c_decimal*]Y + c_numeric0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.numericz c_numeric*VR +c_real0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.float4zc_real*n j +c_double_precision0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.float8zc_double_precision*L +H +c_money0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbmoneyzc_money2 Numeric types : query.sqlBpostgres_numeric_typesì +—SELECT c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money FROM postgres_numeric_types LIMIT 1GetPostgresNumericTypes:one"O + c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogboolz c_boolean"F +c_bit0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogbitzc_bit"Q + +c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint2z +c_smallint"O + c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint4z c_integer"M +c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint8zc_bigint"R + c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericz c_decimal"R + c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericz c_numeric"K +c_real0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat4zc_real"c +c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat8zc_double_precision"@ +c_money0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesbmoneyzc_money: query.sqlW +%TRUNCATE TABLE postgres_numeric_typesTruncatePostgresNumericTypes:exec: query.sqlê +òSELECT c_boolean, + c_bit, c_smallint, c_integer, c_bigint, - c_real, - c_numeric, c_decimal, + c_numeric, + c_real, c_double_precision, c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, - c_cidr, - c_inet, - c_macaddr -) -VALUES ( - $1, - $2, - $3, - $4, - $5, - $6, - $7, - $8, - $9, - $10, - $11, - $12, - $13, - $14, - $15, - $16, - $17, - $18, - $19, - $20, - $21, - $22, - $23 -)InsertPostgresTypesBatch :copyfrom*RN - c_boolean0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.boolz c_boolean*TP - -c_smallint0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.int2z -c_smallint*RN - c_integer0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.int4z c_integer*PL -c_bigint0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.int8zc_bigint*NJ -c_real0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.float4zc_real*UQ - c_numeric0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.numericz c_numeric*UQ - c_decimal0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.numericz c_decimal*fb -c_double_precision0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.float8zc_double_precision*D @ -c_money0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbmoneyzc_money*A -= -c_date0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbdatezc_date*L H -c_time0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.timezc_time*[ W - c_timestamp0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.timestampz c_timestamp*m i -c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.timestamptzzc_timestamp_with_tz*XT - -c_interval0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.intervalz -c_interval*NJ -c_char0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.bpcharzc_char*UQ - c_varchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.varcharz c_varchar*ie -c_character_varying0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.varcharzc_character_varying*GC -c_bpchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbbpcharzc_bpchar*A= -c_text0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbtextzc_text*A= -c_uuid0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbuuidzc_uuid*A= -c_cidr0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbcidrzc_cidr*A= -c_inet0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbinetzc_inet*JF - c_macaddr0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesb macaddrz c_macaddr: query.sqlBpostgres_types­ -„SELECT + COUNT(*) AS cnt +FROM postgres_numeric_types +GROUP BY c_boolean, c_bit, c_smallint, c_integer, c_bigint, - c_real, - c_numeric, c_decimal, + c_numeric, + c_real, c_double_precision, - c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, - c_json, - c_json_string_override, - c_jsonb, - c_jsonpath, - c_xml, - c_cidr, - c_inet, - c_macaddr, - c_macaddr8::TEXT AS c_macaddr8 -FROM postgres_types -LIMIT 1GetPostgresTypes:one"G - c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogboolz c_boolean"> -c_bit0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbitzc_bit"I - -c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb + c_money +LIMIT 1GetPostgresNumericTypesCnt:one"O + c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogboolz c_boolean"F +c_bit0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogbitzc_bit"Q + +c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb pg_catalogint2z -c_smallint"G - c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint4z c_integer"E -c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint8zc_bigint"C -c_real0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat4zc_real"J - c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumericz c_numeric"J - c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumericz c_decimal"[ -c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat8zc_double_precision"8 -c_money0ÿÿÿÿÿÿÿÿÿRpostgres_typesbmoneyzc_money"5 -c_date0ÿÿÿÿÿÿÿÿÿRpostgres_typesbdatezc_date"A -c_time0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogtimezc_time"P - c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestampz c_timestamp"b -c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestamptzzc_timestamp_with_tz"M - -c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogintervalz -c_interval"C -c_char0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbpcharzc_char"J - c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarcharz c_varchar"^ -c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarcharzc_character_varying"; -c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesbbpcharzc_bpchar"5 -c_text0ÿÿÿÿÿÿÿÿÿRpostgres_typesbtextzc_text"5 -c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_typesbuuidzc_uuid"5 -c_json0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjsonzc_json"U -c_json_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjsonzc_json_string_override"8 -c_jsonb0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjsonbzc_jsonb"A - -c_jsonpath0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -jsonpathz -c_jsonpath"2 -c_xml0ÿÿÿÿÿÿÿÿÿRpostgres_typesbxmlzc_xml"5 -c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_typesbcidrzc_cidr"5 -c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_typesbinetzc_inet"> - c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_typesb macaddrz c_macaddr"! - -c_macaddr80ÿÿÿÿÿÿÿÿÿbtext: query.sql¤ -úSELECT - c_smallint, +c_smallint"O + c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint4z c_integer"M +c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint8zc_bigint"R + c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericz c_decimal"R + c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericz c_numeric"K +c_real0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat4zc_real"c +c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat8zc_double_precision"@ +c_money0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesbmoneyzc_money" +cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sql× +ìINSERT INTO postgres_numeric_types +( c_boolean, + c_bit, + c_smallint, c_integer, c_bigint, - c_real, - c_numeric, c_decimal, + c_numeric, + c_real, c_double_precision, - c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, + c_money +) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)InsertPostgresNumericTypesBatch :copyfrom*ZV + c_boolean0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.boolz c_boolean*QM +c_bit0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.bitzc_bit*\X + +c_smallint0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int2z +c_smallint*ZV + c_integer0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int4z c_integer*XT +c_bigint0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int8zc_bigint*]Y + c_decimal0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.numericz c_decimal*]Y + c_numeric0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.numericz c_numeric*VR +c_real0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.float4zc_real*n j +c_double_precision0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.float8zc_double_precision*L +H +c_money0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbmoneyzc_money: query.sqlBpostgres_numeric_types© + +INSERT INTO postgres_string_types +( + c_char, + c_varchar, + c_character_varying, + c_bpchar, + c_text +) +VALUES ($1, $2, $3, $4, $5)InsertPostgresStringTypes:exec*UQ +c_char0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.bpcharzc_char*\X + c_varchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.varcharz c_varchar*pl +c_character_varying0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.varcharzc_character_varying*NJ +c_bpchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbbpcharzc_bpchar*HD +c_text0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbtextzc_text2 String types : query.sqlBpostgres_string_types¢ +INSERT INTO postgres_string_types +( + c_char, + c_varchar, + c_character_varying, + c_bpchar, + c_text +) VALUES ($1, $2, $3, $4, $5)InsertPostgresStringTypesBatch :copyfrom*UQ +c_char0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.bpcharzc_char*\X + c_varchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.varcharz c_varchar*pl +c_character_varying0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.varcharzc_character_varying*NJ +c_bpchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbbpcharzc_bpchar*HD +c_text0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbtextzc_text: query.sqlBpostgres_string_types• +bSELECT c_char, c_varchar, c_character_varying, c_bpchar, c_text FROM postgres_string_types LIMIT 1GetPostgresStringTypes:one"J +c_char0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogbpcharzc_char"Q + c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarcharz c_varchar"e +c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarcharzc_character_varying"B +c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbbpcharzc_bpchar"< +c_text0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbtextzc_text: query.sqlU +$TRUNCATE TABLE postgres_string_typesTruncatePostgresStringTypes:exec: query.sql¸ +áSELECT c_char, c_varchar, c_character_varying, c_bpchar, c_text, - c_uuid, - c_cidr, - c_inet, - c_macaddr, COUNT(*) AS cnt -FROM postgres_types +FROM postgres_string_types GROUP BY - c_smallint, - c_boolean, - c_integer, - c_bigint, - c_real, - c_numeric, - c_decimal, - c_double_precision, - c_money, + c_char, + c_varchar, + c_character_varying, + c_bpchar, + c_text +LIMIT 1GetPostgresStringTypesCnt:one"J +c_char0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogbpcharzc_char"Q + c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarcharz c_varchar"e +c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarcharzc_character_varying"B +c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbbpcharzc_bpchar"< +c_text0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbtextzc_text" +cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sqlì +ØWITH txt_query AS ( + SELECT + c_text, + to_tsquery('english', $1) AS query, + to_tsvector('english', c_text) AS tsv + FROM postgres_string_types + WHERE c_text @@ to_tsquery('english', $1) +) + +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 GetPostgresStringTypesTextSearch:one"0 +c_text0ÿÿÿÿÿÿÿÿÿR  txt_querybtextzc_text"3 +query0ÿÿÿÿÿÿÿÿÿR  txt_queryb tsqueryzquery"0 +tsv0ÿÿÿÿÿÿÿÿÿR  txt_queryb +tsvectorztsv" +rnk0ÿÿÿÿÿÿÿÿÿ@breal*%! + +to_tsquery0ÿÿÿÿÿÿÿÿÿbtext: query.sqlØ +• +INSERT INTO postgres_datetime_types +( + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval +) VALUES ($1, $2, $3, $4, $5)InsertPostgresDateTimeTypes:exec*JF +c_date0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbdatezc_date*UQ +c_time0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timezc_time*d` + c_timestamp0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timestampz c_timestamp*vr +c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timestamptzzc_timestamp_with_tz*a] + +c_interval0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.intervalz +c_interval2 DateTime types : query.sqlBpostgres_datetime_typesÁ +hSELECT c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval FROM postgres_datetime_types LIMIT 1GetPostgresDateTimeTypes:one"> +c_date0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesbdatezc_date"J +c_time0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalogtimezc_time"Y + c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestampz c_timestamp"k +c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestamptzzc_timestamp_with_tz"V + +c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalogintervalz +c_interval: query.sqlY +&TRUNCATE TABLE postgres_datetime_typesTruncatePostgresDateTimeTypes:exec: query.sqlè +ëSELECT c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, + COUNT(*) AS cnt +FROM postgres_datetime_types +GROUP BY + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval +LIMIT 1GetPostgresDateTimeTypesCnt:one"> +c_date0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesbdatezc_date"J +c_time0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalogtimezc_time"Y + c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestampz c_timestamp"k +c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestamptzzc_timestamp_with_tz"V + +c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalogintervalz +c_interval" +cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sqlÎ +”INSERT INTO postgres_datetime_types +( + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval +) VALUES ($1, $2, $3, $4, $5) InsertPostgresDateTimeTypesBatch :copyfrom*JF +c_date0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbdatezc_date*UQ +c_time0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timezc_time*d` + c_timestamp0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timestampz c_timestamp*vr +c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timestamptzzc_timestamp_with_tz*a] + +c_interval0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.intervalz +c_interval: query.sqlBpostgres_datetime_types‰ +” +INSERT INTO postgres_network_types +( c_cidr, c_inet, - c_macaddr -LIMIT 1GetPostgresTypesCnt:one"I + c_macaddr, + c_macaddr8 +) VALUES ( + $1, + $2, + $3, + $4::macaddr8 +)InsertPostgresNetworkTypes:exec*KG +c_cidr0ÿÿÿÿÿÿÿÿÿ8R publicpostgres_network_typesbcidrzc_cidr*KG +c_inet0ÿÿÿÿÿÿÿÿÿ8R publicpostgres_network_typesbinetzc_inet*TP + c_macaddr0ÿÿÿÿÿÿÿÿÿ8R publicpostgres_network_typesb macaddrz c_macaddr*'# -c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint2z -c_smallint"G - c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogboolz c_boolean"G - c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint4z c_integer"E -c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint8zc_bigint"C -c_real0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat4zc_real"J - c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumericz c_numeric"J - c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumericz c_decimal"[ -c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat8zc_double_precision"8 -c_money0ÿÿÿÿÿÿÿÿÿRpostgres_typesbmoneyzc_money"5 -c_date0ÿÿÿÿÿÿÿÿÿRpostgres_typesbdatezc_date"A -c_time0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogtimezc_time"P - c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestampz c_timestamp"b -c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestamptzzc_timestamp_with_tz"M - -c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogintervalz -c_interval"C -c_char0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbpcharzc_char"J - c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarcharz c_varchar"^ -c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarcharzc_character_varying"; -c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesbbpcharzc_bpchar"5 -c_text0ÿÿÿÿÿÿÿÿÿRpostgres_typesbtextzc_text"5 -c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_typesbuuidzc_uuid"5 -c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_typesbcidrzc_cidr"5 -c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_typesbinetzc_inet"> - c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_typesb macaddrz c_macaddr" -cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sql° -†SELECT - MAX(c_integer) AS max_integer, - MAX(c_varchar) AS max_varchar, - MAX(c_timestamp) AS max_timestamp -FROM postgres_typesGetPostgresFunctions:one"( - max_integer0ÿÿÿÿÿÿÿÿÿ@b -anyarray"( - max_varchar0ÿÿÿÿÿÿÿÿÿ@b -anyarray"* - max_timestamp0ÿÿÿÿÿÿÿÿÿ@b -anyarray: query.sqlÿ -ŒINSERT INTO postgres_geometric_types ( - c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle +c_macaddr80ÿÿÿÿÿÿÿÿÿb +macaddr82 Network types : query.sqlBpostgres_network_types‰ +tSELECT + c_cidr, + c_inet, + c_macaddr, + c_macaddr8::TEXT AS c_macaddr8 +FROM postgres_network_types +LIMIT 1GetPostgresNetworkTypes:one"= +c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbcidrzc_cidr"= +c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbinetzc_inet"F + c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesb macaddrz c_macaddr"! + +c_macaddr80ÿÿÿÿÿÿÿÿÿbtext: query.sqlW +%TRUNCATE TABLE postgres_network_typesTruncatePostgresNetworkTypes:exec: query.sqlª +”SELECT + c_cidr, + c_inet, + c_macaddr, + COUNT(*) AS cnt +FROM postgres_network_types +GROUP BY + c_cidr, + c_inet, + c_macaddr +LIMIT 1GetPostgresNetworkTypesCnt:one"= +c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbcidrzc_cidr"= +c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbinetzc_inet"F + c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesb macaddrz c_macaddr" +cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sql +`INSERT INTO postgres_network_types +( + c_cidr, + c_inet, + c_macaddr +) VALUES ($1, $2, $3)InsertPostgresNetworkTypesBatch :copyfrom*IE +c_cidr0ÿÿÿÿÿÿÿÿÿR publicpostgres_network_typesbcidrzc_cidr*IE +c_inet0ÿÿÿÿÿÿÿÿÿR publicpostgres_network_typesbinetzc_inet*RN + c_macaddr0ÿÿÿÿÿÿÿÿÿR publicpostgres_network_typesb macaddrz c_macaddr: query.sqlBpostgres_network_typesÜ +¤ +INSERT INTO postgres_special_types +( + c_json, + c_json_string_override, + c_jsonb, + c_jsonpath, + c_xml, + c_xml_string_override, + c_uuid, + c_enum ) -VALUES ($1, $2, $3, $4, $5, $6, $7)InsertPostgresGeoTypes:exec*NJ -c_point0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpointzc_point*KG -c_line0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblinezc_line*KG -c_lseg0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblsegzc_lseg*HD -c_box0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbboxzc_box*KG -c_path0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpathzc_path*TP - c_polygon0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesb polygonz c_polygon*QM -c_circle0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbcirclezc_circle: query.sqlBpostgres_geometric_typesˆ -ŒINSERT INTO postgres_geometric_types ( - c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle +VALUES ( + $1::json, + $2::json, + $3::jsonb, + $4::jsonpath, + $5::xml, + $6::xml, + $7, + $8::c_enum +)InsertPostgresSpecialTypes:exec* +c_json0ÿÿÿÿÿÿÿÿÿbjson*/+ +c_json_string_override0ÿÿÿÿÿÿÿÿÿbjson*! +c_jsonb0ÿÿÿÿÿÿÿÿÿbjsonb*'# + +c_jsonpath0ÿÿÿÿÿÿÿÿÿb +jsonpath* +c_xml0ÿÿÿÿÿÿÿÿÿbxml*-) +c_xml_string_override0ÿÿÿÿÿÿÿÿÿbxml*KG +c_uuid0ÿÿÿÿÿÿÿÿÿ8R publicpostgres_special_typesbuuidzc_uuid*! +c_enum0ÿÿÿÿÿÿÿÿÿbc_enum2 Special types : query.sqlBpostgres_special_types +­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 1GetPostgresSpecialTypes:one"= +c_json0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjsonzc_json"] +c_json_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjsonzc_json_string_override"@ +c_jsonb0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjsonbzc_jsonb"I + +c_jsonpath0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesb +jsonpathz +c_jsonpath": +c_xml0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbxmlzc_xml"Z +c_xml_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbxmlzc_xml_string_override"= +c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbuuidzc_uuid"? +c_enum0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbc_enumzc_enum: query.sqlW +%TRUNCATE TABLE postgres_special_typesTruncatePostgresSpecialTypes:exec: query.sqlá +CINSERT INTO postgres_special_types +( + c_uuid ) -VALUES ($1, $2, $3, $4, $5, $6, $7)InsertPostgresGeoTypesBatch :copyfrom*NJ -c_point0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpointzc_point*KG -c_line0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblinezc_line*KG -c_lseg0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblsegzc_lseg*HD -c_box0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbboxzc_box*KG -c_path0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpathzc_path*TP - c_polygon0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesb polygonz c_polygon*QM -c_circle0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbcirclezc_circle: query.sqlBpostgres_geometric_typesæ -hSELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgres_geometric_types LIMIT 1GetPostgresGeoTypes:one"B -c_point0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpointzc_point"? -c_line0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblinezc_line"? -c_lseg0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblsegzc_lseg"< -c_box0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbboxzc_box"? -c_path0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpathzc_path"H - c_polygon0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesb polygonz c_polygon"E -c_circle0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbcirclezc_circle: query.sqlH -TRUNCATE TABLE postgres_typesTruncatePostgresTypes:exec: query.sqlU -'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sqlÍ -ÎINSERT INTO postgres_array_types +VALUES ( + $1 +)InsertPostgresSpecialTypesBatch :copyfrom*IE +c_uuid0ÿÿÿÿÿÿÿÿÿR publicpostgres_special_typesbuuidzc_uuid: query.sqlBpostgres_special_typesì +^SELECT + c_uuid, + COUNT(*) AS cnt +FROM postgres_special_types +GROUP BY + c_uuid +LIMIT 1GetPostgresSpecialTypesCnt:one"= +c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbuuidzc_uuid" +cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sqlÝ +Ï +INSERT INTO postgres_array_types ( c_bytea, c_boolean_array, @@ -10723,7 +10761,7 @@ VALUES ($1, $2, $3, $4, $5, $6, $7)InsertPostgresArrayTypes:exec*JF c_integer_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.int4zc_integer_arrayˆ*lh c_decimal_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.numericzc_decimal_arrayˆ*XT c_date_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbdatez c_date_arrayˆ*rn -c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.timestampzc_timestamp_arrayˆ: query.sqlBpostgres_array_types¥ +c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.timestampzc_timestamp_arrayˆ2 Array types : query.sqlBpostgres_array_types¥ ’SELECT c_bytea, c_boolean_array, c_text_array, c_integer_array, c_decimal_array, c_date_array, c_timestamp_array FROM postgres_array_types LIMIT 1GetPostgresArrayTypes:one"> c_bytea0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbbyteazc_bytea"^ c_boolean_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb @@ -10735,16 +10773,99 @@ pg_catalogint4zc_integer_array pg_catalognumericzc_decimal_arrayˆ"L c_date_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbdatez c_date_arrayˆ"g c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb -pg_catalog timestampzc_timestamp_arrayˆ: query.sqlÑ -6INSERT INTO postgres_array_types (c_bytea) VALUES ($1)InsertPostgresArrayTypesBatch :copyfrom*JF -c_bytea0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbbyteazc_bytea: query.sqlBpostgres_array_typesë -^SELECT +pg_catalog timestampzc_timestamp_arrayˆ: query.sql +ÓINSERT INTO postgres_array_types ( + c_bytea, + c_boolean_array, + c_text_array, + c_integer_array, + c_decimal_array, + c_timestamp_array +) +VALUES ( + $1, + $2, + $3, + $4, + $5, + $6 +)InsertPostgresArrayTypesBatch :copyfrom*JF +c_bytea0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbbyteazc_bytea*ie +c_boolean_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.boolzc_boolean_arrayˆ*XT + c_text_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbtextz c_text_arrayˆ*ie +c_integer_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.int4zc_integer_arrayˆ*lh +c_decimal_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.numericzc_decimal_arrayˆ*rn +c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.timestampzc_timestamp_arrayˆ: query.sqlBpostgres_array_types– +®SELECT c_bytea, + c_boolean_array, + c_text_array, + c_integer_array, + c_decimal_array, + c_timestamp_array, COUNT(*) AS cnt FROM postgres_array_types GROUP BY - c_bytea + c_bytea, + c_boolean_array, + c_text_array, + c_integer_array, + c_decimal_array, + c_timestamp_array LIMIT 1GetPostgresArrayTypesCnt:one"> -c_bytea0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbbyteazc_bytea" +c_bytea0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbbyteazc_bytea"^ +c_boolean_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb +pg_catalogboolzc_boolean_arrayˆ"L + c_text_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbtextz c_text_arrayˆ"^ +c_integer_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb +pg_catalogint4zc_integer_arrayˆ"a +c_decimal_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb +pg_catalognumericzc_decimal_arrayˆ"g +c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb +pg_catalog timestampzc_timestamp_arrayˆ" cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sqlS -#TRUNCATE TABLE postgres_array_typesTruncatePostgresArrayTypes:exec: query.sql"v1.27.0*{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"netstandard2.0","namespaceName":"NpgsqlDapperLegacyExampleGen","useDapper":true,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}}],"debugRequest":false} \ No newline at end of file +#TRUNCATE TABLE postgres_array_typesTruncatePostgresArrayTypes:exec: query.sql± +« +INSERT INTO postgres_geometric_types ( + c_point, + c_line, + c_lseg, + c_box, + c_path, + c_polygon, + c_circle +) +VALUES ($1, $2, $3, $4, $5, $6, $7)InsertPostgresGeoTypes:exec*NJ +c_point0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpointzc_point*KG +c_line0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblinezc_line*KG +c_lseg0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblsegzc_lseg*HD +c_box0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbboxzc_box*KG +c_path0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpathzc_path*TP + c_polygon0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesb polygonz c_polygon*QM +c_circle0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbcirclezc_circle2 Geometric types : query.sqlBpostgres_geometric_types¦ +ªINSERT INTO postgres_geometric_types ( + c_point, + c_line, + c_lseg, + c_box, + c_path, + c_polygon, + c_circle +) +VALUES ($1, $2, $3, $4, $5, $6, $7)InsertPostgresGeoTypesBatch :copyfrom*NJ +c_point0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpointzc_point*KG +c_line0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblinezc_line*KG +c_lseg0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblsegzc_lseg*HD +c_box0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbboxzc_box*KG +c_path0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpathzc_path*TP + c_polygon0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesb polygonz c_polygon*QM +c_circle0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbcirclezc_circle: query.sqlBpostgres_geometric_typesæ +hSELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgres_geometric_types LIMIT 1GetPostgresGeoTypes:one"B +c_point0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpointzc_point"? +c_line0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblinezc_line"? +c_lseg0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblsegzc_lseg"< +c_box0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbboxzc_box"? +c_path0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpathzc_path"H + c_polygon0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesb polygonz c_polygon"E +c_circle0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbcirclezc_circle: query.sqlU +'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sql"v1.27.0*â{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"netstandard2.0","namespaceName":"NpgsqlDapperLegacyExampleGen","useDapper":true,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_xml_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}}],"debugRequest":false} \ No newline at end of file diff --git a/examples/NpgsqlExample/Models.cs b/examples/NpgsqlExample/Models.cs index ead0cb95..a30721ec 100644 --- a/examples/NpgsqlExample/Models.cs +++ b/examples/NpgsqlExample/Models.cs @@ -1,6 +1,7 @@ // auto-generated by sqlc - do not edit using NpgsqlTypes; using System; +using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.NetworkInformation; @@ -10,6 +11,90 @@ namespace NpgsqlExampleGen; public readonly record struct Author(long Id, string Name, string? Bio); public readonly record struct Book(Guid Id, string Name, long AuthorId, string? Description); -public readonly record struct PostgresType(bool? CBoolean, byte[]? CBit, short? CSmallint, int? CInteger, long? CBigint, decimal? CDecimal, decimal? CNumeric, float? CReal, double? CDoublePrecision, decimal? CMoney, DateTime? CDate, TimeSpan? CTime, DateTime? CTimestamp, DateTime? CTimestampWithTz, TimeSpan? CInterval, string? CChar, string? CVarchar, string? CCharacterVarying, string? CBpchar, string? CText, JsonElement? CJson, JsonElement? CJsonStringOverride, JsonElement? CJsonb, string? CJsonpath, XmlDocument? CXml, NpgsqlCidr? CCidr, IPAddress? CInet, PhysicalAddress? CMacaddr, string? CMacaddr8, Guid? CUuid); +public readonly record struct PostgresNumericType(bool? CBoolean, byte[]? CBit, short? CSmallint, int? CInteger, long? CBigint, decimal? CDecimal, decimal? CNumeric, float? CReal, double? CDoublePrecision, decimal? CMoney); +public readonly record struct PostgresStringType(string? CChar, string? CVarchar, string? CCharacterVarying, string? CBpchar, string? CText); +public readonly record struct PostgresDatetimeType(DateTime? CDate, TimeSpan? CTime, DateTime? CTimestamp, DateTime? CTimestampWithTz, TimeSpan? CInterval); +public readonly record struct PostgresNetworkType(NpgsqlCidr? CCidr, IPAddress? CInet, PhysicalAddress? CMacaddr, string? CMacaddr8); +public readonly record struct PostgresArrayType(byte[]? CBytea, bool[]? CBooleanArray, string[]? CTextArray, int[]? CIntegerArray, decimal[]? CDecimalArray, DateTime[]? CDateArray, DateTime[]? CTimestampArray); public readonly record struct PostgresGeometricType(NpgsqlPoint? CPoint, NpgsqlLine? CLine, NpgsqlLSeg? CLseg, NpgsqlBox? CBox, NpgsqlPath? CPath, NpgsqlPolygon? CPolygon, NpgsqlCircle? CCircle); -public readonly record struct PostgresArrayType(byte[]? CBytea, bool[]? CBooleanArray, string[]? CTextArray, int[]? CIntegerArray, decimal[]? CDecimalArray, DateTime[]? CDateArray, DateTime[]? CTimestampArray); \ No newline at end of file +public readonly record struct PostgresSpecialType(Guid? CUuid, CEnum? CEnum, JsonElement? CJson, JsonElement? CJsonStringOverride, JsonElement? CJsonb, string? CJsonpath, XmlDocument? CXml, XmlDocument? CXmlStringOverride); +public readonly record struct ExtendedBio(string AuthorName, string Name, ExtendedBioType? BioType); +public enum CEnum +{ + Invalid = 0, // reserved for invalid enum value + Small = 1, + Medium = 2, + Big = 3 +} + +public static class CEnumExtensions +{ + private static readonly Dictionary StringToEnum = new Dictionary() + { + [string.Empty] = CEnum.Invalid, + ["small"] = CEnum.Small, + ["medium"] = CEnum.Medium, + ["big"] = CEnum.Big + }; + private static readonly Dictionary EnumToString = new Dictionary() + { + [CEnum.Invalid] = string.Empty, + [CEnum.Small] = "small", + [CEnum.Medium] = "medium", + [CEnum.Big] = "big" + }; + public static CEnum ToCEnum(this string me) + { + return StringToEnum[me]; + } + + public static string Stringify(this CEnum me) + { + return EnumToString[me]; + } + + public static HashSet ToCEnumSet(this string me) + { + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); + } +} + +public enum ExtendedBioType +{ + Invalid = 0, // reserved for invalid enum value + Autobiography = 1, + Biography = 2, + Memoir = 3 +} + +public static class ExtendedBioTypeExtensions +{ + private static readonly Dictionary StringToEnum = new Dictionary() + { + [string.Empty] = ExtendedBioType.Invalid, + ["Autobiography"] = ExtendedBioType.Autobiography, + ["Biography"] = ExtendedBioType.Biography, + ["Memoir"] = ExtendedBioType.Memoir + }; + private static readonly Dictionary EnumToString = new Dictionary() + { + [ExtendedBioType.Invalid] = string.Empty, + [ExtendedBioType.Autobiography] = "Autobiography", + [ExtendedBioType.Biography] = "Biography", + [ExtendedBioType.Memoir] = "Memoir" + }; + public static ExtendedBioType ToExtendedBioType(this string me) + { + return StringToEnum[me]; + } + + public static string Stringify(this ExtendedBioType me) + { + return EnumToString[me]; + } + + public static HashSet ToExtendedBioTypeSet(this string me) + { + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); + } +} \ No newline at end of file diff --git a/examples/NpgsqlExample/QuerySql.cs b/examples/NpgsqlExample/QuerySql.cs index 8034e3f0..2e689fbf 100644 --- a/examples/NpgsqlExample/QuerySql.cs +++ b/examples/NpgsqlExample/QuerySql.cs @@ -40,14 +40,14 @@ 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) { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(GetAuthorSql)) { @@ -71,10 +71,7 @@ public static QuerySql WithTransaction(NpgsqlTransaction transaction) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetAuthorSql; @@ -97,14 +94,14 @@ 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) { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(ListAuthorsSql)) { @@ -146,7 +143,7 @@ public async Task> ListAuthors(ListAuthorsArgs args) { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(CreateAuthorSql)) { @@ -172,10 +169,7 @@ public async Task> ListAuthors(ListAuthorsArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = CreateAuthorSql; @@ -207,7 +201,7 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(CreateAuthorReturnIdSql)) { @@ -220,10 +214,7 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = CreateAuthorReturnIdSql; @@ -235,14 +226,14 @@ 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) { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(GetAuthorByIdSql)) { @@ -266,10 +257,7 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetAuthorByIdSql; @@ -292,14 +280,14 @@ 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) { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(GetAuthorByNamePatternSql)) { @@ -332,13 +320,13 @@ 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) { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(DeleteAuthorSql)) { @@ -351,10 +339,7 @@ public async Task DeleteAuthor(DeleteAuthorArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = DeleteAuthorSql; @@ -369,7 +354,7 @@ public async Task TruncateAuthors() { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(TruncateAuthorsSql)) { @@ -381,10 +366,7 @@ public async Task TruncateAuthors() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = TruncateAuthorsSql; @@ -393,13 +375,13 @@ 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) { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(UpdateAuthorsSql)) { @@ -410,10 +392,7 @@ public async Task UpdateAuthors(UpdateAuthorsArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = UpdateAuthorsSql; @@ -423,14 +402,14 @@ 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) { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(GetAuthorsByIdsSql)) { @@ -463,14 +442,14 @@ 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) { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(GetAuthorsByIdsAndNamesSql)) { @@ -512,7 +491,7 @@ public async Task CreateBook(CreateBookArgs args) { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(CreateBookSql)) { @@ -525,10 +504,7 @@ public async Task CreateBook(CreateBookArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = CreateBookSql; @@ -540,13 +516,13 @@ 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() { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(ListAllAuthorsBooksSql)) { @@ -577,13 +553,13 @@ 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() { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(GetDuplicateAuthorsSql)) { @@ -614,14 +590,14 @@ 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) { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(GetAuthorsByBookNameSql)) { @@ -654,46 +630,19 @@ public async Task> GetAuthorsByBookName(GetAuthors } } - private const string InsertPostgresTypesSql = "INSERT INTO postgres_types(c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_real, c_numeric, c_decimal, c_double_precision, c_money, c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_char, c_varchar, c_character_varying, c_bpchar, c_text, c_uuid, c_json, c_json_string_override, c_jsonb, c_jsonpath, c_xml, c_cidr, c_inet, c_macaddr, c_macaddr8) VALUES ( @c_boolean, @c_bit, @c_smallint, @c_integer, @c_bigint, @c_real, @c_numeric, @c_decimal, @c_double_precision, @c_money, @c_date, @c_time, @c_timestamp, @c_timestamp_with_tz, @c_interval, @c_char, @c_varchar, @c_character_varying, @c_bpchar, @c_text, @c_uuid, @c_json :: json, @c_json_string_override :: json, @c_jsonb :: jsonb, @c_jsonpath :: jsonpath, @c_xml :: xml, @c_cidr, @c_inet, @c_macaddr :: macaddr, @c_macaddr8 :: macaddr8 ) "; - public readonly record struct InsertPostgresTypesArgs(bool? CBoolean, byte[]? CBit, short? CSmallint, int? CInteger, long? CBigint, float? CReal, decimal? CNumeric, decimal? CDecimal, double? CDoublePrecision, decimal? CMoney, DateTime? CDate, TimeSpan? CTime, DateTime? CTimestamp, DateTime? CTimestampWithTz, TimeSpan? CInterval, string? CChar, string? CVarchar, string? CCharacterVarying, string? CBpchar, string? CText, Guid? CUuid, JsonElement? CJson, string? CJsonStringOverride, JsonElement? CJsonb, string? CJsonpath, XmlDocument? CXml, NpgsqlCidr? CCidr, IPAddress? CInet, PhysicalAddress? CMacaddr, string? CMacaddr8); - public async Task InsertPostgresTypes(InsertPostgresTypesArgs args) + private const string CreateExtendedBioSql = "INSERT INTO extended.bios (author_name, name, bio_type) VALUES (@author_name, @name, @bio_type)"; + public readonly record struct CreateExtendedBioArgs(string AuthorName, string Name, ExtendedBioType? BioType); + public async Task CreateExtendedBio(CreateExtendedBioArgs args) { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { - using (var command = connection.CreateCommand(InsertPostgresTypesSql)) + using (var command = connection.CreateCommand(CreateExtendedBioSql)) { - command.Parameters.AddWithValue("@c_boolean", args.CBoolean ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_bit", args.CBit ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_smallint", args.CSmallint ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_integer", args.CInteger ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_bigint", args.CBigint ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_real", args.CReal ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_numeric", args.CNumeric ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_decimal", args.CDecimal ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_double_precision", args.CDoublePrecision ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_money", args.CMoney ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_date", args.CDate ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_time", args.CTime ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_timestamp", args.CTimestamp ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_timestamp_with_tz", args.CTimestampWithTz ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_interval", args.CInterval ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_char", args.CChar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_varchar", args.CVarchar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_character_varying", args.CCharacterVarying ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_bpchar", args.CBpchar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_text", args.CText ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_uuid", args.CUuid ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_json", args.CJson.HasValue ? args.CJson.Value.GetRawText() : (object)DBNull.Value); - command.Parameters.AddWithValue("@c_json_string_override", args.CJsonStringOverride ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_jsonb", args.CJsonb.HasValue ? args.CJsonb.Value.GetRawText() : (object)DBNull.Value); - command.Parameters.AddWithValue("@c_jsonpath", args.CJsonpath ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_xml", args.CXml != null ? args.CXml.OuterXml : (object)DBNull.Value); - command.Parameters.AddWithValue("@c_cidr", args.CCidr ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_inet", args.CInet ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_macaddr", args.CMacaddr ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_macaddr8", args.CMacaddr8 ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@author_name", args.AuthorName); + command.Parameters.AddWithValue("@name", args.Name); + command.Parameters.AddWithValue("@bio_type", args.BioType != null ? args.BioType.Value.Stringify() : (object)DBNull.Value); await command.ExecuteNonQueryAsync(); } } @@ -702,143 +651,39 @@ public async Task InsertPostgresTypes(InsertPostgresTypesArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = InsertPostgresTypesSql; + command.CommandText = CreateExtendedBioSql; command.Transaction = this.Transaction; - command.Parameters.AddWithValue("@c_boolean", args.CBoolean ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_bit", args.CBit ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_smallint", args.CSmallint ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_integer", args.CInteger ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_bigint", args.CBigint ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_real", args.CReal ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_numeric", args.CNumeric ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_decimal", args.CDecimal ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_double_precision", args.CDoublePrecision ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_money", args.CMoney ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_date", args.CDate ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_time", args.CTime ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_timestamp", args.CTimestamp ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_timestamp_with_tz", args.CTimestampWithTz ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_interval", args.CInterval ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_char", args.CChar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_varchar", args.CVarchar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_character_varying", args.CCharacterVarying ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_bpchar", args.CBpchar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_text", args.CText ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_uuid", args.CUuid ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_json", args.CJson.HasValue ? args.CJson.Value.GetRawText() : (object)DBNull.Value); - command.Parameters.AddWithValue("@c_json_string_override", args.CJsonStringOverride ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_jsonb", args.CJsonb.HasValue ? args.CJsonb.Value.GetRawText() : (object)DBNull.Value); - command.Parameters.AddWithValue("@c_jsonpath", args.CJsonpath ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_xml", args.CXml != null ? args.CXml.OuterXml : (object)DBNull.Value); - command.Parameters.AddWithValue("@c_cidr", args.CCidr ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_inet", args.CInet ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_macaddr", args.CMacaddr ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_macaddr8", args.CMacaddr8 ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@author_name", args.AuthorName); + command.Parameters.AddWithValue("@name", args.Name); + command.Parameters.AddWithValue("@bio_type", args.BioType != null ? args.BioType.Value.Stringify() : (object)DBNull.Value); await command.ExecuteNonQueryAsync(); } } - private const string InsertPostgresTypesBatchSql = "COPY postgres_types (c_boolean, c_smallint, c_integer, c_bigint, c_real, c_numeric, c_decimal, c_double_precision, c_money, c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_char, c_varchar, c_character_varying, c_bpchar, c_text, c_uuid, c_cidr, c_inet, c_macaddr) FROM STDIN (FORMAT BINARY)"; - public readonly record struct InsertPostgresTypesBatchArgs(bool? CBoolean, short? CSmallint, int? CInteger, long? CBigint, float? CReal, decimal? CNumeric, decimal? CDecimal, double? CDoublePrecision, decimal? CMoney, DateTime? CDate, TimeSpan? CTime, DateTime? CTimestamp, DateTime? CTimestampWithTz, TimeSpan? CInterval, string? CChar, string? CVarchar, string? CCharacterVarying, string? CBpchar, string? CText, Guid? CUuid, NpgsqlCidr? CCidr, IPAddress? CInet, PhysicalAddress? CMacaddr); - public async Task InsertPostgresTypesBatch(List args) - { - using (var connection = new NpgsqlConnection(ConnectionString)) - { - await connection.OpenAsync(); - using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresTypesBatchSql)) - { - foreach (var row in args) - { - await writer.StartRowAsync(); - await writer.WriteAsync(row.CBoolean ?? (object)DBNull.Value); - await writer.WriteAsync(row.CSmallint ?? (object)DBNull.Value); - await writer.WriteAsync(row.CInteger ?? (object)DBNull.Value); - await writer.WriteAsync(row.CBigint ?? (object)DBNull.Value); - await writer.WriteAsync(row.CReal ?? (object)DBNull.Value); - await writer.WriteAsync(row.CNumeric ?? (object)DBNull.Value); - await writer.WriteAsync(row.CDecimal ?? (object)DBNull.Value); - await writer.WriteAsync(row.CDoublePrecision ?? (object)DBNull.Value); - await writer.WriteAsync(row.CMoney ?? (object)DBNull.Value, NpgsqlDbType.Money); - await writer.WriteAsync(row.CDate ?? (object)DBNull.Value, NpgsqlDbType.Date); - await writer.WriteAsync(row.CTime ?? (object)DBNull.Value, NpgsqlDbType.Time); - await writer.WriteAsync(row.CTimestamp ?? (object)DBNull.Value); - await writer.WriteAsync(row.CTimestampWithTz ?? (object)DBNull.Value); - await writer.WriteAsync(row.CInterval ?? (object)DBNull.Value, NpgsqlDbType.Interval); - await writer.WriteAsync(row.CChar ?? (object)DBNull.Value); - await writer.WriteAsync(row.CVarchar ?? (object)DBNull.Value); - await writer.WriteAsync(row.CCharacterVarying ?? (object)DBNull.Value); - await writer.WriteAsync(row.CBpchar ?? (object)DBNull.Value); - await writer.WriteAsync(row.CText ?? (object)DBNull.Value); - await writer.WriteAsync(row.CUuid ?? (object)DBNull.Value); - await writer.WriteAsync(row.CCidr ?? (object)DBNull.Value); - await writer.WriteAsync(row.CInet ?? (object)DBNull.Value); - await writer.WriteAsync(row.CMacaddr ?? (object)DBNull.Value); - } - - await writer.CompleteAsync(); - } - - await connection.CloseAsync(); - } - } - - private const string GetPostgresTypesSql = "SELECT c_boolean , c_bit, c_smallint, c_integer, c_bigint, c_real, c_numeric, c_decimal, c_double_precision, c_money, c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_char, c_varchar, c_character_varying, c_bpchar, c_text, c_uuid, c_json, c_json_string_override, c_jsonb, c_jsonpath, c_xml, c_cidr, c_inet, c_macaddr, c_macaddr8 :: TEXT AS c_macaddr8 FROM postgres_types LIMIT 1 "; - public readonly record struct GetPostgresTypesRow(bool? CBoolean, byte[]? CBit, short? CSmallint, int? CInteger, long? CBigint, float? CReal, decimal? CNumeric, decimal? CDecimal, double? CDoublePrecision, decimal? CMoney, DateTime? CDate, TimeSpan? CTime, DateTime? CTimestamp, DateTime? CTimestampWithTz, TimeSpan? CInterval, string? CChar, string? CVarchar, string? CCharacterVarying, string? CBpchar, string? CText, Guid? CUuid, JsonElement? CJson, string? CJsonStringOverride, JsonElement? CJsonb, string? CJsonpath, XmlDocument? CXml, NpgsqlCidr? CCidr, IPAddress? CInet, PhysicalAddress? CMacaddr, string? CMacaddr8); - public async Task GetPostgresTypes() + private const string GetFirstExtendedBioByTypeSql = "SELECT author_name, name, bio_type FROM extended.bios WHERE bio_type = @bio_type LIMIT 1"; + public readonly record struct GetFirstExtendedBioByTypeRow(string AuthorName, string Name, ExtendedBioType? BioType); + public readonly record struct GetFirstExtendedBioByTypeArgs(ExtendedBioType? BioType); + public async Task GetFirstExtendedBioByType(GetFirstExtendedBioByTypeArgs args) { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { - using (var command = connection.CreateCommand(GetPostgresTypesSql)) + using (var command = connection.CreateCommand(GetFirstExtendedBioByTypeSql)) { + command.Parameters.AddWithValue("@bio_type", args.BioType != null ? args.BioType.Value.Stringify() : (object)DBNull.Value); using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetPostgresTypesRow + return new GetFirstExtendedBioByTypeRow { - CBoolean = reader.IsDBNull(0) ? null : reader.GetBoolean(0), - CBit = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), - CSmallint = reader.IsDBNull(2) ? null : reader.GetInt16(2), - CInteger = reader.IsDBNull(3) ? null : reader.GetInt32(3), - CBigint = reader.IsDBNull(4) ? null : reader.GetInt64(4), - CReal = reader.IsDBNull(5) ? null : reader.GetFloat(5), - CNumeric = reader.IsDBNull(6) ? null : reader.GetDecimal(6), - CDecimal = reader.IsDBNull(7) ? null : reader.GetDecimal(7), - CDoublePrecision = reader.IsDBNull(8) ? null : reader.GetDouble(8), - CMoney = reader.IsDBNull(9) ? null : reader.GetDecimal(9), - CDate = reader.IsDBNull(10) ? null : reader.GetDateTime(10), - CTime = reader.IsDBNull(11) ? null : reader.GetFieldValue(11), - CTimestamp = reader.IsDBNull(12) ? null : reader.GetDateTime(12), - CTimestampWithTz = reader.IsDBNull(13) ? null : reader.GetDateTime(13), - CInterval = reader.IsDBNull(14) ? null : reader.GetFieldValue(14), - CChar = reader.IsDBNull(15) ? null : reader.GetString(15), - CVarchar = reader.IsDBNull(16) ? null : reader.GetString(16), - CCharacterVarying = reader.IsDBNull(17) ? null : reader.GetString(17), - CBpchar = reader.IsDBNull(18) ? null : reader.GetString(18), - CText = reader.IsDBNull(19) ? null : reader.GetString(19), - CUuid = reader.IsDBNull(20) ? null : reader.GetFieldValue(20), - CJson = reader.IsDBNull(21) ? null : JsonSerializer.Deserialize(reader.GetString(21)), - CJsonStringOverride = reader.IsDBNull(22) ? null : reader.GetString(22), - CJsonb = reader.IsDBNull(23) ? null : JsonSerializer.Deserialize(reader.GetString(23)), - CJsonpath = reader.IsDBNull(24) ? null : reader.GetString(24), - CXml = reader.IsDBNull(25) ? null : (new Func((r, o) => - { - var xmlDoc = new XmlDocument(); - xmlDoc.LoadXml(r.GetString(o)); - return xmlDoc; - }))(reader, 25), - CCidr = reader.IsDBNull(26) ? null : reader.GetFieldValue(26), - CInet = reader.IsDBNull(27) ? null : reader.GetFieldValue(27), - CMacaddr = reader.IsDBNull(28) ? null : reader.GetFieldValue(28), - CMacaddr8 = reader.IsDBNull(29) ? null : reader.GetString(29) + AuthorName = reader.GetString(0), + Name = reader.GetString(1), + BioType = reader.IsDBNull(2) ? null : reader.GetString(2).ToExtendedBioType() }; } } @@ -849,55 +694,21 @@ public async Task InsertPostgresTypesBatch(List ar } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = GetPostgresTypesSql; + command.CommandText = GetFirstExtendedBioByTypeSql; command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@bio_type", args.BioType != null ? args.BioType.Value.Stringify() : (object)DBNull.Value); using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetPostgresTypesRow + return new GetFirstExtendedBioByTypeRow { - CBoolean = reader.IsDBNull(0) ? null : reader.GetBoolean(0), - CBit = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), - CSmallint = reader.IsDBNull(2) ? null : reader.GetInt16(2), - CInteger = reader.IsDBNull(3) ? null : reader.GetInt32(3), - CBigint = reader.IsDBNull(4) ? null : reader.GetInt64(4), - CReal = reader.IsDBNull(5) ? null : reader.GetFloat(5), - CNumeric = reader.IsDBNull(6) ? null : reader.GetDecimal(6), - CDecimal = reader.IsDBNull(7) ? null : reader.GetDecimal(7), - CDoublePrecision = reader.IsDBNull(8) ? null : reader.GetDouble(8), - CMoney = reader.IsDBNull(9) ? null : reader.GetDecimal(9), - CDate = reader.IsDBNull(10) ? null : reader.GetDateTime(10), - CTime = reader.IsDBNull(11) ? null : reader.GetFieldValue(11), - CTimestamp = reader.IsDBNull(12) ? null : reader.GetDateTime(12), - CTimestampWithTz = reader.IsDBNull(13) ? null : reader.GetDateTime(13), - CInterval = reader.IsDBNull(14) ? null : reader.GetFieldValue(14), - CChar = reader.IsDBNull(15) ? null : reader.GetString(15), - CVarchar = reader.IsDBNull(16) ? null : reader.GetString(16), - CCharacterVarying = reader.IsDBNull(17) ? null : reader.GetString(17), - CBpchar = reader.IsDBNull(18) ? null : reader.GetString(18), - CText = reader.IsDBNull(19) ? null : reader.GetString(19), - CUuid = reader.IsDBNull(20) ? null : reader.GetFieldValue(20), - CJson = reader.IsDBNull(21) ? null : JsonSerializer.Deserialize(reader.GetString(21)), - CJsonStringOverride = reader.IsDBNull(22) ? null : reader.GetString(22), - CJsonb = reader.IsDBNull(23) ? null : JsonSerializer.Deserialize(reader.GetString(23)), - CJsonpath = reader.IsDBNull(24) ? null : reader.GetString(24), - CXml = reader.IsDBNull(25) ? null : (new Func((r, o) => - { - var xmlDoc = new XmlDocument(); - xmlDoc.LoadXml(r.GetString(o)); - return xmlDoc; - }))(reader, 25), - CCidr = reader.IsDBNull(26) ? null : reader.GetFieldValue(26), - CInet = reader.IsDBNull(27) ? null : reader.GetFieldValue(27), - CMacaddr = reader.IsDBNull(28) ? null : reader.GetFieldValue(28), - CMacaddr8 = reader.IsDBNull(29) ? null : reader.GetString(29) + AuthorName = reader.GetString(0), + Name = reader.GetString(1), + BioType = reader.IsDBNull(2) ? null : reader.GetString(2).ToExtendedBioType() }; } } @@ -906,109 +717,39 @@ public async Task InsertPostgresTypesBatch(List ar return null; } - private const string GetPostgresTypesCntSql = "SELECT c_smallint , c_boolean, c_integer, c_bigint, c_real, c_numeric, c_decimal, c_double_precision, c_money, c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_char, c_varchar, c_character_varying, c_bpchar, c_text, c_uuid, c_cidr, c_inet, c_macaddr, COUNT (* ) AS cnt FROM postgres_types GROUP BY c_smallint, c_boolean, c_integer, c_bigint, c_real, c_numeric, c_decimal, c_double_precision, c_money, c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_char, c_varchar, c_character_varying, c_bpchar, c_text, c_uuid, c_cidr, c_inet, c_macaddr LIMIT 1 "; - public readonly record struct GetPostgresTypesCntRow(short? CSmallint, bool? CBoolean, int? CInteger, long? CBigint, float? CReal, decimal? CNumeric, decimal? CDecimal, double? CDoublePrecision, decimal? CMoney, DateTime? CDate, TimeSpan? CTime, DateTime? CTimestamp, DateTime? CTimestampWithTz, TimeSpan? CInterval, string? CChar, string? CVarchar, string? CCharacterVarying, string? CBpchar, string? CText, Guid? CUuid, NpgsqlCidr? CCidr, IPAddress? CInet, PhysicalAddress? CMacaddr, long Cnt); - public async Task GetPostgresTypesCnt() + private const string TruncateExtendedBiosSql = "TRUNCATE TABLE extended.bios"; + public async Task TruncateExtendedBios() { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { - using (var command = connection.CreateCommand(GetPostgresTypesCntSql)) + using (var command = connection.CreateCommand(TruncateExtendedBiosSql)) { - using (var reader = await command.ExecuteReaderAsync()) - { - if (await reader.ReadAsync()) - { - return new GetPostgresTypesCntRow - { - CSmallint = reader.IsDBNull(0) ? null : reader.GetInt16(0), - CBoolean = reader.IsDBNull(1) ? null : reader.GetBoolean(1), - CInteger = reader.IsDBNull(2) ? null : reader.GetInt32(2), - CBigint = reader.IsDBNull(3) ? null : reader.GetInt64(3), - CReal = reader.IsDBNull(4) ? null : reader.GetFloat(4), - CNumeric = reader.IsDBNull(5) ? null : reader.GetDecimal(5), - CDecimal = reader.IsDBNull(6) ? null : reader.GetDecimal(6), - CDoublePrecision = reader.IsDBNull(7) ? null : reader.GetDouble(7), - CMoney = reader.IsDBNull(8) ? null : reader.GetDecimal(8), - CDate = reader.IsDBNull(9) ? null : reader.GetDateTime(9), - CTime = reader.IsDBNull(10) ? null : reader.GetFieldValue(10), - CTimestamp = reader.IsDBNull(11) ? null : reader.GetDateTime(11), - CTimestampWithTz = reader.IsDBNull(12) ? null : reader.GetDateTime(12), - CInterval = reader.IsDBNull(13) ? null : reader.GetFieldValue(13), - CChar = reader.IsDBNull(14) ? null : reader.GetString(14), - CVarchar = reader.IsDBNull(15) ? null : reader.GetString(15), - CCharacterVarying = reader.IsDBNull(16) ? null : reader.GetString(16), - CBpchar = reader.IsDBNull(17) ? null : reader.GetString(17), - CText = reader.IsDBNull(18) ? null : reader.GetString(18), - CUuid = reader.IsDBNull(19) ? null : reader.GetFieldValue(19), - CCidr = reader.IsDBNull(20) ? null : reader.GetFieldValue(20), - CInet = reader.IsDBNull(21) ? null : reader.GetFieldValue(21), - CMacaddr = reader.IsDBNull(22) ? null : reader.GetFieldValue(22), - Cnt = reader.GetInt64(23) - }; - } - } + await command.ExecuteNonQueryAsync(); } } - return null; + return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = GetPostgresTypesCntSql; + command.CommandText = TruncateExtendedBiosSql; command.Transaction = this.Transaction; - using (var reader = await command.ExecuteReaderAsync()) - { - if (await reader.ReadAsync()) - { - return new GetPostgresTypesCntRow - { - CSmallint = reader.IsDBNull(0) ? null : reader.GetInt16(0), - CBoolean = reader.IsDBNull(1) ? null : reader.GetBoolean(1), - CInteger = reader.IsDBNull(2) ? null : reader.GetInt32(2), - CBigint = reader.IsDBNull(3) ? null : reader.GetInt64(3), - CReal = reader.IsDBNull(4) ? null : reader.GetFloat(4), - CNumeric = reader.IsDBNull(5) ? null : reader.GetDecimal(5), - CDecimal = reader.IsDBNull(6) ? null : reader.GetDecimal(6), - CDoublePrecision = reader.IsDBNull(7) ? null : reader.GetDouble(7), - CMoney = reader.IsDBNull(8) ? null : reader.GetDecimal(8), - CDate = reader.IsDBNull(9) ? null : reader.GetDateTime(9), - CTime = reader.IsDBNull(10) ? null : reader.GetFieldValue(10), - CTimestamp = reader.IsDBNull(11) ? null : reader.GetDateTime(11), - CTimestampWithTz = reader.IsDBNull(12) ? null : reader.GetDateTime(12), - CInterval = reader.IsDBNull(13) ? null : reader.GetFieldValue(13), - CChar = reader.IsDBNull(14) ? null : reader.GetString(14), - CVarchar = reader.IsDBNull(15) ? null : reader.GetString(15), - CCharacterVarying = reader.IsDBNull(16) ? null : reader.GetString(16), - CBpchar = reader.IsDBNull(17) ? null : reader.GetString(17), - CText = reader.IsDBNull(18) ? null : reader.GetString(18), - CUuid = reader.IsDBNull(19) ? null : reader.GetFieldValue(19), - CCidr = reader.IsDBNull(20) ? null : reader.GetFieldValue(20), - CInet = reader.IsDBNull(21) ? null : reader.GetFieldValue(21), - CMacaddr = reader.IsDBNull(22) ? null : reader.GetFieldValue(22), - Cnt = reader.GetInt64(23) - }; - } - } + await command.ExecuteNonQueryAsync(); } - - return null; } - 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_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() { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(GetPostgresFunctionsSql)) { @@ -1031,10 +772,7 @@ public async Task InsertPostgresTypesBatch(List ar } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetPostgresFunctionsSql; @@ -1056,23 +794,26 @@ public async Task InsertPostgresTypesBatch(List ar return null; } - 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) + 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) { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { - using (var command = connection.CreateCommand(InsertPostgresGeoTypesSql)) + using (var command = connection.CreateCommand(InsertPostgresNumericTypesSql)) { - command.Parameters.AddWithValue("@c_point", args.CPoint ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_line", args.CLine ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_lseg", args.CLseg ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_box", args.CBox ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_path", args.CPath ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_polygon", args.CPolygon ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_circle", args.CCircle ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_boolean", args.CBoolean ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_bit", args.CBit ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_smallint", args.CSmallint ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_integer", args.CInteger ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_bigint", args.CBigint ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_decimal", args.CDecimal ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_numeric", args.CNumeric ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_real", args.CReal ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_double_precision", args.CDoublePrecision ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_money", args.CMoney ?? (object)DBNull.Value); await command.ExecuteNonQueryAsync(); } } @@ -1081,44 +822,663 @@ public async Task InsertPostgresGeoTypes(InsertPostgresGeoTypesArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = InsertPostgresGeoTypesSql; + command.CommandText = InsertPostgresNumericTypesSql; command.Transaction = this.Transaction; - command.Parameters.AddWithValue("@c_point", args.CPoint ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_line", args.CLine ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_lseg", args.CLseg ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_box", args.CBox ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_path", args.CPath ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_polygon", args.CPolygon ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_circle", args.CCircle ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_boolean", args.CBoolean ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_bit", args.CBit ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_smallint", args.CSmallint ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_integer", args.CInteger ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_bigint", args.CBigint ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_decimal", args.CDecimal ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_numeric", args.CNumeric ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_real", args.CReal ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_double_precision", args.CDoublePrecision ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_money", args.CMoney ?? (object)DBNull.Value); await command.ExecuteNonQueryAsync(); } } - private const string InsertPostgresGeoTypesBatchSql = "COPY postgres_geometric_types (c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle) FROM STDIN (FORMAT BINARY)"; - public readonly record struct InsertPostgresGeoTypesBatchArgs(NpgsqlPoint? CPoint, NpgsqlLine? CLine, NpgsqlLSeg? CLseg, NpgsqlBox? CBox, NpgsqlPath? CPath, NpgsqlPolygon? CPolygon, NpgsqlCircle? CCircle); - public async Task InsertPostgresGeoTypesBatch(List args) + private const string GetPostgresNumericTypesSql = "SELECT c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money FROM postgres_numeric_types LIMIT 1"; + public readonly record struct GetPostgresNumericTypesRow(bool? CBoolean, byte[]? CBit, short? CSmallint, int? CInteger, long? CBigint, decimal? CDecimal, decimal? CNumeric, float? CReal, double? CDoublePrecision, decimal? CMoney); + public async Task GetPostgresNumericTypes() { - using (var connection = new NpgsqlConnection(ConnectionString)) + if (this.Transaction == null) { - await connection.OpenAsync(); - using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresGeoTypesBatchSql)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { - foreach (var row in args) + using (var command = connection.CreateCommand(GetPostgresNumericTypesSql)) { - await writer.StartRowAsync(); - await writer.WriteAsync(row.CPoint ?? (object)DBNull.Value); - await writer.WriteAsync(row.CLine ?? (object)DBNull.Value); - await writer.WriteAsync(row.CLseg ?? (object)DBNull.Value); - await writer.WriteAsync(row.CBox ?? (object)DBNull.Value); - await writer.WriteAsync(row.CPath ?? (object)DBNull.Value); - await writer.WriteAsync(row.CPolygon ?? (object)DBNull.Value); - await writer.WriteAsync(row.CCircle ?? (object)DBNull.Value); + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresNumericTypesRow + { + CBoolean = reader.IsDBNull(0) ? null : reader.GetBoolean(0), + CBit = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CSmallint = reader.IsDBNull(2) ? null : reader.GetInt16(2), + CInteger = reader.IsDBNull(3) ? null : reader.GetInt32(3), + CBigint = reader.IsDBNull(4) ? null : reader.GetInt64(4), + CDecimal = reader.IsDBNull(5) ? null : reader.GetDecimal(5), + CNumeric = reader.IsDBNull(6) ? null : reader.GetDecimal(6), + CReal = reader.IsDBNull(7) ? null : reader.GetFloat(7), + CDoublePrecision = reader.IsDBNull(8) ? null : reader.GetDouble(8), + CMoney = reader.IsDBNull(9) ? null : reader.GetDecimal(9) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresNumericTypesSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresNumericTypesRow + { + CBoolean = reader.IsDBNull(0) ? null : reader.GetBoolean(0), + CBit = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CSmallint = reader.IsDBNull(2) ? null : reader.GetInt16(2), + CInteger = reader.IsDBNull(3) ? null : reader.GetInt32(3), + CBigint = reader.IsDBNull(4) ? null : reader.GetInt64(4), + CDecimal = reader.IsDBNull(5) ? null : reader.GetDecimal(5), + CNumeric = reader.IsDBNull(6) ? null : reader.GetDecimal(6), + CReal = reader.IsDBNull(7) ? null : reader.GetFloat(7), + CDoublePrecision = reader.IsDBNull(8) ? null : reader.GetDouble(8), + CMoney = reader.IsDBNull(9) ? null : reader.GetDecimal(9) + }; + } + } + } + + return null; + } + + private const string TruncatePostgresNumericTypesSql = "TRUNCATE TABLE postgres_numeric_types"; + public async Task TruncatePostgresNumericTypes() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(TruncatePostgresNumericTypesSql)) + { + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncatePostgresNumericTypesSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } + + 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() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(GetPostgresNumericTypesCntSql)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresNumericTypesCntRow + { + CBoolean = reader.IsDBNull(0) ? null : reader.GetBoolean(0), + CBit = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CSmallint = reader.IsDBNull(2) ? null : reader.GetInt16(2), + CInteger = reader.IsDBNull(3) ? null : reader.GetInt32(3), + CBigint = reader.IsDBNull(4) ? null : reader.GetInt64(4), + CDecimal = reader.IsDBNull(5) ? null : reader.GetDecimal(5), + CNumeric = reader.IsDBNull(6) ? null : reader.GetDecimal(6), + CReal = reader.IsDBNull(7) ? null : reader.GetFloat(7), + CDoublePrecision = reader.IsDBNull(8) ? null : reader.GetDouble(8), + CMoney = reader.IsDBNull(9) ? null : reader.GetDecimal(9), + Cnt = reader.GetInt64(10) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresNumericTypesCntSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresNumericTypesCntRow + { + CBoolean = reader.IsDBNull(0) ? null : reader.GetBoolean(0), + CBit = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CSmallint = reader.IsDBNull(2) ? null : reader.GetInt16(2), + CInteger = reader.IsDBNull(3) ? null : reader.GetInt32(3), + CBigint = reader.IsDBNull(4) ? null : reader.GetInt64(4), + CDecimal = reader.IsDBNull(5) ? null : reader.GetDecimal(5), + CNumeric = reader.IsDBNull(6) ? null : reader.GetDecimal(6), + CReal = reader.IsDBNull(7) ? null : reader.GetFloat(7), + CDoublePrecision = reader.IsDBNull(8) ? null : reader.GetDouble(8), + CMoney = reader.IsDBNull(9) ? null : reader.GetDecimal(9), + Cnt = reader.GetInt64(10) + }; + } + } + } + + return null; + } + + private const string InsertPostgresNumericTypesBatchSql = "COPY postgres_numeric_types (c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money) FROM STDIN (FORMAT BINARY)"; + public readonly record struct InsertPostgresNumericTypesBatchArgs(bool? CBoolean, byte[]? CBit, short? CSmallint, int? CInteger, long? CBigint, decimal? CDecimal, decimal? CNumeric, float? CReal, double? CDoublePrecision, decimal? CMoney); + public async Task InsertPostgresNumericTypesBatch(List args) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresNumericTypesBatchSql)) + { + foreach (var row in args) + { + await writer.StartRowAsync(); + await writer.WriteAsync(row.CBoolean ?? (object)DBNull.Value); + await writer.WriteAsync(row.CBit ?? (object)DBNull.Value); + await writer.WriteAsync(row.CSmallint ?? (object)DBNull.Value); + await writer.WriteAsync(row.CInteger ?? (object)DBNull.Value); + await writer.WriteAsync(row.CBigint ?? (object)DBNull.Value); + await writer.WriteAsync(row.CDecimal ?? (object)DBNull.Value); + await writer.WriteAsync(row.CNumeric ?? (object)DBNull.Value); + await writer.WriteAsync(row.CReal ?? (object)DBNull.Value); + await writer.WriteAsync(row.CDoublePrecision ?? (object)DBNull.Value); + await writer.WriteAsync(row.CMoney ?? (object)DBNull.Value, NpgsqlDbType.Money); + } + + await writer.CompleteAsync(); + } + + await connection.CloseAsync(); + } + } + + private const string InsertPostgresStringTypesSql = " INSERT INTO postgres_string_types ( c_char, c_varchar, c_character_varying, c_bpchar, c_text ) VALUES (@c_char, @c_varchar, @c_character_varying, @c_bpchar, @c_text)"; + public readonly record struct InsertPostgresStringTypesArgs(string? CChar, string? CVarchar, string? CCharacterVarying, string? CBpchar, string? CText); + public async Task InsertPostgresStringTypes(InsertPostgresStringTypesArgs args) + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(InsertPostgresStringTypesSql)) + { + command.Parameters.AddWithValue("@c_char", args.CChar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_varchar", args.CVarchar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_character_varying", args.CCharacterVarying ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_bpchar", args.CBpchar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_text", args.CText ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = InsertPostgresStringTypesSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@c_char", args.CChar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_varchar", args.CVarchar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_character_varying", args.CCharacterVarying ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_bpchar", args.CBpchar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_text", args.CText ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + private const string InsertPostgresStringTypesBatchSql = "COPY postgres_string_types (c_char, c_varchar, c_character_varying, c_bpchar, c_text) FROM STDIN (FORMAT BINARY)"; + public readonly record struct InsertPostgresStringTypesBatchArgs(string? CChar, string? CVarchar, string? CCharacterVarying, string? CBpchar, string? CText); + public async Task InsertPostgresStringTypesBatch(List args) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresStringTypesBatchSql)) + { + foreach (var row in args) + { + await writer.StartRowAsync(); + await writer.WriteAsync(row.CChar ?? (object)DBNull.Value); + await writer.WriteAsync(row.CVarchar ?? (object)DBNull.Value); + await writer.WriteAsync(row.CCharacterVarying ?? (object)DBNull.Value); + await writer.WriteAsync(row.CBpchar ?? (object)DBNull.Value); + await writer.WriteAsync(row.CText ?? (object)DBNull.Value); + } + + await writer.CompleteAsync(); + } + + await connection.CloseAsync(); + } + } + + private const string GetPostgresStringTypesSql = "SELECT c_char, c_varchar, c_character_varying, c_bpchar, c_text FROM postgres_string_types LIMIT 1"; + public readonly record struct GetPostgresStringTypesRow(string? CChar, string? CVarchar, string? CCharacterVarying, string? CBpchar, string? CText); + public async Task GetPostgresStringTypes() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(GetPostgresStringTypesSql)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresStringTypesRow + { + CChar = reader.IsDBNull(0) ? null : reader.GetString(0), + CVarchar = reader.IsDBNull(1) ? null : reader.GetString(1), + CCharacterVarying = reader.IsDBNull(2) ? null : reader.GetString(2), + CBpchar = reader.IsDBNull(3) ? null : reader.GetString(3), + CText = reader.IsDBNull(4) ? null : reader.GetString(4) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresStringTypesSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresStringTypesRow + { + CChar = reader.IsDBNull(0) ? null : reader.GetString(0), + CVarchar = reader.IsDBNull(1) ? null : reader.GetString(1), + CCharacterVarying = reader.IsDBNull(2) ? null : reader.GetString(2), + CBpchar = reader.IsDBNull(3) ? null : reader.GetString(3), + CText = reader.IsDBNull(4) ? null : reader.GetString(4) + }; + } + } + } + + return null; + } + + private const string TruncatePostgresStringTypesSql = "TRUNCATE TABLE postgres_string_types"; + public async Task TruncatePostgresStringTypes() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(TruncatePostgresStringTypesSql)) + { + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncatePostgresStringTypesSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } + + private const string GetPostgresStringTypesCntSql = "SELECT c_char, c_varchar, c_character_varying, c_bpchar, c_text, COUNT(*) AS cnt FROM postgres_string_types GROUP BY c_char, c_varchar, c_character_varying, c_bpchar, c_text LIMIT 1"; + public readonly record struct GetPostgresStringTypesCntRow(string? CChar, string? CVarchar, string? CCharacterVarying, string? CBpchar, string? CText, long Cnt); + public async Task GetPostgresStringTypesCnt() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(GetPostgresStringTypesCntSql)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresStringTypesCntRow + { + CChar = reader.IsDBNull(0) ? null : reader.GetString(0), + CVarchar = reader.IsDBNull(1) ? null : reader.GetString(1), + CCharacterVarying = reader.IsDBNull(2) ? null : reader.GetString(2), + CBpchar = reader.IsDBNull(3) ? null : reader.GetString(3), + CText = reader.IsDBNull(4) ? null : reader.GetString(4), + Cnt = reader.GetInt64(5) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresStringTypesCntSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresStringTypesCntRow + { + CChar = reader.IsDBNull(0) ? null : reader.GetString(0), + CVarchar = reader.IsDBNull(1) ? null : reader.GetString(1), + CCharacterVarying = reader.IsDBNull(2) ? null : reader.GetString(2), + CBpchar = reader.IsDBNull(3) ? null : reader.GetString(3), + CText = reader.IsDBNull(4) ? null : reader.GetString(4), + Cnt = reader.GetInt64(5) + }; + } + } + } + + 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"; + 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) + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(GetPostgresStringTypesTextSearchSql)) + { + command.Parameters.AddWithValue("@to_tsquery", args.ToTsquery); + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresStringTypesTextSearchRow + { + CText = reader.IsDBNull(0) ? null : reader.GetString(0), + Query = reader.GetFieldValue(1), + Tsv = reader.GetFieldValue(2), + Rnk = reader.GetFloat(3) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresStringTypesTextSearchSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@to_tsquery", args.ToTsquery); + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresStringTypesTextSearchRow + { + CText = reader.IsDBNull(0) ? null : reader.GetString(0), + Query = reader.GetFieldValue(1), + Tsv = reader.GetFieldValue(2), + Rnk = reader.GetFloat(3) + }; + } + } + } + + return null; + } + + private const string InsertPostgresDateTimeTypesSql = " INSERT INTO postgres_datetime_types ( c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval ) VALUES (@c_date, @c_time, @c_timestamp, @c_timestamp_with_tz, @c_interval)"; + public readonly record struct InsertPostgresDateTimeTypesArgs(DateTime? CDate, TimeSpan? CTime, DateTime? CTimestamp, DateTime? CTimestampWithTz, TimeSpan? CInterval); + public async Task InsertPostgresDateTimeTypes(InsertPostgresDateTimeTypesArgs args) + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(InsertPostgresDateTimeTypesSql)) + { + command.Parameters.AddWithValue("@c_date", args.CDate ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_time", args.CTime ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_timestamp", args.CTimestamp ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_timestamp_with_tz", args.CTimestampWithTz ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_interval", args.CInterval ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = InsertPostgresDateTimeTypesSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@c_date", args.CDate ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_time", args.CTime ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_timestamp", args.CTimestamp ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_timestamp_with_tz", args.CTimestampWithTz ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_interval", args.CInterval ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + private const string GetPostgresDateTimeTypesSql = "SELECT c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval FROM postgres_datetime_types LIMIT 1"; + public readonly record struct GetPostgresDateTimeTypesRow(DateTime? CDate, TimeSpan? CTime, DateTime? CTimestamp, DateTime? CTimestampWithTz, TimeSpan? CInterval); + public async Task GetPostgresDateTimeTypes() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(GetPostgresDateTimeTypesSql)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresDateTimeTypesRow + { + CDate = reader.IsDBNull(0) ? null : reader.GetDateTime(0), + CTime = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CTimestamp = reader.IsDBNull(2) ? null : reader.GetDateTime(2), + CTimestampWithTz = reader.IsDBNull(3) ? null : reader.GetDateTime(3), + CInterval = reader.IsDBNull(4) ? null : reader.GetFieldValue(4) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresDateTimeTypesSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresDateTimeTypesRow + { + CDate = reader.IsDBNull(0) ? null : reader.GetDateTime(0), + CTime = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CTimestamp = reader.IsDBNull(2) ? null : reader.GetDateTime(2), + CTimestampWithTz = reader.IsDBNull(3) ? null : reader.GetDateTime(3), + CInterval = reader.IsDBNull(4) ? null : reader.GetFieldValue(4) + }; + } + } + } + + return null; + } + + private const string TruncatePostgresDateTimeTypesSql = "TRUNCATE TABLE postgres_datetime_types"; + public async Task TruncatePostgresDateTimeTypes() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(TruncatePostgresDateTimeTypesSql)) + { + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncatePostgresDateTimeTypesSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } + + 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() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(GetPostgresDateTimeTypesCntSql)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresDateTimeTypesCntRow + { + CDate = reader.IsDBNull(0) ? null : reader.GetDateTime(0), + CTime = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CTimestamp = reader.IsDBNull(2) ? null : reader.GetDateTime(2), + CTimestampWithTz = reader.IsDBNull(3) ? null : reader.GetDateTime(3), + CInterval = reader.IsDBNull(4) ? null : reader.GetFieldValue(4), + Cnt = reader.GetInt64(5) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresDateTimeTypesCntSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresDateTimeTypesCntRow + { + CDate = reader.IsDBNull(0) ? null : reader.GetDateTime(0), + CTime = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CTimestamp = reader.IsDBNull(2) ? null : reader.GetDateTime(2), + CTimestampWithTz = reader.IsDBNull(3) ? null : reader.GetDateTime(3), + CInterval = reader.IsDBNull(4) ? null : reader.GetFieldValue(4), + Cnt = reader.GetInt64(5) + }; + } + } + } + + return null; + } + + private const string InsertPostgresDateTimeTypesBatchSql = "COPY postgres_datetime_types (c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval) FROM STDIN (FORMAT BINARY)"; + public readonly record struct InsertPostgresDateTimeTypesBatchArgs(DateTime? CDate, TimeSpan? CTime, DateTime? CTimestamp, DateTime? CTimestampWithTz, TimeSpan? CInterval); + public async Task InsertPostgresDateTimeTypesBatch(List args) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresDateTimeTypesBatchSql)) + { + foreach (var row in args) + { + await writer.StartRowAsync(); + await writer.WriteAsync(row.CDate ?? (object)DBNull.Value, NpgsqlDbType.Date); + await writer.WriteAsync(row.CTime ?? (object)DBNull.Value, NpgsqlDbType.Time); + await writer.WriteAsync(row.CTimestamp ?? (object)DBNull.Value); + await writer.WriteAsync(row.CTimestampWithTz ?? (object)DBNull.Value); + await writer.WriteAsync(row.CInterval ?? (object)DBNull.Value, NpgsqlDbType.Interval); } await writer.CompleteAsync(); @@ -1128,29 +1488,269 @@ public async Task InsertPostgresGeoTypesBatch(List GetPostgresGeoTypes() + private const string InsertPostgresNetworkTypesSql = " INSERT INTO postgres_network_types ( c_cidr, c_inet, c_macaddr, c_macaddr8 ) VALUES ( @c_cidr, @c_inet, @c_macaddr, @c_macaddr8::macaddr8 )"; + public readonly record struct InsertPostgresNetworkTypesArgs(NpgsqlCidr? CCidr, IPAddress? CInet, PhysicalAddress? CMacaddr, string? CMacaddr8); + public async Task InsertPostgresNetworkTypes(InsertPostgresNetworkTypesArgs args) + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(InsertPostgresNetworkTypesSql)) + { + command.Parameters.AddWithValue("@c_cidr", args.CCidr ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_inet", args.CInet ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_macaddr", args.CMacaddr ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_macaddr8", args.CMacaddr8 ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = InsertPostgresNetworkTypesSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@c_cidr", args.CCidr ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_inet", args.CInet ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_macaddr", args.CMacaddr ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_macaddr8", args.CMacaddr8 ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + private const string GetPostgresNetworkTypesSql = "SELECT c_cidr, c_inet, c_macaddr, c_macaddr8::TEXT AS c_macaddr8 FROM postgres_network_types LIMIT 1"; + public readonly record struct GetPostgresNetworkTypesRow(NpgsqlCidr? CCidr, IPAddress? CInet, PhysicalAddress? CMacaddr, string? CMacaddr8); + public async Task GetPostgresNetworkTypes() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(GetPostgresNetworkTypesSql)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresNetworkTypesRow + { + CCidr = reader.IsDBNull(0) ? null : reader.GetFieldValue(0), + CInet = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CMacaddr = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + CMacaddr8 = reader.IsDBNull(3) ? null : reader.GetString(3) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresNetworkTypesSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresNetworkTypesRow + { + CCidr = reader.IsDBNull(0) ? null : reader.GetFieldValue(0), + CInet = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CMacaddr = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + CMacaddr8 = reader.IsDBNull(3) ? null : reader.GetString(3) + }; + } + } + } + + return null; + } + + private const string TruncatePostgresNetworkTypesSql = "TRUNCATE TABLE postgres_network_types"; + public async Task TruncatePostgresNetworkTypes() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(TruncatePostgresNetworkTypesSql)) + { + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncatePostgresNetworkTypesSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } + + 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() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(GetPostgresNetworkTypesCntSql)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresNetworkTypesCntRow + { + CCidr = reader.IsDBNull(0) ? null : reader.GetFieldValue(0), + CInet = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CMacaddr = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + Cnt = reader.GetInt64(3) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresNetworkTypesCntSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresNetworkTypesCntRow + { + CCidr = reader.IsDBNull(0) ? null : reader.GetFieldValue(0), + CInet = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CMacaddr = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + Cnt = reader.GetInt64(3) + }; + } + } + } + + return null; + } + + private const string InsertPostgresNetworkTypesBatchSql = "COPY postgres_network_types (c_cidr, c_inet, c_macaddr) FROM STDIN (FORMAT BINARY)"; + public readonly record struct InsertPostgresNetworkTypesBatchArgs(NpgsqlCidr? CCidr, IPAddress? CInet, PhysicalAddress? CMacaddr); + public async Task InsertPostgresNetworkTypesBatch(List args) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresNetworkTypesBatchSql)) + { + foreach (var row in args) + { + await writer.StartRowAsync(); + await writer.WriteAsync(row.CCidr ?? (object)DBNull.Value); + await writer.WriteAsync(row.CInet ?? (object)DBNull.Value); + await writer.WriteAsync(row.CMacaddr ?? (object)DBNull.Value); + } + + await writer.CompleteAsync(); + } + + await connection.CloseAsync(); + } + } + + private const string InsertPostgresSpecialTypesSql = " INSERT INTO postgres_special_types ( c_json, c_json_string_override, c_jsonb, c_jsonpath, c_xml, c_xml_string_override, c_uuid, c_enum ) VALUES ( @c_json::json, @c_json_string_override::json, @c_jsonb::jsonb, @c_jsonpath::jsonpath, @c_xml::xml, @c_xml_string_override::xml, @c_uuid, @c_enum::c_enum )"; + public readonly record struct InsertPostgresSpecialTypesArgs(JsonElement? CJson, string? CJsonStringOverride, JsonElement? CJsonb, string? CJsonpath, XmlDocument? CXml, string? CXmlStringOverride, Guid? CUuid, CEnum? CEnum); + public async Task InsertPostgresSpecialTypes(InsertPostgresSpecialTypesArgs args) + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(InsertPostgresSpecialTypesSql)) + { + command.Parameters.AddWithValue("@c_json", args.CJson.HasValue ? args.CJson.Value.GetRawText() : (object)DBNull.Value); + command.Parameters.AddWithValue("@c_json_string_override", args.CJsonStringOverride ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_jsonb", args.CJsonb.HasValue ? args.CJsonb.Value.GetRawText() : (object)DBNull.Value); + command.Parameters.AddWithValue("@c_jsonpath", args.CJsonpath ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_xml", args.CXml != null ? args.CXml.OuterXml : (object)DBNull.Value); + command.Parameters.AddWithValue("@c_xml_string_override", args.CXmlStringOverride ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_uuid", args.CUuid ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_enum", args.CEnum != null ? args.CEnum.Value.Stringify() : (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = InsertPostgresSpecialTypesSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@c_json", args.CJson.HasValue ? args.CJson.Value.GetRawText() : (object)DBNull.Value); + command.Parameters.AddWithValue("@c_json_string_override", args.CJsonStringOverride ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_jsonb", args.CJsonb.HasValue ? args.CJsonb.Value.GetRawText() : (object)DBNull.Value); + command.Parameters.AddWithValue("@c_jsonpath", args.CJsonpath ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_xml", args.CXml != null ? args.CXml.OuterXml : (object)DBNull.Value); + command.Parameters.AddWithValue("@c_xml_string_override", args.CXmlStringOverride ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_uuid", args.CUuid ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_enum", args.CEnum != null ? args.CEnum.Value.Stringify() : (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + 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() { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { - using (var command = connection.CreateCommand(GetPostgresGeoTypesSql)) + using (var command = connection.CreateCommand(GetPostgresSpecialTypesSql)) { using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetPostgresGeoTypesRow + return new GetPostgresSpecialTypesRow { - CPoint = reader.IsDBNull(0) ? null : reader.GetFieldValue(0), - CLine = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), - CLseg = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), - CBox = reader.IsDBNull(3) ? null : reader.GetFieldValue(3), - CPath = reader.IsDBNull(4) ? null : reader.GetFieldValue(4), - CPolygon = reader.IsDBNull(5) ? null : reader.GetFieldValue(5), - CCircle = reader.IsDBNull(6) ? null : reader.GetFieldValue(6) + CJson = reader.IsDBNull(0) ? null : JsonSerializer.Deserialize(reader.GetString(0)), + CJsonStringOverride = reader.IsDBNull(1) ? null : reader.GetString(1), + CJsonb = reader.IsDBNull(2) ? null : JsonSerializer.Deserialize(reader.GetString(2)), + CJsonpath = reader.IsDBNull(3) ? null : reader.GetString(3), + CXml = reader.IsDBNull(4) ? null : (new Func((r, o) => + { + var xmlDoc = new XmlDocument(); + xmlDoc.LoadXml(r.GetString(o)); + return xmlDoc; + }))(reader, 4), + CXmlStringOverride = reader.IsDBNull(5) ? null : reader.GetString(5), + CUuid = reader.IsDBNull(6) ? null : reader.GetFieldValue(6), + CEnum = reader.IsDBNull(7) ? null : reader.GetString(7).ToCEnum() }; } } @@ -1161,27 +1761,30 @@ public async Task InsertPostgresGeoTypesBatch(List(0), - CLine = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), - CLseg = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), - CBox = reader.IsDBNull(3) ? null : reader.GetFieldValue(3), - CPath = reader.IsDBNull(4) ? null : reader.GetFieldValue(4), - CPolygon = reader.IsDBNull(5) ? null : reader.GetFieldValue(5), - CCircle = reader.IsDBNull(6) ? null : reader.GetFieldValue(6) + CJson = reader.IsDBNull(0) ? null : JsonSerializer.Deserialize(reader.GetString(0)), + CJsonStringOverride = reader.IsDBNull(1) ? null : reader.GetString(1), + CJsonb = reader.IsDBNull(2) ? null : JsonSerializer.Deserialize(reader.GetString(2)), + CJsonpath = reader.IsDBNull(3) ? null : reader.GetString(3), + CXml = reader.IsDBNull(4) ? null : (new Func((r, o) => + { + var xmlDoc = new XmlDocument(); + xmlDoc.LoadXml(r.GetString(o)); + return xmlDoc; + }))(reader, 4), + CXmlStringOverride = reader.IsDBNull(5) ? null : reader.GetString(5), + CUuid = reader.IsDBNull(6) ? null : reader.GetFieldValue(6), + CEnum = reader.IsDBNull(7) ? null : reader.GetString(7).ToCEnum() }; } } @@ -1190,14 +1793,14 @@ public async Task InsertPostgresGeoTypesBatch(List args) { - if (this.Transaction == null) + using (var connection = new NpgsqlConnection(ConnectionString)) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + await connection.OpenAsync(); + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresSpecialTypesBatchSql)) { - using (var command = connection.CreateCommand(TruncatePostgresGeoTypesSql)) + foreach (var row in args) { - await command.ExecuteNonQueryAsync(); + await writer.StartRowAsync(); + await writer.WriteAsync(row.CUuid ?? (object)DBNull.Value); } + + await writer.CompleteAsync(); } - return; + await connection.CloseAsync(); } + } - if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + private const string GetPostgresSpecialTypesCntSql = "SELECT c_uuid, COUNT(*) AS cnt FROM postgres_special_types GROUP BY c_uuid LIMIT 1"; + public readonly record struct GetPostgresSpecialTypesCntRow(Guid? CUuid, long Cnt); + public async Task GetPostgresSpecialTypesCnt() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(GetPostgresSpecialTypesCntSql)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresSpecialTypesCntRow + { + CUuid = reader.IsDBNull(0) ? null : reader.GetFieldValue(0), + Cnt = reader.GetInt64(1) + }; + } + } + } + } + + return null; } + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = TruncatePostgresGeoTypesSql; + command.CommandText = GetPostgresSpecialTypesCntSql; command.Transaction = this.Transaction; - await command.ExecuteNonQueryAsync(); + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresSpecialTypesCntRow + { + CUuid = reader.IsDBNull(0) ? null : reader.GetFieldValue(0), + Cnt = reader.GetInt64(1) + }; + } + } } + + 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 readonly record struct InsertPostgresArrayTypesArgs(byte[]? CBytea, bool[]? CBooleanArray, string[]? CTextArray, int[]? CIntegerArray, decimal[]? CDecimalArray, DateTime[]? CDateArray, DateTime[]? CTimestampArray); public async Task InsertPostgresArrayTypes(InsertPostgresArrayTypesArgs args) { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(InsertPostgresArrayTypesSql)) { @@ -1273,10 +1915,7 @@ public async Task InsertPostgresArrayTypes(InsertPostgresArrayTypesArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = InsertPostgresArrayTypesSql; @@ -1298,7 +1937,7 @@ public async Task InsertPostgresArrayTypes(InsertPostgresArrayTypesArgs args) { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(GetPostgresArrayTypesSql)) { @@ -1325,10 +1964,7 @@ public async Task InsertPostgresArrayTypes(InsertPostgresArrayTypesArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetPostgresArrayTypesSql; @@ -1354,8 +1990,8 @@ public async Task InsertPostgresArrayTypes(InsertPostgresArrayTypesArgs args) return null; } - private const string InsertPostgresArrayTypesBatchSql = "COPY postgres_array_types (c_bytea) FROM STDIN (FORMAT BINARY)"; - public readonly record struct InsertPostgresArrayTypesBatchArgs(byte[]? CBytea); + private const string InsertPostgresArrayTypesBatchSql = "COPY postgres_array_types (c_bytea, c_boolean_array, c_text_array, c_integer_array, c_decimal_array, c_timestamp_array) FROM STDIN (FORMAT BINARY)"; + public readonly record struct InsertPostgresArrayTypesBatchArgs(byte[]? CBytea, bool[]? CBooleanArray, string[]? CTextArray, int[]? CIntegerArray, decimal[]? CDecimalArray, DateTime[]? CTimestampArray); public async Task InsertPostgresArrayTypesBatch(List args) { using (var connection = new NpgsqlConnection(ConnectionString)) @@ -1367,6 +2003,11 @@ public async Task InsertPostgresArrayTypesBatch(List GetPostgresArrayTypesCnt() { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(GetPostgresArrayTypesCntSql)) { @@ -1393,7 +2034,12 @@ public async Task InsertPostgresArrayTypesBatch(List(0), - Cnt = reader.GetInt64(1) + CBooleanArray = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CTextArray = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + CIntegerArray = reader.IsDBNull(3) ? null : reader.GetFieldValue(3), + CDecimalArray = reader.IsDBNull(4) ? null : reader.GetFieldValue(4), + CTimestampArray = reader.IsDBNull(5) ? null : reader.GetFieldValue(5), + Cnt = reader.GetInt64(6) }; } } @@ -1404,10 +2050,7 @@ public async Task InsertPostgresArrayTypesBatch(List(0), - Cnt = reader.GetInt64(1) + CBooleanArray = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CTextArray = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + CIntegerArray = reader.IsDBNull(3) ? null : reader.GetFieldValue(3), + CDecimalArray = reader.IsDBNull(4) ? null : reader.GetFieldValue(4), + CTimestampArray = reader.IsDBNull(5) ? null : reader.GetFieldValue(5), + Cnt = reader.GetInt64(6) }; } } @@ -1433,7 +2081,7 @@ public async Task TruncatePostgresArrayTypes() { if (this.Transaction == null) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) { using (var command = connection.CreateCommand(TruncatePostgresArrayTypesSql)) { @@ -1445,13 +2093,164 @@ public async Task TruncatePostgresArrayTypes() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncatePostgresArrayTypesSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } + + 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) + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(InsertPostgresGeoTypesSql)) + { + command.Parameters.AddWithValue("@c_point", args.CPoint ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_line", args.CLine ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_lseg", args.CLseg ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_box", args.CBox ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_path", args.CPath ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_polygon", args.CPolygon ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_circle", args.CCircle ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = InsertPostgresGeoTypesSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@c_point", args.CPoint ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_line", args.CLine ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_lseg", args.CLseg ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_box", args.CBox ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_path", args.CPath ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_polygon", args.CPolygon ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_circle", args.CCircle ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + private const string InsertPostgresGeoTypesBatchSql = "COPY postgres_geometric_types (c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle) FROM STDIN (FORMAT BINARY)"; + public readonly record struct InsertPostgresGeoTypesBatchArgs(NpgsqlPoint? CPoint, NpgsqlLine? CLine, NpgsqlLSeg? CLseg, NpgsqlBox? CBox, NpgsqlPath? CPath, NpgsqlPolygon? CPolygon, NpgsqlCircle? CCircle); + public async Task InsertPostgresGeoTypesBatch(List args) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresGeoTypesBatchSql)) + { + foreach (var row in args) + { + await writer.StartRowAsync(); + await writer.WriteAsync(row.CPoint ?? (object)DBNull.Value); + await writer.WriteAsync(row.CLine ?? (object)DBNull.Value); + await writer.WriteAsync(row.CLseg ?? (object)DBNull.Value); + await writer.WriteAsync(row.CBox ?? (object)DBNull.Value); + await writer.WriteAsync(row.CPath ?? (object)DBNull.Value); + await writer.WriteAsync(row.CPolygon ?? (object)DBNull.Value); + await writer.WriteAsync(row.CCircle ?? (object)DBNull.Value); + } + + await writer.CompleteAsync(); + } + + await connection.CloseAsync(); + } + } + + private const string GetPostgresGeoTypesSql = "SELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgres_geometric_types LIMIT 1"; + public readonly record struct GetPostgresGeoTypesRow(NpgsqlPoint? CPoint, NpgsqlLine? CLine, NpgsqlLSeg? CLseg, NpgsqlBox? CBox, NpgsqlPath? CPath, NpgsqlPolygon? CPolygon, NpgsqlCircle? CCircle); + public async Task GetPostgresGeoTypes() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(GetPostgresGeoTypesSql)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresGeoTypesRow + { + CPoint = reader.IsDBNull(0) ? null : reader.GetFieldValue(0), + CLine = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CLseg = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + CBox = reader.IsDBNull(3) ? null : reader.GetFieldValue(3), + CPath = reader.IsDBNull(4) ? null : reader.GetFieldValue(4), + CPolygon = reader.IsDBNull(5) ? null : reader.GetFieldValue(5), + CCircle = reader.IsDBNull(6) ? null : reader.GetFieldValue(6) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresGeoTypesSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresGeoTypesRow + { + CPoint = reader.IsDBNull(0) ? null : reader.GetFieldValue(0), + CLine = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CLseg = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + CBox = reader.IsDBNull(3) ? null : reader.GetFieldValue(3), + CPath = reader.IsDBNull(4) ? null : reader.GetFieldValue(4), + CPolygon = reader.IsDBNull(5) ? null : reader.GetFieldValue(5), + CCircle = reader.IsDBNull(6) ? null : reader.GetFieldValue(6) + }; + } + } + } + + return null; + } + + private const string TruncatePostgresGeoTypesSql = "TRUNCATE TABLE postgres_geometric_types"; + public async Task TruncatePostgresGeoTypes() + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = NpgsqlDataSource.Create(ConnectionString!)) + { + using (var command = connection.CreateCommand(TruncatePostgresGeoTypesSql)) + { + await command.ExecuteNonQueryAsync(); + } + } + + return; } + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = TruncatePostgresArrayTypesSql; + command.CommandText = TruncatePostgresGeoTypesSql; command.Transaction = this.Transaction; await command.ExecuteNonQueryAsync(); } diff --git a/examples/NpgsqlExample/request.json b/examples/NpgsqlExample/request.json index e9e6d63f..570cc70b 100644 --- a/examples/NpgsqlExample/request.json +++ b/examples/NpgsqlExample/request.json @@ -3,15 +3,17 @@ "version": "2", "engine": "postgresql", "schema": [ - "examples/config/postgresql/schema.sql" + "examples/config/postgresql/authors/schema.sql", + "examples/config/postgresql/types/schema.sql" ], "queries": [ - "examples/config/postgresql/query.sql" + "examples/config/postgresql/authors/query.sql", + "examples/config/postgresql/types/query.sql" ], "codegen": { "out": "examples/NpgsqlExample", "plugin": "csharp", - "options": "eyJkZWJ1Z1JlcXVlc3QiOnRydWUsImdlbmVyYXRlQ3Nwcm9qIjp0cnVlLCJuYW1lc3BhY2VOYW1lIjoiTnBnc3FsRXhhbXBsZUdlbiIsIm92ZXJyaWRlcyI6W3siY29sdW1uIjoiR2V0UG9zdGdyZXNGdW5jdGlvbnM6bWF4X2ludGVnZXIiLCJjc2hhcnBfdHlwZSI6eyJub3ROdWxsIjpmYWxzZSwidHlwZSI6ImludCJ9fSx7ImNvbHVtbiI6IkdldFBvc3RncmVzRnVuY3Rpb25zOm1heF92YXJjaGFyIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6ZmFsc2UsInR5cGUiOiJzdHJpbmcifX0seyJjb2x1bW4iOiJHZXRQb3N0Z3Jlc0Z1bmN0aW9uczptYXhfdGltZXN0YW1wIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6dHJ1ZSwidHlwZSI6IkRhdGVUaW1lIn19LHsiY29sdW1uIjoiKjpjX2pzb25fc3RyaW5nX292ZXJyaWRlIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6ZmFsc2UsInR5cGUiOiJzdHJpbmcifX0seyJjb2x1bW4iOiIqOmNfbWFjYWRkcjgiLCJjc2hhcnBfdHlwZSI6eyJub3ROdWxsIjpmYWxzZSwidHlwZSI6InN0cmluZyJ9fV0sInRhcmdldEZyYW1ld29yayI6Im5ldDguMCIsInVzZURhcHBlciI6ZmFsc2V9", + "options": "eyJkZWJ1Z1JlcXVlc3QiOnRydWUsImdlbmVyYXRlQ3Nwcm9qIjp0cnVlLCJuYW1lc3BhY2VOYW1lIjoiTnBnc3FsRXhhbXBsZUdlbiIsIm92ZXJyaWRlcyI6W3siY29sdW1uIjoiR2V0UG9zdGdyZXNGdW5jdGlvbnM6bWF4X2ludGVnZXIiLCJjc2hhcnBfdHlwZSI6eyJub3ROdWxsIjpmYWxzZSwidHlwZSI6ImludCJ9fSx7ImNvbHVtbiI6IkdldFBvc3RncmVzRnVuY3Rpb25zOm1heF92YXJjaGFyIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6ZmFsc2UsInR5cGUiOiJzdHJpbmcifX0seyJjb2x1bW4iOiJHZXRQb3N0Z3Jlc0Z1bmN0aW9uczptYXhfdGltZXN0YW1wIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6dHJ1ZSwidHlwZSI6IkRhdGVUaW1lIn19LHsiY29sdW1uIjoiKjpjX2pzb25fc3RyaW5nX292ZXJyaWRlIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6ZmFsc2UsInR5cGUiOiJzdHJpbmcifX0seyJjb2x1bW4iOiIqOmNfeG1sX3N0cmluZ19vdmVycmlkZSIsImNzaGFycF90eXBlIjp7Im5vdE51bGwiOmZhbHNlLCJ0eXBlIjoic3RyaW5nIn19LHsiY29sdW1uIjoiKjpjX21hY2FkZHI4IiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6ZmFsc2UsInR5cGUiOiJzdHJpbmcifX1dLCJ0YXJnZXRGcmFtZXdvcmsiOiJuZXQ4LjAiLCJ1c2VEYXBwZXIiOmZhbHNlfQ==", "process": { "cmd": "./dist/LocalRunner" } @@ -115,14 +117,14 @@ }, { "rel": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "columns": [ { "name": "c_boolean", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -133,7 +135,7 @@ "name": "c_bit", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -144,7 +146,7 @@ "name": "c_smallint", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -155,7 +157,7 @@ "name": "c_integer", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -166,7 +168,7 @@ "name": "c_bigint", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -177,7 +179,7 @@ "name": "c_decimal", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -188,7 +190,7 @@ "name": "c_numeric", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -199,7 +201,7 @@ "name": "c_real", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -210,7 +212,7 @@ "name": "c_double_precision", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -221,218 +223,272 @@ "name": "c_money", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "money" } - }, + } + ] + }, + { + "rel": { + "name": "postgres_string_types" + }, + "columns": [ { - "name": "c_date", + "name": "c_char", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "date" + "schema": "pg_catalog", + "name": "bpchar" } }, { - "name": "c_time", + "name": "c_varchar", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { "schema": "pg_catalog", - "name": "time" + "name": "varchar" } }, { - "name": "c_timestamp", + "name": "c_character_varying", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { "schema": "pg_catalog", - "name": "timestamp" + "name": "varchar" } }, { - "name": "c_timestamp_with_tz", + "name": "c_bpchar", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "schema": "pg_catalog", - "name": "timestamptz" + "name": "bpchar" } }, { - "name": "c_interval", + "name": "c_text", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "schema": "pg_catalog", - "name": "interval" + "name": "text" + } + } + ] + }, + { + "rel": { + "name": "postgres_datetime_types" + }, + "columns": [ + { + "name": "c_date", + "length": -1, + "table": { + "name": "postgres_datetime_types" + }, + "type": { + "name": "date" } }, { - "name": "c_char", + "name": "c_time", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "bpchar" + "name": "time" } }, { - "name": "c_varchar", + "name": "c_timestamp", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "varchar" + "name": "timestamp" } }, { - "name": "c_character_varying", + "name": "c_timestamp_with_tz", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "varchar" + "name": "timestamptz" } }, { - "name": "c_bpchar", + "name": "c_interval", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "bpchar" + "schema": "pg_catalog", + "name": "interval" } - }, + } + ] + }, + { + "rel": { + "name": "postgres_network_types" + }, + "columns": [ { - "name": "c_text", + "name": "c_cidr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "text" + "name": "cidr" } }, { - "name": "c_json", + "name": "c_inet", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "json" + "name": "inet" } }, { - "name": "c_json_string_override", + "name": "c_macaddr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "json" + "name": "macaddr" } }, { - "name": "c_jsonb", + "name": "c_macaddr8", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "jsonb" + "name": "macaddr8" } - }, + } + ] + }, + { + "rel": { + "name": "postgres_array_types" + }, + "columns": [ { - "name": "c_jsonpath", + "name": "c_bytea", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "jsonpath" + "name": "bytea" } }, { - "name": "c_xml", + "name": "c_boolean_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "xml" - } + "schema": "pg_catalog", + "name": "bool" + }, + "arrayDims": 1 }, { - "name": "c_cidr", + "name": "c_text_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "cidr" - } + "name": "text" + }, + "arrayDims": 1 }, { - "name": "c_inet", + "name": "c_integer_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "inet" - } + "schema": "pg_catalog", + "name": "int4" + }, + "arrayDims": 1 }, { - "name": "c_macaddr", + "name": "c_decimal_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "macaddr" - } + "schema": "pg_catalog", + "name": "numeric" + }, + "arrayDims": 1 }, { - "name": "c_macaddr8", + "name": "c_date_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "macaddr8" - } + "name": "date" + }, + "arrayDims": 1 }, { - "name": "c_uuid", + "name": "c_timestamp_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "uuid" - } + "schema": "pg_catalog", + "name": "timestamp" + }, + "arrayDims": 1 } ] }, @@ -515,97 +571,101 @@ }, { "rel": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "columns": [ { - "name": "c_bytea", + "name": "c_uuid", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "name": "bytea" + "name": "uuid" } }, { - "name": "c_boolean_array", - "isArray": true, + "name": "c_enum", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "schema": "pg_catalog", - "name": "bool" - }, - "arrayDims": 1 + "name": "c_enum" + } }, { - "name": "c_text_array", - "isArray": true, + "name": "c_json", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "name": "text" - }, - "arrayDims": 1 + "name": "json" + } }, { - "name": "c_integer_array", - "isArray": true, + "name": "c_json_string_override", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "schema": "pg_catalog", - "name": "int4" - }, - "arrayDims": 1 + "name": "json" + } }, { - "name": "c_decimal_array", - "isArray": true, + "name": "c_jsonb", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "schema": "pg_catalog", - "name": "numeric" - }, - "arrayDims": 1 + "name": "jsonb" + } }, { - "name": "c_date_array", - "isArray": true, + "name": "c_jsonpath", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "name": "date" - }, - "arrayDims": 1 + "name": "jsonpath" + } }, { - "name": "c_timestamp_array", - "isArray": true, + "name": "c_xml", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "schema": "pg_catalog", - "name": "timestamp" + "name": "xml" + } + }, + { + "name": "c_xml_string_override", + "length": -1, + "table": { + "name": "postgres_special_types" }, - "arrayDims": 1 + "type": { + "name": "xml" + } } ] } + ], + "enums": [ + { + "name": "c_enum", + "vals": [ + "small", + "medium", + "big" + ] + } ] }, { @@ -32449,6 +32509,67 @@ ] } ] + }, + { + "name": "extended", + "tables": [ + { + "rel": { + "schema": "extended", + "name": "bios" + }, + "columns": [ + { + "name": "author_name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + } + }, + { + "name": "name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + } + }, + { + "name": "bio_type", + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "extended", + "name": "bio_type" + } + } + ] + } + ], + "enums": [ + { + "name": "bio_type", + "vals": [ + "Autobiography", + "Biography", + "Memoir" + ] + } + ] } ] }, @@ -33207,8 +33328,174 @@ "filename": "query.sql" }, { - "text": "INSERT INTO postgres_types\n(\n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_real,\n c_numeric,\n c_decimal,\n c_double_precision,\n c_money,\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n c_uuid,\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_cidr,\n c_inet,\n c_macaddr,\n c_macaddr8\n)\nVALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6,\n $7,\n $8,\n $9,\n $10,\n $11,\n $12,\n $13,\n $14,\n $15,\n $16,\n $17,\n $18,\n $19,\n $20,\n $21,\n $22::json, \n $23::json, \n $24::jsonb,\n $25::jsonpath,\n $26::xml,\n $27,\n $28,\n $29::macaddr,\n $30::macaddr8\n)", - "name": "InsertPostgresTypes", + "text": "INSERT INTO extended.bios (author_name, name, bio_type) VALUES ($1, $2, $3)", + "name": "CreateExtendedBio", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "author_name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "pg_catalog.varchar" + }, + "originalName": "author_name" + } + }, + { + "number": 2, + "column": { + "name": "name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "pg_catalog.varchar" + }, + "originalName": "name" + } + }, + { + "number": 3, + "column": { + "name": "bio_type", + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "extended.bio_type" + }, + "originalName": "bio_type" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "schema": "extended", + "name": "bios" + } + }, + { + "text": "SELECT author_name, name, bio_type FROM extended.bios WHERE bio_type = $1 LIMIT 1", + "name": "GetFirstExtendedBioByType", + "cmd": ":one", + "columns": [ + { + "name": "author_name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "author_name" + }, + { + "name": "name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "name" + }, + { + "name": "bio_type", + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "extended", + "name": "bio_type" + }, + "originalName": "bio_type" + } + ], + "parameters": [ + { + "number": 1, + "column": { + "name": "bio_type", + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "extended.bio_type" + }, + "originalName": "bio_type" + } + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE extended.bios", + "name": "TruncateExtendedBios", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "SELECT\n MAX(c_integer) AS max_integer,\n MAX(c_varchar) AS max_varchar,\n MAX(c_timestamp) AS max_timestamp\nFROM postgres_datetime_types\nCROSS JOIN postgres_numeric_types\nCROSS JOIN postgres_string_types", + "name": "GetPostgresFunctions", + "cmd": ":one", + "columns": [ + { + "name": "max_integer", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "anyarray" + } + }, + { + "name": "max_varchar", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "anyarray" + } + }, + { + "name": "max_timestamp", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "anyarray" + } + } + ], + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO postgres_numeric_types\n(\n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_decimal,\n c_numeric,\n c_real,\n c_double_precision,\n c_money\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", + "name": "InsertPostgresNumericTypes", "cmd": ":exec", "parameters": [ { @@ -33216,10 +33503,9 @@ "column": { "name": "c_boolean", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.bool" @@ -33232,10 +33518,9 @@ "column": { "name": "c_bit", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.bit" @@ -33248,10 +33533,9 @@ "column": { "name": "c_smallint", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.int2" @@ -33264,10 +33548,9 @@ "column": { "name": "c_integer", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.int4" @@ -33280,10 +33563,9 @@ "column": { "name": "c_bigint", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.int8" @@ -33294,17 +33576,16 @@ { "number": 6, "column": { - "name": "c_real", + "name": "c_decimal", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.float4" + "name": "pg_catalog.numeric" }, - "originalName": "c_real" + "originalName": "c_decimal" } }, { @@ -33312,10 +33593,9 @@ "column": { "name": "c_numeric", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.numeric" @@ -33326,17 +33606,16 @@ { "number": 8, "column": { - "name": "c_decimal", + "name": "c_real", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.numeric" + "name": "pg_catalog.float4" }, - "originalName": "c_decimal" + "originalName": "c_real" } }, { @@ -33344,10 +33623,9 @@ "column": { "name": "c_double_precision", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.float8" @@ -33360,914 +33638,1509 @@ "column": { "name": "c_money", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "money" }, "originalName": "c_money" } + } + ], + "comments": [ + " Numeric types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_numeric_types" + } + }, + { + "text": "SELECT c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money FROM postgres_numeric_types LIMIT 1", + "name": "GetPostgresNumericTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_boolean", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bool" + }, + "originalName": "c_boolean" + }, + { + "name": "c_bit", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bit" + }, + "originalName": "c_bit" + }, + { + "name": "c_smallint", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int2" + }, + "originalName": "c_smallint" + }, + { + "name": "c_integer", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int4" + }, + "originalName": "c_integer" + }, + { + "name": "c_bigint", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int8" + }, + "originalName": "c_bigint" + }, + { + "name": "c_decimal", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "numeric" + }, + "originalName": "c_decimal" + }, + { + "name": "c_numeric", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "numeric" + }, + "originalName": "c_numeric" + }, + { + "name": "c_real", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "float4" + }, + "originalName": "c_real" + }, + { + "name": "c_double_precision", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "float8" + }, + "originalName": "c_double_precision" + }, + { + "name": "c_money", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "name": "money" + }, + "originalName": "c_money" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_numeric_types", + "name": "TruncatePostgresNumericTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "SELECT\n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_decimal,\n c_numeric,\n c_real,\n c_double_precision,\n c_money,\n COUNT(*) AS cnt\nFROM postgres_numeric_types\nGROUP BY\n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_decimal,\n c_numeric,\n c_real,\n c_double_precision,\n c_money\nLIMIT 1", + "name": "GetPostgresNumericTypesCnt", + "cmd": ":one", + "columns": [ + { + "name": "c_boolean", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bool" + }, + "originalName": "c_boolean" + }, + { + "name": "c_bit", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bit" + }, + "originalName": "c_bit" + }, + { + "name": "c_smallint", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int2" + }, + "originalName": "c_smallint" + }, + { + "name": "c_integer", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int4" + }, + "originalName": "c_integer" + }, + { + "name": "c_bigint", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int8" + }, + "originalName": "c_bigint" + }, + { + "name": "c_decimal", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "numeric" + }, + "originalName": "c_decimal" + }, + { + "name": "c_numeric", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "numeric" + }, + "originalName": "c_numeric" + }, + { + "name": "c_real", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "float4" + }, + "originalName": "c_real" + }, + { + "name": "c_double_precision", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "float8" + }, + "originalName": "c_double_precision" + }, + { + "name": "c_money", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "name": "money" + }, + "originalName": "c_money" }, { - "number": 11, + "name": "cnt", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "bigint" + } + } + ], + "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_numeric_types\n(\n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_decimal,\n c_numeric,\n c_real,\n c_double_precision,\n c_money\n) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", + "name": "InsertPostgresNumericTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, "column": { - "name": "c_date", + "name": "c_boolean", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "date" + "name": "pg_catalog.bool" }, - "originalName": "c_date" + "originalName": "c_boolean" } }, { - "number": 12, + "number": 2, "column": { - "name": "c_time", + "name": "c_bit", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.time" + "name": "pg_catalog.bit" }, - "originalName": "c_time" + "originalName": "c_bit" } }, { - "number": 13, + "number": 3, "column": { - "name": "c_timestamp", + "name": "c_smallint", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.timestamp" + "name": "pg_catalog.int2" }, - "originalName": "c_timestamp" + "originalName": "c_smallint" } }, { - "number": 14, + "number": 4, "column": { - "name": "c_timestamp_with_tz", + "name": "c_integer", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.timestamptz" + "name": "pg_catalog.int4" }, - "originalName": "c_timestamp_with_tz" + "originalName": "c_integer" } }, { - "number": 15, + "number": 5, "column": { - "name": "c_interval", + "name": "c_bigint", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.interval" + "name": "pg_catalog.int8" }, - "originalName": "c_interval" + "originalName": "c_bigint" } }, { - "number": 16, + "number": 6, "column": { - "name": "c_char", + "name": "c_decimal", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.bpchar" + "name": "pg_catalog.numeric" }, - "originalName": "c_char" + "originalName": "c_decimal" } }, { - "number": 17, + "number": 7, "column": { - "name": "c_varchar", + "name": "c_numeric", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.varchar" + "name": "pg_catalog.numeric" }, - "originalName": "c_varchar" + "originalName": "c_numeric" } }, { - "number": 18, + "number": 8, "column": { - "name": "c_character_varying", + "name": "c_real", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.varchar" + "name": "pg_catalog.float4" }, - "originalName": "c_character_varying" + "originalName": "c_real" } }, { - "number": 19, + "number": 9, "column": { - "name": "c_bpchar", + "name": "c_double_precision", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "bpchar" + "name": "pg_catalog.float8" }, - "originalName": "c_bpchar" + "originalName": "c_double_precision" } }, { - "number": 20, + "number": 10, "column": { - "name": "c_text", + "name": "c_money", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "text" + "name": "money" }, - "originalName": "c_text" + "originalName": "c_money" } - }, + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_numeric_types" + } + }, + { + "text": "\nINSERT INTO postgres_string_types\n(\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text\n)\nVALUES ($1, $2, $3, $4, $5)", + "name": "InsertPostgresStringTypes", + "cmd": ":exec", + "parameters": [ { - "number": 21, + "number": 1, "column": { - "name": "c_uuid", + "name": "c_char", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "uuid" + "name": "pg_catalog.bpchar" }, - "originalName": "c_uuid" + "originalName": "c_char" } }, { - "number": 22, + "number": 2, "column": { - "name": "c_json", + "name": "c_varchar", "length": -1, + "table": { + "schema": "public", + "name": "postgres_string_types" + }, "type": { - "name": "json" - } + "name": "pg_catalog.varchar" + }, + "originalName": "c_varchar" } }, { - "number": 23, - "column": { - "name": "c_json_string_override", - "length": -1, - "type": { - "name": "json" - } - } - }, - { - "number": 24, - "column": { - "name": "c_jsonb", - "length": -1, - "type": { - "name": "jsonb" - } - } - }, - { - "number": 25, - "column": { - "name": "c_jsonpath", - "length": -1, - "type": { - "name": "jsonpath" - } - } - }, - { - "number": 26, - "column": { - "name": "c_xml", - "length": -1, - "type": { - "name": "xml" - } - } - }, - { - "number": 27, + "number": 3, "column": { - "name": "c_cidr", + "name": "c_character_varying", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "cidr" + "name": "pg_catalog.varchar" }, - "originalName": "c_cidr" + "originalName": "c_character_varying" } }, { - "number": 28, + "number": 4, "column": { - "name": "c_inet", + "name": "c_bpchar", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "inet" + "name": "bpchar" }, - "originalName": "c_inet" - } - }, - { - "number": 29, - "column": { - "name": "c_macaddr", - "length": -1, - "type": { - "name": "macaddr" - } + "originalName": "c_bpchar" } }, { - "number": 30, + "number": 5, "column": { - "name": "c_macaddr8", + "name": "c_text", "length": -1, + "table": { + "schema": "public", + "name": "postgres_string_types" + }, "type": { - "name": "macaddr8" - } + "name": "text" + }, + "originalName": "c_text" } } ], + "comments": [ + " String types " + ], "filename": "query.sql", "insert_into_table": { - "name": "postgres_types" + "name": "postgres_string_types" } }, { - "text": "INSERT INTO postgres_types\n(\n c_boolean,\n c_smallint,\n c_integer,\n c_bigint,\n c_real,\n c_numeric,\n c_decimal,\n c_double_precision,\n c_money,\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n c_uuid,\n c_cidr,\n c_inet,\n c_macaddr\n)\nVALUES (\n $1, \n $2, \n $3, \n $4, \n $5, \n $6, \n $7, \n $8, \n $9, \n $10, \n $11, \n $12, \n $13, \n $14, \n $15, \n $16, \n $17, \n $18,\n $19,\n $20,\n $21,\n $22,\n $23\n)", - "name": "InsertPostgresTypesBatch", + "text": "INSERT INTO postgres_string_types \n(\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text\n) VALUES ($1, $2, $3, $4, $5)", + "name": "InsertPostgresStringTypesBatch", "cmd": ":copyfrom", "parameters": [ { "number": 1, "column": { - "name": "c_boolean", + "name": "c_char", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "pg_catalog.bool" + "name": "pg_catalog.bpchar" }, - "originalName": "c_boolean" + "originalName": "c_char" } }, { "number": 2, "column": { - "name": "c_smallint", + "name": "c_varchar", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "pg_catalog.int2" + "name": "pg_catalog.varchar" }, - "originalName": "c_smallint" + "originalName": "c_varchar" } }, { "number": 3, "column": { - "name": "c_integer", + "name": "c_character_varying", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "pg_catalog.int4" + "name": "pg_catalog.varchar" }, - "originalName": "c_integer" + "originalName": "c_character_varying" } }, { "number": 4, "column": { - "name": "c_bigint", + "name": "c_bpchar", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "pg_catalog.int8" + "name": "bpchar" }, - "originalName": "c_bigint" + "originalName": "c_bpchar" } }, { "number": 5, "column": { - "name": "c_real", + "name": "c_text", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "pg_catalog.float4" + "name": "text" }, - "originalName": "c_real" + "originalName": "c_text" } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_string_types" + } + }, + { + "text": "SELECT c_char, c_varchar, c_character_varying, c_bpchar, c_text FROM postgres_string_types LIMIT 1", + "name": "GetPostgresStringTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_char", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bpchar" + }, + "originalName": "c_char" }, { - "number": 6, - "column": { - "name": "c_numeric", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.numeric" - }, - "originalName": "c_numeric" - } + "name": "c_varchar", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "c_varchar" }, { - "number": 7, - "column": { - "name": "c_decimal", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.numeric" - }, - "originalName": "c_decimal" - } + "name": "c_character_varying", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "c_character_varying" }, { - "number": 8, - "column": { - "name": "c_double_precision", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.float8" - }, - "originalName": "c_double_precision" - } + "name": "c_bpchar", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "name": "bpchar" + }, + "originalName": "c_bpchar" }, { - "number": 9, - "column": { - "name": "c_money", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "money" - }, - "originalName": "c_money" - } + "name": "c_text", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "name": "text" + }, + "originalName": "c_text" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_string_types", + "name": "TruncatePostgresStringTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "SELECT\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n COUNT(*) AS cnt\nFROM postgres_string_types\nGROUP BY\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text\nLIMIT 1", + "name": "GetPostgresStringTypesCnt", + "cmd": ":one", + "columns": [ + { + "name": "c_char", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bpchar" + }, + "originalName": "c_char" }, { - "number": 10, - "column": { - "name": "c_date", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "date" - }, - "originalName": "c_date" - } + "name": "c_varchar", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "c_varchar" }, { - "number": 11, - "column": { - "name": "c_time", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.time" - }, - "originalName": "c_time" - } + "name": "c_character_varying", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "c_character_varying" }, { - "number": 12, - "column": { - "name": "c_timestamp", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.timestamp" - }, - "originalName": "c_timestamp" - } + "name": "c_bpchar", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "name": "bpchar" + }, + "originalName": "c_bpchar" }, { - "number": 13, - "column": { - "name": "c_timestamp_with_tz", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.timestamptz" - }, - "originalName": "c_timestamp_with_tz" - } + "name": "c_text", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "name": "text" + }, + "originalName": "c_text" }, { - "number": 14, - "column": { - "name": "c_interval", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.interval" - }, - "originalName": "c_interval" + "name": "cnt", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "bigint" } + } + ], + "filename": "query.sql" + }, + { + "text": "WITH txt_query AS (\n SELECT \n c_text, \n to_tsquery('english', $1) AS query,\n to_tsvector('english', c_text) AS tsv\n FROM postgres_string_types \n WHERE c_text @@ to_tsquery('english', $1)\n)\n\nSELECT txt_query.c_text, txt_query.query, txt_query.tsv, ts_rank(tsv, query) AS rnk\nFROM txt_query\nORDER BY rnk DESC\nLIMIT 1", + "name": "GetPostgresStringTypesTextSearch", + "cmd": ":one", + "columns": [ + { + "name": "c_text", + "length": -1, + "table": { + "name": "txt_query" + }, + "type": { + "name": "text" + }, + "originalName": "c_text" }, { - "number": 15, - "column": { - "name": "c_char", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.bpchar" - }, - "originalName": "c_char" - } + "name": "query", + "notNull": true, + "length": -1, + "table": { + "name": "txt_query" + }, + "type": { + "name": "tsquery" + }, + "originalName": "query" }, { - "number": 16, - "column": { - "name": "c_varchar", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.varchar" - }, - "originalName": "c_varchar" - } + "name": "tsv", + "notNull": true, + "length": -1, + "table": { + "name": "txt_query" + }, + "type": { + "name": "tsvector" + }, + "originalName": "tsv" }, { - "number": 17, - "column": { - "name": "c_character_varying", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.varchar" - }, - "originalName": "c_character_varying" + "name": "rnk", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "real" } - }, + } + ], + "parameters": [ { - "number": 18, + "number": 1, "column": { - "name": "c_bpchar", + "name": "to_tsquery", + "notNull": true, "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, "type": { - "name": "bpchar" - }, - "originalName": "c_bpchar" + "name": "text" + } } - }, + } + ], + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO postgres_datetime_types\n(\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval\n) VALUES ($1, $2, $3, $4, $5)", + "name": "InsertPostgresDateTimeTypes", + "cmd": ":exec", + "parameters": [ { - "number": 19, + "number": 1, "column": { - "name": "c_text", + "name": "c_date", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "text" + "name": "date" }, - "originalName": "c_text" + "originalName": "c_date" } }, { - "number": 20, + "number": 2, "column": { - "name": "c_uuid", + "name": "c_time", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "uuid" + "name": "pg_catalog.time" }, - "originalName": "c_uuid" + "originalName": "c_time" } }, { - "number": 21, + "number": 3, "column": { - "name": "c_cidr", + "name": "c_timestamp", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "cidr" + "name": "pg_catalog.timestamp" }, - "originalName": "c_cidr" + "originalName": "c_timestamp" } }, { - "number": 22, + "number": 4, "column": { - "name": "c_inet", + "name": "c_timestamp_with_tz", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "inet" + "name": "pg_catalog.timestamptz" }, - "originalName": "c_inet" + "originalName": "c_timestamp_with_tz" } }, { - "number": 23, + "number": 5, "column": { - "name": "c_macaddr", + "name": "c_interval", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "macaddr" + "name": "pg_catalog.interval" }, - "originalName": "c_macaddr" + "originalName": "c_interval" } } ], + "comments": [ + " DateTime types " + ], "filename": "query.sql", "insert_into_table": { - "name": "postgres_types" + "name": "postgres_datetime_types" } }, { - "text": "SELECT \n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_real,\n c_numeric,\n c_decimal,\n c_double_precision,\n c_money,\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n c_uuid,\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_cidr,\n c_inet,\n c_macaddr,\n c_macaddr8::TEXT AS c_macaddr8\nFROM postgres_types \nLIMIT 1", - "name": "GetPostgresTypes", + "text": "SELECT c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval FROM postgres_datetime_types LIMIT 1", + "name": "GetPostgresDateTimeTypes", "cmd": ":one", "columns": [ { - "name": "c_boolean", + "name": "c_date", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "schema": "pg_catalog", - "name": "bool" + "name": "date" }, - "originalName": "c_boolean" + "originalName": "c_date" }, { - "name": "c_bit", + "name": "c_time", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "bit" + "name": "time" }, - "originalName": "c_bit" + "originalName": "c_time" }, { - "name": "c_smallint", + "name": "c_timestamp", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "int2" + "name": "timestamp" }, - "originalName": "c_smallint" + "originalName": "c_timestamp" }, { - "name": "c_integer", + "name": "c_timestamp_with_tz", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "int4" + "name": "timestamptz" }, - "originalName": "c_integer" + "originalName": "c_timestamp_with_tz" }, { - "name": "c_bigint", + "name": "c_interval", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "int8" + "name": "interval" }, - "originalName": "c_bigint" - }, + "originalName": "c_interval" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_datetime_types", + "name": "TruncatePostgresDateTimeTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "SELECT\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n COUNT(*) AS cnt\nFROM postgres_datetime_types\nGROUP BY\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval\nLIMIT 1", + "name": "GetPostgresDateTimeTypesCnt", + "cmd": ":one", + "columns": [ { - "name": "c_real", + "name": "c_date", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "schema": "pg_catalog", - "name": "float4" + "name": "date" }, - "originalName": "c_real" + "originalName": "c_date" }, { - "name": "c_numeric", + "name": "c_time", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "numeric" + "name": "time" }, - "originalName": "c_numeric" + "originalName": "c_time" }, { - "name": "c_decimal", + "name": "c_timestamp", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "numeric" + "name": "timestamp" }, - "originalName": "c_decimal" + "originalName": "c_timestamp" }, { - "name": "c_double_precision", + "name": "c_timestamp_with_tz", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "float8" + "name": "timestamptz" }, - "originalName": "c_double_precision" + "originalName": "c_timestamp_with_tz" }, { - "name": "c_money", + "name": "c_interval", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "money" + "schema": "pg_catalog", + "name": "interval" }, - "originalName": "c_money" + "originalName": "c_interval" }, { - "name": "c_date", + "name": "cnt", + "notNull": true, "length": -1, - "table": { - "name": "postgres_types" - }, + "isFuncCall": true, "type": { - "name": "date" - }, - "originalName": "c_date" + "name": "bigint" + } + } + ], + "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_datetime_types\n(\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval\n) VALUES ($1, $2, $3, $4, $5)", + "name": "InsertPostgresDateTimeTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_date", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_datetime_types" + }, + "type": { + "name": "date" + }, + "originalName": "c_date" + } }, { - "name": "c_time", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "time" - }, - "originalName": "c_time" + "number": 2, + "column": { + "name": "c_time", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_datetime_types" + }, + "type": { + "name": "pg_catalog.time" + }, + "originalName": "c_time" + } }, { - "name": "c_timestamp", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "timestamp" - }, - "originalName": "c_timestamp" + "number": 3, + "column": { + "name": "c_timestamp", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_datetime_types" + }, + "type": { + "name": "pg_catalog.timestamp" + }, + "originalName": "c_timestamp" + } }, { - "name": "c_timestamp_with_tz", + "number": 4, + "column": { + "name": "c_timestamp_with_tz", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_datetime_types" + }, + "type": { + "name": "pg_catalog.timestamptz" + }, + "originalName": "c_timestamp_with_tz" + } + }, + { + "number": 5, + "column": { + "name": "c_interval", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_datetime_types" + }, + "type": { + "name": "pg_catalog.interval" + }, + "originalName": "c_interval" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_datetime_types" + } + }, + { + "text": "\nINSERT INTO postgres_network_types\n(\n c_cidr,\n c_inet,\n c_macaddr,\n c_macaddr8\n) VALUES (\n $1, \n $2, \n $3, \n $4::macaddr8\n)", + "name": "InsertPostgresNetworkTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_cidr", + "length": -1, + "isNamedParam": true, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "cidr" + }, + "originalName": "c_cidr" + } + }, + { + "number": 2, + "column": { + "name": "c_inet", + "length": -1, + "isNamedParam": true, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "inet" + }, + "originalName": "c_inet" + } + }, + { + "number": 3, + "column": { + "name": "c_macaddr", + "length": -1, + "isNamedParam": true, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "macaddr" + }, + "originalName": "c_macaddr" + } + }, + { + "number": 4, + "column": { + "name": "c_macaddr8", + "length": -1, + "type": { + "name": "macaddr8" + } + } + } + ], + "comments": [ + " Network types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_network_types" + } + }, + { + "text": "SELECT\n c_cidr,\n c_inet,\n c_macaddr,\n c_macaddr8::TEXT AS c_macaddr8\nFROM postgres_network_types\nLIMIT 1", + "name": "GetPostgresNetworkTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_cidr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "schema": "pg_catalog", - "name": "timestamptz" + "name": "cidr" }, - "originalName": "c_timestamp_with_tz" + "originalName": "c_cidr" }, { - "name": "c_interval", + "name": "c_inet", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "schema": "pg_catalog", - "name": "interval" + "name": "inet" }, - "originalName": "c_interval" + "originalName": "c_inet" }, { - "name": "c_char", + "name": "c_macaddr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "schema": "pg_catalog", - "name": "bpchar" + "name": "macaddr" }, - "originalName": "c_char" + "originalName": "c_macaddr" }, { - "name": "c_varchar", + "name": "c_macaddr8", + "notNull": true, "length": -1, - "table": { - "name": "postgres_types" - }, "type": { - "schema": "pg_catalog", - "name": "varchar" - }, - "originalName": "c_varchar" - }, + "name": "text" + } + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_network_types", + "name": "TruncatePostgresNetworkTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "SELECT\n c_cidr,\n c_inet,\n c_macaddr,\n COUNT(*) AS cnt\nFROM postgres_network_types\nGROUP BY\n c_cidr,\n c_inet,\n c_macaddr\nLIMIT 1", + "name": "GetPostgresNetworkTypesCnt", + "cmd": ":one", + "columns": [ { - "name": "c_character_varying", + "name": "c_cidr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "schema": "pg_catalog", - "name": "varchar" + "name": "cidr" }, - "originalName": "c_character_varying" + "originalName": "c_cidr" }, { - "name": "c_bpchar", + "name": "c_inet", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "bpchar" + "name": "inet" }, - "originalName": "c_bpchar" + "originalName": "c_inet" }, { - "name": "c_text", + "name": "c_macaddr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "text" + "name": "macaddr" }, - "originalName": "c_text" + "originalName": "c_macaddr" }, { - "name": "c_uuid", + "name": "cnt", + "notNull": true, "length": -1, - "table": { - "name": "postgres_types" - }, + "isFuncCall": true, "type": { - "name": "uuid" - }, - "originalName": "c_uuid" + "name": "bigint" + } + } + ], + "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_network_types\n(\n c_cidr,\n c_inet,\n c_macaddr\n) VALUES ($1, $2, $3)", + "name": "InsertPostgresNetworkTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_cidr", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "cidr" + }, + "originalName": "c_cidr" + } + }, + { + "number": 2, + "column": { + "name": "c_inet", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "inet" + }, + "originalName": "c_inet" + } + }, + { + "number": 3, + "column": { + "name": "c_macaddr", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "macaddr" + }, + "originalName": "c_macaddr" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_network_types" + } + }, + { + "text": "\nINSERT INTO postgres_special_types\n(\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum\n)\nVALUES (\n $1::json, \n $2::json, \n $3::jsonb,\n $4::jsonpath,\n $5::xml,\n $6::xml,\n $7,\n $8::c_enum\n)", + "name": "InsertPostgresSpecialTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_json", + "length": -1, + "type": { + "name": "json" + } + } + }, + { + "number": 2, + "column": { + "name": "c_json_string_override", + "length": -1, + "type": { + "name": "json" + } + } + }, + { + "number": 3, + "column": { + "name": "c_jsonb", + "length": -1, + "type": { + "name": "jsonb" + } + } + }, + { + "number": 4, + "column": { + "name": "c_jsonpath", + "length": -1, + "type": { + "name": "jsonpath" + } + } + }, + { + "number": 5, + "column": { + "name": "c_xml", + "length": -1, + "type": { + "name": "xml" + } + } + }, + { + "number": 6, + "column": { + "name": "c_xml_string_override", + "length": -1, + "type": { + "name": "xml" + } + } }, + { + "number": 7, + "column": { + "name": "c_uuid", + "length": -1, + "isNamedParam": true, + "table": { + "schema": "public", + "name": "postgres_special_types" + }, + "type": { + "name": "uuid" + }, + "originalName": "c_uuid" + } + }, + { + "number": 8, + "column": { + "name": "c_enum", + "length": -1, + "type": { + "name": "c_enum" + } + } + } + ], + "comments": [ + " Special types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_special_types" + } + }, + { + "text": "SELECT\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum\nFROM postgres_special_types \nLIMIT 1", + "name": "GetPostgresSpecialTypes", + "cmd": ":one", + "columns": [ { "name": "c_json", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { "name": "json" @@ -34278,7 +35151,7 @@ "name": "c_json_string_override", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { "name": "json" @@ -34289,7 +35162,7 @@ "name": "c_jsonb", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { "name": "jsonb" @@ -34300,7 +35173,7 @@ "name": "c_jsonpath", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { "name": "jsonpath" @@ -34311,7 +35184,7 @@ "name": "c_xml", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { "name": "xml" @@ -34319,321 +35192,528 @@ "originalName": "c_xml" }, { - "name": "c_cidr", + "name": "c_xml_string_override", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { - "name": "cidr" + "name": "xml" }, - "originalName": "c_cidr" + "originalName": "c_xml_string_override" }, { - "name": "c_inet", + "name": "c_uuid", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { - "name": "inet" + "name": "uuid" }, - "originalName": "c_inet" + "originalName": "c_uuid" }, { - "name": "c_macaddr", + "name": "c_enum", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { - "name": "macaddr" + "name": "c_enum" }, - "originalName": "c_macaddr" - }, + "originalName": "c_enum" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_special_types", + "name": "TruncatePostgresSpecialTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_special_types\n(\n c_uuid\n)\nVALUES (\n $1\n)", + "name": "InsertPostgresSpecialTypesBatch", + "cmd": ":copyfrom", + "parameters": [ { - "name": "c_macaddr8", - "notNull": true, - "length": -1, - "type": { - "name": "text" + "number": 1, + "column": { + "name": "c_uuid", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_special_types" + }, + "type": { + "name": "uuid" + }, + "originalName": "c_uuid" } } ], - "filename": "query.sql" + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_special_types" + } }, { - "text": "SELECT\n c_smallint,\n c_boolean,\n c_integer,\n c_bigint,\n c_real,\n c_numeric,\n c_decimal,\n c_double_precision,\n c_money,\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n c_uuid,\n c_cidr,\n c_inet,\n c_macaddr,\n COUNT(*) AS cnt\nFROM postgres_types\nGROUP BY\n c_smallint,\n c_boolean,\n c_integer,\n c_bigint,\n c_real,\n c_numeric,\n c_decimal,\n c_double_precision,\n c_money,\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n c_uuid,\n c_cidr,\n c_inet,\n c_macaddr\nLIMIT 1", - "name": "GetPostgresTypesCnt", + "text": "SELECT\n c_uuid,\n COUNT(*) AS cnt\nFROM postgres_special_types\nGROUP BY\n c_uuid\nLIMIT 1", + "name": "GetPostgresSpecialTypesCnt", "cmd": ":one", "columns": [ { - "name": "c_smallint", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "int2" - }, - "originalName": "c_smallint" - }, - { - "name": "c_boolean", + "name": "c_uuid", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { - "schema": "pg_catalog", - "name": "bool" + "name": "uuid" }, - "originalName": "c_boolean" + "originalName": "c_uuid" }, { - "name": "c_integer", + "name": "cnt", + "notNull": true, "length": -1, - "table": { - "name": "postgres_types" - }, + "isFuncCall": true, "type": { - "schema": "pg_catalog", - "name": "int4" - }, - "originalName": "c_integer" - }, + "name": "bigint" + } + } + ], + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO postgres_array_types\n(\n c_bytea,\n c_boolean_array,\n c_text_array,\n c_integer_array,\n c_decimal_array,\n c_date_array,\n c_timestamp_array\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", + "name": "InsertPostgresArrayTypes", + "cmd": ":exec", + "parameters": [ { - "name": "c_bigint", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "int8" - }, - "originalName": "c_bigint" + "number": 1, + "column": { + "name": "c_bytea", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "bytea" + }, + "originalName": "c_bytea" + } }, { - "name": "c_real", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "float4" - }, - "originalName": "c_real" + "number": 2, + "column": { + "name": "c_boolean_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.bool" + }, + "originalName": "c_boolean_array", + "arrayDims": 1 + } }, { - "name": "c_numeric", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "numeric" - }, - "originalName": "c_numeric" + "number": 3, + "column": { + "name": "c_text_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "text" + }, + "originalName": "c_text_array", + "arrayDims": 1 + } }, { - "name": "c_decimal", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "numeric" - }, - "originalName": "c_decimal" + "number": 4, + "column": { + "name": "c_integer_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.int4" + }, + "originalName": "c_integer_array", + "arrayDims": 1 + } }, { - "name": "c_double_precision", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "float8" - }, - "originalName": "c_double_precision" + "number": 5, + "column": { + "name": "c_decimal_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.numeric" + }, + "originalName": "c_decimal_array", + "arrayDims": 1 + } }, { - "name": "c_money", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "name": "money" - }, - "originalName": "c_money" + "number": 6, + "column": { + "name": "c_date_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "date" + }, + "originalName": "c_date_array", + "arrayDims": 1 + } }, { - "name": "c_date", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "name": "date" - }, - "originalName": "c_date" - }, + "number": 7, + "column": { + "name": "c_timestamp_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.timestamp" + }, + "originalName": "c_timestamp_array", + "arrayDims": 1 + } + } + ], + "comments": [ + " Array types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_array_types" + } + }, + { + "text": "SELECT c_bytea, c_boolean_array, c_text_array, c_integer_array, c_decimal_array, c_date_array, c_timestamp_array FROM postgres_array_types LIMIT 1", + "name": "GetPostgresArrayTypes", + "cmd": ":one", + "columns": [ { - "name": "c_time", + "name": "c_bytea", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "schema": "pg_catalog", - "name": "time" + "name": "bytea" }, - "originalName": "c_time" + "originalName": "c_bytea" }, { - "name": "c_timestamp", + "name": "c_boolean_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { "schema": "pg_catalog", - "name": "timestamp" + "name": "bool" }, - "originalName": "c_timestamp" + "originalName": "c_boolean_array", + "arrayDims": 1 }, { - "name": "c_timestamp_with_tz", + "name": "c_text_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "schema": "pg_catalog", - "name": "timestamptz" + "name": "text" }, - "originalName": "c_timestamp_with_tz" + "originalName": "c_text_array", + "arrayDims": 1 }, { - "name": "c_interval", + "name": "c_integer_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { "schema": "pg_catalog", - "name": "interval" + "name": "int4" }, - "originalName": "c_interval" + "originalName": "c_integer_array", + "arrayDims": 1 }, { - "name": "c_char", + "name": "c_decimal_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { "schema": "pg_catalog", - "name": "bpchar" + "name": "numeric" }, - "originalName": "c_char" + "originalName": "c_decimal_array", + "arrayDims": 1 }, { - "name": "c_varchar", + "name": "c_date_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, - "type": { - "schema": "pg_catalog", - "name": "varchar" + "type": { + "name": "date" }, - "originalName": "c_varchar" + "originalName": "c_date_array", + "arrayDims": 1 }, { - "name": "c_character_varying", + "name": "c_timestamp_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { "schema": "pg_catalog", - "name": "varchar" + "name": "timestamp" }, - "originalName": "c_character_varying" + "originalName": "c_timestamp_array", + "arrayDims": 1 + } + ], + "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_array_types (\n c_bytea,\n c_boolean_array,\n c_text_array,\n c_integer_array,\n c_decimal_array,\n c_timestamp_array\n) \nVALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6\n)", + "name": "InsertPostgresArrayTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_bytea", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "bytea" + }, + "originalName": "c_bytea" + } }, { - "name": "c_bpchar", + "number": 2, + "column": { + "name": "c_boolean_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.bool" + }, + "originalName": "c_boolean_array", + "arrayDims": 1 + } + }, + { + "number": 3, + "column": { + "name": "c_text_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "text" + }, + "originalName": "c_text_array", + "arrayDims": 1 + } + }, + { + "number": 4, + "column": { + "name": "c_integer_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.int4" + }, + "originalName": "c_integer_array", + "arrayDims": 1 + } + }, + { + "number": 5, + "column": { + "name": "c_decimal_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.numeric" + }, + "originalName": "c_decimal_array", + "arrayDims": 1 + } + }, + { + "number": 6, + "column": { + "name": "c_timestamp_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.timestamp" + }, + "originalName": "c_timestamp_array", + "arrayDims": 1 + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_array_types" + } + }, + { + "text": "SELECT\n c_bytea,\n c_boolean_array,\n c_text_array,\n c_integer_array,\n c_decimal_array,\n c_timestamp_array,\n COUNT(*) AS cnt\nFROM postgres_array_types\nGROUP BY\n c_bytea,\n c_boolean_array,\n c_text_array,\n c_integer_array,\n c_decimal_array,\n c_timestamp_array\nLIMIT 1", + "name": "GetPostgresArrayTypesCnt", + "cmd": ":one", + "columns": [ + { + "name": "c_bytea", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "bpchar" + "name": "bytea" }, - "originalName": "c_bpchar" + "originalName": "c_bytea" }, { - "name": "c_text", + "name": "c_boolean_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "text" + "schema": "pg_catalog", + "name": "bool" }, - "originalName": "c_text" + "originalName": "c_boolean_array", + "arrayDims": 1 }, { - "name": "c_uuid", + "name": "c_text_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "uuid" + "name": "text" }, - "originalName": "c_uuid" + "originalName": "c_text_array", + "arrayDims": 1 }, { - "name": "c_cidr", + "name": "c_integer_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "cidr" + "schema": "pg_catalog", + "name": "int4" }, - "originalName": "c_cidr" + "originalName": "c_integer_array", + "arrayDims": 1 }, { - "name": "c_inet", + "name": "c_decimal_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "inet" + "schema": "pg_catalog", + "name": "numeric" }, - "originalName": "c_inet" + "originalName": "c_decimal_array", + "arrayDims": 1 }, { - "name": "c_macaddr", + "name": "c_timestamp_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "macaddr" + "schema": "pg_catalog", + "name": "timestamp" }, - "originalName": "c_macaddr" + "originalName": "c_timestamp_array", + "arrayDims": 1 }, { "name": "cnt", @@ -34648,42 +35728,13 @@ "filename": "query.sql" }, { - "text": "SELECT\n MAX(c_integer) AS max_integer,\n MAX(c_varchar) AS max_varchar,\n MAX(c_timestamp) AS max_timestamp\nFROM postgres_types", - "name": "GetPostgresFunctions", - "cmd": ":one", - "columns": [ - { - "name": "max_integer", - "notNull": true, - "length": -1, - "isFuncCall": true, - "type": { - "name": "anyarray" - } - }, - { - "name": "max_varchar", - "notNull": true, - "length": -1, - "isFuncCall": true, - "type": { - "name": "anyarray" - } - }, - { - "name": "max_timestamp", - "notNull": true, - "length": -1, - "isFuncCall": true, - "type": { - "name": "anyarray" - } - } - ], + "text": "TRUNCATE TABLE postgres_array_types", + "name": "TruncatePostgresArrayTypes", + "cmd": ":exec", "filename": "query.sql" }, { - "text": "INSERT INTO postgres_geometric_types (\n c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", + "text": "\nINSERT INTO postgres_geometric_types (\n c_point, \n c_line, \n c_lseg, \n c_box, \n c_path, \n c_polygon, \n c_circle\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", "name": "InsertPostgresGeoTypes", "cmd": ":exec", "parameters": [ @@ -34793,13 +35844,16 @@ } } ], + "comments": [ + " Geometric types " + ], "filename": "query.sql", "insert_into_table": { "name": "postgres_geometric_types" } }, { - "text": "INSERT INTO postgres_geometric_types (\n c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", + "text": "INSERT INTO postgres_geometric_types (\n c_point, \n c_line, \n c_lseg, \n c_box, \n c_path, \n c_polygon, \n c_circle\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", "name": "InsertPostgresGeoTypesBatch", "cmd": ":copyfrom", "parameters": [ @@ -34999,308 +36053,13 @@ ], "filename": "query.sql" }, - { - "text": "TRUNCATE TABLE postgres_types", - "name": "TruncatePostgresTypes", - "cmd": ":exec", - "filename": "query.sql" - }, { "text": "TRUNCATE TABLE postgres_geometric_types", "name": "TruncatePostgresGeoTypes", "cmd": ":exec", "filename": "query.sql" - }, - { - "text": "INSERT INTO postgres_array_types\n(\n c_bytea,\n c_boolean_array,\n c_text_array,\n c_integer_array,\n c_decimal_array,\n c_date_array,\n c_timestamp_array\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", - "name": "InsertPostgresArrayTypes", - "cmd": ":exec", - "parameters": [ - { - "number": 1, - "column": { - "name": "c_bytea", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "bytea" - }, - "originalName": "c_bytea" - } - }, - { - "number": 2, - "column": { - "name": "c_boolean_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "pg_catalog.bool" - }, - "originalName": "c_boolean_array", - "arrayDims": 1 - } - }, - { - "number": 3, - "column": { - "name": "c_text_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "text" - }, - "originalName": "c_text_array", - "arrayDims": 1 - } - }, - { - "number": 4, - "column": { - "name": "c_integer_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "pg_catalog.int4" - }, - "originalName": "c_integer_array", - "arrayDims": 1 - } - }, - { - "number": 5, - "column": { - "name": "c_decimal_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "pg_catalog.numeric" - }, - "originalName": "c_decimal_array", - "arrayDims": 1 - } - }, - { - "number": 6, - "column": { - "name": "c_date_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "date" - }, - "originalName": "c_date_array", - "arrayDims": 1 - } - }, - { - "number": 7, - "column": { - "name": "c_timestamp_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "pg_catalog.timestamp" - }, - "originalName": "c_timestamp_array", - "arrayDims": 1 - } - } - ], - "filename": "query.sql", - "insert_into_table": { - "name": "postgres_array_types" - } - }, - { - "text": "SELECT c_bytea, c_boolean_array, c_text_array, c_integer_array, c_decimal_array, c_date_array, c_timestamp_array FROM postgres_array_types LIMIT 1", - "name": "GetPostgresArrayTypes", - "cmd": ":one", - "columns": [ - { - "name": "c_bytea", - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "name": "bytea" - }, - "originalName": "c_bytea" - }, - { - "name": "c_boolean_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "schema": "pg_catalog", - "name": "bool" - }, - "originalName": "c_boolean_array", - "arrayDims": 1 - }, - { - "name": "c_text_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "name": "text" - }, - "originalName": "c_text_array", - "arrayDims": 1 - }, - { - "name": "c_integer_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "schema": "pg_catalog", - "name": "int4" - }, - "originalName": "c_integer_array", - "arrayDims": 1 - }, - { - "name": "c_decimal_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "schema": "pg_catalog", - "name": "numeric" - }, - "originalName": "c_decimal_array", - "arrayDims": 1 - }, - { - "name": "c_date_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "name": "date" - }, - "originalName": "c_date_array", - "arrayDims": 1 - }, - { - "name": "c_timestamp_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "schema": "pg_catalog", - "name": "timestamp" - }, - "originalName": "c_timestamp_array", - "arrayDims": 1 - } - ], - "filename": "query.sql" - }, - { - "text": "INSERT INTO postgres_array_types (c_bytea) VALUES ($1)", - "name": "InsertPostgresArrayTypesBatch", - "cmd": ":copyfrom", - "parameters": [ - { - "number": 1, - "column": { - "name": "c_bytea", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "bytea" - }, - "originalName": "c_bytea" - } - } - ], - "filename": "query.sql", - "insert_into_table": { - "name": "postgres_array_types" - } - }, - { - "text": "SELECT\n c_bytea,\n COUNT(*) AS cnt\nFROM postgres_array_types\nGROUP BY\n c_bytea\nLIMIT 1", - "name": "GetPostgresArrayTypesCnt", - "cmd": ":one", - "columns": [ - { - "name": "c_bytea", - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "name": "bytea" - }, - "originalName": "c_bytea" - }, - { - "name": "cnt", - "notNull": true, - "length": -1, - "isFuncCall": true, - "type": { - "name": "bigint" - } - } - ], - "filename": "query.sql" - }, - { - "text": "TRUNCATE TABLE postgres_array_types", - "name": "TruncatePostgresArrayTypes", - "cmd": ":exec", - "filename": "query.sql" } ], "sqlc_version": "v1.27.0", - "plugin_options": "eyJvdmVycmlkZURyaXZlclZlcnNpb24iOiIiLCJnZW5lcmF0ZUNzcHJvaiI6dHJ1ZSwidGFyZ2V0RnJhbWV3b3JrIjoibmV0OC4wIiwibmFtZXNwYWNlTmFtZSI6Ik5wZ3NxbEV4YW1wbGVHZW4iLCJ1c2VEYXBwZXIiOmZhbHNlLCJvdmVycmlkZURhcHBlclZlcnNpb24iOiIiLCJvdmVycmlkZXMiOlt7ImNvbHVtbiI6IkdldFBvc3RncmVzRnVuY3Rpb25zOm1heF9pbnRlZ2VyIiwiY3NoYXJwX3R5cGUiOnsidHlwZSI6ImludCIsIm5vdE51bGwiOmZhbHNlfX0seyJjb2x1bW4iOiJHZXRQb3N0Z3Jlc0Z1bmN0aW9uczptYXhfdmFyY2hhciIsImNzaGFycF90eXBlIjp7InR5cGUiOiJzdHJpbmciLCJub3ROdWxsIjpmYWxzZX19LHsiY29sdW1uIjoiR2V0UG9zdGdyZXNGdW5jdGlvbnM6bWF4X3RpbWVzdGFtcCIsImNzaGFycF90eXBlIjp7InR5cGUiOiJEYXRlVGltZSIsIm5vdE51bGwiOnRydWV9fSx7ImNvbHVtbiI6Iio6Y19qc29uX3N0cmluZ19vdmVycmlkZSIsImNzaGFycF90eXBlIjp7InR5cGUiOiJzdHJpbmciLCJub3ROdWxsIjpmYWxzZX19LHsiY29sdW1uIjoiKjpjX21hY2FkZHI4IiwiY3NoYXJwX3R5cGUiOnsidHlwZSI6InN0cmluZyIsIm5vdE51bGwiOmZhbHNlfX1dLCJkZWJ1Z1JlcXVlc3QiOmZhbHNlfQ==" + "plugin_options": "eyJvdmVycmlkZURyaXZlclZlcnNpb24iOiIiLCJnZW5lcmF0ZUNzcHJvaiI6dHJ1ZSwidGFyZ2V0RnJhbWV3b3JrIjoibmV0OC4wIiwibmFtZXNwYWNlTmFtZSI6Ik5wZ3NxbEV4YW1wbGVHZW4iLCJ1c2VEYXBwZXIiOmZhbHNlLCJvdmVycmlkZURhcHBlclZlcnNpb24iOiIiLCJvdmVycmlkZXMiOlt7ImNvbHVtbiI6IkdldFBvc3RncmVzRnVuY3Rpb25zOm1heF9pbnRlZ2VyIiwiY3NoYXJwX3R5cGUiOnsidHlwZSI6ImludCIsIm5vdE51bGwiOmZhbHNlfX0seyJjb2x1bW4iOiJHZXRQb3N0Z3Jlc0Z1bmN0aW9uczptYXhfdmFyY2hhciIsImNzaGFycF90eXBlIjp7InR5cGUiOiJzdHJpbmciLCJub3ROdWxsIjpmYWxzZX19LHsiY29sdW1uIjoiR2V0UG9zdGdyZXNGdW5jdGlvbnM6bWF4X3RpbWVzdGFtcCIsImNzaGFycF90eXBlIjp7InR5cGUiOiJEYXRlVGltZSIsIm5vdE51bGwiOnRydWV9fSx7ImNvbHVtbiI6Iio6Y19qc29uX3N0cmluZ19vdmVycmlkZSIsImNzaGFycF90eXBlIjp7InR5cGUiOiJzdHJpbmciLCJub3ROdWxsIjpmYWxzZX19LHsiY29sdW1uIjoiKjpjX3htbF9zdHJpbmdfb3ZlcnJpZGUiLCJjc2hhcnBfdHlwZSI6eyJ0eXBlIjoic3RyaW5nIiwibm90TnVsbCI6ZmFsc2V9fSx7ImNvbHVtbiI6Iio6Y19tYWNhZGRyOCIsImNzaGFycF90eXBlIjp7InR5cGUiOiJzdHJpbmciLCJub3ROdWxsIjpmYWxzZX19XSwiZGVidWdSZXF1ZXN0IjpmYWxzZX0=" } \ No newline at end of file diff --git a/examples/NpgsqlExample/request.message b/examples/NpgsqlExample/request.message index 3d5a7604..37e54019 100644 --- a/examples/NpgsqlExample/request.message +++ b/examples/NpgsqlExample/request.message @@ -1,9 +1,9 @@ -Û +™ 2 -postgresql%examples/config/postgresql/schema.sql"$examples/config/postgresql/query.sqlbü -examples/NpgsqlExamplecsharpÃ{"debugRequest":true,"generateCsproj":true,"namespaceName":"NpgsqlExampleGen","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"notNull":false,"type":"int"}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"notNull":false,"type":"string"}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"notNull":true,"type":"DateTime"}},{"column":"*:c_json_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_macaddr8","csharp_type":{"notNull":false,"type":"string"}}],"targetFramework":"net8.0","useDapper":false}* -./dist/LocalRunner©æ public"ýpublicƒ +postgresql-examples/config/postgresql/authors/schema.sql+examples/config/postgresql/types/schema.sql",examples/config/postgresql/authors/query.sql"*examples/config/postgresql/types/query.sqlbÑ +examples/NpgsqlExamplecsharp˜{"debugRequest":true,"generateCsproj":true,"namespaceName":"NpgsqlExampleGen","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"notNull":false,"type":"int"}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"notNull":false,"type":"string"}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"notNull":true,"type":"DateTime"}},{"column":"*:c_json_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_xml_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_macaddr8","csharp_type":{"notNull":false,"type":"string"}}],"targetFramework":"net8.0","useDapper":false}* +./dist/LocalRunnerÃì public"…publicƒ authors) id0ÿÿÿÿÿÿÿÿÿR authorsb  bigserial& name0ÿÿÿÿÿÿÿÿÿR authorsbtext# @@ -13,68 +13,55 @@ postgresql%examples/config/postgresql/schema.sql"$examples/config/postgresql/qu name0ÿÿÿÿÿÿÿÿÿRbooksbtext5 author_id0ÿÿÿÿÿÿÿÿÿRbooksb pg_catalogint8) - description0ÿÿÿÿÿÿÿÿÿRbooksbtextä -postgres_types< - c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbool7 -c_bit0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbit= - -c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint2< - c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint4; -c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint8? - c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumeric? - c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumeric; -c_real0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat4G -c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat8/ -c_money0ÿÿÿÿÿÿÿÿÿRpostgres_typesbmoney- -c_date0ÿÿÿÿÿÿÿÿÿRpostgres_typesbdate9 -c_time0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogtimeC - c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestampM -c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestamptzA - -c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_cataloginterval; -c_char0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbpchar? - c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarcharI -c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarchar1 -c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesbbpchar- -c_text0ÿÿÿÿÿÿÿÿÿRpostgres_typesbtext- -c_json0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjson= -c_json_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjson/ -c_jsonb0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjsonb5 - -c_jsonpath0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -jsonpath+ -c_xml0ÿÿÿÿÿÿÿÿÿRpostgres_typesbxml- -c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_typesbcidr- -c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_typesbinet3 - c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_typesb macaddr5 - -c_macaddr80ÿÿÿÿÿÿÿÿÿRpostgres_typesb -macaddr8- -c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_typesbuuidµ -postgres_geometric_types9 -c_point0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpoint7 -c_line0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbline7 -c_lseg0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblseg5 -c_box0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbbox7 -c_path0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpath= - c_polygon0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesb polygon; -c_circle0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbcircle• + description0ÿÿÿÿÿÿÿÿÿRbooksbtextÔ +postgres_numeric_typesD + c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogbool? +c_bit0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogbitE + +c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint2D + c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint4C +c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint8G + c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericG + c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericC +c_real0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat4O +c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat87 +c_money0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesbmoneyç +postgres_string_typesB +c_char0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogbpcharF + c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarcharP +c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarchar8 +c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbbpchar4 +c_text0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbtext‰ +postgres_datetime_types6 +c_date0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesbdateB +c_time0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalogtimeL + c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestampV +c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestamptzJ + +c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_cataloginterval„ +postgres_network_types5 +c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbcidr5 +c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbinet; + c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesb macaddr= + +c_macaddr80ÿÿÿÿÿÿÿÿÿRpostgres_network_typesb +macaddr8• postgres_array_types5 c_bytea0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbbyteaM c_boolean_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb @@ -86,7 +73,27 @@ pg_catalogint4 pg_catalognumericˆ> c_date_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbdateˆT c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb -pg_catalog timestampˆ" pg_temp"æ² +pg_catalog timestampˆµ +postgres_geometric_types9 +c_point0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpoint7 +c_line0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbline7 +c_lseg0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblseg5 +c_box0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbbox7 +c_path0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpath= + c_polygon0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesb polygon; +c_circle0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbcircleú +postgres_special_types5 +c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbuuid7 +c_enum0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbc_enum5 +c_json0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjsonE +c_json_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjson7 +c_jsonb0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjsonb= + +c_jsonpath0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesb +jsonpath3 +c_xml0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbxmlC +c_xml_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbxml" +c_enumsmallmediumbig" pg_temp"æ² pg_catalog‰ & @@ -10207,7 +10214,14 @@ pg_cataloginformation_schemaviewsb  yes_or_noW pg_cataloginformation_schemaviewsb  yes_or_no] is_trigger_insertable_into0ÿÿÿÿÿÿÿÿÿR' -pg_cataloginformation_schemaviewsb  yes_or_no +pg_cataloginformation_schemaviewsb  yes_or_no"extendedÔ +extendedbiosC + author_name0ÿÿÿÿÿÿÿÿÿRextendedbiosb +pg_catalogvarchar< +name0ÿÿÿÿÿÿÿÿÿRextendedbiosb +pg_catalogvarchar= +bio_type0ÿÿÿÿÿÿÿÿÿRextendedbiosbextendedbio_type", +bio_type Autobiography BiographyMemoir 9SELECT id, name, bio FROM authors WHERE name = $1 LIMIT 1 GetAuthor:one"- id0ÿÿÿÿÿÿÿÿÿR authorsb  bigserialzid", @@ -10298,415 +10312,439 @@ WHERE books.name = $1GetAuthorsByBookName:many"- name0ÿÿÿÿÿÿÿÿÿR authorsbtextzname"( bio0ÿÿÿÿÿÿÿÿÿR authorsbtextzbio" books0ÿÿÿÿÿÿÿÿÿbrbooks*.* -name0ÿÿÿÿÿÿÿÿÿRbooksbtextzname: query.sqlˆ -¬INSERT INTO postgres_types +name0ÿÿÿÿÿÿÿÿÿRbooksbtextzname: query.sqlì +KINSERT INTO extended.bios (author_name, name, bio_type) VALUES ($1, $2, $3)CreateExtendedBio:exec*SO + author_name0ÿÿÿÿÿÿÿÿÿRextendedbiosbpg_catalog.varcharz author_name*EA +name0ÿÿÿÿÿÿÿÿÿRextendedbiosbpg_catalog.varcharzname*JF +bio_type0ÿÿÿÿÿÿÿÿÿRextendedbiosbextended.bio_typezbio_type: query.sqlBextendedbiosª +QSELECT author_name, name, bio_type FROM extended.bios WHERE bio_type = $1 LIMIT 1GetFirstExtendedBioByType:one"P + author_name0ÿÿÿÿÿÿÿÿÿRextendedbiosb +pg_catalogvarcharz author_name"B +name0ÿÿÿÿÿÿÿÿÿRextendedbiosb +pg_catalogvarcharzname"G +bio_type0ÿÿÿÿÿÿÿÿÿRextendedbiosbextendedbio_typezbio_type*JF +bio_type0ÿÿÿÿÿÿÿÿÿRextendedbiosbextended.bio_typezbio_type: query.sqlF +TRUNCATE TABLE extended.biosTruncateExtendedBios:exec: query.sqlü +Ò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_typesGetPostgresFunctions:one"( + max_integer0ÿÿÿÿÿÿÿÿÿ@b +anyarray"( + max_varchar0ÿÿÿÿÿÿÿÿÿ@b +anyarray"* + max_timestamp0ÿÿÿÿÿÿÿÿÿ@b +anyarray: query.sqlà +í +INSERT INTO postgres_numeric_types ( c_boolean, c_bit, c_smallint, c_integer, c_bigint, - c_real, - c_numeric, c_decimal, + c_numeric, + c_real, c_double_precision, - c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, - c_json, - c_json_string_override, - c_jsonb, - c_jsonpath, - c_xml, - c_cidr, - c_inet, - c_macaddr, - c_macaddr8 + c_money ) -VALUES ( - $1, - $2, - $3, - $4, - $5, - $6, - $7, - $8, - $9, - $10, - $11, - $12, - $13, - $14, - $15, - $16, - $17, - $18, - $19, - $20, - $21, - $22::json, - $23::json, - $24::jsonb, - $25::jsonpath, - $26::xml, - $27, - $28, - $29::macaddr, - $30::macaddr8 -)InsertPostgresTypes:exec*TP - c_boolean0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.boolz c_boolean*KG -c_bit0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.bitzc_bit*VR - -c_smallint0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.int2z -c_smallint*TP - c_integer0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.int4z c_integer*RN -c_bigint0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.int8zc_bigint*PL -c_real0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.float4zc_real*WS - c_numeric0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.numericz c_numeric*WS - c_decimal0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.numericz c_decimal*h d -c_double_precision0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.float8zc_double_precision*F -B -c_money0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbmoneyzc_money*C ? -c_date0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbdatezc_date*N J -c_time0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.timezc_time*] Y - c_timestamp0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.timestampz c_timestamp*ok -c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.timestamptzzc_timestamp_with_tz*ZV - -c_interval0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.intervalz -c_interval*PL -c_char0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.bpcharzc_char*WS - c_varchar0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.varcharz c_varchar*kg -c_character_varying0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.varcharzc_character_varying*IE -c_bpchar0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbbpcharzc_bpchar*C? -c_text0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbtextzc_text*C? -c_uuid0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbuuidzc_uuid* -c_json0ÿÿÿÿÿÿÿÿÿbjson*/+ -c_json_string_override0ÿÿÿÿÿÿÿÿÿbjson*! -c_jsonb0ÿÿÿÿÿÿÿÿÿbjsonb*'# - -c_jsonpath0ÿÿÿÿÿÿÿÿÿb -jsonpath* -c_xml0ÿÿÿÿÿÿÿÿÿbxml*C? -c_cidr0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbcidrzc_cidr*C? -c_inet0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbinetzc_inet*%! - c_macaddr0ÿÿÿÿÿÿÿÿÿb macaddr*'# - -c_macaddr80ÿÿÿÿÿÿÿÿÿb -macaddr8: query.sqlBpostgres_types‡ -ÜINSERT INTO postgres_types -( +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)InsertPostgresNumericTypes:exec*ZV + c_boolean0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.boolz c_boolean*QM +c_bit0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.bitzc_bit*\X + +c_smallint0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int2z +c_smallint*ZV + c_integer0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int4z c_integer*XT +c_bigint0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int8zc_bigint*]Y + c_decimal0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.numericz c_decimal*]Y + c_numeric0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.numericz c_numeric*VR +c_real0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.float4zc_real*n j +c_double_precision0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.float8zc_double_precision*L +H +c_money0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbmoneyzc_money2 Numeric types : query.sqlBpostgres_numeric_typesì +—SELECT c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money FROM postgres_numeric_types LIMIT 1GetPostgresNumericTypes:one"O + c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogboolz c_boolean"F +c_bit0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogbitzc_bit"Q + +c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint2z +c_smallint"O + c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint4z c_integer"M +c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint8zc_bigint"R + c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericz c_decimal"R + c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericz c_numeric"K +c_real0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat4zc_real"c +c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat8zc_double_precision"@ +c_money0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesbmoneyzc_money: query.sqlW +%TRUNCATE TABLE postgres_numeric_typesTruncatePostgresNumericTypes:exec: query.sqlê +òSELECT c_boolean, + c_bit, c_smallint, c_integer, c_bigint, - c_real, - c_numeric, c_decimal, + c_numeric, + c_real, c_double_precision, c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, - c_cidr, - c_inet, - c_macaddr -) -VALUES ( - $1, - $2, - $3, - $4, - $5, - $6, - $7, - $8, - $9, - $10, - $11, - $12, - $13, - $14, - $15, - $16, - $17, - $18, - $19, - $20, - $21, - $22, - $23 -)InsertPostgresTypesBatch :copyfrom*RN - c_boolean0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.boolz c_boolean*TP - -c_smallint0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.int2z -c_smallint*RN - c_integer0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.int4z c_integer*PL -c_bigint0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.int8zc_bigint*NJ -c_real0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.float4zc_real*UQ - c_numeric0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.numericz c_numeric*UQ - c_decimal0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.numericz c_decimal*fb -c_double_precision0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.float8zc_double_precision*D @ -c_money0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbmoneyzc_money*A -= -c_date0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbdatezc_date*L H -c_time0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.timezc_time*[ W - c_timestamp0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.timestampz c_timestamp*m i -c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.timestamptzzc_timestamp_with_tz*XT - -c_interval0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.intervalz -c_interval*NJ -c_char0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.bpcharzc_char*UQ - c_varchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.varcharz c_varchar*ie -c_character_varying0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.varcharzc_character_varying*GC -c_bpchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbbpcharzc_bpchar*A= -c_text0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbtextzc_text*A= -c_uuid0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbuuidzc_uuid*A= -c_cidr0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbcidrzc_cidr*A= -c_inet0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbinetzc_inet*JF - c_macaddr0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesb macaddrz c_macaddr: query.sqlBpostgres_types­ -„SELECT + COUNT(*) AS cnt +FROM postgres_numeric_types +GROUP BY c_boolean, c_bit, c_smallint, c_integer, c_bigint, - c_real, - c_numeric, c_decimal, + c_numeric, + c_real, c_double_precision, - c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, - c_json, - c_json_string_override, - c_jsonb, - c_jsonpath, - c_xml, - c_cidr, - c_inet, - c_macaddr, - c_macaddr8::TEXT AS c_macaddr8 -FROM postgres_types -LIMIT 1GetPostgresTypes:one"G - c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogboolz c_boolean"> -c_bit0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbitzc_bit"I - -c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb + c_money +LIMIT 1GetPostgresNumericTypesCnt:one"O + c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogboolz c_boolean"F +c_bit0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogbitzc_bit"Q + +c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb pg_catalogint2z -c_smallint"G - c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint4z c_integer"E -c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint8zc_bigint"C -c_real0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat4zc_real"J - c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumericz c_numeric"J - c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumericz c_decimal"[ -c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat8zc_double_precision"8 -c_money0ÿÿÿÿÿÿÿÿÿRpostgres_typesbmoneyzc_money"5 -c_date0ÿÿÿÿÿÿÿÿÿRpostgres_typesbdatezc_date"A -c_time0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogtimezc_time"P - c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestampz c_timestamp"b -c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestamptzzc_timestamp_with_tz"M - -c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogintervalz -c_interval"C -c_char0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbpcharzc_char"J - c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarcharz c_varchar"^ -c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarcharzc_character_varying"; -c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesbbpcharzc_bpchar"5 -c_text0ÿÿÿÿÿÿÿÿÿRpostgres_typesbtextzc_text"5 -c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_typesbuuidzc_uuid"5 -c_json0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjsonzc_json"U -c_json_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjsonzc_json_string_override"8 -c_jsonb0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjsonbzc_jsonb"A - -c_jsonpath0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -jsonpathz -c_jsonpath"2 -c_xml0ÿÿÿÿÿÿÿÿÿRpostgres_typesbxmlzc_xml"5 -c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_typesbcidrzc_cidr"5 -c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_typesbinetzc_inet"> - c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_typesb macaddrz c_macaddr"! - -c_macaddr80ÿÿÿÿÿÿÿÿÿbtext: query.sql¤ -úSELECT - c_smallint, +c_smallint"O + c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint4z c_integer"M +c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint8zc_bigint"R + c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericz c_decimal"R + c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericz c_numeric"K +c_real0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat4zc_real"c +c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat8zc_double_precision"@ +c_money0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesbmoneyzc_money" +cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sql× +ìINSERT INTO postgres_numeric_types +( c_boolean, + c_bit, + c_smallint, c_integer, c_bigint, - c_real, - c_numeric, c_decimal, + c_numeric, + c_real, c_double_precision, - c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, + c_money +) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)InsertPostgresNumericTypesBatch :copyfrom*ZV + c_boolean0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.boolz c_boolean*QM +c_bit0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.bitzc_bit*\X + +c_smallint0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int2z +c_smallint*ZV + c_integer0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int4z c_integer*XT +c_bigint0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int8zc_bigint*]Y + c_decimal0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.numericz c_decimal*]Y + c_numeric0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.numericz c_numeric*VR +c_real0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.float4zc_real*n j +c_double_precision0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.float8zc_double_precision*L +H +c_money0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbmoneyzc_money: query.sqlBpostgres_numeric_types© + +INSERT INTO postgres_string_types +( + c_char, + c_varchar, + c_character_varying, + c_bpchar, + c_text +) +VALUES ($1, $2, $3, $4, $5)InsertPostgresStringTypes:exec*UQ +c_char0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.bpcharzc_char*\X + c_varchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.varcharz c_varchar*pl +c_character_varying0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.varcharzc_character_varying*NJ +c_bpchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbbpcharzc_bpchar*HD +c_text0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbtextzc_text2 String types : query.sqlBpostgres_string_types¢ +INSERT INTO postgres_string_types +( + c_char, + c_varchar, + c_character_varying, + c_bpchar, + c_text +) VALUES ($1, $2, $3, $4, $5)InsertPostgresStringTypesBatch :copyfrom*UQ +c_char0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.bpcharzc_char*\X + c_varchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.varcharz c_varchar*pl +c_character_varying0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.varcharzc_character_varying*NJ +c_bpchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbbpcharzc_bpchar*HD +c_text0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbtextzc_text: query.sqlBpostgres_string_types• +bSELECT c_char, c_varchar, c_character_varying, c_bpchar, c_text FROM postgres_string_types LIMIT 1GetPostgresStringTypes:one"J +c_char0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogbpcharzc_char"Q + c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarcharz c_varchar"e +c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarcharzc_character_varying"B +c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbbpcharzc_bpchar"< +c_text0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbtextzc_text: query.sqlU +$TRUNCATE TABLE postgres_string_typesTruncatePostgresStringTypes:exec: query.sql¸ +áSELECT c_char, c_varchar, c_character_varying, c_bpchar, c_text, - c_uuid, - c_cidr, - c_inet, - c_macaddr, COUNT(*) AS cnt -FROM postgres_types +FROM postgres_string_types GROUP BY - c_smallint, - c_boolean, - c_integer, - c_bigint, - c_real, - c_numeric, - c_decimal, - c_double_precision, - c_money, + c_char, + c_varchar, + c_character_varying, + c_bpchar, + c_text +LIMIT 1GetPostgresStringTypesCnt:one"J +c_char0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogbpcharzc_char"Q + c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarcharz c_varchar"e +c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarcharzc_character_varying"B +c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbbpcharzc_bpchar"< +c_text0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbtextzc_text" +cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sqlì +ØWITH txt_query AS ( + SELECT + c_text, + to_tsquery('english', $1) AS query, + to_tsvector('english', c_text) AS tsv + FROM postgres_string_types + WHERE c_text @@ to_tsquery('english', $1) +) + +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 GetPostgresStringTypesTextSearch:one"0 +c_text0ÿÿÿÿÿÿÿÿÿR  txt_querybtextzc_text"3 +query0ÿÿÿÿÿÿÿÿÿR  txt_queryb tsqueryzquery"0 +tsv0ÿÿÿÿÿÿÿÿÿR  txt_queryb +tsvectorztsv" +rnk0ÿÿÿÿÿÿÿÿÿ@breal*%! + +to_tsquery0ÿÿÿÿÿÿÿÿÿbtext: query.sqlØ +• +INSERT INTO postgres_datetime_types +( + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval +) VALUES ($1, $2, $3, $4, $5)InsertPostgresDateTimeTypes:exec*JF +c_date0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbdatezc_date*UQ +c_time0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timezc_time*d` + c_timestamp0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timestampz c_timestamp*vr +c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timestamptzzc_timestamp_with_tz*a] + +c_interval0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.intervalz +c_interval2 DateTime types : query.sqlBpostgres_datetime_typesÁ +hSELECT c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval FROM postgres_datetime_types LIMIT 1GetPostgresDateTimeTypes:one"> +c_date0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesbdatezc_date"J +c_time0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalogtimezc_time"Y + c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestampz c_timestamp"k +c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestamptzzc_timestamp_with_tz"V + +c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalogintervalz +c_interval: query.sqlY +&TRUNCATE TABLE postgres_datetime_typesTruncatePostgresDateTimeTypes:exec: query.sqlè +ëSELECT c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, + COUNT(*) AS cnt +FROM postgres_datetime_types +GROUP BY + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval +LIMIT 1GetPostgresDateTimeTypesCnt:one"> +c_date0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesbdatezc_date"J +c_time0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalogtimezc_time"Y + c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestampz c_timestamp"k +c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestamptzzc_timestamp_with_tz"V + +c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalogintervalz +c_interval" +cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sqlÎ +”INSERT INTO postgres_datetime_types +( + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval +) VALUES ($1, $2, $3, $4, $5) InsertPostgresDateTimeTypesBatch :copyfrom*JF +c_date0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbdatezc_date*UQ +c_time0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timezc_time*d` + c_timestamp0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timestampz c_timestamp*vr +c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timestamptzzc_timestamp_with_tz*a] + +c_interval0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.intervalz +c_interval: query.sqlBpostgres_datetime_types‰ +” +INSERT INTO postgres_network_types +( c_cidr, c_inet, - c_macaddr -LIMIT 1GetPostgresTypesCnt:one"I + c_macaddr, + c_macaddr8 +) VALUES ( + $1, + $2, + $3, + $4::macaddr8 +)InsertPostgresNetworkTypes:exec*KG +c_cidr0ÿÿÿÿÿÿÿÿÿ8R publicpostgres_network_typesbcidrzc_cidr*KG +c_inet0ÿÿÿÿÿÿÿÿÿ8R publicpostgres_network_typesbinetzc_inet*TP + c_macaddr0ÿÿÿÿÿÿÿÿÿ8R publicpostgres_network_typesb macaddrz c_macaddr*'# -c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint2z -c_smallint"G - c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogboolz c_boolean"G - c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint4z c_integer"E -c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint8zc_bigint"C -c_real0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat4zc_real"J - c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumericz c_numeric"J - c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumericz c_decimal"[ -c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat8zc_double_precision"8 -c_money0ÿÿÿÿÿÿÿÿÿRpostgres_typesbmoneyzc_money"5 -c_date0ÿÿÿÿÿÿÿÿÿRpostgres_typesbdatezc_date"A -c_time0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogtimezc_time"P - c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestampz c_timestamp"b -c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestamptzzc_timestamp_with_tz"M - -c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogintervalz -c_interval"C -c_char0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbpcharzc_char"J - c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarcharz c_varchar"^ -c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarcharzc_character_varying"; -c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesbbpcharzc_bpchar"5 -c_text0ÿÿÿÿÿÿÿÿÿRpostgres_typesbtextzc_text"5 -c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_typesbuuidzc_uuid"5 -c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_typesbcidrzc_cidr"5 -c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_typesbinetzc_inet"> - c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_typesb macaddrz c_macaddr" -cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sql° -†SELECT - MAX(c_integer) AS max_integer, - MAX(c_varchar) AS max_varchar, - MAX(c_timestamp) AS max_timestamp -FROM postgres_typesGetPostgresFunctions:one"( - max_integer0ÿÿÿÿÿÿÿÿÿ@b -anyarray"( - max_varchar0ÿÿÿÿÿÿÿÿÿ@b -anyarray"* - max_timestamp0ÿÿÿÿÿÿÿÿÿ@b -anyarray: query.sqlÿ -ŒINSERT INTO postgres_geometric_types ( - c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle +c_macaddr80ÿÿÿÿÿÿÿÿÿb +macaddr82 Network types : query.sqlBpostgres_network_types‰ +tSELECT + c_cidr, + c_inet, + c_macaddr, + c_macaddr8::TEXT AS c_macaddr8 +FROM postgres_network_types +LIMIT 1GetPostgresNetworkTypes:one"= +c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbcidrzc_cidr"= +c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbinetzc_inet"F + c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesb macaddrz c_macaddr"! + +c_macaddr80ÿÿÿÿÿÿÿÿÿbtext: query.sqlW +%TRUNCATE TABLE postgres_network_typesTruncatePostgresNetworkTypes:exec: query.sqlª +”SELECT + c_cidr, + c_inet, + c_macaddr, + COUNT(*) AS cnt +FROM postgres_network_types +GROUP BY + c_cidr, + c_inet, + c_macaddr +LIMIT 1GetPostgresNetworkTypesCnt:one"= +c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbcidrzc_cidr"= +c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbinetzc_inet"F + c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesb macaddrz c_macaddr" +cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sql +`INSERT INTO postgres_network_types +( + c_cidr, + c_inet, + c_macaddr +) VALUES ($1, $2, $3)InsertPostgresNetworkTypesBatch :copyfrom*IE +c_cidr0ÿÿÿÿÿÿÿÿÿR publicpostgres_network_typesbcidrzc_cidr*IE +c_inet0ÿÿÿÿÿÿÿÿÿR publicpostgres_network_typesbinetzc_inet*RN + c_macaddr0ÿÿÿÿÿÿÿÿÿR publicpostgres_network_typesb macaddrz c_macaddr: query.sqlBpostgres_network_typesÜ +¤ +INSERT INTO postgres_special_types +( + c_json, + c_json_string_override, + c_jsonb, + c_jsonpath, + c_xml, + c_xml_string_override, + c_uuid, + c_enum ) -VALUES ($1, $2, $3, $4, $5, $6, $7)InsertPostgresGeoTypes:exec*NJ -c_point0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpointzc_point*KG -c_line0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblinezc_line*KG -c_lseg0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblsegzc_lseg*HD -c_box0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbboxzc_box*KG -c_path0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpathzc_path*TP - c_polygon0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesb polygonz c_polygon*QM -c_circle0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbcirclezc_circle: query.sqlBpostgres_geometric_typesˆ -ŒINSERT INTO postgres_geometric_types ( - c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle +VALUES ( + $1::json, + $2::json, + $3::jsonb, + $4::jsonpath, + $5::xml, + $6::xml, + $7, + $8::c_enum +)InsertPostgresSpecialTypes:exec* +c_json0ÿÿÿÿÿÿÿÿÿbjson*/+ +c_json_string_override0ÿÿÿÿÿÿÿÿÿbjson*! +c_jsonb0ÿÿÿÿÿÿÿÿÿbjsonb*'# + +c_jsonpath0ÿÿÿÿÿÿÿÿÿb +jsonpath* +c_xml0ÿÿÿÿÿÿÿÿÿbxml*-) +c_xml_string_override0ÿÿÿÿÿÿÿÿÿbxml*KG +c_uuid0ÿÿÿÿÿÿÿÿÿ8R publicpostgres_special_typesbuuidzc_uuid*! +c_enum0ÿÿÿÿÿÿÿÿÿbc_enum2 Special types : query.sqlBpostgres_special_types +­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 1GetPostgresSpecialTypes:one"= +c_json0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjsonzc_json"] +c_json_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjsonzc_json_string_override"@ +c_jsonb0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjsonbzc_jsonb"I + +c_jsonpath0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesb +jsonpathz +c_jsonpath": +c_xml0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbxmlzc_xml"Z +c_xml_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbxmlzc_xml_string_override"= +c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbuuidzc_uuid"? +c_enum0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbc_enumzc_enum: query.sqlW +%TRUNCATE TABLE postgres_special_typesTruncatePostgresSpecialTypes:exec: query.sqlá +CINSERT INTO postgres_special_types +( + c_uuid ) -VALUES ($1, $2, $3, $4, $5, $6, $7)InsertPostgresGeoTypesBatch :copyfrom*NJ -c_point0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpointzc_point*KG -c_line0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblinezc_line*KG -c_lseg0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblsegzc_lseg*HD -c_box0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbboxzc_box*KG -c_path0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpathzc_path*TP - c_polygon0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesb polygonz c_polygon*QM -c_circle0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbcirclezc_circle: query.sqlBpostgres_geometric_typesæ -hSELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgres_geometric_types LIMIT 1GetPostgresGeoTypes:one"B -c_point0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpointzc_point"? -c_line0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblinezc_line"? -c_lseg0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblsegzc_lseg"< -c_box0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbboxzc_box"? -c_path0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpathzc_path"H - c_polygon0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesb polygonz c_polygon"E -c_circle0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbcirclezc_circle: query.sqlH -TRUNCATE TABLE postgres_typesTruncatePostgresTypes:exec: query.sqlU -'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sqlÍ -ÎINSERT INTO postgres_array_types +VALUES ( + $1 +)InsertPostgresSpecialTypesBatch :copyfrom*IE +c_uuid0ÿÿÿÿÿÿÿÿÿR publicpostgres_special_typesbuuidzc_uuid: query.sqlBpostgres_special_typesì +^SELECT + c_uuid, + COUNT(*) AS cnt +FROM postgres_special_types +GROUP BY + c_uuid +LIMIT 1GetPostgresSpecialTypesCnt:one"= +c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbuuidzc_uuid" +cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sqlÝ +Ï +INSERT INTO postgres_array_types ( c_bytea, c_boolean_array, @@ -10723,7 +10761,7 @@ VALUES ($1, $2, $3, $4, $5, $6, $7)InsertPostgresArrayTypes:exec*JF c_integer_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.int4zc_integer_arrayˆ*lh c_decimal_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.numericzc_decimal_arrayˆ*XT c_date_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbdatez c_date_arrayˆ*rn -c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.timestampzc_timestamp_arrayˆ: query.sqlBpostgres_array_types¥ +c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.timestampzc_timestamp_arrayˆ2 Array types : query.sqlBpostgres_array_types¥ ’SELECT c_bytea, c_boolean_array, c_text_array, c_integer_array, c_decimal_array, c_date_array, c_timestamp_array FROM postgres_array_types LIMIT 1GetPostgresArrayTypes:one"> c_bytea0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbbyteazc_bytea"^ c_boolean_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb @@ -10735,16 +10773,99 @@ pg_catalogint4zc_integer_array pg_catalognumericzc_decimal_arrayˆ"L c_date_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbdatez c_date_arrayˆ"g c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb -pg_catalog timestampzc_timestamp_arrayˆ: query.sqlÑ -6INSERT INTO postgres_array_types (c_bytea) VALUES ($1)InsertPostgresArrayTypesBatch :copyfrom*JF -c_bytea0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbbyteazc_bytea: query.sqlBpostgres_array_typesë -^SELECT +pg_catalog timestampzc_timestamp_arrayˆ: query.sql +ÓINSERT INTO postgres_array_types ( + c_bytea, + c_boolean_array, + c_text_array, + c_integer_array, + c_decimal_array, + c_timestamp_array +) +VALUES ( + $1, + $2, + $3, + $4, + $5, + $6 +)InsertPostgresArrayTypesBatch :copyfrom*JF +c_bytea0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbbyteazc_bytea*ie +c_boolean_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.boolzc_boolean_arrayˆ*XT + c_text_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbtextz c_text_arrayˆ*ie +c_integer_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.int4zc_integer_arrayˆ*lh +c_decimal_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.numericzc_decimal_arrayˆ*rn +c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.timestampzc_timestamp_arrayˆ: query.sqlBpostgres_array_types– +®SELECT c_bytea, + c_boolean_array, + c_text_array, + c_integer_array, + c_decimal_array, + c_timestamp_array, COUNT(*) AS cnt FROM postgres_array_types GROUP BY - c_bytea + c_bytea, + c_boolean_array, + c_text_array, + c_integer_array, + c_decimal_array, + c_timestamp_array LIMIT 1GetPostgresArrayTypesCnt:one"> -c_bytea0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbbyteazc_bytea" +c_bytea0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbbyteazc_bytea"^ +c_boolean_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb +pg_catalogboolzc_boolean_arrayˆ"L + c_text_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbtextz c_text_arrayˆ"^ +c_integer_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb +pg_catalogint4zc_integer_arrayˆ"a +c_decimal_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb +pg_catalognumericzc_decimal_arrayˆ"g +c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb +pg_catalog timestampzc_timestamp_arrayˆ" cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sqlS -#TRUNCATE TABLE postgres_array_typesTruncatePostgresArrayTypes:exec: query.sql"v1.27.0*ú{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"net8.0","namespaceName":"NpgsqlExampleGen","useDapper":false,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}}],"debugRequest":false} \ No newline at end of file +#TRUNCATE TABLE postgres_array_typesTruncatePostgresArrayTypes:exec: query.sql± +« +INSERT INTO postgres_geometric_types ( + c_point, + c_line, + c_lseg, + c_box, + c_path, + c_polygon, + c_circle +) +VALUES ($1, $2, $3, $4, $5, $6, $7)InsertPostgresGeoTypes:exec*NJ +c_point0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpointzc_point*KG +c_line0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblinezc_line*KG +c_lseg0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblsegzc_lseg*HD +c_box0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbboxzc_box*KG +c_path0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpathzc_path*TP + c_polygon0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesb polygonz c_polygon*QM +c_circle0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbcirclezc_circle2 Geometric types : query.sqlBpostgres_geometric_types¦ +ªINSERT INTO postgres_geometric_types ( + c_point, + c_line, + c_lseg, + c_box, + c_path, + c_polygon, + c_circle +) +VALUES ($1, $2, $3, $4, $5, $6, $7)InsertPostgresGeoTypesBatch :copyfrom*NJ +c_point0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpointzc_point*KG +c_line0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblinezc_line*KG +c_lseg0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblsegzc_lseg*HD +c_box0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbboxzc_box*KG +c_path0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpathzc_path*TP + c_polygon0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesb polygonz c_polygon*QM +c_circle0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbcirclezc_circle: query.sqlBpostgres_geometric_typesæ +hSELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgres_geometric_types LIMIT 1GetPostgresGeoTypes:one"B +c_point0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpointzc_point"? +c_line0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblinezc_line"? +c_lseg0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblsegzc_lseg"< +c_box0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbboxzc_box"? +c_path0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpathzc_path"H + c_polygon0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesb polygonz c_polygon"E +c_circle0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbcirclezc_circle: query.sqlU +'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sql"v1.27.0*Ï{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"net8.0","namespaceName":"NpgsqlExampleGen","useDapper":false,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_xml_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}}],"debugRequest":false} \ No newline at end of file diff --git a/examples/NpgsqlLegacyExample/Models.cs b/examples/NpgsqlLegacyExample/Models.cs index 3778fa9f..6482da2a 100644 --- a/examples/NpgsqlLegacyExample/Models.cs +++ b/examples/NpgsqlLegacyExample/Models.cs @@ -3,6 +3,7 @@ namespace NpgsqlLegacyExampleGen { using NpgsqlTypes; using System; + using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.NetworkInformation; @@ -22,7 +23,7 @@ public class Book public long AuthorId { get; set; } public string Description { get; set; } }; - public class PostgresType + public class PostgresNumericType { public bool? CBoolean { get; set; } public byte[] CBit { get; set; } @@ -34,26 +35,39 @@ public class PostgresType public float? CReal { get; set; } public double? CDoublePrecision { get; set; } public decimal? CMoney { get; set; } - public DateTime? CDate { get; set; } - public TimeSpan? CTime { get; set; } - public DateTime? CTimestamp { get; set; } - public DateTime? CTimestampWithTz { get; set; } - public TimeSpan? CInterval { get; set; } + }; + public class PostgresStringType + { public string CChar { get; set; } public string CVarchar { get; set; } public string CCharacterVarying { get; set; } public string CBpchar { get; set; } public string CText { get; set; } - public JsonElement? CJson { get; set; } - public JsonElement? CJsonStringOverride { get; set; } - public JsonElement? CJsonb { get; set; } - public string CJsonpath { get; set; } - public XmlDocument CXml { get; set; } + }; + public class PostgresDatetimeType + { + public DateTime? CDate { get; set; } + public TimeSpan? CTime { get; set; } + public DateTime? CTimestamp { get; set; } + public DateTime? CTimestampWithTz { get; set; } + public TimeSpan? CInterval { get; set; } + }; + public class PostgresNetworkType + { public NpgsqlCidr? CCidr { get; set; } public IPAddress CInet { get; set; } public PhysicalAddress CMacaddr { get; set; } public string CMacaddr8 { get; set; } - public Guid? CUuid { get; set; } + }; + public class PostgresArrayType + { + public byte[] CBytea { get; set; } + public bool[] CBooleanArray { get; set; } + public string[] CTextArray { get; set; } + public int[] CIntegerArray { get; set; } + public decimal[] CDecimalArray { get; set; } + public DateTime[] CDateArray { get; set; } + public DateTime[] CTimestampArray { get; set; } }; public class PostgresGeometricType { @@ -65,14 +79,100 @@ public class PostgresGeometricType public NpgsqlPolygon? CPolygon { get; set; } public NpgsqlCircle? CCircle { get; set; } }; - public class PostgresArrayType + public class PostgresSpecialType { - public byte[] CBytea { get; set; } - public bool[] CBooleanArray { get; set; } - public string[] CTextArray { get; set; } - public int[] CIntegerArray { get; set; } - public decimal[] CDecimalArray { get; set; } - public DateTime[] CDateArray { get; set; } - public DateTime[] CTimestampArray { get; set; } + public Guid? CUuid { get; set; } + public CEnum? CEnum { get; set; } + public JsonElement? CJson { get; set; } + public JsonElement? CJsonStringOverride { get; set; } + public JsonElement? CJsonb { get; set; } + public string CJsonpath { get; set; } + public XmlDocument CXml { get; set; } + public XmlDocument CXmlStringOverride { get; set; } + }; + public class ExtendedBio + { + public string AuthorName { get; set; } + public string Name { get; set; } + public ExtendedBioType? BioType { get; set; } }; + public enum CEnum + { + Invalid = 0, // reserved for invalid enum value + Small = 1, + Medium = 2, + Big = 3 + } + + public static class CEnumExtensions + { + private static readonly Dictionary StringToEnum = new Dictionary() + { + [string.Empty] = CEnum.Invalid, + ["small"] = CEnum.Small, + ["medium"] = CEnum.Medium, + ["big"] = CEnum.Big + }; + private static readonly Dictionary EnumToString = new Dictionary() + { + [CEnum.Invalid] = string.Empty, + [CEnum.Small] = "small", + [CEnum.Medium] = "medium", + [CEnum.Big] = "big" + }; + public static CEnum ToCEnum(this string me) + { + return StringToEnum[me]; + } + + public static string Stringify(this CEnum me) + { + return EnumToString[me]; + } + + public static HashSet ToCEnumSet(this string me) + { + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); + } + } + + public enum ExtendedBioType + { + Invalid = 0, // reserved for invalid enum value + Autobiography = 1, + Biography = 2, + Memoir = 3 + } + + public static class ExtendedBioTypeExtensions + { + private static readonly Dictionary StringToEnum = new Dictionary() + { + [string.Empty] = ExtendedBioType.Invalid, + ["Autobiography"] = ExtendedBioType.Autobiography, + ["Biography"] = ExtendedBioType.Biography, + ["Memoir"] = ExtendedBioType.Memoir + }; + private static readonly Dictionary EnumToString = new Dictionary() + { + [ExtendedBioType.Invalid] = string.Empty, + [ExtendedBioType.Autobiography] = "Autobiography", + [ExtendedBioType.Biography] = "Biography", + [ExtendedBioType.Memoir] = "Memoir" + }; + public static ExtendedBioType ToExtendedBioType(this string me) + { + return StringToEnum[me]; + } + + public static string Stringify(this ExtendedBioType me) + { + return EnumToString[me]; + } + + public static HashSet ToExtendedBioTypeSet(this string me) + { + return new HashSet(me.Split(',').ToList().Select(v => StringToEnum[v])); + } + } } \ No newline at end of file diff --git a/examples/NpgsqlLegacyExample/QuerySql.cs b/examples/NpgsqlLegacyExample/QuerySql.cs index c7df7495..e52ec5c5 100644 --- a/examples/NpgsqlLegacyExample/QuerySql.cs +++ b/examples/NpgsqlLegacyExample/QuerySql.cs @@ -41,7 +41,7 @@ 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; } @@ -80,10 +80,7 @@ public async Task GetAuthor(GetAuthorArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetAuthorSql; @@ -106,7 +103,7 @@ 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; } @@ -200,10 +197,7 @@ public async Task CreateAuthor(CreateAuthorArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = CreateAuthorSql; @@ -255,10 +249,7 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = CreateAuthorReturnIdSql; @@ -270,7 +261,7 @@ 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; } @@ -309,10 +300,7 @@ public async Task GetAuthorById(GetAuthorByIdArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetAuthorByIdSql; @@ -335,7 +323,7 @@ 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; } @@ -383,7 +371,7 @@ 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; } @@ -405,10 +393,7 @@ public async Task DeleteAuthor(DeleteAuthorArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = DeleteAuthorSql; @@ -435,10 +420,7 @@ public async Task TruncateAuthors() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = TruncateAuthorsSql; @@ -447,7 +429,7 @@ 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; } @@ -467,10 +449,7 @@ public async Task UpdateAuthors(UpdateAuthorsArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = UpdateAuthorsSql; @@ -480,7 +459,7 @@ 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; } @@ -528,7 +507,7 @@ 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; } @@ -606,10 +585,7 @@ public async Task CreateBook(CreateBookArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = CreateBookSql; @@ -621,7 +597,7 @@ 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; } @@ -662,7 +638,7 @@ 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; } @@ -703,7 +679,7 @@ 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; } @@ -752,78 +728,24 @@ public async Task> GetAuthorsByBookName(GetAuthors } } - private const string InsertPostgresTypesSql = "INSERT INTO postgres_types(c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_real, c_numeric, c_decimal, c_double_precision, c_money, c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_char, c_varchar, c_character_varying, c_bpchar, c_text, c_uuid, c_json, c_json_string_override, c_jsonb, c_jsonpath, c_xml, c_cidr, c_inet, c_macaddr, c_macaddr8) VALUES ( @c_boolean, @c_bit, @c_smallint, @c_integer, @c_bigint, @c_real, @c_numeric, @c_decimal, @c_double_precision, @c_money, @c_date, @c_time, @c_timestamp, @c_timestamp_with_tz, @c_interval, @c_char, @c_varchar, @c_character_varying, @c_bpchar, @c_text, @c_uuid, @c_json :: json, @c_json_string_override :: json, @c_jsonb :: jsonb, @c_jsonpath :: jsonpath, @c_xml :: xml, @c_cidr, @c_inet, @c_macaddr :: macaddr, @c_macaddr8 :: macaddr8 ) "; - public class InsertPostgresTypesArgs + private const string CreateExtendedBioSql = "INSERT INTO extended.bios (author_name, name, bio_type) VALUES (@author_name, @name, @bio_type)"; + public class CreateExtendedBioArgs { - public bool? CBoolean { get; set; } - public byte[] CBit { get; set; } - public short? CSmallint { get; set; } - public int? CInteger { get; set; } - public long? CBigint { get; set; } - public float? CReal { get; set; } - public decimal? CNumeric { get; set; } - public decimal? CDecimal { get; set; } - public double? CDoublePrecision { get; set; } - public decimal? CMoney { get; set; } - public DateTime? CDate { get; set; } - public TimeSpan? CTime { get; set; } - public DateTime? CTimestamp { get; set; } - public DateTime? CTimestampWithTz { get; set; } - public TimeSpan? CInterval { get; set; } - public string CChar { get; set; } - public string CVarchar { get; set; } - public string CCharacterVarying { get; set; } - public string CBpchar { get; set; } - public string CText { get; set; } - public Guid? CUuid { get; set; } - public JsonElement? CJson { get; set; } - public string CJsonStringOverride { get; set; } - public JsonElement? CJsonb { get; set; } - public string CJsonpath { get; set; } - public XmlDocument CXml { get; set; } - public NpgsqlCidr? CCidr { get; set; } - public IPAddress CInet { get; set; } - public PhysicalAddress CMacaddr { get; set; } - public string CMacaddr8 { get; set; } + public string AuthorName { get; set; } + public string Name { get; set; } + public ExtendedBioType? BioType { get; set; } }; - public async Task InsertPostgresTypes(InsertPostgresTypesArgs args) + public async Task CreateExtendedBio(CreateExtendedBioArgs args) { if (this.Transaction == null) { using (var connection = NpgsqlDataSource.Create(ConnectionString)) { - using (var command = connection.CreateCommand(InsertPostgresTypesSql)) + using (var command = connection.CreateCommand(CreateExtendedBioSql)) { - command.Parameters.AddWithValue("@c_boolean", args.CBoolean ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_bit", args.CBit ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_smallint", args.CSmallint ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_integer", args.CInteger ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_bigint", args.CBigint ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_real", args.CReal ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_numeric", args.CNumeric ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_decimal", args.CDecimal ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_double_precision", args.CDoublePrecision ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_money", args.CMoney ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_date", args.CDate ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_time", args.CTime ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_timestamp", args.CTimestamp ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_timestamp_with_tz", args.CTimestampWithTz ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_interval", args.CInterval ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_char", args.CChar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_varchar", args.CVarchar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_character_varying", args.CCharacterVarying ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_bpchar", args.CBpchar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_text", args.CText ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_uuid", args.CUuid ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_json", args.CJson.HasValue ? args.CJson.Value.GetRawText() : (object)DBNull.Value); - command.Parameters.AddWithValue("@c_json_string_override", args.CJsonStringOverride ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_jsonb", args.CJsonb.HasValue ? args.CJsonb.Value.GetRawText() : (object)DBNull.Value); - command.Parameters.AddWithValue("@c_jsonpath", args.CJsonpath ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_xml", args.CXml != null ? args.CXml.OuterXml : (object)DBNull.Value); - command.Parameters.AddWithValue("@c_cidr", args.CCidr ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_inet", args.CInet ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_macaddr", args.CMacaddr ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_macaddr8", args.CMacaddr8 ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@author_name", args.AuthorName); + command.Parameters.AddWithValue("@name", args.Name); + command.Parameters.AddWithValue("@bio_type", args.BioType != null ? args.BioType.Value.Stringify() : (object)DBNull.Value); await command.ExecuteNonQueryAsync(); } } @@ -832,200 +754,47 @@ public async Task InsertPostgresTypes(InsertPostgresTypesArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = InsertPostgresTypesSql; + command.CommandText = CreateExtendedBioSql; command.Transaction = this.Transaction; - command.Parameters.AddWithValue("@c_boolean", args.CBoolean ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_bit", args.CBit ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_smallint", args.CSmallint ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_integer", args.CInteger ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_bigint", args.CBigint ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_real", args.CReal ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_numeric", args.CNumeric ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_decimal", args.CDecimal ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_double_precision", args.CDoublePrecision ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_money", args.CMoney ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_date", args.CDate ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_time", args.CTime ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_timestamp", args.CTimestamp ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_timestamp_with_tz", args.CTimestampWithTz ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_interval", args.CInterval ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_char", args.CChar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_varchar", args.CVarchar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_character_varying", args.CCharacterVarying ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_bpchar", args.CBpchar ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_text", args.CText ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_uuid", args.CUuid ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_json", args.CJson.HasValue ? args.CJson.Value.GetRawText() : (object)DBNull.Value); - command.Parameters.AddWithValue("@c_json_string_override", args.CJsonStringOverride ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_jsonb", args.CJsonb.HasValue ? args.CJsonb.Value.GetRawText() : (object)DBNull.Value); - command.Parameters.AddWithValue("@c_jsonpath", args.CJsonpath ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_xml", args.CXml != null ? args.CXml.OuterXml : (object)DBNull.Value); - command.Parameters.AddWithValue("@c_cidr", args.CCidr ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_inet", args.CInet ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_macaddr", args.CMacaddr ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_macaddr8", args.CMacaddr8 ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@author_name", args.AuthorName); + command.Parameters.AddWithValue("@name", args.Name); + command.Parameters.AddWithValue("@bio_type", args.BioType != null ? args.BioType.Value.Stringify() : (object)DBNull.Value); await command.ExecuteNonQueryAsync(); } } - private const string InsertPostgresTypesBatchSql = "COPY postgres_types (c_boolean, c_smallint, c_integer, c_bigint, c_real, c_numeric, c_decimal, c_double_precision, c_money, c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_char, c_varchar, c_character_varying, c_bpchar, c_text, c_uuid, c_cidr, c_inet, c_macaddr) FROM STDIN (FORMAT BINARY)"; - public class InsertPostgresTypesBatchArgs + private const string GetFirstExtendedBioByTypeSql = "SELECT author_name, name, bio_type FROM extended.bios WHERE bio_type = @bio_type LIMIT 1"; + public class GetFirstExtendedBioByTypeRow { - public bool? CBoolean { get; set; } - public short? CSmallint { get; set; } - public int? CInteger { get; set; } - public long? CBigint { get; set; } - public float? CReal { get; set; } - public decimal? CNumeric { get; set; } - public decimal? CDecimal { get; set; } - public double? CDoublePrecision { get; set; } - public decimal? CMoney { get; set; } - public DateTime? CDate { get; set; } - public TimeSpan? CTime { get; set; } - public DateTime? CTimestamp { get; set; } - public DateTime? CTimestampWithTz { get; set; } - public TimeSpan? CInterval { get; set; } - public string CChar { get; set; } - public string CVarchar { get; set; } - public string CCharacterVarying { get; set; } - public string CBpchar { get; set; } - public string CText { get; set; } - public Guid? CUuid { get; set; } - public NpgsqlCidr? CCidr { get; set; } - public IPAddress CInet { get; set; } - public PhysicalAddress CMacaddr { get; set; } + public string AuthorName { get; set; } + public string Name { get; set; } + public ExtendedBioType? BioType { get; set; } }; - public async Task InsertPostgresTypesBatch(List args) - { - using (var connection = new NpgsqlConnection(ConnectionString)) - { - await connection.OpenAsync(); - using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresTypesBatchSql)) - { - foreach (var row in args) - { - await writer.StartRowAsync(); - await writer.WriteAsync(row.CBoolean ?? (object)DBNull.Value); - await writer.WriteAsync(row.CSmallint ?? (object)DBNull.Value); - await writer.WriteAsync(row.CInteger ?? (object)DBNull.Value); - await writer.WriteAsync(row.CBigint ?? (object)DBNull.Value); - await writer.WriteAsync(row.CReal ?? (object)DBNull.Value); - await writer.WriteAsync(row.CNumeric ?? (object)DBNull.Value); - await writer.WriteAsync(row.CDecimal ?? (object)DBNull.Value); - await writer.WriteAsync(row.CDoublePrecision ?? (object)DBNull.Value); - await writer.WriteAsync(row.CMoney ?? (object)DBNull.Value, NpgsqlDbType.Money); - await writer.WriteAsync(row.CDate ?? (object)DBNull.Value, NpgsqlDbType.Date); - await writer.WriteAsync(row.CTime ?? (object)DBNull.Value, NpgsqlDbType.Time); - await writer.WriteAsync(row.CTimestamp ?? (object)DBNull.Value); - await writer.WriteAsync(row.CTimestampWithTz ?? (object)DBNull.Value); - await writer.WriteAsync(row.CInterval ?? (object)DBNull.Value, NpgsqlDbType.Interval); - await writer.WriteAsync(row.CChar ?? (object)DBNull.Value); - await writer.WriteAsync(row.CVarchar ?? (object)DBNull.Value); - await writer.WriteAsync(row.CCharacterVarying ?? (object)DBNull.Value); - await writer.WriteAsync(row.CBpchar ?? (object)DBNull.Value); - await writer.WriteAsync(row.CText ?? (object)DBNull.Value); - await writer.WriteAsync(row.CUuid ?? (object)DBNull.Value); - await writer.WriteAsync(row.CCidr ?? (object)DBNull.Value); - await writer.WriteAsync(row.CInet ?? (object)DBNull.Value); - await writer.WriteAsync(row.CMacaddr ?? (object)DBNull.Value); - } - - await writer.CompleteAsync(); - } - - await connection.CloseAsync(); - } - } - - private const string GetPostgresTypesSql = "SELECT c_boolean , c_bit, c_smallint, c_integer, c_bigint, c_real, c_numeric, c_decimal, c_double_precision, c_money, c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_char, c_varchar, c_character_varying, c_bpchar, c_text, c_uuid, c_json, c_json_string_override, c_jsonb, c_jsonpath, c_xml, c_cidr, c_inet, c_macaddr, c_macaddr8 :: TEXT AS c_macaddr8 FROM postgres_types LIMIT 1 "; - public class GetPostgresTypesRow + public class GetFirstExtendedBioByTypeArgs { - public bool? CBoolean { get; set; } - public byte[] CBit { get; set; } - public short? CSmallint { get; set; } - public int? CInteger { get; set; } - public long? CBigint { get; set; } - public float? CReal { get; set; } - public decimal? CNumeric { get; set; } - public decimal? CDecimal { get; set; } - public double? CDoublePrecision { get; set; } - public decimal? CMoney { get; set; } - public DateTime? CDate { get; set; } - public TimeSpan? CTime { get; set; } - public DateTime? CTimestamp { get; set; } - public DateTime? CTimestampWithTz { get; set; } - public TimeSpan? CInterval { get; set; } - public string CChar { get; set; } - public string CVarchar { get; set; } - public string CCharacterVarying { get; set; } - public string CBpchar { get; set; } - public string CText { get; set; } - public Guid? CUuid { get; set; } - public JsonElement? CJson { get; set; } - public string CJsonStringOverride { get; set; } - public JsonElement? CJsonb { get; set; } - public string CJsonpath { get; set; } - public XmlDocument CXml { get; set; } - public NpgsqlCidr? CCidr { get; set; } - public IPAddress CInet { get; set; } - public PhysicalAddress CMacaddr { get; set; } - public string CMacaddr8 { get; set; } + public ExtendedBioType? BioType { get; set; } }; - public async Task GetPostgresTypes() + public async Task GetFirstExtendedBioByType(GetFirstExtendedBioByTypeArgs args) { if (this.Transaction == null) { using (var connection = NpgsqlDataSource.Create(ConnectionString)) { - using (var command = connection.CreateCommand(GetPostgresTypesSql)) + using (var command = connection.CreateCommand(GetFirstExtendedBioByTypeSql)) { + command.Parameters.AddWithValue("@bio_type", args.BioType != null ? args.BioType.Value.Stringify() : (object)DBNull.Value); using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetPostgresTypesRow + return new GetFirstExtendedBioByTypeRow { - CBoolean = reader.IsDBNull(0) ? (bool? )null : reader.GetBoolean(0), - CBit = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), - CSmallint = reader.IsDBNull(2) ? (short? )null : reader.GetInt16(2), - CInteger = reader.IsDBNull(3) ? (int? )null : reader.GetInt32(3), - CBigint = reader.IsDBNull(4) ? (long? )null : reader.GetInt64(4), - CReal = reader.IsDBNull(5) ? (float? )null : reader.GetFloat(5), - CNumeric = reader.IsDBNull(6) ? (decimal? )null : reader.GetDecimal(6), - CDecimal = reader.IsDBNull(7) ? (decimal? )null : reader.GetDecimal(7), - CDoublePrecision = reader.IsDBNull(8) ? (double? )null : reader.GetDouble(8), - CMoney = reader.IsDBNull(9) ? (decimal? )null : reader.GetDecimal(9), - CDate = reader.IsDBNull(10) ? (DateTime? )null : reader.GetDateTime(10), - CTime = reader.IsDBNull(11) ? (TimeSpan? )null : reader.GetFieldValue(11), - CTimestamp = reader.IsDBNull(12) ? (DateTime? )null : reader.GetDateTime(12), - CTimestampWithTz = reader.IsDBNull(13) ? (DateTime? )null : reader.GetDateTime(13), - CInterval = reader.IsDBNull(14) ? (TimeSpan? )null : reader.GetFieldValue(14), - CChar = reader.IsDBNull(15) ? null : reader.GetString(15), - CVarchar = reader.IsDBNull(16) ? null : reader.GetString(16), - CCharacterVarying = reader.IsDBNull(17) ? null : reader.GetString(17), - CBpchar = reader.IsDBNull(18) ? null : reader.GetString(18), - CText = reader.IsDBNull(19) ? null : reader.GetString(19), - CUuid = reader.IsDBNull(20) ? (Guid? )null : reader.GetFieldValue(20), - CJson = reader.IsDBNull(21) ? (JsonElement? )null : JsonSerializer.Deserialize(reader.GetString(21)), - CJsonStringOverride = reader.IsDBNull(22) ? null : reader.GetString(22), - CJsonb = reader.IsDBNull(23) ? (JsonElement? )null : JsonSerializer.Deserialize(reader.GetString(23)), - CJsonpath = reader.IsDBNull(24) ? null : reader.GetString(24), - CXml = reader.IsDBNull(25) ? null : (new Func((r, o) => - { - var xmlDoc = new XmlDocument(); - xmlDoc.LoadXml(r.GetString(o)); - return xmlDoc; - }))(reader, 25), - CCidr = reader.IsDBNull(26) ? (NpgsqlCidr? )null : reader.GetFieldValue(26), - CInet = reader.IsDBNull(27) ? null : reader.GetFieldValue(27), - CMacaddr = reader.IsDBNull(28) ? null : reader.GetFieldValue(28), - CMacaddr8 = reader.IsDBNull(29) ? null : reader.GetString(29) + AuthorName = reader.GetString(0), + Name = reader.GetString(1), + BioType = reader.IsDBNull(2) ? (ExtendedBioType? )null : reader.GetString(2).ToExtendedBioType() }; } } @@ -1036,55 +805,21 @@ public async Task GetPostgresTypes() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = GetPostgresTypesSql; + command.CommandText = GetFirstExtendedBioByTypeSql; command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@bio_type", args.BioType != null ? args.BioType.Value.Stringify() : (object)DBNull.Value); using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetPostgresTypesRow + return new GetFirstExtendedBioByTypeRow { - CBoolean = reader.IsDBNull(0) ? (bool? )null : reader.GetBoolean(0), - CBit = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), - CSmallint = reader.IsDBNull(2) ? (short? )null : reader.GetInt16(2), - CInteger = reader.IsDBNull(3) ? (int? )null : reader.GetInt32(3), - CBigint = reader.IsDBNull(4) ? (long? )null : reader.GetInt64(4), - CReal = reader.IsDBNull(5) ? (float? )null : reader.GetFloat(5), - CNumeric = reader.IsDBNull(6) ? (decimal? )null : reader.GetDecimal(6), - CDecimal = reader.IsDBNull(7) ? (decimal? )null : reader.GetDecimal(7), - CDoublePrecision = reader.IsDBNull(8) ? (double? )null : reader.GetDouble(8), - CMoney = reader.IsDBNull(9) ? (decimal? )null : reader.GetDecimal(9), - CDate = reader.IsDBNull(10) ? (DateTime? )null : reader.GetDateTime(10), - CTime = reader.IsDBNull(11) ? (TimeSpan? )null : reader.GetFieldValue(11), - CTimestamp = reader.IsDBNull(12) ? (DateTime? )null : reader.GetDateTime(12), - CTimestampWithTz = reader.IsDBNull(13) ? (DateTime? )null : reader.GetDateTime(13), - CInterval = reader.IsDBNull(14) ? (TimeSpan? )null : reader.GetFieldValue(14), - CChar = reader.IsDBNull(15) ? null : reader.GetString(15), - CVarchar = reader.IsDBNull(16) ? null : reader.GetString(16), - CCharacterVarying = reader.IsDBNull(17) ? null : reader.GetString(17), - CBpchar = reader.IsDBNull(18) ? null : reader.GetString(18), - CText = reader.IsDBNull(19) ? null : reader.GetString(19), - CUuid = reader.IsDBNull(20) ? (Guid? )null : reader.GetFieldValue(20), - CJson = reader.IsDBNull(21) ? (JsonElement? )null : JsonSerializer.Deserialize(reader.GetString(21)), - CJsonStringOverride = reader.IsDBNull(22) ? null : reader.GetString(22), - CJsonb = reader.IsDBNull(23) ? (JsonElement? )null : JsonSerializer.Deserialize(reader.GetString(23)), - CJsonpath = reader.IsDBNull(24) ? null : reader.GetString(24), - CXml = reader.IsDBNull(25) ? null : (new Func((r, o) => - { - var xmlDoc = new XmlDocument(); - xmlDoc.LoadXml(r.GetString(o)); - return xmlDoc; - }))(reader, 25), - CCidr = reader.IsDBNull(26) ? (NpgsqlCidr? )null : reader.GetFieldValue(26), - CInet = reader.IsDBNull(27) ? null : reader.GetFieldValue(27), - CMacaddr = reader.IsDBNull(28) ? null : reader.GetFieldValue(28), - CMacaddr8 = reader.IsDBNull(29) ? null : reader.GetString(29) + AuthorName = reader.GetString(0), + Name = reader.GetString(1), + BioType = reader.IsDBNull(2) ? (ExtendedBioType? )null : reader.GetString(2).ToExtendedBioType() }; } } @@ -1093,72 +828,965 @@ public async Task GetPostgresTypes() return null; } - private const string GetPostgresTypesCntSql = "SELECT c_smallint , c_boolean, c_integer, c_bigint, c_real, c_numeric, c_decimal, c_double_precision, c_money, c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_char, c_varchar, c_character_varying, c_bpchar, c_text, c_uuid, c_cidr, c_inet, c_macaddr, COUNT (* ) AS cnt FROM postgres_types GROUP BY c_smallint, c_boolean, c_integer, c_bigint, c_real, c_numeric, c_decimal, c_double_precision, c_money, c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, c_char, c_varchar, c_character_varying, c_bpchar, c_text, c_uuid, c_cidr, c_inet, c_macaddr LIMIT 1 "; - public class GetPostgresTypesCntRow + private const string TruncateExtendedBiosSql = "TRUNCATE TABLE extended.bios"; + public async Task TruncateExtendedBios() { - public short? CSmallint { get; set; } - public bool? CBoolean { get; set; } - public int? CInteger { get; set; } + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(TruncateExtendedBiosSql)) + { + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncateExtendedBiosSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } + + 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; } + public string MaxVarchar { get; set; } + public DateTime MaxTimestamp { get; set; } + }; + public async Task GetPostgresFunctions() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(GetPostgresFunctionsSql)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresFunctionsRow + { + MaxInteger = reader.IsDBNull(0) ? (int? )null : reader.GetInt32(0), + MaxVarchar = reader.IsDBNull(1) ? null : reader.GetString(1), + MaxTimestamp = reader.GetDateTime(2) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresFunctionsSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresFunctionsRow + { + MaxInteger = reader.IsDBNull(0) ? (int? )null : reader.GetInt32(0), + MaxVarchar = reader.IsDBNull(1) ? null : reader.GetString(1), + MaxTimestamp = reader.GetDateTime(2) + }; + } + } + } + + 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)"; + public class InsertPostgresNumericTypesArgs + { + public bool? CBoolean { get; set; } + public byte[] CBit { get; set; } + public short? CSmallint { get; set; } + public int? CInteger { get; set; } public long? CBigint { get; set; } + public decimal? CDecimal { get; set; } + public decimal? CNumeric { get; set; } public float? CReal { get; set; } + public double? CDoublePrecision { get; set; } + public decimal? CMoney { get; set; } + }; + public async Task InsertPostgresNumericTypes(InsertPostgresNumericTypesArgs args) + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(InsertPostgresNumericTypesSql)) + { + command.Parameters.AddWithValue("@c_boolean", args.CBoolean ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_bit", args.CBit ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_smallint", args.CSmallint ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_integer", args.CInteger ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_bigint", args.CBigint ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_decimal", args.CDecimal ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_numeric", args.CNumeric ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_real", args.CReal ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_double_precision", args.CDoublePrecision ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_money", args.CMoney ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = InsertPostgresNumericTypesSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@c_boolean", args.CBoolean ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_bit", args.CBit ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_smallint", args.CSmallint ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_integer", args.CInteger ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_bigint", args.CBigint ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_decimal", args.CDecimal ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_numeric", args.CNumeric ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_real", args.CReal ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_double_precision", args.CDoublePrecision ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_money", args.CMoney ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + private const string GetPostgresNumericTypesSql = "SELECT c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money FROM postgres_numeric_types LIMIT 1"; + public class GetPostgresNumericTypesRow + { + public bool? CBoolean { get; set; } + public byte[] CBit { get; set; } + public short? CSmallint { get; set; } + public int? CInteger { get; set; } + public long? CBigint { get; set; } + public decimal? CDecimal { get; set; } public decimal? CNumeric { get; set; } + public float? CReal { get; set; } + public double? CDoublePrecision { get; set; } + public decimal? CMoney { get; set; } + }; + public async Task GetPostgresNumericTypes() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(GetPostgresNumericTypesSql)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresNumericTypesRow + { + CBoolean = reader.IsDBNull(0) ? (bool? )null : reader.GetBoolean(0), + CBit = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CSmallint = reader.IsDBNull(2) ? (short? )null : reader.GetInt16(2), + CInteger = reader.IsDBNull(3) ? (int? )null : reader.GetInt32(3), + CBigint = reader.IsDBNull(4) ? (long? )null : reader.GetInt64(4), + CDecimal = reader.IsDBNull(5) ? (decimal? )null : reader.GetDecimal(5), + CNumeric = reader.IsDBNull(6) ? (decimal? )null : reader.GetDecimal(6), + CReal = reader.IsDBNull(7) ? (float? )null : reader.GetFloat(7), + CDoublePrecision = reader.IsDBNull(8) ? (double? )null : reader.GetDouble(8), + CMoney = reader.IsDBNull(9) ? (decimal? )null : reader.GetDecimal(9) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresNumericTypesSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresNumericTypesRow + { + CBoolean = reader.IsDBNull(0) ? (bool? )null : reader.GetBoolean(0), + CBit = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CSmallint = reader.IsDBNull(2) ? (short? )null : reader.GetInt16(2), + CInteger = reader.IsDBNull(3) ? (int? )null : reader.GetInt32(3), + CBigint = reader.IsDBNull(4) ? (long? )null : reader.GetInt64(4), + CDecimal = reader.IsDBNull(5) ? (decimal? )null : reader.GetDecimal(5), + CNumeric = reader.IsDBNull(6) ? (decimal? )null : reader.GetDecimal(6), + CReal = reader.IsDBNull(7) ? (float? )null : reader.GetFloat(7), + CDoublePrecision = reader.IsDBNull(8) ? (double? )null : reader.GetDouble(8), + CMoney = reader.IsDBNull(9) ? (decimal? )null : reader.GetDecimal(9) + }; + } + } + } + + return null; + } + + private const string TruncatePostgresNumericTypesSql = "TRUNCATE TABLE postgres_numeric_types"; + public async Task TruncatePostgresNumericTypes() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(TruncatePostgresNumericTypesSql)) + { + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncatePostgresNumericTypesSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } + + 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; } + public byte[] CBit { get; set; } + public short? CSmallint { get; set; } + public int? CInteger { get; set; } + public long? CBigint { get; set; } public decimal? CDecimal { get; set; } + public decimal? CNumeric { get; set; } + public float? CReal { get; set; } public double? CDoublePrecision { get; set; } public decimal? CMoney { get; set; } - public DateTime? CDate { get; set; } - public TimeSpan? CTime { get; set; } - public DateTime? CTimestamp { get; set; } - public DateTime? CTimestampWithTz { get; set; } - public TimeSpan? CInterval { get; set; } - public string CChar { get; set; } - public string CVarchar { get; set; } - public string CCharacterVarying { get; set; } - public string CBpchar { get; set; } - public string CText { get; set; } - public Guid? CUuid { get; set; } + public long Cnt { get; set; } + }; + public async Task GetPostgresNumericTypesCnt() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(GetPostgresNumericTypesCntSql)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresNumericTypesCntRow + { + CBoolean = reader.IsDBNull(0) ? (bool? )null : reader.GetBoolean(0), + CBit = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CSmallint = reader.IsDBNull(2) ? (short? )null : reader.GetInt16(2), + CInteger = reader.IsDBNull(3) ? (int? )null : reader.GetInt32(3), + CBigint = reader.IsDBNull(4) ? (long? )null : reader.GetInt64(4), + CDecimal = reader.IsDBNull(5) ? (decimal? )null : reader.GetDecimal(5), + CNumeric = reader.IsDBNull(6) ? (decimal? )null : reader.GetDecimal(6), + CReal = reader.IsDBNull(7) ? (float? )null : reader.GetFloat(7), + CDoublePrecision = reader.IsDBNull(8) ? (double? )null : reader.GetDouble(8), + CMoney = reader.IsDBNull(9) ? (decimal? )null : reader.GetDecimal(9), + Cnt = reader.GetInt64(10) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresNumericTypesCntSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresNumericTypesCntRow + { + CBoolean = reader.IsDBNull(0) ? (bool? )null : reader.GetBoolean(0), + CBit = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CSmallint = reader.IsDBNull(2) ? (short? )null : reader.GetInt16(2), + CInteger = reader.IsDBNull(3) ? (int? )null : reader.GetInt32(3), + CBigint = reader.IsDBNull(4) ? (long? )null : reader.GetInt64(4), + CDecimal = reader.IsDBNull(5) ? (decimal? )null : reader.GetDecimal(5), + CNumeric = reader.IsDBNull(6) ? (decimal? )null : reader.GetDecimal(6), + CReal = reader.IsDBNull(7) ? (float? )null : reader.GetFloat(7), + CDoublePrecision = reader.IsDBNull(8) ? (double? )null : reader.GetDouble(8), + CMoney = reader.IsDBNull(9) ? (decimal? )null : reader.GetDecimal(9), + Cnt = reader.GetInt64(10) + }; + } + } + } + + return null; + } + + private const string InsertPostgresNumericTypesBatchSql = "COPY postgres_numeric_types (c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money) FROM STDIN (FORMAT BINARY)"; + public class InsertPostgresNumericTypesBatchArgs + { + public bool? CBoolean { get; set; } + public byte[] CBit { get; set; } + public short? CSmallint { get; set; } + public int? CInteger { get; set; } + public long? CBigint { get; set; } + public decimal? CDecimal { get; set; } + public decimal? CNumeric { get; set; } + public float? CReal { get; set; } + public double? CDoublePrecision { get; set; } + public decimal? CMoney { get; set; } + }; + public async Task InsertPostgresNumericTypesBatch(List args) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresNumericTypesBatchSql)) + { + foreach (var row in args) + { + await writer.StartRowAsync(); + await writer.WriteAsync(row.CBoolean ?? (object)DBNull.Value); + await writer.WriteAsync(row.CBit ?? (object)DBNull.Value); + await writer.WriteAsync(row.CSmallint ?? (object)DBNull.Value); + await writer.WriteAsync(row.CInteger ?? (object)DBNull.Value); + await writer.WriteAsync(row.CBigint ?? (object)DBNull.Value); + await writer.WriteAsync(row.CDecimal ?? (object)DBNull.Value); + await writer.WriteAsync(row.CNumeric ?? (object)DBNull.Value); + await writer.WriteAsync(row.CReal ?? (object)DBNull.Value); + await writer.WriteAsync(row.CDoublePrecision ?? (object)DBNull.Value); + await writer.WriteAsync(row.CMoney ?? (object)DBNull.Value, NpgsqlDbType.Money); + } + + await writer.CompleteAsync(); + } + + await connection.CloseAsync(); + } + } + + private const string InsertPostgresStringTypesSql = " INSERT INTO postgres_string_types ( c_char, c_varchar, c_character_varying, c_bpchar, c_text ) VALUES (@c_char, @c_varchar, @c_character_varying, @c_bpchar, @c_text)"; + public class InsertPostgresStringTypesArgs + { + public string CChar { get; set; } + public string CVarchar { get; set; } + public string CCharacterVarying { get; set; } + public string CBpchar { get; set; } + public string CText { get; set; } + }; + public async Task InsertPostgresStringTypes(InsertPostgresStringTypesArgs args) + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(InsertPostgresStringTypesSql)) + { + command.Parameters.AddWithValue("@c_char", args.CChar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_varchar", args.CVarchar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_character_varying", args.CCharacterVarying ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_bpchar", args.CBpchar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_text", args.CText ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = InsertPostgresStringTypesSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@c_char", args.CChar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_varchar", args.CVarchar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_character_varying", args.CCharacterVarying ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_bpchar", args.CBpchar ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_text", args.CText ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + private const string InsertPostgresStringTypesBatchSql = "COPY postgres_string_types (c_char, c_varchar, c_character_varying, c_bpchar, c_text) FROM STDIN (FORMAT BINARY)"; + public class InsertPostgresStringTypesBatchArgs + { + public string CChar { get; set; } + public string CVarchar { get; set; } + public string CCharacterVarying { get; set; } + public string CBpchar { get; set; } + public string CText { get; set; } + }; + public async Task InsertPostgresStringTypesBatch(List args) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresStringTypesBatchSql)) + { + foreach (var row in args) + { + await writer.StartRowAsync(); + await writer.WriteAsync(row.CChar ?? (object)DBNull.Value); + await writer.WriteAsync(row.CVarchar ?? (object)DBNull.Value); + await writer.WriteAsync(row.CCharacterVarying ?? (object)DBNull.Value); + await writer.WriteAsync(row.CBpchar ?? (object)DBNull.Value); + await writer.WriteAsync(row.CText ?? (object)DBNull.Value); + } + + await writer.CompleteAsync(); + } + + await connection.CloseAsync(); + } + } + + private const string GetPostgresStringTypesSql = "SELECT c_char, c_varchar, c_character_varying, c_bpchar, c_text FROM postgres_string_types LIMIT 1"; + public class GetPostgresStringTypesRow + { + public string CChar { get; set; } + public string CVarchar { get; set; } + public string CCharacterVarying { get; set; } + public string CBpchar { get; set; } + public string CText { get; set; } + }; + public async Task GetPostgresStringTypes() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(GetPostgresStringTypesSql)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresStringTypesRow + { + CChar = reader.IsDBNull(0) ? null : reader.GetString(0), + CVarchar = reader.IsDBNull(1) ? null : reader.GetString(1), + CCharacterVarying = reader.IsDBNull(2) ? null : reader.GetString(2), + CBpchar = reader.IsDBNull(3) ? null : reader.GetString(3), + CText = reader.IsDBNull(4) ? null : reader.GetString(4) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresStringTypesSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresStringTypesRow + { + CChar = reader.IsDBNull(0) ? null : reader.GetString(0), + CVarchar = reader.IsDBNull(1) ? null : reader.GetString(1), + CCharacterVarying = reader.IsDBNull(2) ? null : reader.GetString(2), + CBpchar = reader.IsDBNull(3) ? null : reader.GetString(3), + CText = reader.IsDBNull(4) ? null : reader.GetString(4) + }; + } + } + } + + return null; + } + + private const string TruncatePostgresStringTypesSql = "TRUNCATE TABLE postgres_string_types"; + public async Task TruncatePostgresStringTypes() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(TruncatePostgresStringTypesSql)) + { + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncatePostgresStringTypesSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } + + private const string GetPostgresStringTypesCntSql = "SELECT c_char, c_varchar, c_character_varying, c_bpchar, c_text, COUNT(*) AS cnt FROM postgres_string_types GROUP BY c_char, c_varchar, c_character_varying, c_bpchar, c_text LIMIT 1"; + public class GetPostgresStringTypesCntRow + { + public string CChar { get; set; } + public string CVarchar { get; set; } + public string CCharacterVarying { get; set; } + public string CBpchar { get; set; } + public string CText { get; set; } + public long Cnt { get; set; } + }; + public async Task GetPostgresStringTypesCnt() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(GetPostgresStringTypesCntSql)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresStringTypesCntRow + { + CChar = reader.IsDBNull(0) ? null : reader.GetString(0), + CVarchar = reader.IsDBNull(1) ? null : reader.GetString(1), + CCharacterVarying = reader.IsDBNull(2) ? null : reader.GetString(2), + CBpchar = reader.IsDBNull(3) ? null : reader.GetString(3), + CText = reader.IsDBNull(4) ? null : reader.GetString(4), + Cnt = reader.GetInt64(5) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresStringTypesCntSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresStringTypesCntRow + { + CChar = reader.IsDBNull(0) ? null : reader.GetString(0), + CVarchar = reader.IsDBNull(1) ? null : reader.GetString(1), + CCharacterVarying = reader.IsDBNull(2) ? null : reader.GetString(2), + CBpchar = reader.IsDBNull(3) ? null : reader.GetString(3), + CText = reader.IsDBNull(4) ? null : reader.GetString(4), + Cnt = reader.GetInt64(5) + }; + } + } + } + + 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"; + public class GetPostgresStringTypesTextSearchRow + { + public string CText { get; set; } + public NpgsqlTsQuery Query { get; set; } + public NpgsqlTsVector Tsv { get; set; } + public float Rnk { get; set; } + }; + public class GetPostgresStringTypesTextSearchArgs + { + public string ToTsquery { get; set; } + }; + public async Task GetPostgresStringTypesTextSearch(GetPostgresStringTypesTextSearchArgs args) + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(GetPostgresStringTypesTextSearchSql)) + { + command.Parameters.AddWithValue("@to_tsquery", args.ToTsquery); + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresStringTypesTextSearchRow + { + CText = reader.IsDBNull(0) ? null : reader.GetString(0), + Query = reader.GetFieldValue(1), + Tsv = reader.GetFieldValue(2), + Rnk = reader.GetFloat(3) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresStringTypesTextSearchSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@to_tsquery", args.ToTsquery); + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresStringTypesTextSearchRow + { + CText = reader.IsDBNull(0) ? null : reader.GetString(0), + Query = reader.GetFieldValue(1), + Tsv = reader.GetFieldValue(2), + Rnk = reader.GetFloat(3) + }; + } + } + } + + return null; + } + + private const string InsertPostgresDateTimeTypesSql = " INSERT INTO postgres_datetime_types ( c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval ) VALUES (@c_date, @c_time, @c_timestamp, @c_timestamp_with_tz, @c_interval)"; + public class InsertPostgresDateTimeTypesArgs + { + public DateTime? CDate { get; set; } + public TimeSpan? CTime { get; set; } + public DateTime? CTimestamp { get; set; } + public DateTime? CTimestampWithTz { get; set; } + public TimeSpan? CInterval { get; set; } + }; + public async Task InsertPostgresDateTimeTypes(InsertPostgresDateTimeTypesArgs args) + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(InsertPostgresDateTimeTypesSql)) + { + command.Parameters.AddWithValue("@c_date", args.CDate ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_time", args.CTime ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_timestamp", args.CTimestamp ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_timestamp_with_tz", args.CTimestampWithTz ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_interval", args.CInterval ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = InsertPostgresDateTimeTypesSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@c_date", args.CDate ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_time", args.CTime ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_timestamp", args.CTimestamp ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_timestamp_with_tz", args.CTimestampWithTz ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_interval", args.CInterval ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + private const string GetPostgresDateTimeTypesSql = "SELECT c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval FROM postgres_datetime_types LIMIT 1"; + public class GetPostgresDateTimeTypesRow + { + public DateTime? CDate { get; set; } + public TimeSpan? CTime { get; set; } + public DateTime? CTimestamp { get; set; } + public DateTime? CTimestampWithTz { get; set; } + public TimeSpan? CInterval { get; set; } + }; + public async Task GetPostgresDateTimeTypes() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(GetPostgresDateTimeTypesSql)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresDateTimeTypesRow + { + CDate = reader.IsDBNull(0) ? (DateTime? )null : reader.GetDateTime(0), + CTime = reader.IsDBNull(1) ? (TimeSpan? )null : reader.GetFieldValue(1), + CTimestamp = reader.IsDBNull(2) ? (DateTime? )null : reader.GetDateTime(2), + CTimestampWithTz = reader.IsDBNull(3) ? (DateTime? )null : reader.GetDateTime(3), + CInterval = reader.IsDBNull(4) ? (TimeSpan? )null : reader.GetFieldValue(4) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresDateTimeTypesSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresDateTimeTypesRow + { + CDate = reader.IsDBNull(0) ? (DateTime? )null : reader.GetDateTime(0), + CTime = reader.IsDBNull(1) ? (TimeSpan? )null : reader.GetFieldValue(1), + CTimestamp = reader.IsDBNull(2) ? (DateTime? )null : reader.GetDateTime(2), + CTimestampWithTz = reader.IsDBNull(3) ? (DateTime? )null : reader.GetDateTime(3), + CInterval = reader.IsDBNull(4) ? (TimeSpan? )null : reader.GetFieldValue(4) + }; + } + } + } + + return null; + } + + private const string TruncatePostgresDateTimeTypesSql = "TRUNCATE TABLE postgres_datetime_types"; + public async Task TruncatePostgresDateTimeTypes() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(TruncatePostgresDateTimeTypesSql)) + { + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncatePostgresDateTimeTypesSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } + + 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; } + public TimeSpan? CTime { get; set; } + public DateTime? CTimestamp { get; set; } + public DateTime? CTimestampWithTz { get; set; } + public TimeSpan? CInterval { get; set; } + public long Cnt { get; set; } + }; + public async Task GetPostgresDateTimeTypesCnt() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(GetPostgresDateTimeTypesCntSql)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresDateTimeTypesCntRow + { + CDate = reader.IsDBNull(0) ? (DateTime? )null : reader.GetDateTime(0), + CTime = reader.IsDBNull(1) ? (TimeSpan? )null : reader.GetFieldValue(1), + CTimestamp = reader.IsDBNull(2) ? (DateTime? )null : reader.GetDateTime(2), + CTimestampWithTz = reader.IsDBNull(3) ? (DateTime? )null : reader.GetDateTime(3), + CInterval = reader.IsDBNull(4) ? (TimeSpan? )null : reader.GetFieldValue(4), + Cnt = reader.GetInt64(5) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresDateTimeTypesCntSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresDateTimeTypesCntRow + { + CDate = reader.IsDBNull(0) ? (DateTime? )null : reader.GetDateTime(0), + CTime = reader.IsDBNull(1) ? (TimeSpan? )null : reader.GetFieldValue(1), + CTimestamp = reader.IsDBNull(2) ? (DateTime? )null : reader.GetDateTime(2), + CTimestampWithTz = reader.IsDBNull(3) ? (DateTime? )null : reader.GetDateTime(3), + CInterval = reader.IsDBNull(4) ? (TimeSpan? )null : reader.GetFieldValue(4), + Cnt = reader.GetInt64(5) + }; + } + } + } + + return null; + } + + private const string InsertPostgresDateTimeTypesBatchSql = "COPY postgres_datetime_types (c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval) FROM STDIN (FORMAT BINARY)"; + public class InsertPostgresDateTimeTypesBatchArgs + { + public DateTime? CDate { get; set; } + public TimeSpan? CTime { get; set; } + public DateTime? CTimestamp { get; set; } + public DateTime? CTimestampWithTz { get; set; } + public TimeSpan? CInterval { get; set; } + }; + public async Task InsertPostgresDateTimeTypesBatch(List args) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresDateTimeTypesBatchSql)) + { + foreach (var row in args) + { + await writer.StartRowAsync(); + await writer.WriteAsync(row.CDate ?? (object)DBNull.Value, NpgsqlDbType.Date); + await writer.WriteAsync(row.CTime ?? (object)DBNull.Value, NpgsqlDbType.Time); + await writer.WriteAsync(row.CTimestamp ?? (object)DBNull.Value); + await writer.WriteAsync(row.CTimestampWithTz ?? (object)DBNull.Value); + await writer.WriteAsync(row.CInterval ?? (object)DBNull.Value, NpgsqlDbType.Interval); + } + + await writer.CompleteAsync(); + } + + await connection.CloseAsync(); + } + } + + private const string InsertPostgresNetworkTypesSql = " INSERT INTO postgres_network_types ( c_cidr, c_inet, c_macaddr, c_macaddr8 ) VALUES ( @c_cidr, @c_inet, @c_macaddr, @c_macaddr8::macaddr8 )"; + public class InsertPostgresNetworkTypesArgs + { + public NpgsqlCidr? CCidr { get; set; } + public IPAddress CInet { get; set; } + public PhysicalAddress CMacaddr { get; set; } + public string CMacaddr8 { get; set; } + }; + public async Task InsertPostgresNetworkTypes(InsertPostgresNetworkTypesArgs args) + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(InsertPostgresNetworkTypesSql)) + { + command.Parameters.AddWithValue("@c_cidr", args.CCidr ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_inet", args.CInet ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_macaddr", args.CMacaddr ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_macaddr8", args.CMacaddr8 ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = InsertPostgresNetworkTypesSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@c_cidr", args.CCidr ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_inet", args.CInet ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_macaddr", args.CMacaddr ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_macaddr8", args.CMacaddr8 ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + private const string GetPostgresNetworkTypesSql = "SELECT c_cidr, c_inet, c_macaddr, c_macaddr8::TEXT AS c_macaddr8 FROM postgres_network_types LIMIT 1"; + public class GetPostgresNetworkTypesRow + { public NpgsqlCidr? CCidr { get; set; } public IPAddress CInet { get; set; } public PhysicalAddress CMacaddr { get; set; } - public long Cnt { get; set; } + public string CMacaddr8 { get; set; } }; - public async Task GetPostgresTypesCnt() + public async Task GetPostgresNetworkTypes() { if (this.Transaction == null) { using (var connection = NpgsqlDataSource.Create(ConnectionString)) { - using (var command = connection.CreateCommand(GetPostgresTypesCntSql)) + using (var command = connection.CreateCommand(GetPostgresNetworkTypesSql)) { using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetPostgresTypesCntRow + return new GetPostgresNetworkTypesRow { - CSmallint = reader.IsDBNull(0) ? (short? )null : reader.GetInt16(0), - CBoolean = reader.IsDBNull(1) ? (bool? )null : reader.GetBoolean(1), - CInteger = reader.IsDBNull(2) ? (int? )null : reader.GetInt32(2), - CBigint = reader.IsDBNull(3) ? (long? )null : reader.GetInt64(3), - CReal = reader.IsDBNull(4) ? (float? )null : reader.GetFloat(4), - CNumeric = reader.IsDBNull(5) ? (decimal? )null : reader.GetDecimal(5), - CDecimal = reader.IsDBNull(6) ? (decimal? )null : reader.GetDecimal(6), - CDoublePrecision = reader.IsDBNull(7) ? (double? )null : reader.GetDouble(7), - CMoney = reader.IsDBNull(8) ? (decimal? )null : reader.GetDecimal(8), - CDate = reader.IsDBNull(9) ? (DateTime? )null : reader.GetDateTime(9), - CTime = reader.IsDBNull(10) ? (TimeSpan? )null : reader.GetFieldValue(10), - CTimestamp = reader.IsDBNull(11) ? (DateTime? )null : reader.GetDateTime(11), - CTimestampWithTz = reader.IsDBNull(12) ? (DateTime? )null : reader.GetDateTime(12), - CInterval = reader.IsDBNull(13) ? (TimeSpan? )null : reader.GetFieldValue(13), - CChar = reader.IsDBNull(14) ? null : reader.GetString(14), - CVarchar = reader.IsDBNull(15) ? null : reader.GetString(15), - CCharacterVarying = reader.IsDBNull(16) ? null : reader.GetString(16), - CBpchar = reader.IsDBNull(17) ? null : reader.GetString(17), - CText = reader.IsDBNull(18) ? null : reader.GetString(18), - CUuid = reader.IsDBNull(19) ? (Guid? )null : reader.GetFieldValue(19), - CCidr = reader.IsDBNull(20) ? (NpgsqlCidr? )null : reader.GetFieldValue(20), - CInet = reader.IsDBNull(21) ? null : reader.GetFieldValue(21), - CMacaddr = reader.IsDBNull(22) ? null : reader.GetFieldValue(22), - Cnt = reader.GetInt64(23) + CCidr = reader.IsDBNull(0) ? (NpgsqlCidr? )null : reader.GetFieldValue(0), + CInet = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CMacaddr = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + CMacaddr8 = reader.IsDBNull(3) ? null : reader.GetString(3) }; } } @@ -1169,44 +1797,21 @@ public async Task GetPostgresTypesCnt() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = GetPostgresTypesCntSql; + command.CommandText = GetPostgresNetworkTypesSql; command.Transaction = this.Transaction; using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetPostgresTypesCntRow + return new GetPostgresNetworkTypesRow { - CSmallint = reader.IsDBNull(0) ? (short? )null : reader.GetInt16(0), - CBoolean = reader.IsDBNull(1) ? (bool? )null : reader.GetBoolean(1), - CInteger = reader.IsDBNull(2) ? (int? )null : reader.GetInt32(2), - CBigint = reader.IsDBNull(3) ? (long? )null : reader.GetInt64(3), - CReal = reader.IsDBNull(4) ? (float? )null : reader.GetFloat(4), - CNumeric = reader.IsDBNull(5) ? (decimal? )null : reader.GetDecimal(5), - CDecimal = reader.IsDBNull(6) ? (decimal? )null : reader.GetDecimal(6), - CDoublePrecision = reader.IsDBNull(7) ? (double? )null : reader.GetDouble(7), - CMoney = reader.IsDBNull(8) ? (decimal? )null : reader.GetDecimal(8), - CDate = reader.IsDBNull(9) ? (DateTime? )null : reader.GetDateTime(9), - CTime = reader.IsDBNull(10) ? (TimeSpan? )null : reader.GetFieldValue(10), - CTimestamp = reader.IsDBNull(11) ? (DateTime? )null : reader.GetDateTime(11), - CTimestampWithTz = reader.IsDBNull(12) ? (DateTime? )null : reader.GetDateTime(12), - CInterval = reader.IsDBNull(13) ? (TimeSpan? )null : reader.GetFieldValue(13), - CChar = reader.IsDBNull(14) ? null : reader.GetString(14), - CVarchar = reader.IsDBNull(15) ? null : reader.GetString(15), - CCharacterVarying = reader.IsDBNull(16) ? null : reader.GetString(16), - CBpchar = reader.IsDBNull(17) ? null : reader.GetString(17), - CText = reader.IsDBNull(18) ? null : reader.GetString(18), - CUuid = reader.IsDBNull(19) ? (Guid? )null : reader.GetFieldValue(19), - CCidr = reader.IsDBNull(20) ? (NpgsqlCidr? )null : reader.GetFieldValue(20), - CInet = reader.IsDBNull(21) ? null : reader.GetFieldValue(21), - CMacaddr = reader.IsDBNull(22) ? null : reader.GetFieldValue(22), - Cnt = reader.GetInt64(23) + CCidr = reader.IsDBNull(0) ? (NpgsqlCidr? )null : reader.GetFieldValue(0), + CInet = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CMacaddr = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + CMacaddr8 = reader.IsDBNull(3) ? null : reader.GetString(3) }; } } @@ -1215,30 +1820,58 @@ public async Task GetPostgresTypesCnt() return null; } - 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_types "; - public class GetPostgresFunctionsRow + private const string TruncatePostgresNetworkTypesSql = "TRUNCATE TABLE postgres_network_types"; + public async Task TruncatePostgresNetworkTypes() { - public int? MaxInteger { get; set; } - public string MaxVarchar { get; set; } - public DateTime MaxTimestamp { get; set; } + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(TruncatePostgresNetworkTypesSql)) + { + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncatePostgresNetworkTypesSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } + + 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 class GetPostgresNetworkTypesCntRow + { + public NpgsqlCidr? CCidr { get; set; } + public IPAddress CInet { get; set; } + public PhysicalAddress CMacaddr { get; set; } + public long Cnt { get; set; } }; - public async Task GetPostgresFunctions() + public async Task GetPostgresNetworkTypesCnt() { if (this.Transaction == null) { using (var connection = NpgsqlDataSource.Create(ConnectionString)) { - using (var command = connection.CreateCommand(GetPostgresFunctionsSql)) + using (var command = connection.CreateCommand(GetPostgresNetworkTypesCntSql)) { using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetPostgresFunctionsRow + return new GetPostgresNetworkTypesCntRow { - MaxInteger = reader.IsDBNull(0) ? (int? )null : reader.GetInt32(0), - MaxVarchar = reader.IsDBNull(1) ? null : reader.GetString(1), - MaxTimestamp = reader.GetDateTime(2) + CCidr = reader.IsDBNull(0) ? (NpgsqlCidr? )null : reader.GetFieldValue(0), + CInet = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CMacaddr = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + Cnt = reader.GetInt64(3) }; } } @@ -1249,23 +1882,21 @@ public async Task GetPostgresFunctions() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = GetPostgresFunctionsSql; + command.CommandText = GetPostgresNetworkTypesCntSql; command.Transaction = this.Transaction; using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetPostgresFunctionsRow + return new GetPostgresNetworkTypesCntRow { - MaxInteger = reader.IsDBNull(0) ? (int? )null : reader.GetInt32(0), - MaxVarchar = reader.IsDBNull(1) ? null : reader.GetString(1), - MaxTimestamp = reader.GetDateTime(2) + CCidr = reader.IsDBNull(0) ? (NpgsqlCidr? )null : reader.GetFieldValue(0), + CInet = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CMacaddr = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + Cnt = reader.GetInt64(3) }; } } @@ -1274,128 +1905,127 @@ public async Task GetPostgresFunctions() return null; } - 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 class InsertPostgresGeoTypesArgs + private const string InsertPostgresNetworkTypesBatchSql = "COPY postgres_network_types (c_cidr, c_inet, c_macaddr) FROM STDIN (FORMAT BINARY)"; + public class InsertPostgresNetworkTypesBatchArgs { - public NpgsqlPoint? CPoint { get; set; } - public NpgsqlLine? CLine { get; set; } - public NpgsqlLSeg? CLseg { get; set; } - public NpgsqlBox? CBox { get; set; } - public NpgsqlPath? CPath { get; set; } - public NpgsqlPolygon? CPolygon { get; set; } - public NpgsqlCircle? CCircle { get; set; } + public NpgsqlCidr? CCidr { get; set; } + public IPAddress CInet { get; set; } + public PhysicalAddress CMacaddr { get; set; } }; - public async Task InsertPostgresGeoTypes(InsertPostgresGeoTypesArgs args) + public async Task InsertPostgresNetworkTypesBatch(List args) { - if (this.Transaction == null) + using (var connection = new NpgsqlConnection(ConnectionString)) { - using (var connection = NpgsqlDataSource.Create(ConnectionString)) + await connection.OpenAsync(); + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresNetworkTypesBatchSql)) { - using (var command = connection.CreateCommand(InsertPostgresGeoTypesSql)) + foreach (var row in args) { - command.Parameters.AddWithValue("@c_point", args.CPoint ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_line", args.CLine ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_lseg", args.CLseg ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_box", args.CBox ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_path", args.CPath ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_polygon", args.CPolygon ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_circle", args.CCircle ?? (object)DBNull.Value); - await command.ExecuteNonQueryAsync(); + await writer.StartRowAsync(); + await writer.WriteAsync(row.CCidr ?? (object)DBNull.Value); + await writer.WriteAsync(row.CInet ?? (object)DBNull.Value); + await writer.WriteAsync(row.CMacaddr ?? (object)DBNull.Value); } - } - - return; - } - if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } + await writer.CompleteAsync(); + } - using (var command = this.Transaction.Connection.CreateCommand()) - { - command.CommandText = InsertPostgresGeoTypesSql; - command.Transaction = this.Transaction; - command.Parameters.AddWithValue("@c_point", args.CPoint ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_line", args.CLine ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_lseg", args.CLseg ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_box", args.CBox ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_path", args.CPath ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_polygon", args.CPolygon ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@c_circle", args.CCircle ?? (object)DBNull.Value); - await command.ExecuteNonQueryAsync(); + await connection.CloseAsync(); } } - private const string InsertPostgresGeoTypesBatchSql = "COPY postgres_geometric_types (c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle) FROM STDIN (FORMAT BINARY)"; - public class InsertPostgresGeoTypesBatchArgs + private const string InsertPostgresSpecialTypesSql = " INSERT INTO postgres_special_types ( c_json, c_json_string_override, c_jsonb, c_jsonpath, c_xml, c_xml_string_override, c_uuid, c_enum ) VALUES ( @c_json::json, @c_json_string_override::json, @c_jsonb::jsonb, @c_jsonpath::jsonpath, @c_xml::xml, @c_xml_string_override::xml, @c_uuid, @c_enum::c_enum )"; + public class InsertPostgresSpecialTypesArgs { - public NpgsqlPoint? CPoint { get; set; } - public NpgsqlLine? CLine { get; set; } - public NpgsqlLSeg? CLseg { get; set; } - public NpgsqlBox? CBox { get; set; } - public NpgsqlPath? CPath { get; set; } - public NpgsqlPolygon? CPolygon { get; set; } - public NpgsqlCircle? CCircle { get; set; } + public JsonElement? CJson { get; set; } + public string CJsonStringOverride { get; set; } + public JsonElement? CJsonb { get; set; } + public string CJsonpath { get; set; } + public XmlDocument CXml { get; set; } + public string CXmlStringOverride { get; set; } + public Guid? CUuid { get; set; } + public CEnum? CEnum { get; set; } }; - public async Task InsertPostgresGeoTypesBatch(List args) + public async Task InsertPostgresSpecialTypes(InsertPostgresSpecialTypesArgs args) { - using (var connection = new NpgsqlConnection(ConnectionString)) + if (this.Transaction == null) { - await connection.OpenAsync(); - using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresGeoTypesBatchSql)) + using (var connection = NpgsqlDataSource.Create(ConnectionString)) { - foreach (var row in args) + using (var command = connection.CreateCommand(InsertPostgresSpecialTypesSql)) { - await writer.StartRowAsync(); - await writer.WriteAsync(row.CPoint ?? (object)DBNull.Value); - await writer.WriteAsync(row.CLine ?? (object)DBNull.Value); - await writer.WriteAsync(row.CLseg ?? (object)DBNull.Value); - await writer.WriteAsync(row.CBox ?? (object)DBNull.Value); - await writer.WriteAsync(row.CPath ?? (object)DBNull.Value); - await writer.WriteAsync(row.CPolygon ?? (object)DBNull.Value); - await writer.WriteAsync(row.CCircle ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_json", args.CJson.HasValue ? args.CJson.Value.GetRawText() : (object)DBNull.Value); + command.Parameters.AddWithValue("@c_json_string_override", args.CJsonStringOverride ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_jsonb", args.CJsonb.HasValue ? args.CJsonb.Value.GetRawText() : (object)DBNull.Value); + command.Parameters.AddWithValue("@c_jsonpath", args.CJsonpath ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_xml", args.CXml != null ? args.CXml.OuterXml : (object)DBNull.Value); + command.Parameters.AddWithValue("@c_xml_string_override", args.CXmlStringOverride ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_uuid", args.CUuid ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_enum", args.CEnum != null ? args.CEnum.Value.Stringify() : (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); } - - await writer.CompleteAsync(); } - await connection.CloseAsync(); + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = InsertPostgresSpecialTypesSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@c_json", args.CJson.HasValue ? args.CJson.Value.GetRawText() : (object)DBNull.Value); + command.Parameters.AddWithValue("@c_json_string_override", args.CJsonStringOverride ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_jsonb", args.CJsonb.HasValue ? args.CJsonb.Value.GetRawText() : (object)DBNull.Value); + command.Parameters.AddWithValue("@c_jsonpath", args.CJsonpath ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_xml", args.CXml != null ? args.CXml.OuterXml : (object)DBNull.Value); + command.Parameters.AddWithValue("@c_xml_string_override", args.CXmlStringOverride ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_uuid", args.CUuid ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_enum", args.CEnum != null ? args.CEnum.Value.Stringify() : (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); } } - private const string GetPostgresGeoTypesSql = "SELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgres_geometric_types LIMIT 1"; - public class GetPostgresGeoTypesRow + 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 class GetPostgresSpecialTypesRow { - public NpgsqlPoint? CPoint { get; set; } - public NpgsqlLine? CLine { get; set; } - public NpgsqlLSeg? CLseg { get; set; } - public NpgsqlBox? CBox { get; set; } - public NpgsqlPath? CPath { get; set; } - public NpgsqlPolygon? CPolygon { get; set; } - public NpgsqlCircle? CCircle { get; set; } + public JsonElement? CJson { get; set; } + public string CJsonStringOverride { get; set; } + public JsonElement? CJsonb { get; set; } + public string CJsonpath { get; set; } + public XmlDocument CXml { get; set; } + public string CXmlStringOverride { get; set; } + public Guid? CUuid { get; set; } + public CEnum? CEnum { get; set; } }; - public async Task GetPostgresGeoTypes() + public async Task GetPostgresSpecialTypes() { if (this.Transaction == null) { using (var connection = NpgsqlDataSource.Create(ConnectionString)) { - using (var command = connection.CreateCommand(GetPostgresGeoTypesSql)) + using (var command = connection.CreateCommand(GetPostgresSpecialTypesSql)) { using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetPostgresGeoTypesRow + return new GetPostgresSpecialTypesRow { - CPoint = reader.IsDBNull(0) ? (NpgsqlPoint? )null : reader.GetFieldValue(0), - CLine = reader.IsDBNull(1) ? (NpgsqlLine? )null : reader.GetFieldValue(1), - CLseg = reader.IsDBNull(2) ? (NpgsqlLSeg? )null : reader.GetFieldValue(2), - CBox = reader.IsDBNull(3) ? (NpgsqlBox? )null : reader.GetFieldValue(3), - CPath = reader.IsDBNull(4) ? (NpgsqlPath? )null : reader.GetFieldValue(4), - CPolygon = reader.IsDBNull(5) ? (NpgsqlPolygon? )null : reader.GetFieldValue(5), - CCircle = reader.IsDBNull(6) ? (NpgsqlCircle? )null : reader.GetFieldValue(6) + CJson = reader.IsDBNull(0) ? (JsonElement? )null : JsonSerializer.Deserialize(reader.GetString(0)), + CJsonStringOverride = reader.IsDBNull(1) ? null : reader.GetString(1), + CJsonb = reader.IsDBNull(2) ? (JsonElement? )null : JsonSerializer.Deserialize(reader.GetString(2)), + CJsonpath = reader.IsDBNull(3) ? null : reader.GetString(3), + CXml = reader.IsDBNull(4) ? null : (new Func((r, o) => + { + var xmlDoc = new XmlDocument(); + xmlDoc.LoadXml(r.GetString(o)); + return xmlDoc; + }))(reader, 4), + CXmlStringOverride = reader.IsDBNull(5) ? null : reader.GetString(5), + CUuid = reader.IsDBNull(6) ? (Guid? )null : reader.GetFieldValue(6), + CEnum = reader.IsDBNull(7) ? (CEnum? )null : reader.GetString(7).ToCEnum() }; } } @@ -1406,27 +2036,30 @@ public async Task GetPostgresGeoTypes() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = GetPostgresGeoTypesSql; + command.CommandText = GetPostgresSpecialTypesSql; command.Transaction = this.Transaction; using (var reader = await command.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { - return new GetPostgresGeoTypesRow + return new GetPostgresSpecialTypesRow { - CPoint = reader.IsDBNull(0) ? (NpgsqlPoint? )null : reader.GetFieldValue(0), - CLine = reader.IsDBNull(1) ? (NpgsqlLine? )null : reader.GetFieldValue(1), - CLseg = reader.IsDBNull(2) ? (NpgsqlLSeg? )null : reader.GetFieldValue(2), - CBox = reader.IsDBNull(3) ? (NpgsqlBox? )null : reader.GetFieldValue(3), - CPath = reader.IsDBNull(4) ? (NpgsqlPath? )null : reader.GetFieldValue(4), - CPolygon = reader.IsDBNull(5) ? (NpgsqlPolygon? )null : reader.GetFieldValue(5), - CCircle = reader.IsDBNull(6) ? (NpgsqlCircle? )null : reader.GetFieldValue(6) + CJson = reader.IsDBNull(0) ? (JsonElement? )null : JsonSerializer.Deserialize(reader.GetString(0)), + CJsonStringOverride = reader.IsDBNull(1) ? null : reader.GetString(1), + CJsonb = reader.IsDBNull(2) ? (JsonElement? )null : JsonSerializer.Deserialize(reader.GetString(2)), + CJsonpath = reader.IsDBNull(3) ? null : reader.GetString(3), + CXml = reader.IsDBNull(4) ? null : (new Func((r, o) => + { + var xmlDoc = new XmlDocument(); + xmlDoc.LoadXml(r.GetString(o)); + return xmlDoc; + }))(reader, 4), + CXmlStringOverride = reader.IsDBNull(5) ? null : reader.GetString(5), + CUuid = reader.IsDBNull(6) ? (Guid? )null : reader.GetFieldValue(6), + CEnum = reader.IsDBNull(7) ? (CEnum? )null : reader.GetString(7).ToCEnum() }; } } @@ -1435,14 +2068,14 @@ public async Task GetPostgresGeoTypes() return null; } - private const string TruncatePostgresTypesSql = "TRUNCATE TABLE postgres_types"; - public async Task TruncatePostgresTypes() + private const string TruncatePostgresSpecialTypesSql = "TRUNCATE TABLE postgres_special_types"; + public async Task TruncatePostgresSpecialTypes() { if (this.Transaction == null) { using (var connection = NpgsqlDataSource.Create(ConnectionString)) { - using (var command = connection.CreateCommand(TruncatePostgresTypesSql)) + using (var command = connection.CreateCommand(TruncatePostgresSpecialTypesSql)) { await command.ExecuteNonQueryAsync(); } @@ -1452,48 +2085,94 @@ public async Task TruncatePostgresTypes() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + command.CommandText = TruncatePostgresSpecialTypesSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); } + } + + private const string InsertPostgresSpecialTypesBatchSql = "COPY postgres_special_types (c_uuid) FROM STDIN (FORMAT BINARY)"; + public class InsertPostgresSpecialTypesBatchArgs + { + public Guid? CUuid { get; set; } + }; + public async Task InsertPostgresSpecialTypesBatch(List args) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresSpecialTypesBatchSql)) + { + foreach (var row in args) + { + await writer.StartRowAsync(); + await writer.WriteAsync(row.CUuid ?? (object)DBNull.Value); + } - using (var command = this.Transaction.Connection.CreateCommand()) - { - command.CommandText = TruncatePostgresTypesSql; - command.Transaction = this.Transaction; - await command.ExecuteNonQueryAsync(); + await writer.CompleteAsync(); + } + + await connection.CloseAsync(); } } - private const string TruncatePostgresGeoTypesSql = "TRUNCATE TABLE postgres_geometric_types"; - public async Task TruncatePostgresGeoTypes() + private const string GetPostgresSpecialTypesCntSql = "SELECT c_uuid, COUNT(*) AS cnt FROM postgres_special_types GROUP BY c_uuid LIMIT 1"; + public class GetPostgresSpecialTypesCntRow + { + public Guid? CUuid { get; set; } + public long Cnt { get; set; } + }; + public async Task GetPostgresSpecialTypesCnt() { if (this.Transaction == null) { using (var connection = NpgsqlDataSource.Create(ConnectionString)) { - using (var command = connection.CreateCommand(TruncatePostgresGeoTypesSql)) + using (var command = connection.CreateCommand(GetPostgresSpecialTypesCntSql)) { - await command.ExecuteNonQueryAsync(); + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresSpecialTypesCntRow + { + CUuid = reader.IsDBNull(0) ? (Guid? )null : reader.GetFieldValue(0), + Cnt = reader.GetInt64(1) + }; + } + } } } - return; + return null; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = TruncatePostgresGeoTypesSql; + command.CommandText = GetPostgresSpecialTypesCntSql; command.Transaction = this.Transaction; - await command.ExecuteNonQueryAsync(); + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresSpecialTypesCntRow + { + CUuid = reader.IsDBNull(0) ? (Guid? )null : reader.GetFieldValue(0), + Cnt = reader.GetInt64(1) + }; + } + } } + + 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; } @@ -1527,10 +2206,7 @@ public async Task InsertPostgresArrayTypes(InsertPostgresArrayTypesArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = InsertPostgresArrayTypesSql; @@ -1588,10 +2264,7 @@ public async Task GetPostgresArrayTypes() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetPostgresArrayTypesSql; @@ -1617,10 +2290,15 @@ public async Task GetPostgresArrayTypes() return null; } - private const string InsertPostgresArrayTypesBatchSql = "COPY postgres_array_types (c_bytea) FROM STDIN (FORMAT BINARY)"; + private const string InsertPostgresArrayTypesBatchSql = "COPY postgres_array_types (c_bytea, c_boolean_array, c_text_array, c_integer_array, c_decimal_array, c_timestamp_array) FROM STDIN (FORMAT BINARY)"; public class InsertPostgresArrayTypesBatchArgs { public byte[] CBytea { get; set; } + public bool[] CBooleanArray { get; set; } + public string[] CTextArray { get; set; } + public int[] CIntegerArray { get; set; } + public decimal[] CDecimalArray { get; set; } + public DateTime[] CTimestampArray { get; set; } }; public async Task InsertPostgresArrayTypesBatch(List args) { @@ -1633,6 +2311,11 @@ public async Task InsertPostgresArrayTypesBatch(List GetPostgresArrayTypesCnt() @@ -1663,7 +2351,12 @@ public async Task GetPostgresArrayTypesCnt() return new GetPostgresArrayTypesCntRow { CBytea = reader.IsDBNull(0) ? null : reader.GetFieldValue(0), - Cnt = reader.GetInt64(1) + CBooleanArray = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CTextArray = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + CIntegerArray = reader.IsDBNull(3) ? null : reader.GetFieldValue(3), + CDecimalArray = reader.IsDBNull(4) ? null : reader.GetFieldValue(4), + CTimestampArray = reader.IsDBNull(5) ? null : reader.GetFieldValue(5), + Cnt = reader.GetInt64(6) }; } } @@ -1674,10 +2367,7 @@ public async Task GetPostgresArrayTypesCnt() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetPostgresArrayTypesCntSql; @@ -1689,7 +2379,12 @@ public async Task GetPostgresArrayTypesCnt() return new GetPostgresArrayTypesCntRow { CBytea = reader.IsDBNull(0) ? null : reader.GetFieldValue(0), - Cnt = reader.GetInt64(1) + CBooleanArray = reader.IsDBNull(1) ? null : reader.GetFieldValue(1), + CTextArray = reader.IsDBNull(2) ? null : reader.GetFieldValue(2), + CIntegerArray = reader.IsDBNull(3) ? null : reader.GetFieldValue(3), + CDecimalArray = reader.IsDBNull(4) ? null : reader.GetFieldValue(4), + CTimestampArray = reader.IsDBNull(5) ? null : reader.GetFieldValue(5), + Cnt = reader.GetInt64(6) }; } } @@ -1715,13 +2410,191 @@ public async Task TruncatePostgresArrayTypes() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncatePostgresArrayTypesSql; + command.Transaction = this.Transaction; + await command.ExecuteNonQueryAsync(); + } + } + + 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 class InsertPostgresGeoTypesArgs + { + public NpgsqlPoint? CPoint { get; set; } + public NpgsqlLine? CLine { get; set; } + public NpgsqlLSeg? CLseg { get; set; } + public NpgsqlBox? CBox { get; set; } + public NpgsqlPath? CPath { get; set; } + public NpgsqlPolygon? CPolygon { get; set; } + public NpgsqlCircle? CCircle { get; set; } + }; + public async Task InsertPostgresGeoTypes(InsertPostgresGeoTypesArgs args) + { + if (this.Transaction == null) { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(InsertPostgresGeoTypesSql)) + { + command.Parameters.AddWithValue("@c_point", args.CPoint ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_line", args.CLine ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_lseg", args.CLseg ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_box", args.CBox ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_path", args.CPath ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_polygon", args.CPolygon ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_circle", args.CCircle ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + return; } + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { - command.CommandText = TruncatePostgresArrayTypesSql; + command.CommandText = InsertPostgresGeoTypesSql; + command.Transaction = this.Transaction; + command.Parameters.AddWithValue("@c_point", args.CPoint ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_line", args.CLine ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_lseg", args.CLseg ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_box", args.CBox ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_path", args.CPath ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_polygon", args.CPolygon ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@c_circle", args.CCircle ?? (object)DBNull.Value); + await command.ExecuteNonQueryAsync(); + } + } + + private const string InsertPostgresGeoTypesBatchSql = "COPY postgres_geometric_types (c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle) FROM STDIN (FORMAT BINARY)"; + public class InsertPostgresGeoTypesBatchArgs + { + public NpgsqlPoint? CPoint { get; set; } + public NpgsqlLine? CLine { get; set; } + public NpgsqlLSeg? CLseg { get; set; } + public NpgsqlBox? CBox { get; set; } + public NpgsqlPath? CPath { get; set; } + public NpgsqlPolygon? CPolygon { get; set; } + public NpgsqlCircle? CCircle { get; set; } + }; + public async Task InsertPostgresGeoTypesBatch(List args) + { + using (var connection = new NpgsqlConnection(ConnectionString)) + { + await connection.OpenAsync(); + using (var writer = await connection.BeginBinaryImportAsync(InsertPostgresGeoTypesBatchSql)) + { + foreach (var row in args) + { + await writer.StartRowAsync(); + await writer.WriteAsync(row.CPoint ?? (object)DBNull.Value); + await writer.WriteAsync(row.CLine ?? (object)DBNull.Value); + await writer.WriteAsync(row.CLseg ?? (object)DBNull.Value); + await writer.WriteAsync(row.CBox ?? (object)DBNull.Value); + await writer.WriteAsync(row.CPath ?? (object)DBNull.Value); + await writer.WriteAsync(row.CPolygon ?? (object)DBNull.Value); + await writer.WriteAsync(row.CCircle ?? (object)DBNull.Value); + } + + await writer.CompleteAsync(); + } + + await connection.CloseAsync(); + } + } + + private const string GetPostgresGeoTypesSql = "SELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgres_geometric_types LIMIT 1"; + public class GetPostgresGeoTypesRow + { + public NpgsqlPoint? CPoint { get; set; } + public NpgsqlLine? CLine { get; set; } + public NpgsqlLSeg? CLseg { get; set; } + public NpgsqlBox? CBox { get; set; } + public NpgsqlPath? CPath { get; set; } + public NpgsqlPolygon? CPolygon { get; set; } + public NpgsqlCircle? CCircle { get; set; } + }; + public async Task GetPostgresGeoTypes() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(GetPostgresGeoTypesSql)) + { + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresGeoTypesRow + { + CPoint = reader.IsDBNull(0) ? (NpgsqlPoint? )null : reader.GetFieldValue(0), + CLine = reader.IsDBNull(1) ? (NpgsqlLine? )null : reader.GetFieldValue(1), + CLseg = reader.IsDBNull(2) ? (NpgsqlLSeg? )null : reader.GetFieldValue(2), + CBox = reader.IsDBNull(3) ? (NpgsqlBox? )null : reader.GetFieldValue(3), + CPath = reader.IsDBNull(4) ? (NpgsqlPath? )null : reader.GetFieldValue(4), + CPolygon = reader.IsDBNull(5) ? (NpgsqlPolygon? )null : reader.GetFieldValue(5), + CCircle = reader.IsDBNull(6) ? (NpgsqlCircle? )null : reader.GetFieldValue(6) + }; + } + } + } + } + + return null; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = GetPostgresGeoTypesSql; + command.Transaction = this.Transaction; + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + return new GetPostgresGeoTypesRow + { + CPoint = reader.IsDBNull(0) ? (NpgsqlPoint? )null : reader.GetFieldValue(0), + CLine = reader.IsDBNull(1) ? (NpgsqlLine? )null : reader.GetFieldValue(1), + CLseg = reader.IsDBNull(2) ? (NpgsqlLSeg? )null : reader.GetFieldValue(2), + CBox = reader.IsDBNull(3) ? (NpgsqlBox? )null : reader.GetFieldValue(3), + CPath = reader.IsDBNull(4) ? (NpgsqlPath? )null : reader.GetFieldValue(4), + CPolygon = reader.IsDBNull(5) ? (NpgsqlPolygon? )null : reader.GetFieldValue(5), + CCircle = reader.IsDBNull(6) ? (NpgsqlCircle? )null : reader.GetFieldValue(6) + }; + } + } + } + + return null; + } + + private const string TruncatePostgresGeoTypesSql = "TRUNCATE TABLE postgres_geometric_types"; + public async Task TruncatePostgresGeoTypes() + { + if (this.Transaction == null) + { + using (var connection = NpgsqlDataSource.Create(ConnectionString)) + { + using (var command = connection.CreateCommand(TruncatePostgresGeoTypesSql)) + { + await command.ExecuteNonQueryAsync(); + } + } + + return; + } + + if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) + throw new InvalidOperationException("Transaction is provided, but its connection is null."); + using (var command = this.Transaction.Connection.CreateCommand()) + { + command.CommandText = TruncatePostgresGeoTypesSql; command.Transaction = this.Transaction; await command.ExecuteNonQueryAsync(); } diff --git a/examples/NpgsqlLegacyExample/request.json b/examples/NpgsqlLegacyExample/request.json index 54141e9d..8e122bc0 100644 --- a/examples/NpgsqlLegacyExample/request.json +++ b/examples/NpgsqlLegacyExample/request.json @@ -3,15 +3,17 @@ "version": "2", "engine": "postgresql", "schema": [ - "examples/config/postgresql/schema.sql" + "examples/config/postgresql/authors/schema.sql", + "examples/config/postgresql/types/schema.sql" ], "queries": [ - "examples/config/postgresql/query.sql" + "examples/config/postgresql/authors/query.sql", + "examples/config/postgresql/types/query.sql" ], "codegen": { "out": "examples/NpgsqlLegacyExample", "plugin": "csharp", - "options": "eyJkZWJ1Z1JlcXVlc3QiOnRydWUsImdlbmVyYXRlQ3Nwcm9qIjp0cnVlLCJuYW1lc3BhY2VOYW1lIjoiTnBnc3FsTGVnYWN5RXhhbXBsZUdlbiIsIm92ZXJyaWRlcyI6W3siY29sdW1uIjoiR2V0UG9zdGdyZXNGdW5jdGlvbnM6bWF4X2ludGVnZXIiLCJjc2hhcnBfdHlwZSI6eyJub3ROdWxsIjpmYWxzZSwidHlwZSI6ImludCJ9fSx7ImNvbHVtbiI6IkdldFBvc3RncmVzRnVuY3Rpb25zOm1heF92YXJjaGFyIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6ZmFsc2UsInR5cGUiOiJzdHJpbmcifX0seyJjb2x1bW4iOiJHZXRQb3N0Z3Jlc0Z1bmN0aW9uczptYXhfdGltZXN0YW1wIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6dHJ1ZSwidHlwZSI6IkRhdGVUaW1lIn19LHsiY29sdW1uIjoiKjpjX2pzb25fc3RyaW5nX292ZXJyaWRlIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6ZmFsc2UsInR5cGUiOiJzdHJpbmcifX0seyJjb2x1bW4iOiIqOmNfbWFjYWRkcjgiLCJjc2hhcnBfdHlwZSI6eyJub3ROdWxsIjpmYWxzZSwidHlwZSI6InN0cmluZyJ9fV0sInRhcmdldEZyYW1ld29yayI6Im5ldHN0YW5kYXJkMi4wIiwidXNlRGFwcGVyIjpmYWxzZX0=", + "options": "eyJkZWJ1Z1JlcXVlc3QiOnRydWUsImdlbmVyYXRlQ3Nwcm9qIjp0cnVlLCJuYW1lc3BhY2VOYW1lIjoiTnBnc3FsTGVnYWN5RXhhbXBsZUdlbiIsIm92ZXJyaWRlcyI6W3siY29sdW1uIjoiR2V0UG9zdGdyZXNGdW5jdGlvbnM6bWF4X2ludGVnZXIiLCJjc2hhcnBfdHlwZSI6eyJub3ROdWxsIjpmYWxzZSwidHlwZSI6ImludCJ9fSx7ImNvbHVtbiI6IkdldFBvc3RncmVzRnVuY3Rpb25zOm1heF92YXJjaGFyIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6ZmFsc2UsInR5cGUiOiJzdHJpbmcifX0seyJjb2x1bW4iOiJHZXRQb3N0Z3Jlc0Z1bmN0aW9uczptYXhfdGltZXN0YW1wIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6dHJ1ZSwidHlwZSI6IkRhdGVUaW1lIn19LHsiY29sdW1uIjoiKjpjX2pzb25fc3RyaW5nX292ZXJyaWRlIiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6ZmFsc2UsInR5cGUiOiJzdHJpbmcifX0seyJjb2x1bW4iOiIqOmNfeG1sX3N0cmluZ19vdmVycmlkZSIsImNzaGFycF90eXBlIjp7Im5vdE51bGwiOmZhbHNlLCJ0eXBlIjoic3RyaW5nIn19LHsiY29sdW1uIjoiKjpjX21hY2FkZHI4IiwiY3NoYXJwX3R5cGUiOnsibm90TnVsbCI6ZmFsc2UsInR5cGUiOiJzdHJpbmcifX1dLCJ0YXJnZXRGcmFtZXdvcmsiOiJuZXRzdGFuZGFyZDIuMCIsInVzZURhcHBlciI6ZmFsc2V9", "process": { "cmd": "./dist/LocalRunner" } @@ -115,14 +117,14 @@ }, { "rel": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "columns": [ { "name": "c_boolean", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -133,7 +135,7 @@ "name": "c_bit", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -144,7 +146,7 @@ "name": "c_smallint", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -155,7 +157,7 @@ "name": "c_integer", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -166,7 +168,7 @@ "name": "c_bigint", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -177,7 +179,7 @@ "name": "c_decimal", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -188,7 +190,7 @@ "name": "c_numeric", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -199,7 +201,7 @@ "name": "c_real", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -210,7 +212,7 @@ "name": "c_double_precision", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "schema": "pg_catalog", @@ -221,218 +223,272 @@ "name": "c_money", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "money" } - }, + } + ] + }, + { + "rel": { + "name": "postgres_string_types" + }, + "columns": [ { - "name": "c_date", + "name": "c_char", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "date" + "schema": "pg_catalog", + "name": "bpchar" } }, { - "name": "c_time", + "name": "c_varchar", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { "schema": "pg_catalog", - "name": "time" + "name": "varchar" } }, { - "name": "c_timestamp", + "name": "c_character_varying", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { "schema": "pg_catalog", - "name": "timestamp" + "name": "varchar" } }, { - "name": "c_timestamp_with_tz", + "name": "c_bpchar", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "schema": "pg_catalog", - "name": "timestamptz" + "name": "bpchar" } }, { - "name": "c_interval", + "name": "c_text", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "schema": "pg_catalog", - "name": "interval" + "name": "text" + } + } + ] + }, + { + "rel": { + "name": "postgres_datetime_types" + }, + "columns": [ + { + "name": "c_date", + "length": -1, + "table": { + "name": "postgres_datetime_types" + }, + "type": { + "name": "date" } }, { - "name": "c_char", + "name": "c_time", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "bpchar" + "name": "time" } }, { - "name": "c_varchar", + "name": "c_timestamp", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "varchar" + "name": "timestamp" } }, { - "name": "c_character_varying", + "name": "c_timestamp_with_tz", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "varchar" + "name": "timestamptz" } }, { - "name": "c_bpchar", + "name": "c_interval", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "bpchar" + "schema": "pg_catalog", + "name": "interval" } - }, + } + ] + }, + { + "rel": { + "name": "postgres_network_types" + }, + "columns": [ { - "name": "c_text", + "name": "c_cidr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "text" + "name": "cidr" } }, { - "name": "c_json", + "name": "c_inet", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "json" + "name": "inet" } }, { - "name": "c_json_string_override", + "name": "c_macaddr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "json" + "name": "macaddr" } }, { - "name": "c_jsonb", + "name": "c_macaddr8", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "jsonb" + "name": "macaddr8" } - }, + } + ] + }, + { + "rel": { + "name": "postgres_array_types" + }, + "columns": [ { - "name": "c_jsonpath", + "name": "c_bytea", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "jsonpath" + "name": "bytea" } }, { - "name": "c_xml", + "name": "c_boolean_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "xml" - } + "schema": "pg_catalog", + "name": "bool" + }, + "arrayDims": 1 }, { - "name": "c_cidr", + "name": "c_text_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "cidr" - } + "name": "text" + }, + "arrayDims": 1 }, { - "name": "c_inet", + "name": "c_integer_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "inet" - } + "schema": "pg_catalog", + "name": "int4" + }, + "arrayDims": 1 }, { - "name": "c_macaddr", + "name": "c_decimal_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "macaddr" - } + "schema": "pg_catalog", + "name": "numeric" + }, + "arrayDims": 1 }, { - "name": "c_macaddr8", + "name": "c_date_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "macaddr8" - } + "name": "date" + }, + "arrayDims": 1 }, { - "name": "c_uuid", + "name": "c_timestamp_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "uuid" - } + "schema": "pg_catalog", + "name": "timestamp" + }, + "arrayDims": 1 } ] }, @@ -515,97 +571,101 @@ }, { "rel": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "columns": [ { - "name": "c_bytea", + "name": "c_uuid", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "name": "bytea" + "name": "uuid" } }, { - "name": "c_boolean_array", - "isArray": true, + "name": "c_enum", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "schema": "pg_catalog", - "name": "bool" - }, - "arrayDims": 1 + "name": "c_enum" + } }, { - "name": "c_text_array", - "isArray": true, + "name": "c_json", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "name": "text" - }, - "arrayDims": 1 + "name": "json" + } }, { - "name": "c_integer_array", - "isArray": true, + "name": "c_json_string_override", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "schema": "pg_catalog", - "name": "int4" - }, - "arrayDims": 1 + "name": "json" + } }, { - "name": "c_decimal_array", - "isArray": true, + "name": "c_jsonb", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "schema": "pg_catalog", - "name": "numeric" - }, - "arrayDims": 1 + "name": "jsonb" + } }, { - "name": "c_date_array", - "isArray": true, + "name": "c_jsonpath", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "name": "date" - }, - "arrayDims": 1 + "name": "jsonpath" + } }, { - "name": "c_timestamp_array", - "isArray": true, + "name": "c_xml", "length": -1, "table": { - "name": "postgres_array_types" + "name": "postgres_special_types" }, "type": { - "schema": "pg_catalog", - "name": "timestamp" + "name": "xml" + } + }, + { + "name": "c_xml_string_override", + "length": -1, + "table": { + "name": "postgres_special_types" }, - "arrayDims": 1 + "type": { + "name": "xml" + } } ] } + ], + "enums": [ + { + "name": "c_enum", + "vals": [ + "small", + "medium", + "big" + ] + } ] }, { @@ -32449,6 +32509,67 @@ ] } ] + }, + { + "name": "extended", + "tables": [ + { + "rel": { + "schema": "extended", + "name": "bios" + }, + "columns": [ + { + "name": "author_name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + } + }, + { + "name": "name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + } + }, + { + "name": "bio_type", + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "extended", + "name": "bio_type" + } + } + ] + } + ], + "enums": [ + { + "name": "bio_type", + "vals": [ + "Autobiography", + "Biography", + "Memoir" + ] + } + ] } ] }, @@ -33207,8 +33328,174 @@ "filename": "query.sql" }, { - "text": "INSERT INTO postgres_types\n(\n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_real,\n c_numeric,\n c_decimal,\n c_double_precision,\n c_money,\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n c_uuid,\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_cidr,\n c_inet,\n c_macaddr,\n c_macaddr8\n)\nVALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6,\n $7,\n $8,\n $9,\n $10,\n $11,\n $12,\n $13,\n $14,\n $15,\n $16,\n $17,\n $18,\n $19,\n $20,\n $21,\n $22::json, \n $23::json, \n $24::jsonb,\n $25::jsonpath,\n $26::xml,\n $27,\n $28,\n $29::macaddr,\n $30::macaddr8\n)", - "name": "InsertPostgresTypes", + "text": "INSERT INTO extended.bios (author_name, name, bio_type) VALUES ($1, $2, $3)", + "name": "CreateExtendedBio", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "author_name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "pg_catalog.varchar" + }, + "originalName": "author_name" + } + }, + { + "number": 2, + "column": { + "name": "name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "pg_catalog.varchar" + }, + "originalName": "name" + } + }, + { + "number": 3, + "column": { + "name": "bio_type", + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "extended.bio_type" + }, + "originalName": "bio_type" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "schema": "extended", + "name": "bios" + } + }, + { + "text": "SELECT author_name, name, bio_type FROM extended.bios WHERE bio_type = $1 LIMIT 1", + "name": "GetFirstExtendedBioByType", + "cmd": ":one", + "columns": [ + { + "name": "author_name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "author_name" + }, + { + "name": "name", + "notNull": true, + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "name" + }, + { + "name": "bio_type", + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "schema": "extended", + "name": "bio_type" + }, + "originalName": "bio_type" + } + ], + "parameters": [ + { + "number": 1, + "column": { + "name": "bio_type", + "length": -1, + "table": { + "schema": "extended", + "name": "bios" + }, + "type": { + "name": "extended.bio_type" + }, + "originalName": "bio_type" + } + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE extended.bios", + "name": "TruncateExtendedBios", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "SELECT\n MAX(c_integer) AS max_integer,\n MAX(c_varchar) AS max_varchar,\n MAX(c_timestamp) AS max_timestamp\nFROM postgres_datetime_types\nCROSS JOIN postgres_numeric_types\nCROSS JOIN postgres_string_types", + "name": "GetPostgresFunctions", + "cmd": ":one", + "columns": [ + { + "name": "max_integer", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "anyarray" + } + }, + { + "name": "max_varchar", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "anyarray" + } + }, + { + "name": "max_timestamp", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "anyarray" + } + } + ], + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO postgres_numeric_types\n(\n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_decimal,\n c_numeric,\n c_real,\n c_double_precision,\n c_money\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", + "name": "InsertPostgresNumericTypes", "cmd": ":exec", "parameters": [ { @@ -33216,10 +33503,9 @@ "column": { "name": "c_boolean", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.bool" @@ -33232,10 +33518,9 @@ "column": { "name": "c_bit", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.bit" @@ -33248,10 +33533,9 @@ "column": { "name": "c_smallint", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.int2" @@ -33264,10 +33548,9 @@ "column": { "name": "c_integer", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.int4" @@ -33280,10 +33563,9 @@ "column": { "name": "c_bigint", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.int8" @@ -33294,17 +33576,16 @@ { "number": 6, "column": { - "name": "c_real", + "name": "c_decimal", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.float4" + "name": "pg_catalog.numeric" }, - "originalName": "c_real" + "originalName": "c_decimal" } }, { @@ -33312,10 +33593,9 @@ "column": { "name": "c_numeric", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.numeric" @@ -33326,17 +33606,16 @@ { "number": 8, "column": { - "name": "c_decimal", + "name": "c_real", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.numeric" + "name": "pg_catalog.float4" }, - "originalName": "c_decimal" + "originalName": "c_real" } }, { @@ -33344,10 +33623,9 @@ "column": { "name": "c_double_precision", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "pg_catalog.float8" @@ -33360,914 +33638,1509 @@ "column": { "name": "c_money", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { "name": "money" }, "originalName": "c_money" } + } + ], + "comments": [ + " Numeric types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_numeric_types" + } + }, + { + "text": "SELECT c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money FROM postgres_numeric_types LIMIT 1", + "name": "GetPostgresNumericTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_boolean", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bool" + }, + "originalName": "c_boolean" + }, + { + "name": "c_bit", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bit" + }, + "originalName": "c_bit" + }, + { + "name": "c_smallint", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int2" + }, + "originalName": "c_smallint" + }, + { + "name": "c_integer", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int4" + }, + "originalName": "c_integer" + }, + { + "name": "c_bigint", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int8" + }, + "originalName": "c_bigint" + }, + { + "name": "c_decimal", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "numeric" + }, + "originalName": "c_decimal" + }, + { + "name": "c_numeric", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "numeric" + }, + "originalName": "c_numeric" + }, + { + "name": "c_real", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "float4" + }, + "originalName": "c_real" + }, + { + "name": "c_double_precision", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "float8" + }, + "originalName": "c_double_precision" + }, + { + "name": "c_money", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "name": "money" + }, + "originalName": "c_money" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_numeric_types", + "name": "TruncatePostgresNumericTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "SELECT\n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_decimal,\n c_numeric,\n c_real,\n c_double_precision,\n c_money,\n COUNT(*) AS cnt\nFROM postgres_numeric_types\nGROUP BY\n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_decimal,\n c_numeric,\n c_real,\n c_double_precision,\n c_money\nLIMIT 1", + "name": "GetPostgresNumericTypesCnt", + "cmd": ":one", + "columns": [ + { + "name": "c_boolean", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bool" + }, + "originalName": "c_boolean" + }, + { + "name": "c_bit", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bit" + }, + "originalName": "c_bit" + }, + { + "name": "c_smallint", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int2" + }, + "originalName": "c_smallint" + }, + { + "name": "c_integer", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int4" + }, + "originalName": "c_integer" + }, + { + "name": "c_bigint", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "int8" + }, + "originalName": "c_bigint" + }, + { + "name": "c_decimal", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "numeric" + }, + "originalName": "c_decimal" + }, + { + "name": "c_numeric", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "numeric" + }, + "originalName": "c_numeric" + }, + { + "name": "c_real", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "float4" + }, + "originalName": "c_real" + }, + { + "name": "c_double_precision", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "schema": "pg_catalog", + "name": "float8" + }, + "originalName": "c_double_precision" + }, + { + "name": "c_money", + "length": -1, + "table": { + "name": "postgres_numeric_types" + }, + "type": { + "name": "money" + }, + "originalName": "c_money" }, { - "number": 11, + "name": "cnt", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "bigint" + } + } + ], + "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_numeric_types\n(\n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_decimal,\n c_numeric,\n c_real,\n c_double_precision,\n c_money\n) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", + "name": "InsertPostgresNumericTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, "column": { - "name": "c_date", + "name": "c_boolean", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "date" + "name": "pg_catalog.bool" }, - "originalName": "c_date" + "originalName": "c_boolean" } }, { - "number": 12, + "number": 2, "column": { - "name": "c_time", + "name": "c_bit", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.time" + "name": "pg_catalog.bit" }, - "originalName": "c_time" + "originalName": "c_bit" } }, { - "number": 13, + "number": 3, "column": { - "name": "c_timestamp", + "name": "c_smallint", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.timestamp" + "name": "pg_catalog.int2" }, - "originalName": "c_timestamp" + "originalName": "c_smallint" } }, { - "number": 14, + "number": 4, "column": { - "name": "c_timestamp_with_tz", + "name": "c_integer", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.timestamptz" + "name": "pg_catalog.int4" }, - "originalName": "c_timestamp_with_tz" + "originalName": "c_integer" } }, { - "number": 15, + "number": 5, "column": { - "name": "c_interval", + "name": "c_bigint", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.interval" + "name": "pg_catalog.int8" }, - "originalName": "c_interval" + "originalName": "c_bigint" } }, { - "number": 16, + "number": 6, "column": { - "name": "c_char", + "name": "c_decimal", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.bpchar" + "name": "pg_catalog.numeric" }, - "originalName": "c_char" + "originalName": "c_decimal" } }, { - "number": 17, + "number": 7, "column": { - "name": "c_varchar", + "name": "c_numeric", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.varchar" + "name": "pg_catalog.numeric" }, - "originalName": "c_varchar" + "originalName": "c_numeric" } }, { - "number": 18, + "number": 8, "column": { - "name": "c_character_varying", + "name": "c_real", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "pg_catalog.varchar" + "name": "pg_catalog.float4" }, - "originalName": "c_character_varying" + "originalName": "c_real" } }, { - "number": 19, + "number": 9, "column": { - "name": "c_bpchar", + "name": "c_double_precision", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "bpchar" + "name": "pg_catalog.float8" }, - "originalName": "c_bpchar" + "originalName": "c_double_precision" } }, { - "number": 20, + "number": 10, "column": { - "name": "c_text", + "name": "c_money", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_numeric_types" }, "type": { - "name": "text" + "name": "money" }, - "originalName": "c_text" + "originalName": "c_money" } - }, + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_numeric_types" + } + }, + { + "text": "\nINSERT INTO postgres_string_types\n(\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text\n)\nVALUES ($1, $2, $3, $4, $5)", + "name": "InsertPostgresStringTypes", + "cmd": ":exec", + "parameters": [ { - "number": 21, + "number": 1, "column": { - "name": "c_uuid", + "name": "c_char", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "uuid" + "name": "pg_catalog.bpchar" }, - "originalName": "c_uuid" + "originalName": "c_char" } }, { - "number": 22, + "number": 2, "column": { - "name": "c_json", + "name": "c_varchar", "length": -1, + "table": { + "schema": "public", + "name": "postgres_string_types" + }, "type": { - "name": "json" - } + "name": "pg_catalog.varchar" + }, + "originalName": "c_varchar" } }, { - "number": 23, - "column": { - "name": "c_json_string_override", - "length": -1, - "type": { - "name": "json" - } - } - }, - { - "number": 24, - "column": { - "name": "c_jsonb", - "length": -1, - "type": { - "name": "jsonb" - } - } - }, - { - "number": 25, - "column": { - "name": "c_jsonpath", - "length": -1, - "type": { - "name": "jsonpath" - } - } - }, - { - "number": 26, - "column": { - "name": "c_xml", - "length": -1, - "type": { - "name": "xml" - } - } - }, - { - "number": 27, + "number": 3, "column": { - "name": "c_cidr", + "name": "c_character_varying", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "cidr" + "name": "pg_catalog.varchar" }, - "originalName": "c_cidr" + "originalName": "c_character_varying" } }, { - "number": 28, + "number": 4, "column": { - "name": "c_inet", + "name": "c_bpchar", "length": -1, - "isNamedParam": true, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "inet" + "name": "bpchar" }, - "originalName": "c_inet" - } - }, - { - "number": 29, - "column": { - "name": "c_macaddr", - "length": -1, - "type": { - "name": "macaddr" - } + "originalName": "c_bpchar" } }, { - "number": 30, + "number": 5, "column": { - "name": "c_macaddr8", + "name": "c_text", "length": -1, + "table": { + "schema": "public", + "name": "postgres_string_types" + }, "type": { - "name": "macaddr8" - } + "name": "text" + }, + "originalName": "c_text" } } ], + "comments": [ + " String types " + ], "filename": "query.sql", "insert_into_table": { - "name": "postgres_types" + "name": "postgres_string_types" } }, { - "text": "INSERT INTO postgres_types\n(\n c_boolean,\n c_smallint,\n c_integer,\n c_bigint,\n c_real,\n c_numeric,\n c_decimal,\n c_double_precision,\n c_money,\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n c_uuid,\n c_cidr,\n c_inet,\n c_macaddr\n)\nVALUES (\n $1, \n $2, \n $3, \n $4, \n $5, \n $6, \n $7, \n $8, \n $9, \n $10, \n $11, \n $12, \n $13, \n $14, \n $15, \n $16, \n $17, \n $18,\n $19,\n $20,\n $21,\n $22,\n $23\n)", - "name": "InsertPostgresTypesBatch", + "text": "INSERT INTO postgres_string_types \n(\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text\n) VALUES ($1, $2, $3, $4, $5)", + "name": "InsertPostgresStringTypesBatch", "cmd": ":copyfrom", "parameters": [ { "number": 1, "column": { - "name": "c_boolean", + "name": "c_char", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "pg_catalog.bool" + "name": "pg_catalog.bpchar" }, - "originalName": "c_boolean" + "originalName": "c_char" } }, { "number": 2, "column": { - "name": "c_smallint", + "name": "c_varchar", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "pg_catalog.int2" + "name": "pg_catalog.varchar" }, - "originalName": "c_smallint" + "originalName": "c_varchar" } }, { "number": 3, "column": { - "name": "c_integer", + "name": "c_character_varying", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "pg_catalog.int4" + "name": "pg_catalog.varchar" }, - "originalName": "c_integer" + "originalName": "c_character_varying" } }, { "number": 4, "column": { - "name": "c_bigint", + "name": "c_bpchar", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "pg_catalog.int8" + "name": "bpchar" }, - "originalName": "c_bigint" + "originalName": "c_bpchar" } }, { "number": 5, "column": { - "name": "c_real", + "name": "c_text", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_string_types" }, "type": { - "name": "pg_catalog.float4" + "name": "text" }, - "originalName": "c_real" + "originalName": "c_text" } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_string_types" + } + }, + { + "text": "SELECT c_char, c_varchar, c_character_varying, c_bpchar, c_text FROM postgres_string_types LIMIT 1", + "name": "GetPostgresStringTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_char", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bpchar" + }, + "originalName": "c_char" }, { - "number": 6, - "column": { - "name": "c_numeric", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.numeric" - }, - "originalName": "c_numeric" - } + "name": "c_varchar", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "c_varchar" }, { - "number": 7, - "column": { - "name": "c_decimal", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.numeric" - }, - "originalName": "c_decimal" - } + "name": "c_character_varying", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "c_character_varying" }, { - "number": 8, - "column": { - "name": "c_double_precision", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.float8" - }, - "originalName": "c_double_precision" - } + "name": "c_bpchar", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "name": "bpchar" + }, + "originalName": "c_bpchar" }, { - "number": 9, - "column": { - "name": "c_money", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "money" - }, - "originalName": "c_money" - } + "name": "c_text", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "name": "text" + }, + "originalName": "c_text" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_string_types", + "name": "TruncatePostgresStringTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "SELECT\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n COUNT(*) AS cnt\nFROM postgres_string_types\nGROUP BY\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text\nLIMIT 1", + "name": "GetPostgresStringTypesCnt", + "cmd": ":one", + "columns": [ + { + "name": "c_char", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "bpchar" + }, + "originalName": "c_char" }, { - "number": 10, - "column": { - "name": "c_date", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "date" - }, - "originalName": "c_date" - } + "name": "c_varchar", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "c_varchar" }, { - "number": 11, - "column": { - "name": "c_time", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.time" - }, - "originalName": "c_time" - } + "name": "c_character_varying", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "schema": "pg_catalog", + "name": "varchar" + }, + "originalName": "c_character_varying" }, { - "number": 12, - "column": { - "name": "c_timestamp", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.timestamp" - }, - "originalName": "c_timestamp" - } + "name": "c_bpchar", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "name": "bpchar" + }, + "originalName": "c_bpchar" }, { - "number": 13, - "column": { - "name": "c_timestamp_with_tz", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.timestamptz" - }, - "originalName": "c_timestamp_with_tz" - } + "name": "c_text", + "length": -1, + "table": { + "name": "postgres_string_types" + }, + "type": { + "name": "text" + }, + "originalName": "c_text" }, { - "number": 14, - "column": { - "name": "c_interval", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.interval" - }, - "originalName": "c_interval" + "name": "cnt", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "bigint" } + } + ], + "filename": "query.sql" + }, + { + "text": "WITH txt_query AS (\n SELECT \n c_text, \n to_tsquery('english', $1) AS query,\n to_tsvector('english', c_text) AS tsv\n FROM postgres_string_types \n WHERE c_text @@ to_tsquery('english', $1)\n)\n\nSELECT txt_query.c_text, txt_query.query, txt_query.tsv, ts_rank(tsv, query) AS rnk\nFROM txt_query\nORDER BY rnk DESC\nLIMIT 1", + "name": "GetPostgresStringTypesTextSearch", + "cmd": ":one", + "columns": [ + { + "name": "c_text", + "length": -1, + "table": { + "name": "txt_query" + }, + "type": { + "name": "text" + }, + "originalName": "c_text" }, { - "number": 15, - "column": { - "name": "c_char", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.bpchar" - }, - "originalName": "c_char" - } + "name": "query", + "notNull": true, + "length": -1, + "table": { + "name": "txt_query" + }, + "type": { + "name": "tsquery" + }, + "originalName": "query" }, { - "number": 16, - "column": { - "name": "c_varchar", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.varchar" - }, - "originalName": "c_varchar" - } + "name": "tsv", + "notNull": true, + "length": -1, + "table": { + "name": "txt_query" + }, + "type": { + "name": "tsvector" + }, + "originalName": "tsv" }, { - "number": 17, - "column": { - "name": "c_character_varying", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, - "type": { - "name": "pg_catalog.varchar" - }, - "originalName": "c_character_varying" + "name": "rnk", + "notNull": true, + "length": -1, + "isFuncCall": true, + "type": { + "name": "real" } - }, + } + ], + "parameters": [ { - "number": 18, + "number": 1, "column": { - "name": "c_bpchar", + "name": "to_tsquery", + "notNull": true, "length": -1, - "table": { - "schema": "public", - "name": "postgres_types" - }, "type": { - "name": "bpchar" - }, - "originalName": "c_bpchar" + "name": "text" + } } - }, + } + ], + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO postgres_datetime_types\n(\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval\n) VALUES ($1, $2, $3, $4, $5)", + "name": "InsertPostgresDateTimeTypes", + "cmd": ":exec", + "parameters": [ { - "number": 19, + "number": 1, "column": { - "name": "c_text", + "name": "c_date", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "text" + "name": "date" }, - "originalName": "c_text" + "originalName": "c_date" } }, { - "number": 20, + "number": 2, "column": { - "name": "c_uuid", + "name": "c_time", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "uuid" + "name": "pg_catalog.time" }, - "originalName": "c_uuid" + "originalName": "c_time" } }, { - "number": 21, + "number": 3, "column": { - "name": "c_cidr", + "name": "c_timestamp", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "cidr" + "name": "pg_catalog.timestamp" }, - "originalName": "c_cidr" + "originalName": "c_timestamp" } }, { - "number": 22, + "number": 4, "column": { - "name": "c_inet", + "name": "c_timestamp_with_tz", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "inet" + "name": "pg_catalog.timestamptz" }, - "originalName": "c_inet" + "originalName": "c_timestamp_with_tz" } }, { - "number": 23, + "number": 5, "column": { - "name": "c_macaddr", + "name": "c_interval", "length": -1, "table": { "schema": "public", - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "macaddr" + "name": "pg_catalog.interval" }, - "originalName": "c_macaddr" + "originalName": "c_interval" } } ], + "comments": [ + " DateTime types " + ], "filename": "query.sql", "insert_into_table": { - "name": "postgres_types" + "name": "postgres_datetime_types" } }, { - "text": "SELECT \n c_boolean,\n c_bit,\n c_smallint,\n c_integer,\n c_bigint,\n c_real,\n c_numeric,\n c_decimal,\n c_double_precision,\n c_money,\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n c_uuid,\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_cidr,\n c_inet,\n c_macaddr,\n c_macaddr8::TEXT AS c_macaddr8\nFROM postgres_types \nLIMIT 1", - "name": "GetPostgresTypes", + "text": "SELECT c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval FROM postgres_datetime_types LIMIT 1", + "name": "GetPostgresDateTimeTypes", "cmd": ":one", "columns": [ { - "name": "c_boolean", + "name": "c_date", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "schema": "pg_catalog", - "name": "bool" + "name": "date" }, - "originalName": "c_boolean" + "originalName": "c_date" }, { - "name": "c_bit", + "name": "c_time", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "bit" + "name": "time" }, - "originalName": "c_bit" + "originalName": "c_time" }, { - "name": "c_smallint", + "name": "c_timestamp", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "int2" + "name": "timestamp" }, - "originalName": "c_smallint" + "originalName": "c_timestamp" }, { - "name": "c_integer", + "name": "c_timestamp_with_tz", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "int4" + "name": "timestamptz" }, - "originalName": "c_integer" + "originalName": "c_timestamp_with_tz" }, { - "name": "c_bigint", + "name": "c_interval", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "int8" + "name": "interval" }, - "originalName": "c_bigint" - }, + "originalName": "c_interval" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_datetime_types", + "name": "TruncatePostgresDateTimeTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "SELECT\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n COUNT(*) AS cnt\nFROM postgres_datetime_types\nGROUP BY\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval\nLIMIT 1", + "name": "GetPostgresDateTimeTypesCnt", + "cmd": ":one", + "columns": [ { - "name": "c_real", + "name": "c_date", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "schema": "pg_catalog", - "name": "float4" + "name": "date" }, - "originalName": "c_real" + "originalName": "c_date" }, { - "name": "c_numeric", + "name": "c_time", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "numeric" + "name": "time" }, - "originalName": "c_numeric" + "originalName": "c_time" }, { - "name": "c_decimal", + "name": "c_timestamp", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "numeric" + "name": "timestamp" }, - "originalName": "c_decimal" + "originalName": "c_timestamp" }, { - "name": "c_double_precision", + "name": "c_timestamp_with_tz", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { "schema": "pg_catalog", - "name": "float8" + "name": "timestamptz" }, - "originalName": "c_double_precision" + "originalName": "c_timestamp_with_tz" }, { - "name": "c_money", + "name": "c_interval", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_datetime_types" }, "type": { - "name": "money" + "schema": "pg_catalog", + "name": "interval" }, - "originalName": "c_money" + "originalName": "c_interval" }, { - "name": "c_date", + "name": "cnt", + "notNull": true, "length": -1, - "table": { - "name": "postgres_types" - }, + "isFuncCall": true, "type": { - "name": "date" - }, - "originalName": "c_date" + "name": "bigint" + } + } + ], + "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_datetime_types\n(\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval\n) VALUES ($1, $2, $3, $4, $5)", + "name": "InsertPostgresDateTimeTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_date", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_datetime_types" + }, + "type": { + "name": "date" + }, + "originalName": "c_date" + } }, { - "name": "c_time", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "time" - }, - "originalName": "c_time" + "number": 2, + "column": { + "name": "c_time", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_datetime_types" + }, + "type": { + "name": "pg_catalog.time" + }, + "originalName": "c_time" + } }, { - "name": "c_timestamp", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "timestamp" - }, - "originalName": "c_timestamp" + "number": 3, + "column": { + "name": "c_timestamp", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_datetime_types" + }, + "type": { + "name": "pg_catalog.timestamp" + }, + "originalName": "c_timestamp" + } }, { - "name": "c_timestamp_with_tz", + "number": 4, + "column": { + "name": "c_timestamp_with_tz", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_datetime_types" + }, + "type": { + "name": "pg_catalog.timestamptz" + }, + "originalName": "c_timestamp_with_tz" + } + }, + { + "number": 5, + "column": { + "name": "c_interval", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_datetime_types" + }, + "type": { + "name": "pg_catalog.interval" + }, + "originalName": "c_interval" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_datetime_types" + } + }, + { + "text": "\nINSERT INTO postgres_network_types\n(\n c_cidr,\n c_inet,\n c_macaddr,\n c_macaddr8\n) VALUES (\n $1, \n $2, \n $3, \n $4::macaddr8\n)", + "name": "InsertPostgresNetworkTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_cidr", + "length": -1, + "isNamedParam": true, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "cidr" + }, + "originalName": "c_cidr" + } + }, + { + "number": 2, + "column": { + "name": "c_inet", + "length": -1, + "isNamedParam": true, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "inet" + }, + "originalName": "c_inet" + } + }, + { + "number": 3, + "column": { + "name": "c_macaddr", + "length": -1, + "isNamedParam": true, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "macaddr" + }, + "originalName": "c_macaddr" + } + }, + { + "number": 4, + "column": { + "name": "c_macaddr8", + "length": -1, + "type": { + "name": "macaddr8" + } + } + } + ], + "comments": [ + " Network types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_network_types" + } + }, + { + "text": "SELECT\n c_cidr,\n c_inet,\n c_macaddr,\n c_macaddr8::TEXT AS c_macaddr8\nFROM postgres_network_types\nLIMIT 1", + "name": "GetPostgresNetworkTypes", + "cmd": ":one", + "columns": [ + { + "name": "c_cidr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "schema": "pg_catalog", - "name": "timestamptz" + "name": "cidr" }, - "originalName": "c_timestamp_with_tz" + "originalName": "c_cidr" }, { - "name": "c_interval", + "name": "c_inet", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "schema": "pg_catalog", - "name": "interval" + "name": "inet" }, - "originalName": "c_interval" + "originalName": "c_inet" }, { - "name": "c_char", + "name": "c_macaddr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "schema": "pg_catalog", - "name": "bpchar" + "name": "macaddr" }, - "originalName": "c_char" + "originalName": "c_macaddr" }, { - "name": "c_varchar", + "name": "c_macaddr8", + "notNull": true, "length": -1, - "table": { - "name": "postgres_types" - }, "type": { - "schema": "pg_catalog", - "name": "varchar" - }, - "originalName": "c_varchar" - }, + "name": "text" + } + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_network_types", + "name": "TruncatePostgresNetworkTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "SELECT\n c_cidr,\n c_inet,\n c_macaddr,\n COUNT(*) AS cnt\nFROM postgres_network_types\nGROUP BY\n c_cidr,\n c_inet,\n c_macaddr\nLIMIT 1", + "name": "GetPostgresNetworkTypesCnt", + "cmd": ":one", + "columns": [ { - "name": "c_character_varying", + "name": "c_cidr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "schema": "pg_catalog", - "name": "varchar" + "name": "cidr" }, - "originalName": "c_character_varying" + "originalName": "c_cidr" }, { - "name": "c_bpchar", + "name": "c_inet", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "bpchar" + "name": "inet" }, - "originalName": "c_bpchar" + "originalName": "c_inet" }, { - "name": "c_text", + "name": "c_macaddr", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_network_types" }, "type": { - "name": "text" + "name": "macaddr" }, - "originalName": "c_text" + "originalName": "c_macaddr" }, { - "name": "c_uuid", + "name": "cnt", + "notNull": true, "length": -1, - "table": { - "name": "postgres_types" - }, + "isFuncCall": true, "type": { - "name": "uuid" - }, - "originalName": "c_uuid" + "name": "bigint" + } + } + ], + "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_network_types\n(\n c_cidr,\n c_inet,\n c_macaddr\n) VALUES ($1, $2, $3)", + "name": "InsertPostgresNetworkTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_cidr", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "cidr" + }, + "originalName": "c_cidr" + } + }, + { + "number": 2, + "column": { + "name": "c_inet", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "inet" + }, + "originalName": "c_inet" + } + }, + { + "number": 3, + "column": { + "name": "c_macaddr", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_network_types" + }, + "type": { + "name": "macaddr" + }, + "originalName": "c_macaddr" + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_network_types" + } + }, + { + "text": "\nINSERT INTO postgres_special_types\n(\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum\n)\nVALUES (\n $1::json, \n $2::json, \n $3::jsonb,\n $4::jsonpath,\n $5::xml,\n $6::xml,\n $7,\n $8::c_enum\n)", + "name": "InsertPostgresSpecialTypes", + "cmd": ":exec", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_json", + "length": -1, + "type": { + "name": "json" + } + } + }, + { + "number": 2, + "column": { + "name": "c_json_string_override", + "length": -1, + "type": { + "name": "json" + } + } + }, + { + "number": 3, + "column": { + "name": "c_jsonb", + "length": -1, + "type": { + "name": "jsonb" + } + } + }, + { + "number": 4, + "column": { + "name": "c_jsonpath", + "length": -1, + "type": { + "name": "jsonpath" + } + } + }, + { + "number": 5, + "column": { + "name": "c_xml", + "length": -1, + "type": { + "name": "xml" + } + } + }, + { + "number": 6, + "column": { + "name": "c_xml_string_override", + "length": -1, + "type": { + "name": "xml" + } + } }, + { + "number": 7, + "column": { + "name": "c_uuid", + "length": -1, + "isNamedParam": true, + "table": { + "schema": "public", + "name": "postgres_special_types" + }, + "type": { + "name": "uuid" + }, + "originalName": "c_uuid" + } + }, + { + "number": 8, + "column": { + "name": "c_enum", + "length": -1, + "type": { + "name": "c_enum" + } + } + } + ], + "comments": [ + " Special types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_special_types" + } + }, + { + "text": "SELECT\n c_json,\n c_json_string_override,\n c_jsonb,\n c_jsonpath,\n c_xml,\n c_xml_string_override,\n c_uuid,\n c_enum\nFROM postgres_special_types \nLIMIT 1", + "name": "GetPostgresSpecialTypes", + "cmd": ":one", + "columns": [ { "name": "c_json", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { "name": "json" @@ -34278,7 +35151,7 @@ "name": "c_json_string_override", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { "name": "json" @@ -34289,7 +35162,7 @@ "name": "c_jsonb", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { "name": "jsonb" @@ -34300,7 +35173,7 @@ "name": "c_jsonpath", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { "name": "jsonpath" @@ -34311,7 +35184,7 @@ "name": "c_xml", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { "name": "xml" @@ -34319,321 +35192,528 @@ "originalName": "c_xml" }, { - "name": "c_cidr", + "name": "c_xml_string_override", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { - "name": "cidr" + "name": "xml" }, - "originalName": "c_cidr" + "originalName": "c_xml_string_override" }, { - "name": "c_inet", + "name": "c_uuid", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { - "name": "inet" + "name": "uuid" }, - "originalName": "c_inet" + "originalName": "c_uuid" }, { - "name": "c_macaddr", + "name": "c_enum", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { - "name": "macaddr" + "name": "c_enum" }, - "originalName": "c_macaddr" - }, + "originalName": "c_enum" + } + ], + "filename": "query.sql" + }, + { + "text": "TRUNCATE TABLE postgres_special_types", + "name": "TruncatePostgresSpecialTypes", + "cmd": ":exec", + "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_special_types\n(\n c_uuid\n)\nVALUES (\n $1\n)", + "name": "InsertPostgresSpecialTypesBatch", + "cmd": ":copyfrom", + "parameters": [ { - "name": "c_macaddr8", - "notNull": true, - "length": -1, - "type": { - "name": "text" + "number": 1, + "column": { + "name": "c_uuid", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_special_types" + }, + "type": { + "name": "uuid" + }, + "originalName": "c_uuid" } } ], - "filename": "query.sql" + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_special_types" + } }, { - "text": "SELECT\n c_smallint,\n c_boolean,\n c_integer,\n c_bigint,\n c_real,\n c_numeric,\n c_decimal,\n c_double_precision,\n c_money,\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n c_uuid,\n c_cidr,\n c_inet,\n c_macaddr,\n COUNT(*) AS cnt\nFROM postgres_types\nGROUP BY\n c_smallint,\n c_boolean,\n c_integer,\n c_bigint,\n c_real,\n c_numeric,\n c_decimal,\n c_double_precision,\n c_money,\n c_date,\n c_time,\n c_timestamp,\n c_timestamp_with_tz,\n c_interval,\n c_char,\n c_varchar,\n c_character_varying,\n c_bpchar,\n c_text,\n c_uuid,\n c_cidr,\n c_inet,\n c_macaddr\nLIMIT 1", - "name": "GetPostgresTypesCnt", + "text": "SELECT\n c_uuid,\n COUNT(*) AS cnt\nFROM postgres_special_types\nGROUP BY\n c_uuid\nLIMIT 1", + "name": "GetPostgresSpecialTypesCnt", "cmd": ":one", "columns": [ { - "name": "c_smallint", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "int2" - }, - "originalName": "c_smallint" - }, - { - "name": "c_boolean", + "name": "c_uuid", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_special_types" }, "type": { - "schema": "pg_catalog", - "name": "bool" + "name": "uuid" }, - "originalName": "c_boolean" + "originalName": "c_uuid" }, { - "name": "c_integer", + "name": "cnt", + "notNull": true, "length": -1, - "table": { - "name": "postgres_types" - }, + "isFuncCall": true, "type": { - "schema": "pg_catalog", - "name": "int4" - }, - "originalName": "c_integer" - }, + "name": "bigint" + } + } + ], + "filename": "query.sql" + }, + { + "text": "\nINSERT INTO postgres_array_types\n(\n c_bytea,\n c_boolean_array,\n c_text_array,\n c_integer_array,\n c_decimal_array,\n c_date_array,\n c_timestamp_array\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", + "name": "InsertPostgresArrayTypes", + "cmd": ":exec", + "parameters": [ { - "name": "c_bigint", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "int8" - }, - "originalName": "c_bigint" + "number": 1, + "column": { + "name": "c_bytea", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "bytea" + }, + "originalName": "c_bytea" + } }, { - "name": "c_real", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "float4" - }, - "originalName": "c_real" + "number": 2, + "column": { + "name": "c_boolean_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.bool" + }, + "originalName": "c_boolean_array", + "arrayDims": 1 + } }, { - "name": "c_numeric", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "numeric" - }, - "originalName": "c_numeric" + "number": 3, + "column": { + "name": "c_text_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "text" + }, + "originalName": "c_text_array", + "arrayDims": 1 + } }, { - "name": "c_decimal", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "numeric" - }, - "originalName": "c_decimal" + "number": 4, + "column": { + "name": "c_integer_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.int4" + }, + "originalName": "c_integer_array", + "arrayDims": 1 + } }, { - "name": "c_double_precision", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "schema": "pg_catalog", - "name": "float8" - }, - "originalName": "c_double_precision" + "number": 5, + "column": { + "name": "c_decimal_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.numeric" + }, + "originalName": "c_decimal_array", + "arrayDims": 1 + } }, { - "name": "c_money", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "name": "money" - }, - "originalName": "c_money" + "number": 6, + "column": { + "name": "c_date_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "date" + }, + "originalName": "c_date_array", + "arrayDims": 1 + } }, { - "name": "c_date", - "length": -1, - "table": { - "name": "postgres_types" - }, - "type": { - "name": "date" - }, - "originalName": "c_date" - }, + "number": 7, + "column": { + "name": "c_timestamp_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.timestamp" + }, + "originalName": "c_timestamp_array", + "arrayDims": 1 + } + } + ], + "comments": [ + " Array types " + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_array_types" + } + }, + { + "text": "SELECT c_bytea, c_boolean_array, c_text_array, c_integer_array, c_decimal_array, c_date_array, c_timestamp_array FROM postgres_array_types LIMIT 1", + "name": "GetPostgresArrayTypes", + "cmd": ":one", + "columns": [ { - "name": "c_time", + "name": "c_bytea", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "schema": "pg_catalog", - "name": "time" + "name": "bytea" }, - "originalName": "c_time" + "originalName": "c_bytea" }, { - "name": "c_timestamp", + "name": "c_boolean_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { "schema": "pg_catalog", - "name": "timestamp" + "name": "bool" }, - "originalName": "c_timestamp" + "originalName": "c_boolean_array", + "arrayDims": 1 }, { - "name": "c_timestamp_with_tz", + "name": "c_text_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "schema": "pg_catalog", - "name": "timestamptz" + "name": "text" }, - "originalName": "c_timestamp_with_tz" + "originalName": "c_text_array", + "arrayDims": 1 }, { - "name": "c_interval", + "name": "c_integer_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { "schema": "pg_catalog", - "name": "interval" + "name": "int4" }, - "originalName": "c_interval" + "originalName": "c_integer_array", + "arrayDims": 1 }, { - "name": "c_char", + "name": "c_decimal_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { "schema": "pg_catalog", - "name": "bpchar" + "name": "numeric" }, - "originalName": "c_char" + "originalName": "c_decimal_array", + "arrayDims": 1 }, { - "name": "c_varchar", + "name": "c_date_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, - "type": { - "schema": "pg_catalog", - "name": "varchar" + "type": { + "name": "date" }, - "originalName": "c_varchar" + "originalName": "c_date_array", + "arrayDims": 1 }, { - "name": "c_character_varying", + "name": "c_timestamp_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { "schema": "pg_catalog", - "name": "varchar" + "name": "timestamp" }, - "originalName": "c_character_varying" + "originalName": "c_timestamp_array", + "arrayDims": 1 + } + ], + "filename": "query.sql" + }, + { + "text": "INSERT INTO postgres_array_types (\n c_bytea,\n c_boolean_array,\n c_text_array,\n c_integer_array,\n c_decimal_array,\n c_timestamp_array\n) \nVALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6\n)", + "name": "InsertPostgresArrayTypesBatch", + "cmd": ":copyfrom", + "parameters": [ + { + "number": 1, + "column": { + "name": "c_bytea", + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "bytea" + }, + "originalName": "c_bytea" + } }, { - "name": "c_bpchar", + "number": 2, + "column": { + "name": "c_boolean_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.bool" + }, + "originalName": "c_boolean_array", + "arrayDims": 1 + } + }, + { + "number": 3, + "column": { + "name": "c_text_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "text" + }, + "originalName": "c_text_array", + "arrayDims": 1 + } + }, + { + "number": 4, + "column": { + "name": "c_integer_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.int4" + }, + "originalName": "c_integer_array", + "arrayDims": 1 + } + }, + { + "number": 5, + "column": { + "name": "c_decimal_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.numeric" + }, + "originalName": "c_decimal_array", + "arrayDims": 1 + } + }, + { + "number": 6, + "column": { + "name": "c_timestamp_array", + "isArray": true, + "length": -1, + "table": { + "schema": "public", + "name": "postgres_array_types" + }, + "type": { + "name": "pg_catalog.timestamp" + }, + "originalName": "c_timestamp_array", + "arrayDims": 1 + } + } + ], + "filename": "query.sql", + "insert_into_table": { + "name": "postgres_array_types" + } + }, + { + "text": "SELECT\n c_bytea,\n c_boolean_array,\n c_text_array,\n c_integer_array,\n c_decimal_array,\n c_timestamp_array,\n COUNT(*) AS cnt\nFROM postgres_array_types\nGROUP BY\n c_bytea,\n c_boolean_array,\n c_text_array,\n c_integer_array,\n c_decimal_array,\n c_timestamp_array\nLIMIT 1", + "name": "GetPostgresArrayTypesCnt", + "cmd": ":one", + "columns": [ + { + "name": "c_bytea", "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "bpchar" + "name": "bytea" }, - "originalName": "c_bpchar" + "originalName": "c_bytea" }, { - "name": "c_text", + "name": "c_boolean_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "text" + "schema": "pg_catalog", + "name": "bool" }, - "originalName": "c_text" + "originalName": "c_boolean_array", + "arrayDims": 1 }, { - "name": "c_uuid", + "name": "c_text_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "uuid" + "name": "text" }, - "originalName": "c_uuid" + "originalName": "c_text_array", + "arrayDims": 1 }, { - "name": "c_cidr", + "name": "c_integer_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "cidr" + "schema": "pg_catalog", + "name": "int4" }, - "originalName": "c_cidr" + "originalName": "c_integer_array", + "arrayDims": 1 }, { - "name": "c_inet", + "name": "c_decimal_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "inet" + "schema": "pg_catalog", + "name": "numeric" }, - "originalName": "c_inet" + "originalName": "c_decimal_array", + "arrayDims": 1 }, { - "name": "c_macaddr", + "name": "c_timestamp_array", + "isArray": true, "length": -1, "table": { - "name": "postgres_types" + "name": "postgres_array_types" }, "type": { - "name": "macaddr" + "schema": "pg_catalog", + "name": "timestamp" }, - "originalName": "c_macaddr" + "originalName": "c_timestamp_array", + "arrayDims": 1 }, { "name": "cnt", @@ -34648,42 +35728,13 @@ "filename": "query.sql" }, { - "text": "SELECT\n MAX(c_integer) AS max_integer,\n MAX(c_varchar) AS max_varchar,\n MAX(c_timestamp) AS max_timestamp\nFROM postgres_types", - "name": "GetPostgresFunctions", - "cmd": ":one", - "columns": [ - { - "name": "max_integer", - "notNull": true, - "length": -1, - "isFuncCall": true, - "type": { - "name": "anyarray" - } - }, - { - "name": "max_varchar", - "notNull": true, - "length": -1, - "isFuncCall": true, - "type": { - "name": "anyarray" - } - }, - { - "name": "max_timestamp", - "notNull": true, - "length": -1, - "isFuncCall": true, - "type": { - "name": "anyarray" - } - } - ], + "text": "TRUNCATE TABLE postgres_array_types", + "name": "TruncatePostgresArrayTypes", + "cmd": ":exec", "filename": "query.sql" }, { - "text": "INSERT INTO postgres_geometric_types (\n c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", + "text": "\nINSERT INTO postgres_geometric_types (\n c_point, \n c_line, \n c_lseg, \n c_box, \n c_path, \n c_polygon, \n c_circle\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", "name": "InsertPostgresGeoTypes", "cmd": ":exec", "parameters": [ @@ -34793,13 +35844,16 @@ } } ], + "comments": [ + " Geometric types " + ], "filename": "query.sql", "insert_into_table": { "name": "postgres_geometric_types" } }, { - "text": "INSERT INTO postgres_geometric_types (\n c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", + "text": "INSERT INTO postgres_geometric_types (\n c_point, \n c_line, \n c_lseg, \n c_box, \n c_path, \n c_polygon, \n c_circle\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", "name": "InsertPostgresGeoTypesBatch", "cmd": ":copyfrom", "parameters": [ @@ -34999,308 +36053,13 @@ ], "filename": "query.sql" }, - { - "text": "TRUNCATE TABLE postgres_types", - "name": "TruncatePostgresTypes", - "cmd": ":exec", - "filename": "query.sql" - }, { "text": "TRUNCATE TABLE postgres_geometric_types", "name": "TruncatePostgresGeoTypes", "cmd": ":exec", "filename": "query.sql" - }, - { - "text": "INSERT INTO postgres_array_types\n(\n c_bytea,\n c_boolean_array,\n c_text_array,\n c_integer_array,\n c_decimal_array,\n c_date_array,\n c_timestamp_array\n)\nVALUES ($1, $2, $3, $4, $5, $6, $7)", - "name": "InsertPostgresArrayTypes", - "cmd": ":exec", - "parameters": [ - { - "number": 1, - "column": { - "name": "c_bytea", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "bytea" - }, - "originalName": "c_bytea" - } - }, - { - "number": 2, - "column": { - "name": "c_boolean_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "pg_catalog.bool" - }, - "originalName": "c_boolean_array", - "arrayDims": 1 - } - }, - { - "number": 3, - "column": { - "name": "c_text_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "text" - }, - "originalName": "c_text_array", - "arrayDims": 1 - } - }, - { - "number": 4, - "column": { - "name": "c_integer_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "pg_catalog.int4" - }, - "originalName": "c_integer_array", - "arrayDims": 1 - } - }, - { - "number": 5, - "column": { - "name": "c_decimal_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "pg_catalog.numeric" - }, - "originalName": "c_decimal_array", - "arrayDims": 1 - } - }, - { - "number": 6, - "column": { - "name": "c_date_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "date" - }, - "originalName": "c_date_array", - "arrayDims": 1 - } - }, - { - "number": 7, - "column": { - "name": "c_timestamp_array", - "isArray": true, - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "pg_catalog.timestamp" - }, - "originalName": "c_timestamp_array", - "arrayDims": 1 - } - } - ], - "filename": "query.sql", - "insert_into_table": { - "name": "postgres_array_types" - } - }, - { - "text": "SELECT c_bytea, c_boolean_array, c_text_array, c_integer_array, c_decimal_array, c_date_array, c_timestamp_array FROM postgres_array_types LIMIT 1", - "name": "GetPostgresArrayTypes", - "cmd": ":one", - "columns": [ - { - "name": "c_bytea", - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "name": "bytea" - }, - "originalName": "c_bytea" - }, - { - "name": "c_boolean_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "schema": "pg_catalog", - "name": "bool" - }, - "originalName": "c_boolean_array", - "arrayDims": 1 - }, - { - "name": "c_text_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "name": "text" - }, - "originalName": "c_text_array", - "arrayDims": 1 - }, - { - "name": "c_integer_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "schema": "pg_catalog", - "name": "int4" - }, - "originalName": "c_integer_array", - "arrayDims": 1 - }, - { - "name": "c_decimal_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "schema": "pg_catalog", - "name": "numeric" - }, - "originalName": "c_decimal_array", - "arrayDims": 1 - }, - { - "name": "c_date_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "name": "date" - }, - "originalName": "c_date_array", - "arrayDims": 1 - }, - { - "name": "c_timestamp_array", - "isArray": true, - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "schema": "pg_catalog", - "name": "timestamp" - }, - "originalName": "c_timestamp_array", - "arrayDims": 1 - } - ], - "filename": "query.sql" - }, - { - "text": "INSERT INTO postgres_array_types (c_bytea) VALUES ($1)", - "name": "InsertPostgresArrayTypesBatch", - "cmd": ":copyfrom", - "parameters": [ - { - "number": 1, - "column": { - "name": "c_bytea", - "length": -1, - "table": { - "schema": "public", - "name": "postgres_array_types" - }, - "type": { - "name": "bytea" - }, - "originalName": "c_bytea" - } - } - ], - "filename": "query.sql", - "insert_into_table": { - "name": "postgres_array_types" - } - }, - { - "text": "SELECT\n c_bytea,\n COUNT(*) AS cnt\nFROM postgres_array_types\nGROUP BY\n c_bytea\nLIMIT 1", - "name": "GetPostgresArrayTypesCnt", - "cmd": ":one", - "columns": [ - { - "name": "c_bytea", - "length": -1, - "table": { - "name": "postgres_array_types" - }, - "type": { - "name": "bytea" - }, - "originalName": "c_bytea" - }, - { - "name": "cnt", - "notNull": true, - "length": -1, - "isFuncCall": true, - "type": { - "name": "bigint" - } - } - ], - "filename": "query.sql" - }, - { - "text": "TRUNCATE TABLE postgres_array_types", - "name": "TruncatePostgresArrayTypes", - "cmd": ":exec", - "filename": "query.sql" } ], "sqlc_version": "v1.27.0", - "plugin_options": "eyJvdmVycmlkZURyaXZlclZlcnNpb24iOiIiLCJnZW5lcmF0ZUNzcHJvaiI6dHJ1ZSwidGFyZ2V0RnJhbWV3b3JrIjoibmV0c3RhbmRhcmQyLjAiLCJuYW1lc3BhY2VOYW1lIjoiTnBnc3FsTGVnYWN5RXhhbXBsZUdlbiIsInVzZURhcHBlciI6ZmFsc2UsIm92ZXJyaWRlRGFwcGVyVmVyc2lvbiI6IiIsIm92ZXJyaWRlcyI6W3siY29sdW1uIjoiR2V0UG9zdGdyZXNGdW5jdGlvbnM6bWF4X2ludGVnZXIiLCJjc2hhcnBfdHlwZSI6eyJ0eXBlIjoiaW50Iiwibm90TnVsbCI6ZmFsc2V9fSx7ImNvbHVtbiI6IkdldFBvc3RncmVzRnVuY3Rpb25zOm1heF92YXJjaGFyIiwiY3NoYXJwX3R5cGUiOnsidHlwZSI6InN0cmluZyIsIm5vdE51bGwiOmZhbHNlfX0seyJjb2x1bW4iOiJHZXRQb3N0Z3Jlc0Z1bmN0aW9uczptYXhfdGltZXN0YW1wIiwiY3NoYXJwX3R5cGUiOnsidHlwZSI6IkRhdGVUaW1lIiwibm90TnVsbCI6dHJ1ZX19LHsiY29sdW1uIjoiKjpjX2pzb25fc3RyaW5nX292ZXJyaWRlIiwiY3NoYXJwX3R5cGUiOnsidHlwZSI6InN0cmluZyIsIm5vdE51bGwiOmZhbHNlfX0seyJjb2x1bW4iOiIqOmNfbWFjYWRkcjgiLCJjc2hhcnBfdHlwZSI6eyJ0eXBlIjoic3RyaW5nIiwibm90TnVsbCI6ZmFsc2V9fV0sImRlYnVnUmVxdWVzdCI6ZmFsc2V9" + "plugin_options": "eyJvdmVycmlkZURyaXZlclZlcnNpb24iOiIiLCJnZW5lcmF0ZUNzcHJvaiI6dHJ1ZSwidGFyZ2V0RnJhbWV3b3JrIjoibmV0c3RhbmRhcmQyLjAiLCJuYW1lc3BhY2VOYW1lIjoiTnBnc3FsTGVnYWN5RXhhbXBsZUdlbiIsInVzZURhcHBlciI6ZmFsc2UsIm92ZXJyaWRlRGFwcGVyVmVyc2lvbiI6IiIsIm92ZXJyaWRlcyI6W3siY29sdW1uIjoiR2V0UG9zdGdyZXNGdW5jdGlvbnM6bWF4X2ludGVnZXIiLCJjc2hhcnBfdHlwZSI6eyJ0eXBlIjoiaW50Iiwibm90TnVsbCI6ZmFsc2V9fSx7ImNvbHVtbiI6IkdldFBvc3RncmVzRnVuY3Rpb25zOm1heF92YXJjaGFyIiwiY3NoYXJwX3R5cGUiOnsidHlwZSI6InN0cmluZyIsIm5vdE51bGwiOmZhbHNlfX0seyJjb2x1bW4iOiJHZXRQb3N0Z3Jlc0Z1bmN0aW9uczptYXhfdGltZXN0YW1wIiwiY3NoYXJwX3R5cGUiOnsidHlwZSI6IkRhdGVUaW1lIiwibm90TnVsbCI6dHJ1ZX19LHsiY29sdW1uIjoiKjpjX2pzb25fc3RyaW5nX292ZXJyaWRlIiwiY3NoYXJwX3R5cGUiOnsidHlwZSI6InN0cmluZyIsIm5vdE51bGwiOmZhbHNlfX0seyJjb2x1bW4iOiIqOmNfeG1sX3N0cmluZ19vdmVycmlkZSIsImNzaGFycF90eXBlIjp7InR5cGUiOiJzdHJpbmciLCJub3ROdWxsIjpmYWxzZX19LHsiY29sdW1uIjoiKjpjX21hY2FkZHI4IiwiY3NoYXJwX3R5cGUiOnsidHlwZSI6InN0cmluZyIsIm5vdE51bGwiOmZhbHNlfX1dLCJkZWJ1Z1JlcXVlc3QiOmZhbHNlfQ==" } \ No newline at end of file diff --git a/examples/NpgsqlLegacyExample/request.message b/examples/NpgsqlLegacyExample/request.message index f5579efe..de7cc006 100644 --- a/examples/NpgsqlLegacyExample/request.message +++ b/examples/NpgsqlLegacyExample/request.message @@ -1,9 +1,9 @@ -ï +­ 2 -postgresql%examples/config/postgresql/schema.sql"$examples/config/postgresql/query.sqlb -examples/NpgsqlLegacyExamplecsharpÑ{"debugRequest":true,"generateCsproj":true,"namespaceName":"NpgsqlLegacyExampleGen","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"notNull":false,"type":"int"}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"notNull":false,"type":"string"}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"notNull":true,"type":"DateTime"}},{"column":"*:c_json_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_macaddr8","csharp_type":{"notNull":false,"type":"string"}}],"targetFramework":"netstandard2.0","useDapper":false}* -./dist/LocalRunner©æ public"ýpublicƒ +postgresql-examples/config/postgresql/authors/schema.sql+examples/config/postgresql/types/schema.sql",examples/config/postgresql/authors/query.sql"*examples/config/postgresql/types/query.sqlbå +examples/NpgsqlLegacyExamplecsharp¦{"debugRequest":true,"generateCsproj":true,"namespaceName":"NpgsqlLegacyExampleGen","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"notNull":false,"type":"int"}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"notNull":false,"type":"string"}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"notNull":true,"type":"DateTime"}},{"column":"*:c_json_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_xml_string_override","csharp_type":{"notNull":false,"type":"string"}},{"column":"*:c_macaddr8","csharp_type":{"notNull":false,"type":"string"}}],"targetFramework":"netstandard2.0","useDapper":false}* +./dist/LocalRunnerÃì public"…publicƒ authors) id0ÿÿÿÿÿÿÿÿÿR authorsb  bigserial& name0ÿÿÿÿÿÿÿÿÿR authorsbtext# @@ -13,68 +13,55 @@ postgresql%examples/config/postgresql/schema.sql"$examples/config/postgresql/qu name0ÿÿÿÿÿÿÿÿÿRbooksbtext5 author_id0ÿÿÿÿÿÿÿÿÿRbooksb pg_catalogint8) - description0ÿÿÿÿÿÿÿÿÿRbooksbtextä -postgres_types< - c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbool7 -c_bit0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbit= - -c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint2< - c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint4; -c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint8? - c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumeric? - c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumeric; -c_real0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat4G -c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat8/ -c_money0ÿÿÿÿÿÿÿÿÿRpostgres_typesbmoney- -c_date0ÿÿÿÿÿÿÿÿÿRpostgres_typesbdate9 -c_time0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogtimeC - c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestampM -c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestamptzA - -c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_cataloginterval; -c_char0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbpchar? - c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarcharI -c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarchar1 -c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesbbpchar- -c_text0ÿÿÿÿÿÿÿÿÿRpostgres_typesbtext- -c_json0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjson= -c_json_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjson/ -c_jsonb0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjsonb5 - -c_jsonpath0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -jsonpath+ -c_xml0ÿÿÿÿÿÿÿÿÿRpostgres_typesbxml- -c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_typesbcidr- -c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_typesbinet3 - c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_typesb macaddr5 - -c_macaddr80ÿÿÿÿÿÿÿÿÿRpostgres_typesb -macaddr8- -c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_typesbuuidµ -postgres_geometric_types9 -c_point0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpoint7 -c_line0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbline7 -c_lseg0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblseg5 -c_box0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbbox7 -c_path0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpath= - c_polygon0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesb polygon; -c_circle0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbcircle• + description0ÿÿÿÿÿÿÿÿÿRbooksbtextÔ +postgres_numeric_typesD + c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogbool? +c_bit0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogbitE + +c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint2D + c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint4C +c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint8G + c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericG + c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericC +c_real0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat4O +c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat87 +c_money0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesbmoneyç +postgres_string_typesB +c_char0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogbpcharF + c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarcharP +c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarchar8 +c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbbpchar4 +c_text0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbtext‰ +postgres_datetime_types6 +c_date0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesbdateB +c_time0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalogtimeL + c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestampV +c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestamptzJ + +c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_cataloginterval„ +postgres_network_types5 +c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbcidr5 +c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbinet; + c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesb macaddr= + +c_macaddr80ÿÿÿÿÿÿÿÿÿRpostgres_network_typesb +macaddr8• postgres_array_types5 c_bytea0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbbyteaM c_boolean_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb @@ -86,7 +73,27 @@ pg_catalogint4 pg_catalognumericˆ> c_date_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbdateˆT c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb -pg_catalog timestampˆ" pg_temp"æ² +pg_catalog timestampˆµ +postgres_geometric_types9 +c_point0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpoint7 +c_line0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbline7 +c_lseg0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblseg5 +c_box0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbbox7 +c_path0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpath= + c_polygon0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesb polygon; +c_circle0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbcircleú +postgres_special_types5 +c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbuuid7 +c_enum0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbc_enum5 +c_json0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjsonE +c_json_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjson7 +c_jsonb0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjsonb= + +c_jsonpath0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesb +jsonpath3 +c_xml0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbxmlC +c_xml_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbxml" +c_enumsmallmediumbig" pg_temp"æ² pg_catalog‰ & @@ -10207,7 +10214,14 @@ pg_cataloginformation_schemaviewsb  yes_or_noW pg_cataloginformation_schemaviewsb  yes_or_no] is_trigger_insertable_into0ÿÿÿÿÿÿÿÿÿR' -pg_cataloginformation_schemaviewsb  yes_or_no +pg_cataloginformation_schemaviewsb  yes_or_no"extendedÔ +extendedbiosC + author_name0ÿÿÿÿÿÿÿÿÿRextendedbiosb +pg_catalogvarchar< +name0ÿÿÿÿÿÿÿÿÿRextendedbiosb +pg_catalogvarchar= +bio_type0ÿÿÿÿÿÿÿÿÿRextendedbiosbextendedbio_type", +bio_type Autobiography BiographyMemoir 9SELECT id, name, bio FROM authors WHERE name = $1 LIMIT 1 GetAuthor:one"- id0ÿÿÿÿÿÿÿÿÿR authorsb  bigserialzid", @@ -10298,415 +10312,439 @@ WHERE books.name = $1GetAuthorsByBookName:many"- name0ÿÿÿÿÿÿÿÿÿR authorsbtextzname"( bio0ÿÿÿÿÿÿÿÿÿR authorsbtextzbio" books0ÿÿÿÿÿÿÿÿÿbrbooks*.* -name0ÿÿÿÿÿÿÿÿÿRbooksbtextzname: query.sqlˆ -¬INSERT INTO postgres_types +name0ÿÿÿÿÿÿÿÿÿRbooksbtextzname: query.sqlì +KINSERT INTO extended.bios (author_name, name, bio_type) VALUES ($1, $2, $3)CreateExtendedBio:exec*SO + author_name0ÿÿÿÿÿÿÿÿÿRextendedbiosbpg_catalog.varcharz author_name*EA +name0ÿÿÿÿÿÿÿÿÿRextendedbiosbpg_catalog.varcharzname*JF +bio_type0ÿÿÿÿÿÿÿÿÿRextendedbiosbextended.bio_typezbio_type: query.sqlBextendedbiosª +QSELECT author_name, name, bio_type FROM extended.bios WHERE bio_type = $1 LIMIT 1GetFirstExtendedBioByType:one"P + author_name0ÿÿÿÿÿÿÿÿÿRextendedbiosb +pg_catalogvarcharz author_name"B +name0ÿÿÿÿÿÿÿÿÿRextendedbiosb +pg_catalogvarcharzname"G +bio_type0ÿÿÿÿÿÿÿÿÿRextendedbiosbextendedbio_typezbio_type*JF +bio_type0ÿÿÿÿÿÿÿÿÿRextendedbiosbextended.bio_typezbio_type: query.sqlF +TRUNCATE TABLE extended.biosTruncateExtendedBios:exec: query.sqlü +Ò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_typesGetPostgresFunctions:one"( + max_integer0ÿÿÿÿÿÿÿÿÿ@b +anyarray"( + max_varchar0ÿÿÿÿÿÿÿÿÿ@b +anyarray"* + max_timestamp0ÿÿÿÿÿÿÿÿÿ@b +anyarray: query.sqlà +í +INSERT INTO postgres_numeric_types ( c_boolean, c_bit, c_smallint, c_integer, c_bigint, - c_real, - c_numeric, c_decimal, + c_numeric, + c_real, c_double_precision, - c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, - c_json, - c_json_string_override, - c_jsonb, - c_jsonpath, - c_xml, - c_cidr, - c_inet, - c_macaddr, - c_macaddr8 + c_money ) -VALUES ( - $1, - $2, - $3, - $4, - $5, - $6, - $7, - $8, - $9, - $10, - $11, - $12, - $13, - $14, - $15, - $16, - $17, - $18, - $19, - $20, - $21, - $22::json, - $23::json, - $24::jsonb, - $25::jsonpath, - $26::xml, - $27, - $28, - $29::macaddr, - $30::macaddr8 -)InsertPostgresTypes:exec*TP - c_boolean0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.boolz c_boolean*KG -c_bit0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.bitzc_bit*VR - -c_smallint0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.int2z -c_smallint*TP - c_integer0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.int4z c_integer*RN -c_bigint0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.int8zc_bigint*PL -c_real0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.float4zc_real*WS - c_numeric0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.numericz c_numeric*WS - c_decimal0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.numericz c_decimal*h d -c_double_precision0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.float8zc_double_precision*F -B -c_money0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbmoneyzc_money*C ? -c_date0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbdatezc_date*N J -c_time0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.timezc_time*] Y - c_timestamp0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.timestampz c_timestamp*ok -c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.timestamptzzc_timestamp_with_tz*ZV - -c_interval0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.intervalz -c_interval*PL -c_char0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.bpcharzc_char*WS - c_varchar0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.varcharz c_varchar*kg -c_character_varying0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbpg_catalog.varcharzc_character_varying*IE -c_bpchar0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbbpcharzc_bpchar*C? -c_text0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbtextzc_text*C? -c_uuid0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbuuidzc_uuid* -c_json0ÿÿÿÿÿÿÿÿÿbjson*/+ -c_json_string_override0ÿÿÿÿÿÿÿÿÿbjson*! -c_jsonb0ÿÿÿÿÿÿÿÿÿbjsonb*'# - -c_jsonpath0ÿÿÿÿÿÿÿÿÿb -jsonpath* -c_xml0ÿÿÿÿÿÿÿÿÿbxml*C? -c_cidr0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbcidrzc_cidr*C? -c_inet0ÿÿÿÿÿÿÿÿÿ8Rpublicpostgres_typesbinetzc_inet*%! - c_macaddr0ÿÿÿÿÿÿÿÿÿb macaddr*'# - -c_macaddr80ÿÿÿÿÿÿÿÿÿb -macaddr8: query.sqlBpostgres_types‡ -ÜINSERT INTO postgres_types -( +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)InsertPostgresNumericTypes:exec*ZV + c_boolean0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.boolz c_boolean*QM +c_bit0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.bitzc_bit*\X + +c_smallint0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int2z +c_smallint*ZV + c_integer0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int4z c_integer*XT +c_bigint0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int8zc_bigint*]Y + c_decimal0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.numericz c_decimal*]Y + c_numeric0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.numericz c_numeric*VR +c_real0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.float4zc_real*n j +c_double_precision0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.float8zc_double_precision*L +H +c_money0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbmoneyzc_money2 Numeric types : query.sqlBpostgres_numeric_typesì +—SELECT c_boolean, c_bit, c_smallint, c_integer, c_bigint, c_decimal, c_numeric, c_real, c_double_precision, c_money FROM postgres_numeric_types LIMIT 1GetPostgresNumericTypes:one"O + c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogboolz c_boolean"F +c_bit0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogbitzc_bit"Q + +c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint2z +c_smallint"O + c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint4z c_integer"M +c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint8zc_bigint"R + c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericz c_decimal"R + c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericz c_numeric"K +c_real0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat4zc_real"c +c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat8zc_double_precision"@ +c_money0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesbmoneyzc_money: query.sqlW +%TRUNCATE TABLE postgres_numeric_typesTruncatePostgresNumericTypes:exec: query.sqlê +òSELECT c_boolean, + c_bit, c_smallint, c_integer, c_bigint, - c_real, - c_numeric, c_decimal, + c_numeric, + c_real, c_double_precision, c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, - c_cidr, - c_inet, - c_macaddr -) -VALUES ( - $1, - $2, - $3, - $4, - $5, - $6, - $7, - $8, - $9, - $10, - $11, - $12, - $13, - $14, - $15, - $16, - $17, - $18, - $19, - $20, - $21, - $22, - $23 -)InsertPostgresTypesBatch :copyfrom*RN - c_boolean0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.boolz c_boolean*TP - -c_smallint0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.int2z -c_smallint*RN - c_integer0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.int4z c_integer*PL -c_bigint0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.int8zc_bigint*NJ -c_real0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.float4zc_real*UQ - c_numeric0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.numericz c_numeric*UQ - c_decimal0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.numericz c_decimal*fb -c_double_precision0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.float8zc_double_precision*D @ -c_money0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbmoneyzc_money*A -= -c_date0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbdatezc_date*L H -c_time0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.timezc_time*[ W - c_timestamp0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.timestampz c_timestamp*m i -c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.timestamptzzc_timestamp_with_tz*XT - -c_interval0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.intervalz -c_interval*NJ -c_char0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.bpcharzc_char*UQ - c_varchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.varcharz c_varchar*ie -c_character_varying0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbpg_catalog.varcharzc_character_varying*GC -c_bpchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbbpcharzc_bpchar*A= -c_text0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbtextzc_text*A= -c_uuid0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbuuidzc_uuid*A= -c_cidr0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbcidrzc_cidr*A= -c_inet0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesbinetzc_inet*JF - c_macaddr0ÿÿÿÿÿÿÿÿÿRpublicpostgres_typesb macaddrz c_macaddr: query.sqlBpostgres_types­ -„SELECT + COUNT(*) AS cnt +FROM postgres_numeric_types +GROUP BY c_boolean, c_bit, c_smallint, c_integer, c_bigint, - c_real, - c_numeric, c_decimal, + c_numeric, + c_real, c_double_precision, - c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, - c_json, - c_json_string_override, - c_jsonb, - c_jsonpath, - c_xml, - c_cidr, - c_inet, - c_macaddr, - c_macaddr8::TEXT AS c_macaddr8 -FROM postgres_types -LIMIT 1GetPostgresTypes:one"G - c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogboolz c_boolean"> -c_bit0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbitzc_bit"I - -c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb + c_money +LIMIT 1GetPostgresNumericTypesCnt:one"O + c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogboolz c_boolean"F +c_bit0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogbitzc_bit"Q + +c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb pg_catalogint2z -c_smallint"G - c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint4z c_integer"E -c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint8zc_bigint"C -c_real0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat4zc_real"J - c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumericz c_numeric"J - c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumericz c_decimal"[ -c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat8zc_double_precision"8 -c_money0ÿÿÿÿÿÿÿÿÿRpostgres_typesbmoneyzc_money"5 -c_date0ÿÿÿÿÿÿÿÿÿRpostgres_typesbdatezc_date"A -c_time0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogtimezc_time"P - c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestampz c_timestamp"b -c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestamptzzc_timestamp_with_tz"M - -c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogintervalz -c_interval"C -c_char0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbpcharzc_char"J - c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarcharz c_varchar"^ -c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarcharzc_character_varying"; -c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesbbpcharzc_bpchar"5 -c_text0ÿÿÿÿÿÿÿÿÿRpostgres_typesbtextzc_text"5 -c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_typesbuuidzc_uuid"5 -c_json0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjsonzc_json"U -c_json_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjsonzc_json_string_override"8 -c_jsonb0ÿÿÿÿÿÿÿÿÿRpostgres_typesbjsonbzc_jsonb"A - -c_jsonpath0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -jsonpathz -c_jsonpath"2 -c_xml0ÿÿÿÿÿÿÿÿÿRpostgres_typesbxmlzc_xml"5 -c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_typesbcidrzc_cidr"5 -c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_typesbinetzc_inet"> - c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_typesb macaddrz c_macaddr"! - -c_macaddr80ÿÿÿÿÿÿÿÿÿbtext: query.sql¤ -úSELECT - c_smallint, +c_smallint"O + c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint4z c_integer"M +c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogint8zc_bigint"R + c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericz c_decimal"R + c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalognumericz c_numeric"K +c_real0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat4zc_real"c +c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesb +pg_catalogfloat8zc_double_precision"@ +c_money0ÿÿÿÿÿÿÿÿÿRpostgres_numeric_typesbmoneyzc_money" +cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sql× +ìINSERT INTO postgres_numeric_types +( c_boolean, + c_bit, + c_smallint, c_integer, c_bigint, - c_real, - c_numeric, c_decimal, + c_numeric, + c_real, c_double_precision, - c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, + c_money +) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)InsertPostgresNumericTypesBatch :copyfrom*ZV + c_boolean0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.boolz c_boolean*QM +c_bit0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.bitzc_bit*\X + +c_smallint0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int2z +c_smallint*ZV + c_integer0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int4z c_integer*XT +c_bigint0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.int8zc_bigint*]Y + c_decimal0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.numericz c_decimal*]Y + c_numeric0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.numericz c_numeric*VR +c_real0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.float4zc_real*n j +c_double_precision0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbpg_catalog.float8zc_double_precision*L +H +c_money0ÿÿÿÿÿÿÿÿÿR publicpostgres_numeric_typesbmoneyzc_money: query.sqlBpostgres_numeric_types© + +INSERT INTO postgres_string_types +( + c_char, + c_varchar, + c_character_varying, + c_bpchar, + c_text +) +VALUES ($1, $2, $3, $4, $5)InsertPostgresStringTypes:exec*UQ +c_char0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.bpcharzc_char*\X + c_varchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.varcharz c_varchar*pl +c_character_varying0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.varcharzc_character_varying*NJ +c_bpchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbbpcharzc_bpchar*HD +c_text0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbtextzc_text2 String types : query.sqlBpostgres_string_types¢ +INSERT INTO postgres_string_types +( + c_char, + c_varchar, + c_character_varying, + c_bpchar, + c_text +) VALUES ($1, $2, $3, $4, $5)InsertPostgresStringTypesBatch :copyfrom*UQ +c_char0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.bpcharzc_char*\X + c_varchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.varcharz c_varchar*pl +c_character_varying0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbpg_catalog.varcharzc_character_varying*NJ +c_bpchar0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbbpcharzc_bpchar*HD +c_text0ÿÿÿÿÿÿÿÿÿRpublicpostgres_string_typesbtextzc_text: query.sqlBpostgres_string_types• +bSELECT c_char, c_varchar, c_character_varying, c_bpchar, c_text FROM postgres_string_types LIMIT 1GetPostgresStringTypes:one"J +c_char0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogbpcharzc_char"Q + c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarcharz c_varchar"e +c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarcharzc_character_varying"B +c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbbpcharzc_bpchar"< +c_text0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbtextzc_text: query.sqlU +$TRUNCATE TABLE postgres_string_typesTruncatePostgresStringTypes:exec: query.sql¸ +áSELECT c_char, c_varchar, c_character_varying, c_bpchar, c_text, - c_uuid, - c_cidr, - c_inet, - c_macaddr, COUNT(*) AS cnt -FROM postgres_types +FROM postgres_string_types GROUP BY - c_smallint, - c_boolean, - c_integer, - c_bigint, - c_real, - c_numeric, - c_decimal, - c_double_precision, - c_money, + c_char, + c_varchar, + c_character_varying, + c_bpchar, + c_text +LIMIT 1GetPostgresStringTypesCnt:one"J +c_char0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogbpcharzc_char"Q + c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarcharz c_varchar"e +c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesb +pg_catalogvarcharzc_character_varying"B +c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbbpcharzc_bpchar"< +c_text0ÿÿÿÿÿÿÿÿÿRpostgres_string_typesbtextzc_text" +cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sqlì +ØWITH txt_query AS ( + SELECT + c_text, + to_tsquery('english', $1) AS query, + to_tsvector('english', c_text) AS tsv + FROM postgres_string_types + WHERE c_text @@ to_tsquery('english', $1) +) + +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 GetPostgresStringTypesTextSearch:one"0 +c_text0ÿÿÿÿÿÿÿÿÿR  txt_querybtextzc_text"3 +query0ÿÿÿÿÿÿÿÿÿR  txt_queryb tsqueryzquery"0 +tsv0ÿÿÿÿÿÿÿÿÿR  txt_queryb +tsvectorztsv" +rnk0ÿÿÿÿÿÿÿÿÿ@breal*%! + +to_tsquery0ÿÿÿÿÿÿÿÿÿbtext: query.sqlØ +• +INSERT INTO postgres_datetime_types +( + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval +) VALUES ($1, $2, $3, $4, $5)InsertPostgresDateTimeTypes:exec*JF +c_date0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbdatezc_date*UQ +c_time0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timezc_time*d` + c_timestamp0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timestampz c_timestamp*vr +c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timestamptzzc_timestamp_with_tz*a] + +c_interval0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.intervalz +c_interval2 DateTime types : query.sqlBpostgres_datetime_typesÁ +hSELECT c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval FROM postgres_datetime_types LIMIT 1GetPostgresDateTimeTypes:one"> +c_date0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesbdatezc_date"J +c_time0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalogtimezc_time"Y + c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestampz c_timestamp"k +c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestamptzzc_timestamp_with_tz"V + +c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalogintervalz +c_interval: query.sqlY +&TRUNCATE TABLE postgres_datetime_typesTruncatePostgresDateTimeTypes:exec: query.sqlè +ëSELECT c_date, c_time, c_timestamp, c_timestamp_with_tz, c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, + COUNT(*) AS cnt +FROM postgres_datetime_types +GROUP BY + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval +LIMIT 1GetPostgresDateTimeTypesCnt:one"> +c_date0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesbdatezc_date"J +c_time0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalogtimezc_time"Y + c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestampz c_timestamp"k +c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalog timestamptzzc_timestamp_with_tz"V + +c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_datetime_typesb +pg_catalogintervalz +c_interval" +cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sqlÎ +”INSERT INTO postgres_datetime_types +( + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval +) VALUES ($1, $2, $3, $4, $5) InsertPostgresDateTimeTypesBatch :copyfrom*JF +c_date0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbdatezc_date*UQ +c_time0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timezc_time*d` + c_timestamp0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timestampz c_timestamp*vr +c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.timestamptzzc_timestamp_with_tz*a] + +c_interval0ÿÿÿÿÿÿÿÿÿR!publicpostgres_datetime_typesbpg_catalog.intervalz +c_interval: query.sqlBpostgres_datetime_types‰ +” +INSERT INTO postgres_network_types +( c_cidr, c_inet, - c_macaddr -LIMIT 1GetPostgresTypesCnt:one"I + c_macaddr, + c_macaddr8 +) VALUES ( + $1, + $2, + $3, + $4::macaddr8 +)InsertPostgresNetworkTypes:exec*KG +c_cidr0ÿÿÿÿÿÿÿÿÿ8R publicpostgres_network_typesbcidrzc_cidr*KG +c_inet0ÿÿÿÿÿÿÿÿÿ8R publicpostgres_network_typesbinetzc_inet*TP + c_macaddr0ÿÿÿÿÿÿÿÿÿ8R publicpostgres_network_typesb macaddrz c_macaddr*'# -c_smallint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint2z -c_smallint"G - c_boolean0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogboolz c_boolean"G - c_integer0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint4z c_integer"E -c_bigint0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogint8zc_bigint"C -c_real0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat4zc_real"J - c_numeric0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumericz c_numeric"J - c_decimal0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalognumericz c_decimal"[ -c_double_precision0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogfloat8zc_double_precision"8 -c_money0ÿÿÿÿÿÿÿÿÿRpostgres_typesbmoneyzc_money"5 -c_date0ÿÿÿÿÿÿÿÿÿRpostgres_typesbdatezc_date"A -c_time0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogtimezc_time"P - c_timestamp0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestampz c_timestamp"b -c_timestamp_with_tz0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalog timestamptzzc_timestamp_with_tz"M - -c_interval0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogintervalz -c_interval"C -c_char0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogbpcharzc_char"J - c_varchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarcharz c_varchar"^ -c_character_varying0ÿÿÿÿÿÿÿÿÿRpostgres_typesb -pg_catalogvarcharzc_character_varying"; -c_bpchar0ÿÿÿÿÿÿÿÿÿRpostgres_typesbbpcharzc_bpchar"5 -c_text0ÿÿÿÿÿÿÿÿÿRpostgres_typesbtextzc_text"5 -c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_typesbuuidzc_uuid"5 -c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_typesbcidrzc_cidr"5 -c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_typesbinetzc_inet"> - c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_typesb macaddrz c_macaddr" -cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sql° -†SELECT - MAX(c_integer) AS max_integer, - MAX(c_varchar) AS max_varchar, - MAX(c_timestamp) AS max_timestamp -FROM postgres_typesGetPostgresFunctions:one"( - max_integer0ÿÿÿÿÿÿÿÿÿ@b -anyarray"( - max_varchar0ÿÿÿÿÿÿÿÿÿ@b -anyarray"* - max_timestamp0ÿÿÿÿÿÿÿÿÿ@b -anyarray: query.sqlÿ -ŒINSERT INTO postgres_geometric_types ( - c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle +c_macaddr80ÿÿÿÿÿÿÿÿÿb +macaddr82 Network types : query.sqlBpostgres_network_types‰ +tSELECT + c_cidr, + c_inet, + c_macaddr, + c_macaddr8::TEXT AS c_macaddr8 +FROM postgres_network_types +LIMIT 1GetPostgresNetworkTypes:one"= +c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbcidrzc_cidr"= +c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbinetzc_inet"F + c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesb macaddrz c_macaddr"! + +c_macaddr80ÿÿÿÿÿÿÿÿÿbtext: query.sqlW +%TRUNCATE TABLE postgres_network_typesTruncatePostgresNetworkTypes:exec: query.sqlª +”SELECT + c_cidr, + c_inet, + c_macaddr, + COUNT(*) AS cnt +FROM postgres_network_types +GROUP BY + c_cidr, + c_inet, + c_macaddr +LIMIT 1GetPostgresNetworkTypesCnt:one"= +c_cidr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbcidrzc_cidr"= +c_inet0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesbinetzc_inet"F + c_macaddr0ÿÿÿÿÿÿÿÿÿRpostgres_network_typesb macaddrz c_macaddr" +cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sql +`INSERT INTO postgres_network_types +( + c_cidr, + c_inet, + c_macaddr +) VALUES ($1, $2, $3)InsertPostgresNetworkTypesBatch :copyfrom*IE +c_cidr0ÿÿÿÿÿÿÿÿÿR publicpostgres_network_typesbcidrzc_cidr*IE +c_inet0ÿÿÿÿÿÿÿÿÿR publicpostgres_network_typesbinetzc_inet*RN + c_macaddr0ÿÿÿÿÿÿÿÿÿR publicpostgres_network_typesb macaddrz c_macaddr: query.sqlBpostgres_network_typesÜ +¤ +INSERT INTO postgres_special_types +( + c_json, + c_json_string_override, + c_jsonb, + c_jsonpath, + c_xml, + c_xml_string_override, + c_uuid, + c_enum ) -VALUES ($1, $2, $3, $4, $5, $6, $7)InsertPostgresGeoTypes:exec*NJ -c_point0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpointzc_point*KG -c_line0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblinezc_line*KG -c_lseg0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblsegzc_lseg*HD -c_box0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbboxzc_box*KG -c_path0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpathzc_path*TP - c_polygon0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesb polygonz c_polygon*QM -c_circle0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbcirclezc_circle: query.sqlBpostgres_geometric_typesˆ -ŒINSERT INTO postgres_geometric_types ( - c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle +VALUES ( + $1::json, + $2::json, + $3::jsonb, + $4::jsonpath, + $5::xml, + $6::xml, + $7, + $8::c_enum +)InsertPostgresSpecialTypes:exec* +c_json0ÿÿÿÿÿÿÿÿÿbjson*/+ +c_json_string_override0ÿÿÿÿÿÿÿÿÿbjson*! +c_jsonb0ÿÿÿÿÿÿÿÿÿbjsonb*'# + +c_jsonpath0ÿÿÿÿÿÿÿÿÿb +jsonpath* +c_xml0ÿÿÿÿÿÿÿÿÿbxml*-) +c_xml_string_override0ÿÿÿÿÿÿÿÿÿbxml*KG +c_uuid0ÿÿÿÿÿÿÿÿÿ8R publicpostgres_special_typesbuuidzc_uuid*! +c_enum0ÿÿÿÿÿÿÿÿÿbc_enum2 Special types : query.sqlBpostgres_special_types +­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 1GetPostgresSpecialTypes:one"= +c_json0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjsonzc_json"] +c_json_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjsonzc_json_string_override"@ +c_jsonb0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbjsonbzc_jsonb"I + +c_jsonpath0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesb +jsonpathz +c_jsonpath": +c_xml0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbxmlzc_xml"Z +c_xml_string_override0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbxmlzc_xml_string_override"= +c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbuuidzc_uuid"? +c_enum0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbc_enumzc_enum: query.sqlW +%TRUNCATE TABLE postgres_special_typesTruncatePostgresSpecialTypes:exec: query.sqlá +CINSERT INTO postgres_special_types +( + c_uuid ) -VALUES ($1, $2, $3, $4, $5, $6, $7)InsertPostgresGeoTypesBatch :copyfrom*NJ -c_point0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpointzc_point*KG -c_line0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblinezc_line*KG -c_lseg0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblsegzc_lseg*HD -c_box0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbboxzc_box*KG -c_path0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpathzc_path*TP - c_polygon0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesb polygonz c_polygon*QM -c_circle0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbcirclezc_circle: query.sqlBpostgres_geometric_typesæ -hSELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgres_geometric_types LIMIT 1GetPostgresGeoTypes:one"B -c_point0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpointzc_point"? -c_line0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblinezc_line"? -c_lseg0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblsegzc_lseg"< -c_box0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbboxzc_box"? -c_path0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpathzc_path"H - c_polygon0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesb polygonz c_polygon"E -c_circle0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbcirclezc_circle: query.sqlH -TRUNCATE TABLE postgres_typesTruncatePostgresTypes:exec: query.sqlU -'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sqlÍ -ÎINSERT INTO postgres_array_types +VALUES ( + $1 +)InsertPostgresSpecialTypesBatch :copyfrom*IE +c_uuid0ÿÿÿÿÿÿÿÿÿR publicpostgres_special_typesbuuidzc_uuid: query.sqlBpostgres_special_typesì +^SELECT + c_uuid, + COUNT(*) AS cnt +FROM postgres_special_types +GROUP BY + c_uuid +LIMIT 1GetPostgresSpecialTypesCnt:one"= +c_uuid0ÿÿÿÿÿÿÿÿÿRpostgres_special_typesbuuidzc_uuid" +cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sqlÝ +Ï +INSERT INTO postgres_array_types ( c_bytea, c_boolean_array, @@ -10723,7 +10761,7 @@ VALUES ($1, $2, $3, $4, $5, $6, $7)InsertPostgresArrayTypes:exec*JF c_integer_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.int4zc_integer_arrayˆ*lh c_decimal_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.numericzc_decimal_arrayˆ*XT c_date_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbdatez c_date_arrayˆ*rn -c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.timestampzc_timestamp_arrayˆ: query.sqlBpostgres_array_types¥ +c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.timestampzc_timestamp_arrayˆ2 Array types : query.sqlBpostgres_array_types¥ ’SELECT c_bytea, c_boolean_array, c_text_array, c_integer_array, c_decimal_array, c_date_array, c_timestamp_array FROM postgres_array_types LIMIT 1GetPostgresArrayTypes:one"> c_bytea0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbbyteazc_bytea"^ c_boolean_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb @@ -10735,16 +10773,99 @@ pg_catalogint4zc_integer_array pg_catalognumericzc_decimal_arrayˆ"L c_date_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbdatez c_date_arrayˆ"g c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb -pg_catalog timestampzc_timestamp_arrayˆ: query.sqlÑ -6INSERT INTO postgres_array_types (c_bytea) VALUES ($1)InsertPostgresArrayTypesBatch :copyfrom*JF -c_bytea0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbbyteazc_bytea: query.sqlBpostgres_array_typesë -^SELECT +pg_catalog timestampzc_timestamp_arrayˆ: query.sql +ÓINSERT INTO postgres_array_types ( + c_bytea, + c_boolean_array, + c_text_array, + c_integer_array, + c_decimal_array, + c_timestamp_array +) +VALUES ( + $1, + $2, + $3, + $4, + $5, + $6 +)InsertPostgresArrayTypesBatch :copyfrom*JF +c_bytea0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbbyteazc_bytea*ie +c_boolean_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.boolzc_boolean_arrayˆ*XT + c_text_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbtextz c_text_arrayˆ*ie +c_integer_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.int4zc_integer_arrayˆ*lh +c_decimal_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.numericzc_decimal_arrayˆ*rn +c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpublicpostgres_array_typesbpg_catalog.timestampzc_timestamp_arrayˆ: query.sqlBpostgres_array_types– +®SELECT c_bytea, + c_boolean_array, + c_text_array, + c_integer_array, + c_decimal_array, + c_timestamp_array, COUNT(*) AS cnt FROM postgres_array_types GROUP BY - c_bytea + c_bytea, + c_boolean_array, + c_text_array, + c_integer_array, + c_decimal_array, + c_timestamp_array LIMIT 1GetPostgresArrayTypesCnt:one"> -c_bytea0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbbyteazc_bytea" +c_bytea0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbbyteazc_bytea"^ +c_boolean_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb +pg_catalogboolzc_boolean_arrayˆ"L + c_text_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesbtextz c_text_arrayˆ"^ +c_integer_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb +pg_catalogint4zc_integer_arrayˆ"a +c_decimal_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb +pg_catalognumericzc_decimal_arrayˆ"g +c_timestamp_array 0ÿÿÿÿÿÿÿÿÿRpostgres_array_typesb +pg_catalog timestampzc_timestamp_arrayˆ" cnt0ÿÿÿÿÿÿÿÿÿ@bbigint: query.sqlS -#TRUNCATE TABLE postgres_array_typesTruncatePostgresArrayTypes:exec: query.sql"v1.27.0*ˆ{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"netstandard2.0","namespaceName":"NpgsqlLegacyExampleGen","useDapper":false,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}}],"debugRequest":false} \ No newline at end of file +#TRUNCATE TABLE postgres_array_typesTruncatePostgresArrayTypes:exec: query.sql± +« +INSERT INTO postgres_geometric_types ( + c_point, + c_line, + c_lseg, + c_box, + c_path, + c_polygon, + c_circle +) +VALUES ($1, $2, $3, $4, $5, $6, $7)InsertPostgresGeoTypes:exec*NJ +c_point0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpointzc_point*KG +c_line0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblinezc_line*KG +c_lseg0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblsegzc_lseg*HD +c_box0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbboxzc_box*KG +c_path0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpathzc_path*TP + c_polygon0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesb polygonz c_polygon*QM +c_circle0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbcirclezc_circle2 Geometric types : query.sqlBpostgres_geometric_types¦ +ªINSERT INTO postgres_geometric_types ( + c_point, + c_line, + c_lseg, + c_box, + c_path, + c_polygon, + c_circle +) +VALUES ($1, $2, $3, $4, $5, $6, $7)InsertPostgresGeoTypesBatch :copyfrom*NJ +c_point0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpointzc_point*KG +c_line0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblinezc_line*KG +c_lseg0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesblsegzc_lseg*HD +c_box0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbboxzc_box*KG +c_path0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbpathzc_path*TP + c_polygon0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesb polygonz c_polygon*QM +c_circle0ÿÿÿÿÿÿÿÿÿR"publicpostgres_geometric_typesbcirclezc_circle: query.sqlBpostgres_geometric_typesæ +hSELECT c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle FROM postgres_geometric_types LIMIT 1GetPostgresGeoTypes:one"B +c_point0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpointzc_point"? +c_line0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblinezc_line"? +c_lseg0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesblsegzc_lseg"< +c_box0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbboxzc_box"? +c_path0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbpathzc_path"H + c_polygon0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesb polygonz c_polygon"E +c_circle0ÿÿÿÿÿÿÿÿÿRpostgres_geometric_typesbcirclezc_circle: query.sqlU +'TRUNCATE TABLE postgres_geometric_typesTruncatePostgresGeoTypes:exec: query.sql"v1.27.0*Ý{"overrideDriverVersion":"","generateCsproj":true,"targetFramework":"netstandard2.0","namespaceName":"NpgsqlLegacyExampleGen","useDapper":false,"overrideDapperVersion":"","overrides":[{"column":"GetPostgresFunctions:max_integer","csharp_type":{"type":"int","notNull":false}},{"column":"GetPostgresFunctions:max_varchar","csharp_type":{"type":"string","notNull":false}},{"column":"GetPostgresFunctions:max_timestamp","csharp_type":{"type":"DateTime","notNull":true}},{"column":"*:c_json_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_xml_string_override","csharp_type":{"type":"string","notNull":false}},{"column":"*:c_macaddr8","csharp_type":{"type":"string","notNull":false}}],"debugRequest":false} \ No newline at end of file diff --git a/examples/SqliteDapperExample/QuerySql.cs b/examples/SqliteDapperExample/QuerySql.cs index 62b430ee..bcaeb84b 100644 --- a/examples/SqliteDapperExample/QuerySql.cs +++ b/examples/SqliteDapperExample/QuerySql.cs @@ -37,7 +37,7 @@ 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; } @@ -62,14 +62,11 @@ public class GetAuthorArgs } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -116,18 +113,12 @@ public async Task CreateAuthor(CreateAuthorArgs args) if (this.Transaction == null) { using (var connection = new SqliteConnection(ConnectionString)) - { await connection.ExecuteAsync(CreateAuthorSql, queryParams); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); await this.Transaction.Connection.ExecuteAsync(CreateAuthorSql, queryParams, transaction: this.Transaction); } @@ -149,20 +140,15 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) if (this.Transaction == null) { using (var connection = new SqliteConnection(ConnectionString)) - { return await connection.QuerySingleAsync(CreateAuthorReturnIdSql, queryParams); - } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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 int Id { get; init; } @@ -187,10 +173,7 @@ public class GetAuthorByIdArgs } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetAuthorByIdSql, queryParams, transaction: this.Transaction); } @@ -221,14 +204,11 @@ public class GetAuthorByIdWithMultipleNamedParamArgs } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -257,7 +237,7 @@ 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; } @@ -269,16 +249,11 @@ public async Task UpdateAuthors(UpdateAuthorsArgs args) if (this.Transaction == null) { using (var connection = new SqliteConnection(ConnectionString)) - { return await connection.ExecuteAsync(UpdateAuthorsSql, queryParams); - } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); return await this.Transaction.Connection.ExecuteAsync(UpdateAuthorsSql, queryParams, transaction: this.Transaction); } @@ -350,7 +325,7 @@ 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; } @@ -362,18 +337,12 @@ public async Task DeleteAuthor(DeleteAuthorArgs args) if (this.Transaction == null) { using (var connection = new SqliteConnection(ConnectionString)) - { await connection.ExecuteAsync(DeleteAuthorSql, queryParams); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); await this.Transaction.Connection.ExecuteAsync(DeleteAuthorSql, queryParams, transaction: this.Transaction); } @@ -395,20 +364,15 @@ public async Task CreateBook(CreateBookArgs args) if (this.Transaction == null) { using (var connection = new SqliteConnection(ConnectionString)) - { return await connection.QuerySingleAsync(CreateBookSql, queryParams); - } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -450,7 +414,7 @@ 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; } @@ -492,7 +456,7 @@ 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; } @@ -548,22 +512,16 @@ public async Task DeleteAllAuthors() if (this.Transaction == null) { using (var connection = new SqliteConnection(ConnectionString)) - { await connection.ExecuteAsync(DeleteAllAuthorsSql); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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) VALUES ( @c_integer , @c_real, @c_text, @c_blob ) "; + private const string InsertSqliteTypesSql = "INSERT INTO types_sqlite (c_integer, c_real, c_text, c_blob) VALUES (@c_integer, @c_real, @c_text, @c_blob)"; public class InsertSqliteTypesArgs { public int? CInteger { get; init; } @@ -581,18 +539,12 @@ public async Task InsertSqliteTypes(InsertSqliteTypesArgs args) if (this.Transaction == null) { using (var connection = new SqliteConnection(ConnectionString)) - { await connection.ExecuteAsync(InsertSqliteTypesSql, queryParams); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); await this.Transaction.Connection.ExecuteAsync(InsertSqliteTypesSql, queryParams, transaction: this.Transaction); } @@ -643,14 +595,11 @@ public class GetSqliteTypesRow } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -671,14 +620,11 @@ public class GetSqliteTypesCntRow } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -697,10 +643,7 @@ public class GetSqliteFunctionsRow } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetSqliteFunctionsSql, transaction: this.Transaction); } @@ -710,18 +653,12 @@ public async Task DeleteAllSqliteTypes() if (this.Transaction == null) { using (var connection = new SqliteConnection(ConnectionString)) - { await connection.ExecuteAsync(DeleteAllSqliteTypesSql); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); await this.Transaction.Connection.ExecuteAsync(DeleteAllSqliteTypesSql, transaction: this.Transaction); } } \ No newline at end of file diff --git a/examples/SqliteDapperExample/request.json b/examples/SqliteDapperExample/request.json index 89eef44a..26e13959 100644 --- a/examples/SqliteDapperExample/request.json +++ b/examples/SqliteDapperExample/request.json @@ -3,10 +3,12 @@ "version": "2", "engine": "sqlite", "schema": [ - "examples/config/sqlite/schema.sql" + "examples/config/sqlite/authors/schema.sql", + "examples/config/sqlite/types/schema.sql" ], "queries": [ - "examples/config/sqlite/query.sql" + "examples/config/sqlite/authors/query.sql", + "examples/config/sqlite/types/query.sql" ], "codegen": { "out": "examples/SqliteDapperExample", @@ -966,7 +968,7 @@ "filename": "query.sql" }, { - "text": "INSERT INTO types_sqlite (c_integer, c_real, c_text, c_blob) VALUES (\n ?, ?, ?, ?\n)", + "text": "INSERT INTO types_sqlite \n(c_integer, c_real, c_text, c_blob) \nVALUES (?, ?, ?, ?)", "name": "InsertSqliteTypes", "cmd": ":exec", "parameters": [ diff --git a/examples/SqliteDapperExample/request.message b/examples/SqliteDapperExample/request.message index b774d0fe..199d63ac 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 b28123ce..9a3db218 100644 --- a/examples/SqliteDapperLegacyExample/QuerySql.cs +++ b/examples/SqliteDapperLegacyExample/QuerySql.cs @@ -38,7 +38,7 @@ 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; } @@ -63,14 +63,11 @@ public async Task GetAuthor(GetAuthorArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -117,18 +114,12 @@ public async Task CreateAuthor(CreateAuthorArgs args) if (this.Transaction == null) { using (var connection = new SqliteConnection(ConnectionString)) - { await connection.ExecuteAsync(CreateAuthorSql, queryParams); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); await this.Transaction.Connection.ExecuteAsync(CreateAuthorSql, queryParams, transaction: this.Transaction); } @@ -150,20 +141,15 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) if (this.Transaction == null) { using (var connection = new SqliteConnection(ConnectionString)) - { return await connection.QuerySingleAsync(CreateAuthorReturnIdSql, queryParams); - } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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 int Id { get; set; } @@ -188,10 +174,7 @@ public async Task GetAuthorById(GetAuthorByIdArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetAuthorByIdSql, queryParams, transaction: this.Transaction); } @@ -222,14 +205,11 @@ public async Task GetAuthorByIdWithMulti } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -258,7 +238,7 @@ 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; } @@ -270,16 +250,11 @@ public async Task UpdateAuthors(UpdateAuthorsArgs args) if (this.Transaction == null) { using (var connection = new SqliteConnection(ConnectionString)) - { return await connection.ExecuteAsync(UpdateAuthorsSql, queryParams); - } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); return await this.Transaction.Connection.ExecuteAsync(UpdateAuthorsSql, queryParams, transaction: this.Transaction); } @@ -351,7 +326,7 @@ 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; } @@ -363,18 +338,12 @@ public async Task DeleteAuthor(DeleteAuthorArgs args) if (this.Transaction == null) { using (var connection = new SqliteConnection(ConnectionString)) - { await connection.ExecuteAsync(DeleteAuthorSql, queryParams); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); await this.Transaction.Connection.ExecuteAsync(DeleteAuthorSql, queryParams, transaction: this.Transaction); } @@ -396,20 +365,15 @@ public async Task CreateBook(CreateBookArgs args) if (this.Transaction == null) { using (var connection = new SqliteConnection(ConnectionString)) - { return await connection.QuerySingleAsync(CreateBookSql, queryParams); - } } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -451,7 +415,7 @@ 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; } @@ -493,7 +457,7 @@ 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; } @@ -549,22 +513,16 @@ public async Task DeleteAllAuthors() if (this.Transaction == null) { using (var connection = new SqliteConnection(ConnectionString)) - { await connection.ExecuteAsync(DeleteAllAuthorsSql); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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) VALUES ( @c_integer , @c_real, @c_text, @c_blob ) "; + private const string InsertSqliteTypesSql = "INSERT INTO types_sqlite (c_integer, c_real, c_text, c_blob) VALUES (@c_integer, @c_real, @c_text, @c_blob)"; public class InsertSqliteTypesArgs { public int? CInteger { get; set; } @@ -582,18 +540,12 @@ public async Task InsertSqliteTypes(InsertSqliteTypesArgs args) if (this.Transaction == null) { using (var connection = new SqliteConnection(ConnectionString)) - { await connection.ExecuteAsync(InsertSqliteTypesSql, queryParams); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); await this.Transaction.Connection.ExecuteAsync(InsertSqliteTypesSql, queryParams, transaction: this.Transaction); } @@ -644,14 +596,11 @@ public async Task GetSqliteTypes() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -672,14 +621,11 @@ public async Task GetSqliteTypesCnt() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); 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; } @@ -698,10 +644,7 @@ public async Task GetSqliteFunctions() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); return await this.Transaction.Connection.QueryFirstOrDefaultAsync(GetSqliteFunctionsSql, transaction: this.Transaction); } @@ -711,18 +654,12 @@ public async Task DeleteAllSqliteTypes() if (this.Transaction == null) { using (var connection = new SqliteConnection(ConnectionString)) - { await connection.ExecuteAsync(DeleteAllSqliteTypesSql); - } - return; } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); await this.Transaction.Connection.ExecuteAsync(DeleteAllSqliteTypesSql, transaction: this.Transaction); } } diff --git a/examples/SqliteDapperLegacyExample/request.json b/examples/SqliteDapperLegacyExample/request.json index d7a8b08b..249c7805 100644 --- a/examples/SqliteDapperLegacyExample/request.json +++ b/examples/SqliteDapperLegacyExample/request.json @@ -3,10 +3,12 @@ "version": "2", "engine": "sqlite", "schema": [ - "examples/config/sqlite/schema.sql" + "examples/config/sqlite/authors/schema.sql", + "examples/config/sqlite/types/schema.sql" ], "queries": [ - "examples/config/sqlite/query.sql" + "examples/config/sqlite/authors/query.sql", + "examples/config/sqlite/types/query.sql" ], "codegen": { "out": "examples/SqliteDapperLegacyExample", @@ -966,7 +968,7 @@ "filename": "query.sql" }, { - "text": "INSERT INTO types_sqlite (c_integer, c_real, c_text, c_blob) VALUES (\n ?, ?, ?, ?\n)", + "text": "INSERT INTO types_sqlite \n(c_integer, c_real, c_text, c_blob) \nVALUES (?, ?, ?, ?)", "name": "InsertSqliteTypes", "cmd": ":exec", "parameters": [ diff --git a/examples/SqliteDapperLegacyExample/request.message b/examples/SqliteDapperLegacyExample/request.message index 8b455052..1cbcf38d 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 f4506830..9a9d7ce2 100644 --- a/examples/SqliteExample/QuerySql.cs +++ b/examples/SqliteExample/QuerySql.cs @@ -34,7 +34,7 @@ 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) @@ -66,10 +66,7 @@ public static QuerySql WithTransaction(SqliteTransaction transaction) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetAuthorSql; @@ -92,7 +89,7 @@ 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) @@ -157,10 +154,7 @@ public async Task CreateAuthor(CreateAuthorArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = CreateAuthorSql; @@ -193,10 +187,7 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = CreateAuthorReturnIdSql; @@ -208,7 +199,7 @@ 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(int Id, string Name, string? Bio); public readonly record struct GetAuthorByIdArgs(int Id); public async Task GetAuthorById(GetAuthorByIdArgs args) @@ -240,10 +231,7 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetAuthorByIdSql; @@ -299,10 +287,7 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetAuthorByIdWithMultipleNamedParamSql; @@ -326,7 +311,7 @@ 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) @@ -367,7 +352,7 @@ 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) { @@ -385,10 +370,7 @@ public async Task UpdateAuthors(UpdateAuthorsArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = UpdateAuthorsSql; @@ -493,7 +475,7 @@ 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) { @@ -513,10 +495,7 @@ public async Task DeleteAuthor(DeleteAuthorArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = DeleteAuthorSql; @@ -547,10 +526,7 @@ public async Task CreateBook(CreateBookArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = CreateBookSql; @@ -562,7 +538,7 @@ 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() { @@ -600,7 +576,7 @@ 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() { @@ -638,7 +614,7 @@ 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) @@ -697,10 +673,7 @@ public async Task DeleteAllAuthors() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = DeleteAllAuthorsSql; @@ -709,7 +682,7 @@ public async Task DeleteAllAuthors() } } - private const string InsertSqliteTypesSql = "INSERT INTO types_sqlite (c_integer, c_real, c_text, c_blob) VALUES ( @c_integer , @c_real, @c_text, @c_blob ) "; + private const string InsertSqliteTypesSql = "INSERT INTO types_sqlite (c_integer, c_real, c_text, c_blob) VALUES (@c_integer, @c_real, @c_text, @c_blob)"; public readonly record struct InsertSqliteTypesArgs(int? CInteger, decimal? CReal, string? CText, byte[]? CBlob); public async Task InsertSqliteTypes(InsertSqliteTypesArgs args) { @@ -732,10 +705,7 @@ public async Task InsertSqliteTypes(InsertSqliteTypesArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = InsertSqliteTypesSql; @@ -801,10 +771,7 @@ public async Task InsertSqliteTypesBatch(List args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetSqliteTypesSql; @@ -827,7 +794,7 @@ 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() { @@ -859,10 +826,7 @@ public async Task InsertSqliteTypesBatch(List args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetSqliteTypesCntSql; @@ -886,7 +850,7 @@ 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() { @@ -916,10 +880,7 @@ public async Task InsertSqliteTypesBatch(List args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetSqliteFunctionsSql; @@ -959,10 +920,7 @@ public async Task DeleteAllSqliteTypes() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = DeleteAllSqliteTypesSql; diff --git a/examples/SqliteExample/request.json b/examples/SqliteExample/request.json index 14a1c32d..6c5ae56a 100644 --- a/examples/SqliteExample/request.json +++ b/examples/SqliteExample/request.json @@ -3,10 +3,12 @@ "version": "2", "engine": "sqlite", "schema": [ - "examples/config/sqlite/schema.sql" + "examples/config/sqlite/authors/schema.sql", + "examples/config/sqlite/types/schema.sql" ], "queries": [ - "examples/config/sqlite/query.sql" + "examples/config/sqlite/authors/query.sql", + "examples/config/sqlite/types/query.sql" ], "codegen": { "out": "examples/SqliteExample", @@ -966,7 +968,7 @@ "filename": "query.sql" }, { - "text": "INSERT INTO types_sqlite (c_integer, c_real, c_text, c_blob) VALUES (\n ?, ?, ?, ?\n)", + "text": "INSERT INTO types_sqlite \n(c_integer, c_real, c_text, c_blob) \nVALUES (?, ?, ?, ?)", "name": "InsertSqliteTypes", "cmd": ":exec", "parameters": [ diff --git a/examples/SqliteExample/request.message b/examples/SqliteExample/request.message index 84b7f159..f923db5f 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 999fc912..2892f905 100644 --- a/examples/SqliteLegacyExample/QuerySql.cs +++ b/examples/SqliteLegacyExample/QuerySql.cs @@ -35,7 +35,7 @@ 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; } @@ -75,10 +75,7 @@ public async Task GetAuthor(GetAuthorArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetAuthorSql; @@ -101,7 +98,7 @@ 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; } @@ -180,10 +177,7 @@ public async Task CreateAuthor(CreateAuthorArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = CreateAuthorSql; @@ -223,10 +217,7 @@ public async Task CreateAuthorReturnId(CreateAuthorReturnIdArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = CreateAuthorReturnIdSql; @@ -238,7 +229,7 @@ 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 int Id { get; set; } @@ -278,10 +269,7 @@ public async Task GetAuthorById(GetAuthorByIdArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetAuthorByIdSql; @@ -346,10 +334,7 @@ public async Task GetAuthorByIdWithMulti } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetAuthorByIdWithMultipleNamedParamSql; @@ -373,7 +358,7 @@ 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; } @@ -422,7 +407,7 @@ 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; } @@ -443,10 +428,7 @@ public async Task UpdateAuthors(UpdateAuthorsArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = UpdateAuthorsSql; @@ -568,7 +550,7 @@ 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; } @@ -591,10 +573,7 @@ public async Task DeleteAuthor(DeleteAuthorArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = DeleteAuthorSql; @@ -632,10 +611,7 @@ public async Task CreateBook(CreateBookArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = CreateBookSql; @@ -647,7 +623,7 @@ 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; } @@ -689,7 +665,7 @@ 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; } @@ -731,7 +707,7 @@ 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; } @@ -799,10 +775,7 @@ public async Task DeleteAllAuthors() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = DeleteAllAuthorsSql; @@ -811,7 +784,7 @@ public async Task DeleteAllAuthors() } } - private const string InsertSqliteTypesSql = "INSERT INTO types_sqlite (c_integer, c_real, c_text, c_blob) VALUES ( @c_integer , @c_real, @c_text, @c_blob ) "; + private const string InsertSqliteTypesSql = "INSERT INTO types_sqlite (c_integer, c_real, c_text, c_blob) VALUES (@c_integer, @c_real, @c_text, @c_blob)"; public class InsertSqliteTypesArgs { public int? CInteger { get; set; } @@ -840,10 +813,7 @@ public async Task InsertSqliteTypes(InsertSqliteTypesArgs args) } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = InsertSqliteTypesSql; @@ -920,10 +890,7 @@ public async Task GetSqliteTypes() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetSqliteTypesSql; @@ -946,7 +913,7 @@ 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; } @@ -985,10 +952,7 @@ public async Task GetSqliteTypesCnt() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetSqliteTypesCntSql; @@ -1012,7 +976,7 @@ 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; } @@ -1047,10 +1011,7 @@ public async Task GetSqliteFunctions() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = GetSqliteFunctionsSql; @@ -1090,10 +1051,7 @@ public async Task DeleteAllSqliteTypes() } if (this.Transaction?.Connection == null || this.Transaction?.Connection.State != System.Data.ConnectionState.Open) - { - throw new System.InvalidOperationException("Transaction is provided, but its connection is null."); - } - + throw new InvalidOperationException("Transaction is provided, but its connection is null."); using (var command = this.Transaction.Connection.CreateCommand()) { command.CommandText = DeleteAllSqliteTypesSql; diff --git a/examples/SqliteLegacyExample/request.json b/examples/SqliteLegacyExample/request.json index b2a9fb66..0bdcc6fe 100644 --- a/examples/SqliteLegacyExample/request.json +++ b/examples/SqliteLegacyExample/request.json @@ -3,10 +3,12 @@ "version": "2", "engine": "sqlite", "schema": [ - "examples/config/sqlite/schema.sql" + "examples/config/sqlite/authors/schema.sql", + "examples/config/sqlite/types/schema.sql" ], "queries": [ - "examples/config/sqlite/query.sql" + "examples/config/sqlite/authors/query.sql", + "examples/config/sqlite/types/query.sql" ], "codegen": { "out": "examples/SqliteLegacyExample", @@ -966,7 +968,7 @@ "filename": "query.sql" }, { - "text": "INSERT INTO types_sqlite (c_integer, c_real, c_text, c_blob) VALUES (\n ?, ?, ?, ?\n)", + "text": "INSERT INTO types_sqlite \n(c_integer, c_real, c_text, c_blob) \nVALUES (?, ?, ?, ?)", "name": "InsertSqliteTypes", "cmd": ":exec", "parameters": [ diff --git a/examples/SqliteLegacyExample/request.message b/examples/SqliteLegacyExample/request.message index d6570860..c8070b76 100644 Binary files a/examples/SqliteLegacyExample/request.message and b/examples/SqliteLegacyExample/request.message differ diff --git a/examples/config/mysql/Dockerfile b/examples/config/mysql/Dockerfile index a74abf31..672ba41d 100644 --- a/examples/config/mysql/Dockerfile +++ b/examples/config/mysql/Dockerfile @@ -1,2 +1,6 @@ FROM mysql:8.3.0 -COPY schema.sql /docker-entrypoint-initdb.d \ No newline at end of file + +COPY types/schema.sql types_schema.sql +COPY authors/schema.sql authors_schema.sql + +RUN (cat types_schema.sql && echo && cat authors_schema.sql) > /docker-entrypoint-initdb.d/schema.sql diff --git a/examples/config/mysql/authors/query.sql b/examples/config/mysql/authors/query.sql new file mode 100644 index 00000000..eb16646b --- /dev/null +++ b/examples/config/mysql/authors/query.sql @@ -0,0 +1,66 @@ +-- name: GetAuthor :one +SELECT * FROM authors WHERE name = ? LIMIT 1; + +-- name: ListAuthors :many +SELECT * +FROM authors +ORDER BY name +LIMIT ? OFFSET ?; + +-- name: CreateAuthor :exec +INSERT INTO authors (id, name, bio) VALUES (?, ?, ?); + +-- name: CreateAuthorReturnId :execlastid +INSERT INTO authors (name, bio) VALUES (?, ?); + +-- name: GetAuthorById :one +SELECT * FROM authors WHERE id = ? LIMIT 1; + +-- name: GetAuthorByNamePattern :many +SELECT * FROM authors +WHERE name LIKE COALESCE(sqlc.narg('name_pattern'), '%'); + +-- name: DeleteAuthor :exec +DELETE FROM authors +WHERE name = ?; + +-- name: DeleteAllAuthors :exec +DELETE FROM authors; + +-- name: UpdateAuthors :execrows +UPDATE authors +SET bio = sqlc.arg('bio') +WHERE bio IS NOT NULL; + +-- name: GetAuthorsByIds :many +SELECT * FROM authors WHERE id IN (sqlc.slice('ids')); + +-- name: GetAuthorsByIdsAndNames :many +SELECT * FROM authors WHERE id IN (sqlc.slice('ids')) AND name IN (sqlc.slice('names')); + +-- name: CreateBook :execlastid +INSERT INTO books (name, author_id) VALUES (?, ?); + +-- name: ListAllAuthorsBooks :many +SELECT sqlc.embed(authors), sqlc.embed(books) +FROM authors JOIN books ON authors.id = books.author_id +ORDER BY authors.name; + +-- name: GetDuplicateAuthors :many +SELECT sqlc.embed(authors1), sqlc.embed(authors2) +FROM authors authors1 JOIN authors authors2 ON authors1.name = authors2.name +WHERE authors1.id < authors2.id; + +-- name: GetAuthorsByBookName :many +SELECT authors.*, sqlc.embed(books) +FROM authors JOIN books ON authors.id = books.author_id +WHERE books.name = ?; + +-- name: CreateExtendedBio :exec +INSERT INTO extended.bios (author_name, name, bio_type, author_type) VALUES (?, ?, ?, ?); + +-- name: GetFirstExtendedBioByType :one +SELECT * FROM extended.bios WHERE bio_type = ? LIMIT 1; + +-- name: TruncateExtendedBios :exec +TRUNCATE TABLE extended.bios; \ No newline at end of file diff --git a/examples/config/mysql/authors/schema.sql b/examples/config/mysql/authors/schema.sql new file mode 100644 index 00000000..290a188a --- /dev/null +++ b/examples/config/mysql/authors/schema.sql @@ -0,0 +1,23 @@ +CREATE TABLE authors ( + id BIGINT PRIMARY KEY AUTO_INCREMENT, + name TEXT NOT NULL, + bio TEXT +); + +CREATE TABLE books ( + id BIGINT PRIMARY KEY AUTO_INCREMENT, + name TEXT NOT NULL, + author_id BIGINT NOT NULL, + description TEXT, + FOREIGN KEY (author_id) REFERENCES authors (id) ON DELETE CASCADE +); + +CREATE SCHEMA extended; + +CREATE TABLE extended.bios ( + author_name VARCHAR(100), + name VARCHAR(100), + bio_type ENUM('Autobiography', 'Biography', 'Memoir'), + author_type SET('Author', 'Editor', 'Translator'), + PRIMARY KEY (author_name, name) +); diff --git a/examples/config/mysql/query.sql b/examples/config/mysql/query.sql deleted file mode 100644 index 570f4a33..00000000 --- a/examples/config/mysql/query.sql +++ /dev/null @@ -1,108 +0,0 @@ --- name: GetAuthor :one -SELECT * FROM authors WHERE name = ? LIMIT 1; - --- name: ListAuthors :many -SELECT * -FROM authors -ORDER BY name -LIMIT ? OFFSET ?; - --- name: CreateAuthor :exec -INSERT INTO authors (id, name, bio) VALUES (?, ?, ?); - --- name: CreateAuthorReturnId :execlastid -INSERT INTO authors (name, bio) VALUES (?, ?); - --- name: GetAuthorById :one -SELECT * FROM authors WHERE id = ? LIMIT 1; - --- name: GetAuthorByNamePattern :many -SELECT * FROM authors -WHERE name LIKE COALESCE(sqlc.narg('name_pattern'), '%'); - --- name: DeleteAuthor :exec -DELETE FROM authors -WHERE name = ?; - --- name: DeleteAllAuthors :exec -DELETE FROM authors; - --- name: UpdateAuthors :execrows -UPDATE authors -SET bio = sqlc.arg('bio') -WHERE bio IS NOT NULL; - --- name: GetAuthorsByIds :many -SELECT * FROM authors WHERE id IN (sqlc.slice('ids')); - --- name: GetAuthorsByIdsAndNames :many -SELECT * FROM authors WHERE id IN (sqlc.slice('ids')) AND name IN (sqlc.slice('names')); - --- name: CreateBook :execlastid -INSERT INTO books (name, author_id) VALUES (?, ?); - --- name: ListAllAuthorsBooks :many -SELECT sqlc.embed(authors), sqlc.embed(books) -FROM authors JOIN books ON authors.id = books.author_id -ORDER BY authors.name; - --- name: GetDuplicateAuthors :many -SELECT sqlc.embed(authors1), sqlc.embed(authors2) -FROM authors authors1 JOIN authors authors2 ON authors1.name = authors2.name -WHERE authors1.id < authors2.id; - --- name: GetAuthorsByBookName :many -SELECT authors.*, sqlc.embed(books) -FROM authors JOIN books ON authors.id = books.author_id -WHERE books.name = ?; - --- name: InsertMysqlTypes :exec -INSERT INTO mysql_types -(c_bit, 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, - 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, c_year, c_date, c_datetime, c_timestamp, - c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob) -VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); - --- name: InsertMysqlTypesBatch :copyfrom -INSERT INTO mysql_types -(c_bit, 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, - 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, c_year, c_date, c_datetime, c_timestamp, - c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob) -VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); - --- name: GetMysqlTypes :one -SELECT * FROM mysql_types LIMIT 1; - --- name: GetMysqlTypesCnt :one -SELECT COUNT(1) AS cnt, c_bool, c_boolean, c_bit, 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, - 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, c_year, c_date, c_datetime, c_timestamp, - c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob -FROM mysql_types -GROUP BY c_bool, c_boolean, c_bit, 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, - 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, c_year, c_date, c_datetime, c_timestamp, - c_binary, c_varbinary, c_tinyblob, c_blob, c_mediumblob, c_longblob -LIMIT 1; - --- name: GetMysqlFunctions :one -SELECT MAX(c_int) AS max_int, MAX(c_varchar) AS max_varchar, MAX(c_timestamp) AS max_timestamp -FROM mysql_types; - --- name: TruncateMysqlTypes :exec -TRUNCATE TABLE mysql_types; - --- name: CreateExtendedBio :exec -INSERT INTO extended.bios (author_name, name, bio_type, author_type) VALUES (?, ?, ?, ?); - --- name: GetFirstExtendedBioByType :one -SELECT * FROM extended.bios WHERE bio_type = ? LIMIT 1; - --- name: TruncateExtendedBios :exec -TRUNCATE TABLE extended.bios; \ No newline at end of file diff --git a/examples/config/mysql/schema.sql b/examples/config/mysql/schema.sql deleted file mode 100644 index 9094a7d8..00000000 --- a/examples/config/mysql/schema.sql +++ /dev/null @@ -1,78 +0,0 @@ -CREATE TABLE authors ( - id BIGINT PRIMARY KEY AUTO_INCREMENT, - name TEXT NOT NULL, - bio TEXT -); - -CREATE TABLE books ( - id BIGINT PRIMARY KEY AUTO_INCREMENT, - name TEXT NOT NULL, - author_id BIGINT NOT NULL, - description TEXT, - FOREIGN KEY (author_id) REFERENCES authors (id) ON DELETE CASCADE -); - -CREATE TABLE mysql_types ( - /* Boolean data types - TINYINT(1) synonyms */ - c_bool BOOL, - c_boolean BOOLEAN, - - /* Integer data types */ - c_tinyint TINYINT(3), - c_smallint SMALLINT, - c_mediumint MEDIUMINT, - c_int INT, - c_integer INTEGER, - c_bigint BIGINT, - - /* Float data types */ - c_float FLOAT, - c_decimal DECIMAL(10,7), - c_dec DEC(10,7), - c_numeric NUMERIC(10,7), - c_fixed FIXED(10,7), - c_double DOUBLE, - c_double_precision DOUBLE PRECISION, - - /* Datetime data types */ - c_year YEAR, - c_date DATE, - c_time TIME, - c_datetime DATETIME, - c_timestamp TIMESTAMP, - - /* String data types */ - c_char CHAR, - c_nchar NCHAR, - c_national_char NATIONAL CHAR, - c_varchar VARCHAR(100), - c_tinytext TINYTEXT, - c_mediumtext MEDIUMTEXT, - c_text TEXT, - c_longtext LONGTEXT, - c_json JSON, - c_json_string_override JSON, - - /* Pre-defined types */ - c_enum ENUM ('small', 'medium', 'big'), - c_set SET ('tea', 'coffee', 'milk'), - - /* Binary data types */ - c_bit BIT(8), - c_binary BINARY(3), - c_varbinary VARBINARY(10), - c_tinyblob TINYBLOB, - c_blob BLOB, - c_mediumblob MEDIUMBLOB, - c_longblob LONGBLOB -); - -CREATE SCHEMA extended; - -CREATE TABLE extended.bios ( - author_name VARCHAR(100), - name VARCHAR(100), - bio_type ENUM ('Autobiography', 'Biography', 'Memoir'), - author_type SET ('Author', 'Editor', 'Translator'), - PRIMARY KEY (author_name, name) -); diff --git a/examples/config/mysql/types/query.sql b/examples/config/mysql/types/query.sql new file mode 100644 index 00000000..de837a17 --- /dev/null +++ b/examples/config/mysql/types/query.sql @@ -0,0 +1,274 @@ +/* Numeric types */ + +-- name: InsertMysqlNumericTypes :exec +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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); + +-- name: InsertMysqlNumericTypesBatch :copyfrom +INSERT INTO mysql_numeric_types +( + 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 +) +VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); + +-- name: GetMysqlNumericTypes :one +SELECT * FROM mysql_numeric_types LIMIT 1; + +-- name: GetMysqlNumericTypesCnt :one +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; + +-- name: TruncateMysqlNumericTypes :exec +TRUNCATE TABLE mysql_numeric_types; + +/* String types */ + +-- name: InsertMysqlStringTypes :exec +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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); + +-- name: InsertMysqlStringTypesBatch :copyfrom +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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); + +-- name: GetMysqlStringTypes :one +SELECT * FROM mysql_string_types LIMIT 1; + +-- name: GetMysqlStringTypesCnt :one +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; + +-- name: TruncateMysqlStringTypes :exec +TRUNCATE TABLE mysql_string_types; + +/* Datetime types */ + +-- name: InsertMysqlDatetimeTypes :exec +INSERT INTO mysql_datetime_types +( + c_year, + c_date, + c_datetime, + c_timestamp, + c_time +) +VALUES (?, ?, ?, ?, ?); + +-- name: InsertMysqlDatetimeTypesBatch :copyfrom +INSERT INTO mysql_datetime_types +( + c_year, + c_date, + c_datetime, + c_timestamp, + c_time +) +VALUES (?, ?, ?, ?, ?); + +-- name: GetMysqlDatetimeTypes :one +SELECT * FROM mysql_datetime_types LIMIT 1; + +-- name: GetMysqlDatetimeTypesCnt :one +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; + +-- name: TruncateMysqlDatetimeTypes :exec +TRUNCATE TABLE mysql_datetime_types; + +/* Binary types */ + +-- name: InsertMysqlBinaryTypes :exec +INSERT INTO mysql_binary_types +( + c_bit, + c_binary, + c_varbinary, + c_tinyblob, + c_blob, + c_mediumblob, + c_longblob +) +VALUES (?, ?, ?, ?, ?, ?, ?); + +-- name: InsertMysqlBinaryTypesBatch :copyfrom +INSERT INTO mysql_binary_types +( + c_bit, + c_binary, + c_varbinary, + c_tinyblob, + c_blob, + c_mediumblob, + c_longblob +) +VALUES (?, ?, ?, ?, ?, ?, ?); + +-- name: GetMysqlBinaryTypes :one +SELECT * FROM mysql_binary_types LIMIT 1; + +-- name: GetMysqlBinaryTypesCnt :one +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; + +-- name: TruncateMysqlBinaryTypes :exec +TRUNCATE TABLE mysql_binary_types; + +/* Functions */ + +-- name: GetMysqlFunctions :one +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; diff --git a/examples/config/mysql/types/schema.sql b/examples/config/mysql/types/schema.sql new file mode 100644 index 00000000..e5755cf5 --- /dev/null +++ b/examples/config/mysql/types/schema.sql @@ -0,0 +1,50 @@ +CREATE TABLE mysql_numeric_types ( + c_bool BOOL, + c_boolean BOOLEAN, + c_tinyint TINYINT(3), + c_smallint SMALLINT, + c_mediumint MEDIUMINT, + c_int INT, + c_integer INTEGER, + c_bigint BIGINT, + c_float FLOAT, + c_decimal DECIMAL(10, 7), + c_dec DEC(10, 7), + c_numeric NUMERIC(10, 7), + c_fixed FIXED(10, 7), + c_double DOUBLE, + c_double_precision DOUBLE PRECISION +); + +CREATE TABLE mysql_string_types ( + c_char CHAR, + c_nchar NCHAR, + c_national_char NATIONAL CHAR, + c_varchar VARCHAR(100), + c_tinytext TINYTEXT, + c_mediumtext MEDIUMTEXT, + c_text TEXT, + c_longtext LONGTEXT, + c_json JSON, + c_json_string_override JSON, + c_enum ENUM ('small', 'medium', 'big'), + c_set SET ('tea', 'coffee', 'milk') +); + +CREATE TABLE mysql_datetime_types ( + c_year YEAR, + c_date DATE, + c_datetime DATETIME, + c_timestamp TIMESTAMP, + c_time TIME +); + +CREATE TABLE mysql_binary_types ( + c_bit BIT(8), + c_binary BINARY(3), + c_varbinary VARBINARY(10), + c_tinyblob TINYBLOB, + c_blob BLOB, + c_mediumblob MEDIUMBLOB, + c_longblob LONGBLOB +); \ No newline at end of file diff --git a/examples/config/postgresql/Dockerfile b/examples/config/postgresql/Dockerfile index b9546fbc..75eab979 100644 --- a/examples/config/postgresql/Dockerfile +++ b/examples/config/postgresql/Dockerfile @@ -1,2 +1,6 @@ FROM postgres:16.2 -COPY schema.sql /docker-entrypoint-initdb.d \ No newline at end of file + +COPY types/schema.sql types_schema.sql +COPY authors/schema.sql authors_schema.sql + +RUN (cat types_schema.sql && echo && cat authors_schema.sql) > /docker-entrypoint-initdb.d/schema.sql diff --git a/examples/config/postgresql/authors/query.sql b/examples/config/postgresql/authors/query.sql new file mode 100644 index 00000000..8fddebde --- /dev/null +++ b/examples/config/postgresql/authors/query.sql @@ -0,0 +1,80 @@ +-- name: GetAuthor :one +SELECT * FROM authors +WHERE name = $1 LIMIT 1; + +-- name: ListAuthors :many +SELECT * +FROM authors +ORDER BY name +LIMIT sqlc.arg('limit') +OFFSET sqlc.arg('offset'); + +-- name: CreateAuthor :one +INSERT INTO authors (id, name, bio) VALUES ($1, $2, $3) RETURNING *; + +-- name: CreateAuthorReturnId :execlastid +INSERT INTO authors (name, bio) VALUES ($1, $2) RETURNING id; + +-- name: GetAuthorById :one +SELECT * FROM authors +WHERE id = $1 LIMIT 1; + +-- name: GetAuthorByNamePattern :many +SELECT * FROM authors +WHERE name LIKE COALESCE(sqlc.narg('name_pattern'), '%'); + +-- name: DeleteAuthor :exec +DELETE FROM authors +WHERE name = $1; + +-- name: TruncateAuthors :exec +TRUNCATE TABLE authors CASCADE; + +-- name: UpdateAuthors :execrows +UPDATE authors +SET bio = $1 +WHERE bio IS NOT NULL; + +-- name: GetAuthorsByIds :many +SELECT * FROM authors +WHERE id = ANY($1::BIGINT []); + +-- name: GetAuthorsByIdsAndNames :many +SELECT * +FROM authors +WHERE id = ANY($1::BIGINT []) AND name = ANY($2::TEXT []);; + +-- name: CreateBook :execlastid +INSERT INTO books (name, author_id) VALUES ($1, $2) RETURNING id; + +-- name: ListAllAuthorsBooks :many +SELECT + sqlc.embed(authors), + sqlc.embed(books) +FROM authors +INNER JOIN books ON authors.id = books.author_id +ORDER BY authors.name; + +-- name: GetDuplicateAuthors :many +SELECT + sqlc.embed(authors1), + sqlc.embed(authors2) +FROM authors AS authors1 +INNER JOIN authors AS authors2 ON authors1.name = authors2.name +WHERE authors1.id < authors2.id; + +-- name: GetAuthorsByBookName :many +SELECT + authors.*, + sqlc.embed(books) +FROM authors INNER JOIN books ON authors.id = books.author_id +WHERE books.name = $1; + +-- name: CreateExtendedBio :exec +INSERT INTO extended.bios (author_name, name, bio_type) VALUES ($1, $2, $3); + +-- name: GetFirstExtendedBioByType :one +SELECT * FROM extended.bios WHERE bio_type = $1 LIMIT 1; + +-- name: TruncateExtendedBios :exec +TRUNCATE TABLE extended.bios; \ No newline at end of file diff --git a/examples/config/postgresql/authors/schema.sql b/examples/config/postgresql/authors/schema.sql new file mode 100644 index 00000000..db1305ba --- /dev/null +++ b/examples/config/postgresql/authors/schema.sql @@ -0,0 +1,24 @@ +CREATE TABLE authors ( + id BIGSERIAL PRIMARY KEY, + name TEXT NOT NULL, + bio TEXT +); + +CREATE TABLE books ( + id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), + name TEXT NOT NULL, + author_id BIGINT NOT NULL, + description TEXT, + FOREIGN KEY (author_id) REFERENCES authors (id) ON DELETE CASCADE +); + +CREATE SCHEMA extended; + +CREATE TYPE extended.bio_type AS ENUM ('Autobiography', 'Biography', 'Memoir'); + +CREATE TABLE extended.bios ( + author_name VARCHAR(100), + name VARCHAR(100), + bio_type extended.bio_type, + PRIMARY KEY (author_name, name) +); diff --git a/examples/config/postgresql/query.sql b/examples/config/postgresql/query.sql deleted file mode 100644 index 085d6390..00000000 --- a/examples/config/postgresql/query.sql +++ /dev/null @@ -1,338 +0,0 @@ --- name: GetAuthor :one -SELECT * FROM authors -WHERE name = $1 LIMIT 1; - --- name: ListAuthors :many -SELECT * -FROM authors -ORDER BY name -LIMIT sqlc.arg('limit') -OFFSET sqlc.arg('offset'); - --- name: CreateAuthor :one -INSERT INTO authors (id, name, bio) VALUES ($1, $2, $3) RETURNING *; - --- name: CreateAuthorReturnId :execlastid -INSERT INTO authors (name, bio) VALUES ($1, $2) RETURNING id; - --- name: GetAuthorById :one -SELECT * FROM authors -WHERE id = $1 LIMIT 1; - --- name: GetAuthorByNamePattern :many -SELECT * FROM authors -WHERE name LIKE COALESCE(sqlc.narg('name_pattern'), '%'); - --- name: DeleteAuthor :exec -DELETE FROM authors -WHERE name = $1; - --- name: TruncateAuthors :exec -TRUNCATE TABLE authors CASCADE; - --- name: UpdateAuthors :execrows -UPDATE authors -SET bio = $1 -WHERE bio IS NOT NULL; - --- name: GetAuthorsByIds :many -SELECT * FROM authors -WHERE id = ANY($1::BIGINT []); - --- name: GetAuthorsByIdsAndNames :many -SELECT * -FROM authors -WHERE id = ANY($1::BIGINT []) AND name = ANY($2::TEXT []);; - --- name: CreateBook :execlastid -INSERT INTO books (name, author_id) VALUES ($1, $2) RETURNING id; - --- name: ListAllAuthorsBooks :many -SELECT - sqlc.embed(authors), - sqlc.embed(books) -FROM authors -INNER JOIN books ON authors.id = books.author_id -ORDER BY authors.name; - --- name: GetDuplicateAuthors :many -SELECT - sqlc.embed(authors1), - sqlc.embed(authors2) -FROM authors AS authors1 -INNER JOIN authors AS authors2 ON authors1.name = authors2.name -WHERE authors1.id < authors2.id; - --- name: GetAuthorsByBookName :many -SELECT - authors.*, - sqlc.embed(books) -FROM authors INNER JOIN books ON authors.id = books.author_id -WHERE books.name = $1; - --- name: InsertPostgresTypes :exec -INSERT INTO postgres_types -( - c_boolean, - c_bit, - c_smallint, - c_integer, - c_bigint, - c_real, - c_numeric, - c_decimal, - c_double_precision, - c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, - c_json, - c_json_string_override, - c_jsonb, - c_jsonpath, - c_xml, - c_cidr, - c_inet, - c_macaddr, - c_macaddr8 -) -VALUES ( - sqlc.narg('c_boolean'), - sqlc.narg('c_bit'), - sqlc.narg('c_smallint'), - sqlc.narg('c_integer'), - sqlc.narg('c_bigint'), - sqlc.narg('c_real'), - sqlc.narg('c_numeric'), - sqlc.narg('c_decimal'), - sqlc.narg('c_double_precision'), - sqlc.narg('c_money'), - sqlc.narg('c_date'), - sqlc.narg('c_time'), - sqlc.narg('c_timestamp'), - sqlc.narg('c_timestamp_with_tz'), - sqlc.narg('c_interval'), - sqlc.narg('c_char'), - sqlc.narg('c_varchar'), - sqlc.narg('c_character_varying'), - sqlc.narg('c_bpchar'), - sqlc.narg('c_text'), - sqlc.narg('c_uuid'), - sqlc.narg('c_json')::json, - sqlc.narg('c_json_string_override')::json, - sqlc.narg('c_jsonb')::jsonb, - sqlc.narg('c_jsonpath')::jsonpath, - sqlc.narg('c_xml')::xml, - sqlc.narg('c_cidr'), - sqlc.narg('c_inet'), - sqlc.narg('c_macaddr')::macaddr, - sqlc.narg('c_macaddr8')::macaddr8 -); - --- name: InsertPostgresTypesBatch :copyfrom -INSERT INTO postgres_types -( - c_boolean, - c_smallint, - c_integer, - c_bigint, - c_real, - c_numeric, - c_decimal, - c_double_precision, - c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, - c_cidr, - c_inet, - c_macaddr -) -VALUES ( - $1, - $2, - $3, - $4, - $5, - $6, - $7, - $8, - $9, - $10, - $11, - $12, - $13, - $14, - $15, - $16, - $17, - $18, - $19, - $20, - $21, - $22, - $23 -); - --- name: GetPostgresTypes :one -SELECT - c_boolean, - c_bit, - c_smallint, - c_integer, - c_bigint, - c_real, - c_numeric, - c_decimal, - c_double_precision, - c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, - c_json, - c_json_string_override, - c_jsonb, - c_jsonpath, - c_xml, - c_cidr, - c_inet, - c_macaddr, - c_macaddr8::TEXT AS c_macaddr8 -FROM postgres_types -LIMIT 1; - --- name: GetPostgresTypesCnt :one -SELECT - c_smallint, - c_boolean, - c_integer, - c_bigint, - c_real, - c_numeric, - c_decimal, - c_double_precision, - c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, - c_cidr, - c_inet, - c_macaddr, - COUNT(*) AS cnt -FROM postgres_types -GROUP BY - c_smallint, - c_boolean, - c_integer, - c_bigint, - c_real, - c_numeric, - c_decimal, - c_double_precision, - c_money, - c_date, - c_time, - c_timestamp, - c_timestamp_with_tz, - c_interval, - c_char, - c_varchar, - c_character_varying, - c_bpchar, - c_text, - c_uuid, - c_cidr, - c_inet, - c_macaddr -LIMIT 1; - --- name: GetPostgresFunctions :one -SELECT - MAX(c_integer) AS max_integer, - MAX(c_varchar) AS max_varchar, - MAX(c_timestamp) AS max_timestamp -FROM postgres_types; - --- name: InsertPostgresGeoTypes :exec -INSERT INTO postgres_geometric_types ( - c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle -) -VALUES ($1, $2, $3, $4, $5, $6, $7); - --- name: InsertPostgresGeoTypesBatch :copyfrom -INSERT INTO postgres_geometric_types ( - c_point, c_line, c_lseg, c_box, c_path, c_polygon, c_circle -) -VALUES ($1, $2, $3, $4, $5, $6, $7); - --- name: GetPostgresGeoTypes :one -SELECT * FROM postgres_geometric_types LIMIT 1; - --- name: TruncatePostgresTypes :exec -TRUNCATE TABLE postgres_types; - --- name: TruncatePostgresGeoTypes :exec -TRUNCATE TABLE postgres_geometric_types; - --- name: InsertPostgresArrayTypes :exec -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 ($1, $2, $3, $4, $5, $6, $7); - --- name: GetPostgresArrayTypes :one -SELECT * FROM postgres_array_types LIMIT 1; - --- name: InsertPostgresArrayTypesBatch :copyfrom -INSERT INTO postgres_array_types (c_bytea) VALUES ($1); - --- name: GetPostgresArrayTypesCnt :one -SELECT - c_bytea, - COUNT(*) AS cnt -FROM postgres_array_types -GROUP BY - c_bytea -LIMIT 1; - --- name: TruncatePostgresArrayTypes :exec -TRUNCATE TABLE postgres_array_types; \ No newline at end of file diff --git a/examples/config/postgresql/types/query.sql b/examples/config/postgresql/types/query.sql new file mode 100644 index 00000000..2738dc59 --- /dev/null +++ b/examples/config/postgresql/types/query.sql @@ -0,0 +1,378 @@ +-- name: GetPostgresFunctions :one +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; + +/* Numeric types */ + +-- name: InsertPostgresNumericTypes :exec +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 ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10); + +-- name: GetPostgresNumericTypes :one +SELECT * FROM postgres_numeric_types LIMIT 1; + +-- name: TruncatePostgresNumericTypes :exec +TRUNCATE TABLE postgres_numeric_types; + +-- name: GetPostgresNumericTypesCnt :one +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; + +-- name: InsertPostgresNumericTypesBatch :copyfrom +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 ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10); + +/* String types */ + +-- name: InsertPostgresStringTypes :exec +INSERT INTO postgres_string_types +( + c_char, + c_varchar, + c_character_varying, + c_bpchar, + c_text +) +VALUES ($1, $2, $3, $4, $5); + +-- name: InsertPostgresStringTypesBatch :copyfrom +INSERT INTO postgres_string_types +( + c_char, + c_varchar, + c_character_varying, + c_bpchar, + c_text +) VALUES ($1, $2, $3, $4, $5); + +-- name: GetPostgresStringTypes :one +SELECT * FROM postgres_string_types LIMIT 1; + +-- name: TruncatePostgresStringTypes :exec +TRUNCATE TABLE postgres_string_types; + +-- name: GetPostgresStringTypesCnt :one +SELECT + c_char, + c_varchar, + c_character_varying, + c_bpchar, + c_text, + COUNT(*) AS cnt +FROM postgres_string_types +GROUP BY + c_char, + c_varchar, + c_character_varying, + c_bpchar, + c_text +LIMIT 1; + +-- name: GetPostgresStringTypesTextSearch :one +WITH txt_query AS ( + SELECT + c_text, + to_tsquery('english', $1) AS query, + to_tsvector('english', c_text) AS tsv + FROM postgres_string_types + WHERE c_text @@ to_tsquery('english', $1) +) + +SELECT txt_query.*, ts_rank(tsv, query) AS rnk +FROM txt_query +ORDER BY rnk DESC +LIMIT 1; + +/* DateTime types */ + +-- name: InsertPostgresDateTimeTypes :exec +INSERT INTO postgres_datetime_types +( + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval +) VALUES ($1, $2, $3, $4, $5); + +-- name: GetPostgresDateTimeTypes :one +SELECT * FROM postgres_datetime_types LIMIT 1; + +-- name: TruncatePostgresDateTimeTypes :exec +TRUNCATE TABLE postgres_datetime_types; + +-- name: GetPostgresDateTimeTypesCnt :one +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; + +-- name: InsertPostgresDateTimeTypesBatch :copyfrom +INSERT INTO postgres_datetime_types +( + c_date, + c_time, + c_timestamp, + c_timestamp_with_tz, + c_interval +) VALUES ($1, $2, $3, $4, $5); + +/* Network types */ + +-- name: InsertPostgresNetworkTypes :exec +INSERT INTO postgres_network_types +( + c_cidr, + c_inet, + c_macaddr, + c_macaddr8 +) VALUES ( + sqlc.narg('c_cidr'), + sqlc.narg('c_inet'), + sqlc.narg('c_macaddr'), + sqlc.narg('c_macaddr8')::macaddr8 +); + +-- name: GetPostgresNetworkTypes :one +SELECT + c_cidr, + c_inet, + c_macaddr, + c_macaddr8::TEXT AS c_macaddr8 +FROM postgres_network_types +LIMIT 1; + +-- name: TruncatePostgresNetworkTypes :exec +TRUNCATE TABLE postgres_network_types; + +-- name: GetPostgresNetworkTypesCnt :one +SELECT + c_cidr, + c_inet, + c_macaddr, + COUNT(*) AS cnt +FROM postgres_network_types +GROUP BY + c_cidr, + c_inet, + c_macaddr +LIMIT 1; + +-- name: InsertPostgresNetworkTypesBatch :copyfrom +INSERT INTO postgres_network_types +( + c_cidr, + c_inet, + c_macaddr +) VALUES ($1, $2, $3); + +/* Special types */ + +-- name: InsertPostgresSpecialTypes :exec +INSERT INTO postgres_special_types +( + c_json, + c_json_string_override, + c_jsonb, + c_jsonpath, + c_xml, + c_xml_string_override, + c_uuid, + c_enum +) +VALUES ( + sqlc.narg('c_json')::json, + sqlc.narg('c_json_string_override')::json, + sqlc.narg('c_jsonb')::jsonb, + sqlc.narg('c_jsonpath')::jsonpath, + sqlc.narg('c_xml')::xml, + sqlc.narg('c_xml_string_override')::xml, + sqlc.narg('c_uuid'), + sqlc.narg('c_enum')::c_enum +); + +-- name: GetPostgresSpecialTypes :one +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; + +-- name: TruncatePostgresSpecialTypes :exec +TRUNCATE TABLE postgres_special_types; + +-- name: InsertPostgresSpecialTypesBatch :copyfrom +INSERT INTO postgres_special_types +( + c_uuid +) +VALUES ( + $1 +); + +-- name: GetPostgresSpecialTypesCnt :one +SELECT + c_uuid, + COUNT(*) AS cnt +FROM postgres_special_types +GROUP BY + c_uuid +LIMIT 1; + +/* Array types */ + +-- name: InsertPostgresArrayTypes :exec +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 ($1, $2, $3, $4, $5, $6, $7); + +-- name: GetPostgresArrayTypes :one +SELECT * FROM postgres_array_types LIMIT 1; + +-- name: InsertPostgresArrayTypesBatch :copyfrom +INSERT INTO postgres_array_types ( + c_bytea, + c_boolean_array, + c_text_array, + c_integer_array, + c_decimal_array, + c_timestamp_array +) +VALUES ( + $1, + $2, + $3, + $4, + $5, + $6 +); + +-- name: GetPostgresArrayTypesCnt :one +SELECT + c_bytea, + c_boolean_array, + c_text_array, + c_integer_array, + c_decimal_array, + c_timestamp_array, + COUNT(*) AS cnt +FROM postgres_array_types +GROUP BY + c_bytea, + c_boolean_array, + c_text_array, + c_integer_array, + c_decimal_array, + c_timestamp_array +LIMIT 1; + +-- name: TruncatePostgresArrayTypes :exec +TRUNCATE TABLE postgres_array_types; + +/* Geometric types */ + +-- name: InsertPostgresGeoTypes :exec +INSERT INTO postgres_geometric_types ( + c_point, + c_line, + c_lseg, + c_box, + c_path, + c_polygon, + c_circle +) +VALUES ($1, $2, $3, $4, $5, $6, $7); + +-- name: InsertPostgresGeoTypesBatch :copyfrom +INSERT INTO postgres_geometric_types ( + c_point, + c_line, + c_lseg, + c_box, + c_path, + c_polygon, + c_circle +) +VALUES ($1, $2, $3, $4, $5, $6, $7); + +-- name: GetPostgresGeoTypes :one +SELECT * FROM postgres_geometric_types LIMIT 1; + +-- name: TruncatePostgresGeoTypes :exec +TRUNCATE TABLE postgres_geometric_types; diff --git a/examples/config/postgresql/schema.sql b/examples/config/postgresql/types/schema.sql similarity index 51% rename from examples/config/postgresql/schema.sql rename to examples/config/postgresql/types/schema.sql index 62b03f38..e269c9a1 100644 --- a/examples/config/postgresql/schema.sql +++ b/examples/config/postgresql/types/schema.sql @@ -1,21 +1,4 @@ -CREATE TABLE authors ( - id BIGSERIAL PRIMARY KEY, - name TEXT NOT NULL, - bio TEXT -); - -CREATE EXTENSION "uuid-ossp"; - -CREATE TABLE books ( - id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), - name TEXT NOT NULL, - author_id BIGINT NOT NULL, - description TEXT, - FOREIGN KEY (author_id) REFERENCES authors (id) ON DELETE CASCADE -); - -CREATE TABLE postgres_types ( - /* Numeric Data Types */ +CREATE TABLE postgres_numeric_types ( c_boolean BOOLEAN, c_bit BIT(10), c_smallint SMALLINT, @@ -25,48 +8,36 @@ CREATE TABLE postgres_types ( c_numeric NUMERIC(10, 7), c_real REAL, c_double_precision DOUBLE PRECISION, - c_money MONEY, - - /* Date and Time Data Types */ - c_date DATE, - c_time TIME, - c_timestamp TIMESTAMP, - c_timestamp_with_tz TIMESTAMP WITH TIME ZONE, - c_interval INTERVAL, + c_money MONEY +); - /* String Data Type Syntax */ +CREATE TABLE postgres_string_types ( c_char CHAR, c_varchar VARCHAR(100), c_character_varying CHARACTER VARYING(100), c_bpchar BPCHAR(100), - c_text TEXT, + c_text TEXT +); - /* JSON Data Types */ - c_json JSON, - c_json_string_override JSON, - c_jsonb JSONB, - c_jsonpath JSONPATH, - c_xml XML, +CREATE TABLE postgres_datetime_types ( + c_date DATE, + c_time TIME, + c_timestamp TIMESTAMP, + c_timestamp_with_tz TIMESTAMP WITH TIME ZONE, + c_interval INTERVAL +); - /* Network Address Data Types */ +CREATE TABLE postgres_network_types ( c_cidr CIDR, c_inet INET, c_macaddr MACADDR, - c_macaddr8 MACADDR8, - - /* Special Data Types */ - c_uuid UUID + c_macaddr8 MACADDR8 ); -CREATE TABLE postgres_geometric_types ( - c_point POINT, - c_line LINE, - c_lseg LSEG, - c_box BOX, - c_path PATH, - c_polygon POLYGON, - c_circle CIRCLE -); +CREATE EXTENSION "pg_trgm"; +CREATE EXTENSION "btree_gin"; + +CREATE INDEX postgres_txt_idx ON postgres_string_types USING GIN (c_text); CREATE TABLE postgres_array_types ( c_bytea BYTEA, @@ -76,4 +47,29 @@ CREATE TABLE postgres_array_types ( c_decimal_array DECIMAL(10, 7) [], c_date_array DATE [], c_timestamp_array TIMESTAMP [] +); + +CREATE TABLE postgres_geometric_types ( + c_point POINT, + c_line LINE, + c_lseg LSEG, + c_box BOX, + c_path PATH, + c_polygon POLYGON, + c_circle CIRCLE +); + +CREATE EXTENSION "uuid-ossp"; + +CREATE TYPE c_enum AS ENUM ('small', 'medium', 'big'); + +CREATE TABLE postgres_special_types ( + c_uuid UUID, + c_enum c_enum, + c_json JSON, + c_json_string_override JSON, + c_jsonb JSONB, + c_jsonpath JSONPATH, + c_xml XML, + c_xml_string_override XML ); \ No newline at end of file diff --git a/examples/config/sqlite/query.sql b/examples/config/sqlite/authors/query.sql similarity index 71% rename from examples/config/sqlite/query.sql rename to examples/config/sqlite/authors/query.sql index be738afb..19b241ae 100644 --- a/examples/config/sqlite/query.sql +++ b/examples/config/sqlite/authors/query.sql @@ -67,36 +67,4 @@ FROM authors INNER JOIN books ON authors.id = books.author_id WHERE books.name = ?; -- name: DeleteAllAuthors :exec -DELETE FROM authors; - --- name: InsertSqliteTypes :exec -INSERT INTO types_sqlite (c_integer, c_real, c_text, c_blob) VALUES ( - ?, ?, ?, ? -); - --- name: InsertSqliteTypesBatch :copyfrom -INSERT INTO types_sqlite (c_integer, c_real, c_text) VALUES (?, ?, ?); - --- name: GetSqliteTypes :one -SELECT * FROM types_sqlite LIMIT 1; - --- name: GetSqliteTypesCnt :one -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; - --- name: GetSqliteFunctions :one -SELECT - MAX(c_integer) AS max_integer, - MAX(c_real) AS max_real, - MAX(c_text) AS max_text -FROM types_sqlite; - --- name: DeleteAllSqliteTypes :exec -DELETE FROM types_sqlite; +DELETE FROM authors; \ No newline at end of file diff --git a/examples/config/sqlite/schema.sql b/examples/config/sqlite/authors/schema.sql similarity index 74% rename from examples/config/sqlite/schema.sql rename to examples/config/sqlite/authors/schema.sql index 1e4e85eb..be2ea8e6 100644 --- a/examples/config/sqlite/schema.sql +++ b/examples/config/sqlite/authors/schema.sql @@ -10,11 +10,4 @@ CREATE TABLE books ( author_id INTEGER NOT NULL, description TEXT, FOREIGN KEY (author_id) REFERENCES authors (id) ON DELETE CASCADE -); - -CREATE TABLE types_sqlite ( - c_integer INTEGER, - c_real REAL, - c_text TEXT, - c_blob BLOB -); +); \ No newline at end of file diff --git a/examples/config/sqlite/types/query.sql b/examples/config/sqlite/types/query.sql new file mode 100644 index 00000000..f3074a00 --- /dev/null +++ b/examples/config/sqlite/types/query.sql @@ -0,0 +1,31 @@ +-- name: InsertSqliteTypes :exec +INSERT INTO types_sqlite +(c_integer, c_real, c_text, c_blob) +VALUES (?, ?, ?, ?); + +-- name: InsertSqliteTypesBatch :copyfrom +INSERT INTO types_sqlite (c_integer, c_real, c_text) VALUES (?, ?, ?); + +-- name: GetSqliteTypes :one +SELECT * FROM types_sqlite LIMIT 1; + +-- name: GetSqliteTypesCnt :one +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; + +-- name: GetSqliteFunctions :one +SELECT + MAX(c_integer) AS max_integer, + MAX(c_real) AS max_real, + MAX(c_text) AS max_text +FROM types_sqlite; + +-- name: DeleteAllSqliteTypes :exec +DELETE FROM types_sqlite; diff --git a/examples/config/sqlite/types/schema.sql b/examples/config/sqlite/types/schema.sql new file mode 100644 index 00000000..f5f7e7d6 --- /dev/null +++ b/examples/config/sqlite/types/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE types_sqlite ( + c_integer INTEGER, + c_real REAL, + c_text TEXT, + c_blob BLOB +); diff --git a/scripts/sync_sqlc_options.sh b/scripts/sync_sqlc_options.sh index ac99e8a8..41daf5e9 100755 --- a/scripts/sync_sqlc_options.sh +++ b/scripts/sync_sqlc_options.sh @@ -14,11 +14,9 @@ cp "$LOCAL_YAML" "$TMP_LOCAL_YML" sql_count=$(yq '.sql | length' "$CI_YAML") for ((i=0; i