public async Task AsyncEnumerator() { var runner = new DataReaderRunner(_provider, _disposer); await using var result = await runner.Run(Query.Plain("SELECT 1"), Integer (0)); await using var enumerator = result.GetAsyncEnumerator(); Assert.IsTrue(await enumerator.MoveNextAsync()); Assert.AreEqual(enumerator.Current, 1); Assert.IsFalse(await enumerator.MoveNextAsync()); }
public async Task EnumeratorReset() { var runner = new DataReaderRunner(_provider, _disposer); await using var result = await runner.Run(Query.Plain("SELECT 1"), Integer (0)); using var enumerator = result.GetEnumerator(); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(enumerator.Current, 1); Assert.IsFalse(enumerator.MoveNext()); Assert.Throws <NotSupportedException>(() => enumerator.Reset()); }
public async Task IterateResultsPartially() { var runner = new DataReaderRunner(_provider, _disposer); await runner.RunNoResult(Query.Plain("CREATE TABLE test_table (a integer, b integer, c integer)")); await runner.RunNoResult(Query.Plain("INSERT INTO test_table (a, b, c) VALUES (1, 2, 3), (2, 3, 4), (5, 6, 7)")); var parser = Integer(0).And(Integer(1)).And(Integer(2)); await using (var results = await runner.Run(Query.Plain("SELECT a, b, c FROM test_table"), parser)) { var((a, b), c) = results.First(); Assert.That(a * b * c, Is.EqualTo(6)); } Assert.That(_connectionCounter, Is.EqualTo(0)); }
public async Task IterateResults() { var runner = new DataReaderRunner(_provider, _disposer); await runner.RunNoResult(Query.Plain("CREATE TABLE test_table (a integer, b integer, c integer)")); await runner.RunNoResult(Query.Plain("INSERT INTO test_table (a, b, c) VALUES (1, 2, 3), (2, 3, 4), (5, 6, 7)")); var parser = Integer(0).And(Integer(1)).And(Integer(2)); var results = await runner.Run(Query.Parameterized($"SELECT a, b, c FROM test_table"), parser); var csSum = results.Select(row => { var((a, b), c) = row; return(a * b * c); }).Sum(); var sqlSum = await runner.RunSingle(Query.Parameterized($"SELECT SUM(a * b * c) AS sum FROM test_table"), Integer("sum")); Assert.That(sqlSum, Is.EqualTo(240)); Assert.That(csSum, Is.EqualTo(sqlSum)); }
public async Task IterateResultsInTransaction() { var runner = new DataReaderRunner(_provider, _disposer); await runner.RunNoResult(Query.Plain("CREATE TABLE test_table (a integer, b integer, c integer)")); await runner.RunNoResult(Query.Plain("INSERT INTO test_table (a, b, c) VALUES (1, 2, 3), (2, 3, 4), (5, 6, 7)")); var parser = Integer(0).And(Integer(1)).And(Integer(2)); await runner.Transaction(async r => { await using var results = await runner.Run(Query.Plain("SELECT a, b, c FROM test_table"), parser); var sum = results.Select(row => { var((a, b), c) = row; return(a *b *c); }).Sum(); Assert.That(sum, Is.EqualTo(240)); return(sum); }); }