Skip to content

Commit 4b3217f

Browse files
author
Oren (electricessence)
committed
API Documentation
1 parent 1275716 commit 4b3217f

File tree

58 files changed

+36247
-5567
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+36247
-5567
lines changed

Documentation.md

Lines changed: 0 additions & 3120 deletions
This file was deleted.

Open.Database.Extensions.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@
3232
</ItemGroup>
3333

3434
<ItemGroup>
35+
<PackageReference Include="docfx.console" Version="2.32.0" />
3536
<PackageReference Include="System.Data.SqlClient" Version="4.4.2" />
3637
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="4.8.0" />
3738
</ItemGroup>
3839

39-
<ItemGroup>
40-
<Folder Include="docs\images\" />
41-
</ItemGroup>
42-
4340
</Project>

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

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

5+
[Full API Documentation Click Here](https://electricessence.github.io/Open.Database.Extensions/Documentation.html)
6+
57
## Connection Factories
68

79
Connection factories facilitate creation and disposal of connections without the concern of a connection reference or need for awareness of a connection string. A `SqlConnectionFactory` is provided and can be overriden to provide more specific dependency injection configurations.

api/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
###############
2+
# temp file #
3+
###############
4+
*.yml

api/.manifest

Lines changed: 259 additions & 0 deletions
Large diffs are not rendered by default.

api/index.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Open.Database.Extensions
2+
3+
Useful set of utilities and abstractions for simplifying modern database operations and ensuring dependency injection compatibility.
4+
5+
## Connection Factories
6+
7+
Connection factories facilitate creation and disposal of connections without the concern of a connection reference or need for awareness of a connection string. A `SqlConnectionFactory` is provided and can be overriden to provide more specific dependency injection configurations.
8+
9+
## Expressive Commands
10+
11+
The provided expressive command classes allow for an expressive means to append parameters and execute the results without lenghty complicated setup.
12+
13+
Extensions are provied to create commands from connection factories.
14+
15+
##### Example
16+
17+
```cs
18+
var result = connectionFactory
19+
.StoredProcedure("[procedure name]")
20+
.AddParam("a",1)
21+
.AddParam("b",true)
22+
.AddParam("c","hello")
23+
.ExecuteScalar();
24+
```
25+
26+
27+
## Asynchronous
28+
29+
End-to-end asynchronous methods suffixed with `Async`.
30+
31+
When using the SQL Client, asychronous methods are available as well as `.ToTargetBlockAsync<T>(target)` and `.AsSourceBlockAsync<T>()` Dataflow methods.
32+
33+
## Extensions
34+
35+
Instead of writing this:
36+
```cs
37+
var myResult = new List<T>();
38+
using(var reader = await mySqlCommand.ExecuteReaderAsync(CommandBehavior.CloseConnection))
39+
{
40+
while(await reader.ReadAsync())
41+
list.Add(transform(reader));
42+
}
43+
```
44+
45+
Is now simplifed to this:
46+
```cs
47+
var myResult = await cmd.ToListAsync(transform);
48+
```
49+
50+
## Deferred Transformation
51+
52+
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.
53+
54+
#### `Results<T>()` and `ResultsAsync<T>()`
55+
56+
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`.
57+
58+
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).
59+
60+
##### Examples
61+
62+
If all the columns in the database map exactly to a field: (A column that has no associated field/property is ignored.)
63+
```cs
64+
var people = cmd.Results<Person>();
65+
```
66+
67+
If the database fields don't map exactly:
68+
69+
```cs
70+
var people = cmd.Results<Person>(
71+
(Field:"FirstName", Column:"first_name"),
72+
(Field:"LastName", Column:"last_name")));
73+
```
74+
or
75+
```cs
76+
var people = cmd.Results<Person>(
77+
("FirstName", "first_name"),
78+
("LastName", "last_name"));
79+
```
80+
or
81+
```cs
82+
var people = cmd.Results<Person>(new Dictionary<string,string>{
83+
{"FirstName", "first_name"},
84+
{"LastName", "last_name"});
85+
```
86+
87+
#### `Retrieve()` and `RetrieveAsync()`
88+
89+
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.
90+
91+
#### `AsSourceBlockAsync<T>()`
92+
93+
(Fully asynchronous.) Retuns a Dataflow source block. Then asynchronously buffers and transforms the results allowing for any possible Dataflow configuration. The source block is marked as complete when there are no more results. If the block is somehow marked as complete externally, the flow of data will stop and the connection will close.
94+
95+
### `AsSourceBlockAsync<T>()` versus `ResultsAsync<T>`
96+
97+
Depending on the level of asynchrony in your application, you may want to avoid too much buffering of data.
98+
99+
`AsSourceBlockAsync<T>()` is fully asynchronous from end-to-end and can keep total buffering to a minimum by consuming (receiving) results as fast as possible, but may incur additional latency between reads.
100+
101+
`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.
102+
103+
Both methods ultimately are using a `Queue<object[]>` or `ConcurrentQueue<object[]>` (Dataflow) to buffer the data, but `ResultsAsync<T>()` buffers the entire data set before dequeuing and transforming the results.

docfx.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"metadata": [
3+
{
4+
"src": [
5+
{
6+
"files": [
7+
"**.csproj"
8+
],
9+
"src": "D:\\Users\\essence\\Development\\- GitHub\\Open.Database.Extensions"
10+
}
11+
],
12+
"dest": "api",
13+
"disableGitFeatures": false
14+
}
15+
],
16+
"build": {
17+
"content": [
18+
{
19+
"files": [
20+
"api/**.yml",
21+
"api/index.md"
22+
]
23+
},
24+
{
25+
"files": [
26+
"toc.yml",
27+
"*.md"
28+
]
29+
}
30+
],
31+
"resource": [
32+
{
33+
"files": [
34+
"images/**"
35+
]
36+
}
37+
],
38+
"overwrite": [
39+
{
40+
"files": [
41+
"apidoc/**.md"
42+
],
43+
"exclude": [
44+
"obj/**",
45+
"docs/**"
46+
]
47+
}
48+
],
49+
"dest": "docs",
50+
"globalMetadataFiles": [],
51+
"fileMetadataFiles": [],
52+
"template": [
53+
"default"
54+
],
55+
"postProcessors": [],
56+
"noLangKeyword": false,
57+
"keepFileLink": false,
58+
"cleanupCacheHistory": false,
59+
"disableGitFeatures": false
60+
}
61+
}

0 commit comments

Comments
 (0)