Skip to content

Commit 71a8005

Browse files
committed
- readme
1 parent 662ae5c commit 71a8005

2 files changed

Lines changed: 59 additions & 57 deletions

File tree

README.md

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
# Shuttle.Core.Data
22

3-
Provides a thin abstraction over ADO.NET.
3+
```
4+
PM> Install-Package Shuttle.Core.Data
5+
```
46

5-
The following may be found on the [documentation site](http://shuttle.github.io/shuttle-core/overview-data/):
7+
Provides a thin abstraction over ADO.NET.
68

79
# Overview
810

9-
The `Shuttle.Core.Data` package provides a thin abstraction over ADO.NET by making use of the `DbProviderFactories`. Even though it provides object/relational mapping mechasnims it is in no way an ORM.
11+
The `Shuttle.Core.Data` package provides a thin abstraction over ADO.NET by making use of the `DbProviderFactories` (see `Shuttle.Core.Data.SqlClient` for .Net Core Provider Factory adapter). Even though it provides object/relational mapping mechanisms it is in no way an ORM.
1012

1113
# IDatabaseContextFactory
1214

1315
As per usual, in order to access a database, we need a database connection. A database connection is represented by a `IDatabaseContext` instance that may be obtained by using an instance of an `IDatabaseContextFactory` implementation.
1416

15-
The `DatabaseContextFactory` implmentation makes use of an `IDbConnectionFactory` implementation, that creates a `System.Data.IDbConnection` by using the provider name and connection string, an `IDbCommandFactory` that creates a `System.Data.IDbCommand` by using `IDbConnection` instance. The `DatabaseContextFactory` also requires an instance of a `IDatabaseContextCache` that stores connections and is assigned to the `DatabaseContext` in order to obtain the active connection.
17+
The `DatabaseContextFactory` implementation makes use of an `IDbConnectionFactory` implementation, that creates a `System.Data.IDbConnection` by using the provider name and connection string, an `IDbCommandFactory` that creates a `System.Data.IDbCommand` by using `IDbConnection` instance. The `DatabaseContextFactory` also requires an instance of a `IDatabaseContextCache` that stores connections and is assigned to the `DatabaseContext` in order to obtain the active connection.
1618

17-
~~~ c#
19+
``` c#
1820
var factory = DatabaseContextFactory.Default();
1921

2022
using (var context = factory.Create("connectionStringName"))
@@ -33,19 +35,19 @@ using (var context = factory.Create(existingIDbConnection))
3335
{
3436
// database interaction
3537
}
36-
~~~
38+
```
3739

3840
# IConfiguredDatabaseContextFactory
3941

4042
You can pre-configure your database context factory using this interface. If you typically connect to only one data source this may be helpful:
4143

42-
~~~ c#
44+
``` c#
4345
IDatabaseContext Create();
4446

4547
void ConfigureWith(string connectionStringName);
4648
void ConfigureWith(string providerName, string connectionString);
4749
void ConfigureWith(IDbConnection dbConnection);
48-
~~~
50+
```
4951

5052
# IDatabaseGateway
5153

@@ -55,49 +57,49 @@ The following section each describe the methods available in the `IDatabaseGatew
5557

5658
## GetReaderUsing
5759

58-
~~~ c#
60+
``` c#
5961
IDataReader GetReaderUsing(IQuery query);
60-
~~~
62+
```
6163

6264
Returns an `IDataReader` instance for the given `select` statement:
6365

64-
~~~ c#
66+
``` c#
6567
var factory = DatabaseContextFactory.Default();
6668
var gateway = new DatabaseGateway();
6769

6870
using (var context = factory.Create("connectionStringName"))
6971
{
7072
var reader = gateway.GetReaderUsing(RawQuery.Create("select Id, Username from dbo.Member"));
7173
}
72-
~~~
74+
```
7375

7476
## ExecuteUsing
7577

76-
~~~ c#
78+
``` c#
7779
int ExecuteUsing(IQuery query);
78-
~~~
80+
```
7981

8082
Executes the given query and returns the number of rows affected:
8183

82-
~~~ c#
84+
``` c#
8385
var factory = DatabaseContextFactory.Default();
8486
var gateway = new DatabaseGateway();
8587

8688
using (var context = factory.Create("connectionStringName"))
8789
{
8890
gateway.ExecuteUsing(RawQuery.Create("delete from dbo.Member where Username = 'mr.resistor'"));
8991
}
90-
~~~
92+
```
9193

9294
## GetScalarUsing<T>
9395

94-
~~~ c#
96+
``` c#
9597
T GetScalarUsing<T>(IQuery query);
96-
~~~
98+
```
9799

98100
Get the scalar value returned by the `select` query. The query shoud return only one value (scalar):
99101

100-
~~~ c#
102+
``` c#
101103
var factory = DatabaseContextFactory.Default();
102104
var gateway = new DatabaseGateway();
103105

@@ -111,54 +113,54 @@ using (var context = factory.Create("connectionStringName"))
111113
RawQuery.Create("select Id from dbo.Member where Username = 'mr.resistor'")
112114
);
113115
}
114-
~~~
116+
```
115117

116118
## GetDataTableFor
117119

118-
~~~ c#
120+
``` c#
119121
DataTable GetDataTableFor(IQuery query);
120-
~~~
122+
```
121123

122124
Returns a `DataTable` containing the rows returned for the given `select` statement.
123125

124-
~~~ c#
126+
``` c#
125127
var factory = DatabaseContextFactory.Default();
126128
var gateway = new DatabaseGateway();
127129

128130
using (var context = factory.Create("connectionStringName"))
129131
{
130132
var table = gateway.GetDataTableFor(RawQuery.Create("select Id, Username from dbo.Member"));
131133
}
132-
~~~
134+
```
133135

134136
## GetRowsUsing
135137

136-
~~~ c#
138+
``` c#
137139
IEnumerable<DataRow> GetRowsUsing(IQuery query);
138-
~~~
140+
```
139141

140142
Returns an enumerable containing the `DataRow` instances returned for a `select` query:
141143

142-
~~~ c#
144+
``` c#
143145
var factory = DatabaseContextFactory.Default();
144146
var gateway = new DatabaseGateway();
145147

146148
using (var context = factory.Create("connectionStringName"))
147149
{
148150
var rows = gateway.GetRowsUsing(RawQuery.Create("select Id, Username from dbo.Member"));
149151
}
150-
~~~
152+
```
151153

152154

153155
## GetSingleRowUsing
154156

155-
~~~ c#
157+
``` c#
156158
DataRow GetSingleRowUsing(IQuery query);
157-
~~~
159+
```
158160

159161
Returns a single `DataRow` containing the values returned for a `select` statement that returns exactly one row:
160162

161-
~~~ c#
163+
``` c#
162164
var factory = DatabaseContextFactory.Default();
163165
var gateway = new DatabaseGateway();
164166

@@ -168,7 +170,7 @@ using (var context = factory.Create("connectionStringName"))
168170
RawQuery.Create("select Id, Username, EMail, DateActivated from dbo.Member where Id = 10")
169171
);
170172
}
171-
~~~
173+
```
172174

173175
# IDataRepository<T>
174176

@@ -178,51 +180,51 @@ The following methods can be used to interact with your object type.
178180

179181
## FetchAllUsing
180182

181-
~~~ c#
183+
``` c#
182184
IEnumerable<T> FetchAllUsing(IQuery query);
183-
~~~
185+
```
184186

185187
Uses the `select` clause represented by the `IQuery` instance to create a list of objects of type `T`. The `select` clause will need to select all the required columns and will, typically, return more than one instance.
186188

187189
## FetchItemUsing
188190

189-
~~~ c#
191+
``` c#
190192
T FetchItemUsing(IQuery query);
191-
~~~
193+
```
192194

193195
Returns a single object instance of type `T` that is hydrated using the data returned from the `select` clause represented by the `IQuery` instance.
194196

195197
## FetchMappedRowsUsing
196198

197-
~~~ c#
199+
``` c#
198200
IEnumerable<MappedRow<T>> FetchMappedRowsUsing(IQuery query);
199-
~~~
201+
```
200202

201203
This is similar to the `FetchAllUsing` method but instead returns a list of `MappedRow<T>` instances. Uses the `select` clause represented by the `IQuery` instance to create a list of `MappedRow` instances of type `T`. The `select` clause will need to select all the required columns and will, typically, return more than one instance.
202204

203205
## FetchMappedRowUsing
204206

205-
~~~ c#
207+
``` c#
206208
MappedRow<T> FetchMappedRowUsing(IQuery query);
207-
~~~
209+
```
208210

209211
Similar to the `FetchItemUsing` method but instead return a `MappedRow<T>` instance that is hydrated using the data returned from the `select` clause represented by the `IQuery` instance.
210212

211213
## Contains
212214

213-
~~~ c#
215+
``` c#
214216
bool Contains(IQuery query);
215-
~~~
217+
```
216218

217219
Returns `true` is the `IQuery` instance `select` clause returns an `int` scalar that equals `1`; else returns `false`.
218220

219221
# IQuery
220222

221223
An `IQuery` represent a database query that can be executed against the relevant database type. There is only one method that needs to be implemented:
222224

223-
~~~ c#
225+
``` c#
224226
void Prepare(IDbCommand command);
225-
~~~
227+
```
226228

227229
This should ensure that the given `IDbCommand` is configured for execution by setting the relvant command attributes and parameters.
228230

@@ -236,27 +238,27 @@ There are two implementations of this interface.
236238

237239
The `RawQuery` enables you to create any query using the native language structure:
238240

239-
~~~ c#
241+
``` c#
240242
var query = RawQuery.Create("select UserName from dbo.Member where Id = @Id")
241243
.AddParameterValue(new MappedColumn<Guid>("Id", DbType.Guid),
242244
new Guid('{75208260-CF93-454E-95EC-FE1903F3664E}'));
243-
~~~
245+
```
244246

245247
## ProcedureQuery
246248

247249
The `ProcedureQuery` is used to execute a stored procedure:
248250

249-
~~~ c#
251+
``` c#
250252
var query = ProcedureQuery.Create("uspMemberById")
251253
.AddParameterValue(new MappedColumn<Guid>("Id", DbType.Guid),
252254
new Guid('{75208260-CF93-454E-95EC-FE1903F3664E}'));
253-
~~~
255+
```
254256

255257
# MappedColumn
256258

257259
Typically you would not want to create a `MappedColumn` each time you need it and these are also quite fixed. A column mapping can, therefore, by defined statically:
258260

259-
~~~ c#
261+
``` c#
260262
using System;
261263
using System.Data;
262264
using Shuttle.Core.Data;
@@ -281,23 +283,23 @@ namespace Shuttle.Ordering.DataAccess
281283
new MappedColumn<string>("CustomerEMail", DbType.String, 130);
282284
}
283285
}
284-
~~~
286+
```
285287

286288
There are quite a few options that you can set on the `MappedColumn` in order to represent your column properly.
287289

288290
## MapFrom
289291

290-
~~~ c#
292+
``` c#
291293
public T MapFrom(DataRow row)
292-
~~~
294+
```
293295

294296
This will return the typed value of the specified column as contained in the passed-in `DataRow`.
295297

296298
# IDataRowMapper<T>
297299

298300
You use this interface to implement a mapper for a `DataRow` that will result in an object of type `T`:
299301

300-
~~~ c#
302+
``` c#
301303
using System.Data;
302304
using Shuttle.Core.Data;
303305
using Shuttle.Process.Custom.Server.Domain;
@@ -322,7 +324,7 @@ namespace Shuttle.ProcessManagement
322324
}
323325
}
324326
}
325-
~~~
327+
```
326328

327329
# MappedRow
328330

@@ -356,7 +358,7 @@ An `IAssembler` implementation is used to create multiple mappings with as few c
356358

357359
Using a `MappedData` instance we can keep adding the `MappedRow` instances to the `MappedData` and then have the assembler return the three `Order` aggregates:
358360

359-
~~~ c#
361+
``` c#
360362
public class OrderAssembler : IAssembler<Order>
361363
{
362364
public IEnumerable<Order> Assemble(MappedData data)
@@ -381,4 +383,4 @@ public class OrderAssembler : IAssembler<Order>
381383
return result;
382384
}
383385
}
384-
~~~
386+
```

Shuttle.Core.Data.Tests/DatabaseContextFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void Should_not_be_able_to_create_an_invalid_connection()
1414
{
1515
Assert.Throws<ArgumentException>(() =>
1616
{
17-
using (new DatabaseContext("System.Data.SqlClient", new SqlConnection("~~~"), new Mock<IDbCommandFactory>().Object))
17+
using (new DatabaseContext("System.Data.SqlClient", new SqlConnection("```"), new Mock<IDbCommandFactory>().Object))
1818
{
1919
}
2020
});

0 commit comments

Comments
 (0)