Esempio n. 1
0
        public async Task ExecuteAsync(IEnumerable <CommandData> commands, CancellationToken cancellationToken = default)
        {
            FieldMap fieldMap = new FieldMap();

            await using AsyncSession session = new AsyncSession(this.Options);

            foreach (CommandData commandData in commands.NotNull())
            {
                Command command = new Command(commandData, fieldMap);

                if (string.IsNullOrWhiteSpace(commandData.CommandText))
                {
                    continue;
                }

                await foreach (DbDataReader dataReader in session.ExecuteAsync(command, cancellationToken).ConfigureAwait(false))
                {
                    TableIdentity      tableInfo  = TableIdentity.FromRecord(dataReader);
                    FieldData[]        fields     = command.GetHeading(tableInfo);
                    MetadataIdentity[] attributes = fields.Select(f => f?.Attribute).ToArray();

                    var binder = FuncCache.GetFieldDataBinder(attributes, tableInfo);

                    if (await dataReader.ReadAsync().ConfigureAwait(false))
                    {
                        binder(dataReader, fields);
                    }
                }
            }

            foreach (FieldData fieldData in fieldMap)
            {
                fieldData.Bind();
            }
        }
Esempio n. 2
0
        public void Execute(IEnumerable <CommandData> commands)
        {
            FieldMap fieldMap = new FieldMap();

            using SyncSession session = new SyncSession(this.Options);

            foreach (CommandData commandData in commands.NotNull())
            {
                Command command = new Command(commandData, fieldMap);

                if (string.IsNullOrWhiteSpace(commandData.CommandText))
                {
                    continue;
                }

                foreach (IDataReader reader in session.Execute(command))
                {
                    TableIdentity      tableInfo = TableIdentity.FromRecord(reader);
                    FieldData[]        fields    = command.GetHeading(tableInfo);
                    MetadataIdentity[] metadata  = fields.Select(f => f?.Attribute).ToArray();

                    var binder = FuncCache.GetFieldDataBinder(metadata, tableInfo);

                    if (reader.Read())
                    {
                        binder(reader, fields);
                    }
                }
            }

            foreach (FieldData fieldData in fieldMap)
            {
                fieldData.Bind();
            }
        }
Esempio n. 3
0
        public IEnumerable <TItem> Read <TItem>()
        {
            TableIdentity       heading = TableIdentity.FromRecord(this.syncReader);
            ResultState <TItem> state   = ResultCache <TItem> .GetResultState(this.schemas, heading);

            while (this.syncReader.Read())
            {
                yield return(state.Item(this.syncReader));
            }
        }
Esempio n. 4
0
            static async Task consumer(AdoHelper helper, DbDataReader reader)
            {
                TableIdentity tableInfo = TableIdentity.FromRecord(reader);

                FieldData[]        fields     = helper.GetHeading(tableInfo);
                MetadataIdentity[] attributes = fields.Select(f => f.Attribute).ToArray();

                var fun = FuncCache.GetFieldDataBinder(attributes, tableInfo);

                if (await reader.ReadAsync())
                {
                    fun(reader, fields);
                }
            }
Esempio n. 5
0
        public async IAsyncEnumerable <TItem> ReadAsync <TItem>([EnumeratorCancellation] CancellationToken cancellationToken = default)
        {
            if (this.asyncReader == null)
            {
                throw new QueryException("Async not available. To use async operations, please supply a connection factory returning a DbConnection instance.");
            }

            TableIdentity       heading = TableIdentity.FromRecord(this.asyncReader);
            ResultState <TItem> state   = ResultCache <TItem> .GetResultState(this.schemas, heading);

            while (await this.asyncReader.ReadAsync(cancellationToken).ConfigureAwait(false))
            {
                yield return(state.Item(this.asyncReader));
            }
        }
Esempio n. 6
0
        private void SetState(IDataReader dataReader)
        {
            TableIdentity heading = TableIdentity.FromRecord(dataReader);

            this.state = ResultCache <TItem> .GetResultState(this.Schemas, heading);
        }