예제 #1
0
        public async Task <Batch> ReadBatchAsync(ReadCommand command, CancellationToken token)
        {
            var db = new DatabaseGateway(
                _dataMoverSettings.ConnectionStrings.Src,
                _dataMoverSettings.DataReadCommandTimeoutSeconds,
                _policyFactory.SrcPolicy);
            var skipInsertColumnsNames = GetSkippedColumnsNames(command.TableSchema.Name);
            var columns = command.TableSchema.Columns.Where(x => !skipInsertColumnsNames.Contains(x.Name)).ToList();
            var rows    = await db.ReadAsync((command, columns), BuildQuery(command, columns),
                                             (a, p) => AddQueryParameters(a.command, p), (a, r) => MapRow(a.columns, r), token);

            return(new Batch
            {
                Columns = columns,
                Rows = rows
            });
        }
        private async Task <List <DatabaseObjectDto> > ReadMetadataAsync(CancellationToken token)
        {
            var db = new DatabaseGateway(_dataMoverSettings.ConnectionStrings.Src,
                                         _dataMoverSettings.SchemaReadCommandTimeoutSeconds, _policyFactory.SrcPolicy);

            var dbName = new MySqlConnectionStringBuilder(_dataMoverSettings.ConnectionStrings.Src).Database;

            var sql = @"select TABLE_NAME as Name, 'table' as Type
from information_schema.TABLES
where TABLE_TYPE = 'BASE TABLE' and TABLE_SCHEMA = @databaseName
union
select TABLE_NAME as Name, 'view' as Type
from information_schema.TABLES
where TABLE_TYPE = 'VIEW' and TABLE_SCHEMA = @databaseName
union
select ROUTINE_NAME, 'function' as Type
from information_schema.ROUTINES
where ROUTINE_TYPE = 'FUNCTION' and ROUTINE_SCHEMA = @databaseName
union
select ROUTINE_NAME, 'procedure' as Type
from information_schema.ROUTINES
where ROUTINE_TYPE = 'PROCEDURE' and ROUTINE_SCHEMA = @databaseName
union
select TRIGGER_NAME, 'trigger' as Type
from information_schema.TRIGGERS
where TRIGGER_SCHEMA = @databaseName;";

            return(await db.ReadAsync(default(Unused), sql,
                                      (_, collection) => collection.AddWithValue("databaseName", dbName),
                                      (_, reader) => new DatabaseObjectDto
            {
                Name = reader.GetString("Name"),
                Type = reader.GetString("Type")
            },
                                      token));
        }