Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Core/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Open.Database.Extensions

(Full API Documenation)[]
[Full API Documentation](https://electricessence.github.io/Open.Database.Extensions/api/index.html)

Useful set of utilities and abstractions for simplifying modern database operations and ensuring dependency injection compatibility.

Expand Down Expand Up @@ -34,14 +34,14 @@ var myResult = new List<T>();
using(var reader = await mySqlCommand.ExecuteReaderAsync(CommandBehavior.CloseConnection))
{
while(await reader.ReadAsync())
list.Add(transform(reader));
myResult.Add(transform(reader));
}
```

Is now simplified to this:

```cs
var myResult = await cmd.ToListAsync(transform);
var myResult = await mySqlCommand.ToListAsync(transform);
```

## Deferred Transformation
Expand Down Expand Up @@ -86,7 +86,7 @@ var people = cmd.Results<Person>(new Dictionary<string,string>{
{"LastName", "last_name"});
```

### `Retrieve()` and `RetrieveAsync()`
#### `Retrieve()` and `RetrieveAsync()`

Queues all the data. Returns a `QueryResult<Queue<object[]>>` containing the requested data and column information. The `.AsDequeueingMappedEnumerable()` extension will iteratively convert the results to dictionaries for ease of access.

Expand Down
123 changes: 121 additions & 2 deletions Core/api/index.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,121 @@
# PLACEHOLDER
TODO: Add .NET projects to the *src* folder and run `docfx` to generate **REAL** *API Documentation*!
# Open.Database.Extensions

[GitHub](https://github.com/electricessence/Open.Database.Extensions)

Useful set of utilities and abstractions for simplifying modern database operations and ensuring dependency injection compatibility.

## Connection Factories

Connection factories facilitate creation and disposal of connections without the concern of a connection reference or need for awareness of a connection string.

## Expressive Commands

The provided expressive command classes allow for an expressive means to append parameters and execute the results without lengthy complicated setup.

Extensions are provided to create commands from connection factories.

### Example

```cs
var result = connectionFactory
.StoredProcedure("[procedure name]")
.AddParam("a",1)
.AddParam("b",true)
.AddParam("c","hello")
.ExecuteScalar();
```

## Extensions

Instead of writing this:

```cs
var myResult = new List<T>();
using(var reader = await mySqlCommand.ExecuteReaderAsync(CommandBehavior.CloseConnection))
{
while(await reader.ReadAsync())
myResult.Add(transform(reader));
}
```

Is now simplified to this:

```cs
var myResult = await mySqlCommand.ToListAsync(transform);
```

## Deferred Transformation

In order to keep connection open time to a minimum, some methods cache data before closing the connection and then subsequently applying the transformations as needed.

### `Results<T>()` and `ResultsAsync<T>()`

Queues all the data. Then using the provided type `T` entity, the data is coerced by which properties intersect with the ones available to the `IDataReader`.

Optionally a field to column override map can be passed as a parameter. If a column is set as `null` then that field is ignored (not applied to the model).

### Examples

If all the columns in the database map exactly to a field: (A column that has no associated field/property is ignored.)

```cs
var people = cmd.Results<Person>();
```

If the database fields don't map exactly:

```cs
var people = cmd.Results<Person>(
(Field:"FirstName", Column:"first_name"),
(Field:"LastName", Column:"last_name")));
```

or

```cs
var people = cmd.Results<Person>(
("FirstName", "first_name"),
("LastName", "last_name"));
```

or

```cs
var people = cmd.Results<Person>(new Dictionary<string,string>{
{"FirstName", "first_name"},
{"LastName", "last_name"});
```

#### `Retrieve()` and `RetrieveAsync()`

Queues all the data. Returns a `QueryResult<Queue<object[]>>` containing the requested data and column information. The `.AsDequeueingMappedEnumerable()` extension will iteratively convert the results to dictionaries for ease of access.

### `ResultsAsync<T>`

`ResultsAsync<T>()` is fully asynchronous from end-to-end but returns an `IEnumerable<T>` that although has fully buffered the all the data into memory, has deferred the transformation until enumerated. This way, the asynchronous data pipeline is fully complete before synchronously transforming the data.

## Transactions

Example:

```cs
// Returns true if the transaction is successful.
public static bool TryTransaction()
=> ConnectionFactory.Using(connection =>
// Open a connection and start a transaction.
connection.ExecuteTransactionConditional(transaction => {

// First procedure does some updates.
var count = transaction
.StoredProcedure("[Updated Procedure]")
.ExecuteNonQuery();

// Second procedure validates the results.
// If it returns true, then the transaction is committed.
// If it returns false, then the transaction is rolled back.
return transaction
.StoredProcedure("[Validation Procedure]")
.AddParam("@ExpectedCount", count)
.ExecuteScalar<bool>();
}));
```
2 changes: 1 addition & 1 deletion Core/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Open.Database.Extensions

(Full API Documenation)[]
[Full API Documentation](https://electricessence.github.io/Open.Database.Extensions/api/index.html)

Useful set of utilities and abstractions for simplifying modern database operations and ensuring dependency injection compatibility.

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Open.Database.Extensions

[Full API Documentation](https://electricessence.github.io/Open.Database.Extensions/api/index.html)

Useful set of utilities and abstractions for simplifying modern database operations and ensuring dependency injection compatibility.

## Connection Factories
Expand Down
8 changes: 4 additions & 4 deletions docs/README.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<article class="content wrap" id="_content" data-uid="">
<h1 id="opendatabaseextensions">Open.Database.Extensions</h1>

<p>(Full API Documenation)[]</p>
<p><a href="https://electricessence.github.io/Open.Database.Extensions/api/index.html">Full API Documentation</a></p>
<p>Useful set of utilities and abstractions for simplifying modern database operations and ensuring dependency injection compatibility.</p>
<h2 id="connection-factories">Connection Factories</h2>
<p>Connection factories facilitate creation and disposal of connections without the concern of a connection reference or need for awareness of a connection string.</p>
Expand All @@ -83,11 +83,11 @@ <h2 id="extensions">Extensions</h2>
using(var reader = await mySqlCommand.ExecuteReaderAsync(CommandBehavior.CloseConnection))
{
while(await reader.ReadAsync())
list.Add(transform(reader));
myResult.Add(transform(reader));
}
</code></pre>
<p>Is now simplified to this:</p>
<pre><code class="lang-cs">var myResult = await cmd.ToListAsync(transform);
<pre><code class="lang-cs">var myResult = await mySqlCommand.ToListAsync(transform);
</code></pre>
<h2 id="deferred-transformation">Deferred Transformation</h2>
<p>In order to keep connection open time to a minimum, some methods cache data before closing the connection and then subsequently applying the transformations as needed.</p>
Expand All @@ -113,7 +113,7 @@ <h3 id="examples">Examples</h3>
{&quot;FirstName&quot;, &quot;first_name&quot;},
{&quot;LastName&quot;, &quot;last_name&quot;});
</code></pre>
<h3 id="retrieve-and-retrieveasync"><code>Retrieve()</code> and <code>RetrieveAsync()</code></h3>
<h4 id="retrieve-and-retrieveasync"><code>Retrieve()</code> and <code>RetrieveAsync()</code></h4>
<p>Queues all the data. Returns a <code>QueryResult&lt;Queue&lt;object[]&gt;&gt;</code> containing the requested data and column information. The <code>.AsDequeueingMappedEnumerable()</code> extension will iteratively convert the results to dictionaries for ease of access.</p>
<h3 id="resultsasynct"><code>ResultsAsync&lt;T&gt;</code></h3>
<p><code>ResultsAsync&lt;T&gt;()</code> is fully asynchronous from end-to-end but returns an <code>IEnumerable&lt;T&gt;</code> that although has fully buffered the all the data into memory, has deferred the transformation until enumerated. This way, the asynchronous data pipeline is fully complete before synchronously transforming the data.</p>
Expand Down
84 changes: 80 additions & 4 deletions docs/api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>PLACEHOLDER </title>
<title>Open.Database.Extensions </title>
<meta name="viewport" content="width=device-width">
<meta name="title" content="PLACEHOLDER ">
<meta name="title" content="Open.Database.Extensions ">
<meta name="generator" content="docfx 2.47.0.0">

<link rel="shortcut icon" href="../favicon.ico">
Expand Down Expand Up @@ -67,9 +67,85 @@
<div class="article row grid-right">
<div class="col-md-10">
<article class="content wrap" id="_content" data-uid="">
<h1 id="placeholder">PLACEHOLDER</h1>
<h1 id="opendatabaseextensions">Open.Database.Extensions</h1>

<p>TODO: Add .NET projects to the <em>src</em> folder and run <code>docfx</code> to generate <strong>REAL</strong> <em>API Documentation</em>!</p>
<p><a href="https://github.com/electricessence/Open.Database.Extensions">GitHub</a></p>
<p>Useful set of utilities and abstractions for simplifying modern database operations and ensuring dependency injection compatibility.</p>
<h2 id="connection-factories">Connection Factories</h2>
<p>Connection factories facilitate creation and disposal of connections without the concern of a connection reference or need for awareness of a connection string.</p>
<h2 id="expressive-commands">Expressive Commands</h2>
<p>The provided expressive command classes allow for an expressive means to append parameters and execute the results without lengthy complicated setup.</p>
<p>Extensions are provided to create commands from connection factories.</p>
<h3 id="example">Example</h3>
<pre><code class="lang-cs">var result = connectionFactory
.StoredProcedure(&quot;[procedure name]&quot;)
.AddParam(&quot;a&quot;,1)
.AddParam(&quot;b&quot;,true)
.AddParam(&quot;c&quot;,&quot;hello&quot;)
.ExecuteScalar();
</code></pre>
<h2 id="extensions">Extensions</h2>
<p>Instead of writing this:</p>
<pre><code class="lang-cs">var myResult = new List&lt;T&gt;();
using(var reader = await mySqlCommand.ExecuteReaderAsync(CommandBehavior.CloseConnection))
{
while(await reader.ReadAsync())
myResult.Add(transform(reader));
}
</code></pre>
<p>Is now simplified to this:</p>
<pre><code class="lang-cs">var myResult = await mySqlCommand.ToListAsync(transform);
</code></pre>
<h2 id="deferred-transformation">Deferred Transformation</h2>
<p>In order to keep connection open time to a minimum, some methods cache data before closing the connection and then subsequently applying the transformations as needed.</p>
<h3 id="resultst-and-resultsasynct"><code>Results&lt;T&gt;()</code> and <code>ResultsAsync&lt;T&gt;()</code></h3>
<p>Queues all the data. Then using the provided type <code>T</code> entity, the data is coerced by which properties intersect with the ones available to the <code>IDataReader</code>.</p>
<p>Optionally a field to column override map can be passed as a parameter. If a column is set as <code>null</code> then that field is ignored (not applied to the model).</p>
<h3 id="examples">Examples</h3>
<p>If all the columns in the database map exactly to a field: (A column that has no associated field/property is ignored.)</p>
<pre><code class="lang-cs">var people = cmd.Results&lt;Person&gt;();
</code></pre>
<p>If the database fields don't map exactly:</p>
<pre><code class="lang-cs">var people = cmd.Results&lt;Person&gt;(
(Field:&quot;FirstName&quot;, Column:&quot;first_name&quot;),
(Field:&quot;LastName&quot;, Column:&quot;last_name&quot;)));
</code></pre>
<p>or</p>
<pre><code class="lang-cs">var people = cmd.Results&lt;Person&gt;(
(&quot;FirstName&quot;, &quot;first_name&quot;),
(&quot;LastName&quot;, &quot;last_name&quot;));
</code></pre>
<p>or</p>
<pre><code class="lang-cs">var people = cmd.Results&lt;Person&gt;(new Dictionary&lt;string,string&gt;{
{&quot;FirstName&quot;, &quot;first_name&quot;},
{&quot;LastName&quot;, &quot;last_name&quot;});
</code></pre>
<h4 id="retrieve-and-retrieveasync"><code>Retrieve()</code> and <code>RetrieveAsync()</code></h4>
<p>Queues all the data. Returns a <code>QueryResult&lt;Queue&lt;object[]&gt;&gt;</code> containing the requested data and column information. The <code>.AsDequeueingMappedEnumerable()</code> extension will iteratively convert the results to dictionaries for ease of access.</p>
<h3 id="resultsasynct"><code>ResultsAsync&lt;T&gt;</code></h3>
<p><code>ResultsAsync&lt;T&gt;()</code> is fully asynchronous from end-to-end but returns an <code>IEnumerable&lt;T&gt;</code> that although has fully buffered the all the data into memory, has deferred the transformation until enumerated. This way, the asynchronous data pipeline is fully complete before synchronously transforming the data.</p>
<h2 id="transactions">Transactions</h2>
<p>Example:</p>
<pre><code class="lang-cs">// Returns true if the transaction is successful.
public static bool TryTransaction()
=&gt; ConnectionFactory.Using(connection =&gt;
// Open a connection and start a transaction.
connection.ExecuteTransactionConditional(transaction =&gt; {

// First procedure does some updates.
var count = transaction
.StoredProcedure(&quot;[Updated Procedure]&quot;)
.ExecuteNonQuery();

// Second procedure validates the results.
// If it returns true, then the transaction is committed.
// If it returns false, then the transaction is rolled back.
return transaction
.StoredProcedure(&quot;[Validation Procedure]&quot;)
.AddParam(&quot;@ExpectedCount&quot;, count)
.ExecuteScalar&lt;bool&gt;();
}));
</code></pre>
</article>
</div>

Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<article class="content wrap" id="_content" data-uid="">
<h1 id="opendatabaseextensions">Open.Database.Extensions</h1>

<p>(Full API Documenation)[]</p>
<p><a href="https://electricessence.github.io/Open.Database.Extensions/api/index.html">Full API Documentation</a></p>
<p>Useful set of utilities and abstractions for simplifying modern database operations and ensuring dependency injection compatibility.</p>
<h2 id="connection-factories">Connection Factories</h2>
<p>Connection factories facilitate creation and disposal of connections without the concern of a connection reference or need for awareness of a connection string.</p>
Expand Down
28 changes: 14 additions & 14 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"output": {
".html": {
"relative_path": "README.html",
"hash": "tyD8A/u7sWAfe+8R1dLxxA=="
"hash": "6n0p5fClpr18KwRHo3OGSg=="
}
},
"is_incremental": true,
"is_incremental": false,
"version": ""
},
{
Expand Down Expand Up @@ -405,10 +405,10 @@
"output": {
".html": {
"relative_path": "api/index.html",
"hash": "tF+QKSRFfWltk151Do+gpA=="
"hash": "R3roe74Czsq4LUqX9ardkg=="
}
},
"is_incremental": true,
"is_incremental": false,
"version": ""
},
{
Expand All @@ -429,10 +429,10 @@
"output": {
".html": {
"relative_path": "index.html",
"hash": "WT75xuCxVHlY08oHgFRFfg=="
"hash": "+6gZq5CVqvXPB5cqlxvhdQ=="
}
},
"is_incremental": true,
"is_incremental": false,
"version": ""
},
{
Expand All @@ -457,13 +457,6 @@
"skipped_file_count": 0
},
"processors": {
"TocDocumentProcessor": {
"can_incremental": false,
"details": "Processor TocDocumentProcessor cannot support incremental build because the processor doesn't implement ISupportIncrementalDocumentProcessor interface.",
"incrementalPhase": "build",
"total_file_count": 0,
"skipped_file_count": 0
},
"ManagedReferenceDocumentProcessor": {
"can_incremental": true,
"incrementalPhase": "build",
Expand All @@ -474,7 +467,14 @@
"can_incremental": true,
"incrementalPhase": "build",
"total_file_count": 3,
"skipped_file_count": 3
"skipped_file_count": 0
},
"TocDocumentProcessor": {
"can_incremental": false,
"details": "Processor TocDocumentProcessor cannot support incremental build because the processor doesn't implement ISupportIncrementalDocumentProcessor interface.",
"incrementalPhase": "build",
"total_file_count": 0,
"skipped_file_count": 0
}
}
},
Expand Down