diff --git a/Core/README.md b/Core/README.md index 823a713..9d14e88 100644 --- a/Core/README.md +++ b/Core/README.md @@ -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. @@ -34,14 +34,14 @@ var myResult = new List(); 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 @@ -86,7 +86,7 @@ var people = cmd.Results(new Dictionary{ {"LastName", "last_name"}); ``` -### `Retrieve()` and `RetrieveAsync()` +#### `Retrieve()` and `RetrieveAsync()` Queues all the data. Returns a `QueryResult>` containing the requested data and column information. The `.AsDequeueingMappedEnumerable()` extension will iteratively convert the results to dictionaries for ease of access. diff --git a/Core/api/index.md b/Core/api/index.md index 78dc9c0..f42e8a8 100644 --- a/Core/api/index.md +++ b/Core/api/index.md @@ -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(); +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()` and `ResultsAsync()` + +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(); +``` + +If the database fields don't map exactly: + +```cs +var people = cmd.Results( + (Field:"FirstName", Column:"first_name"), + (Field:"LastName", Column:"last_name"))); +``` + +or + +```cs +var people = cmd.Results( + ("FirstName", "first_name"), + ("LastName", "last_name")); +``` + +or + +```cs +var people = cmd.Results(new Dictionary{ + {"FirstName", "first_name"}, + {"LastName", "last_name"}); +``` + +#### `Retrieve()` and `RetrieveAsync()` + +Queues all the data. Returns a `QueryResult>` containing the requested data and column information. The `.AsDequeueingMappedEnumerable()` extension will iteratively convert the results to dictionaries for ease of access. + +### `ResultsAsync` + +`ResultsAsync()` is fully asynchronous from end-to-end but returns an `IEnumerable` 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(); + })); +``` diff --git a/Core/index.md b/Core/index.md index 823a713..b95386c 100644 --- a/Core/index.md +++ b/Core/index.md @@ -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. diff --git a/README.md b/README.md index 3e62705..9d14e88 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/README.html b/docs/README.html index 968c6f8..d7b3f49 100644 --- a/docs/README.html +++ b/docs/README.html @@ -62,7 +62,7 @@

Open.Database.Extensions

-

(Full API Documenation)[]

+

Full API Documentation

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.

@@ -83,11 +83,11 @@

Extensions

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:

-
var myResult = await cmd.ToListAsync(transform);
+
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.

@@ -113,7 +113,7 @@

Examples

{"FirstName", "first_name"}, {"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.

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.

diff --git a/docs/api/index.html b/docs/api/index.html index 2c2b114..b847a86 100644 --- a/docs/api/index.html +++ b/docs/api/index.html @@ -5,9 +5,9 @@ - PLACEHOLDER + Open.Database.Extensions - + @@ -67,9 +67,85 @@
-

PLACEHOLDER

+

Open.Database.Extensions

-

TODO: Add .NET projects to the src folder and run docfx to generate REAL API Documentation!

+

GitHub

+

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

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

Extensions

+

Instead of writing this:

+
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:

+
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.)

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

If the database fields don't map exactly:

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

or

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

or

+
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:

+
// 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>();
+    }));
+
diff --git a/docs/index.html b/docs/index.html index 8639a0f..a3b69a3 100644 --- a/docs/index.html +++ b/docs/index.html @@ -62,7 +62,7 @@

Open.Database.Extensions

-

(Full API Documenation)[]

+

Full API Documentation

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.

diff --git a/docs/manifest.json b/docs/manifest.json index 26caada..622db8b 100644 --- a/docs/manifest.json +++ b/docs/manifest.json @@ -9,10 +9,10 @@ "output": { ".html": { "relative_path": "README.html", - "hash": "tyD8A/u7sWAfe+8R1dLxxA==" + "hash": "6n0p5fClpr18KwRHo3OGSg==" } }, - "is_incremental": true, + "is_incremental": false, "version": "" }, { @@ -405,10 +405,10 @@ "output": { ".html": { "relative_path": "api/index.html", - "hash": "tF+QKSRFfWltk151Do+gpA==" + "hash": "R3roe74Czsq4LUqX9ardkg==" } }, - "is_incremental": true, + "is_incremental": false, "version": "" }, { @@ -429,10 +429,10 @@ "output": { ".html": { "relative_path": "index.html", - "hash": "WT75xuCxVHlY08oHgFRFfg==" + "hash": "+6gZq5CVqvXPB5cqlxvhdQ==" } }, - "is_incremental": true, + "is_incremental": false, "version": "" }, { @@ -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", @@ -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 } } },