Skip to content

Commit 73d114d

Browse files
committed
#880 - Separated the MDS and SDS library.
1 parent 7ece61c commit 73d114d

File tree

122 files changed

+35740
-0
lines changed

Some content is hidden

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

122 files changed

+35740
-0
lines changed

RepoDb.SQLite.System/README.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
[![SqLiteBuild](https://img.shields.io/appveyor/ci/mikependon/repodb-o6787?&logo=appveyor)](https://ci.appveyor.com/project/mikependon/repodb-o6787)
2+
[![SqLiteHome](https://img.shields.io/badge/home-github-important?&logo=github)](https://github.com/mikependon/RepoDb)
3+
[![SqLiteVersion](https://img.shields.io/nuget/v/RepoDb.SqLite?&logo=nuget)](https://www.nuget.org/packages/RepoDb.SqLite)
4+
[![SqLiteReleases](https://img.shields.io/badge/releases-core-important?&logo=nuget)](http://repodb.net/release/sqlite)
5+
[![SqLiteUnitTests](https://img.shields.io/appveyor/tests/mikependon/repodb-mhpo4?&logo=appveyor&label=unit%20tests)](https://ci.appveyor.com/project/mikependon/repodb-mhpo4/build/tests)
6+
[![SqLiteIntegrationTests](https://img.shields.io/appveyor/tests/mikependon/repodb-eg27p?&logo=appveyor&label=integration%20tests)](https://ci.appveyor.com/project/mikependon/repodb-eg27p/build/tests)
7+
8+
# RepoDb.SqLite - a hybrid .NET ORM library for SQLite.
9+
10+
RepoDB is an open-source .NET ORM library that bridges the gaps of micro-ORMs and full-ORMs. It helps you simplify the switch-over of when to use the BASIC and ADVANCE operations during the development.
11+
12+
## News/Updates
13+
14+
- Starting at version 1.0.15, the SQLite driver [System.Data.SQLite](https://www.nuget.org/packages/System.DataSQLite) has been removed.
15+
- Starting at version 1.0.16, both the SQLite drivers ([Microsoft.Data.Sqlite](https://www.nuget.org/packages/Microsoft.Data.Sqlite/) and [System.Data.SQLite.Core](https://www.nuget.org/packages/System.Data.SQLite.Core/)) has been supported.
16+
17+
## Important Pages
18+
19+
- [GitHub Home Page](https://github.com/mikependon/RepoDb) - to learn more about the core library.
20+
- [Website](http://repodb.net) - docs, features, classes, references, releases and blogs.
21+
22+
## Community engagements
23+
24+
- [GitHub](https://github.com/mikependon/RepoDb/issues) - for any issues, requests and problems.
25+
- [StackOverflow](https://stackoverflow.com/search?q=RepoDB) - for any technical questions.
26+
- [Twitter](https://twitter.com/search?q=%23repodb) - for the latest news.
27+
- [Gitter Chat](https://gitter.im/RepoDb/community) - for direct and live Q&A.
28+
29+
## Dependencies
30+
31+
- [RepoDb](https://www.nuget.org/packages/RepoDb/) - the core library of RepoDB.
32+
- [Microsoft.Data.Sqlite](https://www.nuget.org/packages/Microsoft.Data.Sqlite.Core/) - the data provider used for SqLite (Microsoft).
33+
- [System.Data.SQLite.Core](https://www.nuget.org/packages/System.Data.SQLite.Core/) - the data provider used for SqLite (SQLite).
34+
35+
## License
36+
37+
[Apache-2.0](http://apache.org/licenses/LICENSE-2.0.html) - Copyright © 2019 - [Michael Camara Pendon](https://twitter.com/mike_pendon)
38+
39+
--------
40+
41+
## Installation
42+
43+
At the Package Manager Console, write the command below.
44+
45+
```csharp
46+
> Install-Package RepoDb.SqLite
47+
```
48+
49+
Or, visit our [installation](http://repodb.net/tutorial/installation) page for more information.
50+
51+
## Get Started
52+
53+
First, the bootstrapper must be initialized.
54+
55+
```csharp
56+
RepoDb.SqLiteBootstrap.Initialize();
57+
```
58+
59+
**Note:** The call must be done once.
60+
61+
After the bootstrap initialization, any library operation can then be called.
62+
63+
Or, visit the official [get-started](http://repodb.net/tutorial/get-started-sqlite) page for SQLite.
64+
65+
### Query
66+
67+
```csharp
68+
using (var connection = new SQLiteConnection(ConnectionString))
69+
{
70+
var customer = connection.Query<Customer>(c => c.Id == 10045);
71+
}
72+
```
73+
74+
### Insert
75+
76+
```csharp
77+
var customer = new Customer
78+
{
79+
FirstName = "John",
80+
LastName = "Doe",
81+
IsActive = true
82+
};
83+
using (var connection = new SQLiteConnection(ConnectionString))
84+
{
85+
var id = connection.Insert<Customer>(customer);
86+
}
87+
```
88+
89+
### Update
90+
91+
```csharp
92+
using (var connection = new SQLiteConnection(ConnectionString))
93+
{
94+
var customer = connection.Query<Customer>(10045);
95+
customer.FirstName = "John";
96+
customer.LastUpdatedUtc = DateTime.UtcNow;
97+
var affectedRows = connection.Update<Customer>(customer);
98+
}
99+
```
100+
101+
### Delete
102+
103+
```csharp
104+
using (var connection = new SQLiteConnection(ConnectionString))
105+
{
106+
var customer = connection.Query<Customer>(10045);
107+
var deletedCount = connection.Delete<Customer>(customer);
108+
}
109+
```
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
using System;
2+
using System.Data.SQLite;
3+
using System.Linq;
4+
using Microsoft.VisualStudio.TestTools.UnitTesting;
5+
using RepoDb.SqLite.IntegrationTests.Models;
6+
using RepoDb.SqLite.IntegrationTests.Setup;
7+
8+
namespace RepoDb.SqLite.IntegrationTests.SDS
9+
{
10+
[TestClass]
11+
public class DbHelperTests
12+
{
13+
[TestInitialize]
14+
public void Initialize()
15+
{
16+
Database.Initialize();
17+
Cleanup();
18+
}
19+
20+
[TestCleanup]
21+
public void Cleanup()
22+
{
23+
Database.Cleanup();
24+
}
25+
26+
#region GetFields
27+
28+
#region Sync
29+
30+
[TestMethod]
31+
public void TestDbHelperGetFields()
32+
{
33+
using (var connection = new SQLiteConnection(Database.ConnectionStringSDS))
34+
{
35+
// Setup
36+
var helper = connection.GetDbHelper();
37+
var tables = Database.CreateSdsCompleteTables(10, connection);
38+
39+
// Act
40+
var fields = helper.GetFields(connection, "SdsCompleteTable", null);
41+
42+
// Assert
43+
using (var reader = connection.ExecuteReader("pragma table_info([SdsCompleteTable]);"))
44+
{
45+
var fieldCount = 0;
46+
47+
while (reader.Read())
48+
{
49+
var name = reader.GetString(1);
50+
var field = fields.FirstOrDefault(f => string.Equals(f.Name, name, StringComparison.OrdinalIgnoreCase));
51+
52+
// Assert
53+
Assert.IsNotNull(field);
54+
55+
fieldCount++;
56+
}
57+
58+
// Assert
59+
Assert.AreEqual(fieldCount, fields.Count());
60+
}
61+
}
62+
}
63+
64+
[TestMethod]
65+
public void TestDbHelperGetFieldsPrimary()
66+
{
67+
using (var connection = new SQLiteConnection(Database.ConnectionStringSDS))
68+
{
69+
// Setup
70+
var helper = connection.GetDbHelper();
71+
var tables = Database.CreateSdsCompleteTables(10, connection);
72+
73+
// Act
74+
var fields = helper.GetFields(connection, "SdsCompleteTable", null);
75+
var primary = fields.FirstOrDefault(f => f.IsPrimary == true);
76+
77+
// Assert
78+
Assert.IsNotNull(primary);
79+
Assert.AreEqual("Id", primary.Name);
80+
}
81+
}
82+
83+
[TestMethod]
84+
public void TestDbHelperGetFieldsIdentity()
85+
{
86+
using (var connection = new SQLiteConnection(Database.ConnectionStringSDS))
87+
{
88+
// Setup
89+
var helper = connection.GetDbHelper();
90+
var tables = Database.CreateSdsCompleteTables(10, connection);
91+
92+
// Act
93+
var fields = helper.GetFields(connection, "SdsCompleteTable", null);
94+
var primary = fields.FirstOrDefault(f => f.IsIdentity == true);
95+
96+
// Assert
97+
Assert.IsNotNull(primary);
98+
Assert.AreEqual("Id", primary.Name);
99+
}
100+
}
101+
102+
#endregion
103+
104+
#region Async
105+
106+
[TestMethod]
107+
public void TestDbHelperGetFieldsAsync()
108+
{
109+
using (var connection = new SQLiteConnection(Database.ConnectionStringSDS))
110+
{
111+
// Setup
112+
var helper = connection.GetDbHelper();
113+
var tables = Database.CreateSdsCompleteTables(10, connection);
114+
115+
// Act
116+
var fields = helper.GetFieldsAsync(connection, "SdsCompleteTable", null).Result;
117+
118+
// Assert
119+
using (var reader = connection.ExecuteReader("pragma table_info([SdsCompleteTable]);"))
120+
{
121+
var fieldCount = 0;
122+
123+
while (reader.Read())
124+
{
125+
var name = reader.GetString(1);
126+
var field = fields.FirstOrDefault(f => string.Equals(f.Name, name, StringComparison.OrdinalIgnoreCase));
127+
128+
// Assert
129+
Assert.IsNotNull(field);
130+
131+
fieldCount++;
132+
}
133+
134+
// Assert
135+
Assert.AreEqual(fieldCount, fields.Count());
136+
}
137+
}
138+
}
139+
140+
[TestMethod]
141+
public void TestDbHelperGetFieldsAsyncPrimary()
142+
{
143+
using (var connection = new SQLiteConnection(Database.ConnectionStringSDS))
144+
{
145+
// Setup
146+
var helper = connection.GetDbHelper();
147+
var tables = Database.CreateSdsCompleteTables(10, connection);
148+
149+
// Act
150+
var fields = helper.GetFieldsAsync(connection, "SdsCompleteTable", null).Result;
151+
var primary = fields.FirstOrDefault(f => f.IsPrimary == true);
152+
153+
// Assert
154+
Assert.IsNotNull(primary);
155+
Assert.AreEqual("Id", primary.Name);
156+
}
157+
}
158+
159+
[TestMethod]
160+
public void TestDbHelperGetFieldsAsyncIdentity()
161+
{
162+
using (var connection = new SQLiteConnection(Database.ConnectionStringSDS))
163+
{
164+
// Setup
165+
var helper = connection.GetDbHelper();
166+
var tables = Database.CreateSdsCompleteTables(10, connection);
167+
168+
// Act
169+
var fields = helper.GetFieldsAsync(connection, "SdsCompleteTable", null).Result;
170+
var primary = fields.FirstOrDefault(f => f.IsIdentity == true);
171+
172+
// Assert
173+
Assert.IsNotNull(primary);
174+
Assert.AreEqual("Id", primary.Name);
175+
}
176+
}
177+
178+
#endregion
179+
180+
#endregion
181+
182+
#region GetScopeIdentity
183+
184+
#region Sync
185+
186+
[TestMethod]
187+
public void TestDbHelperGetScopeIdentity()
188+
{
189+
using (var connection = new SQLiteConnection(Database.ConnectionStringSDS))
190+
{
191+
// Create the tables
192+
Database.CreateSdsTables(connection);
193+
194+
// Setup
195+
var helper = connection.GetDbHelper();
196+
var table = Helper.CreateSdsCompleteTables(1).First();
197+
198+
// Act
199+
var insertResult = connection.Insert<SdsCompleteTable>(table);
200+
201+
// Assert
202+
Assert.IsTrue(Convert.ToInt64(insertResult) > 0);
203+
Assert.IsTrue(table.Id > 0);
204+
205+
// Act
206+
var result = helper.GetScopeIdentity(connection, null);
207+
208+
// Assert
209+
Assert.AreEqual(insertResult, result);
210+
}
211+
}
212+
213+
#endregion
214+
215+
#region Async
216+
217+
[TestMethod]
218+
public void TestDbHelperGetScopeIdentityAsync()
219+
{
220+
using (var connection = new SQLiteConnection(Database.ConnectionStringSDS))
221+
{
222+
// Create the tables
223+
Database.CreateSdsTables(connection);
224+
225+
// Setup
226+
var helper = connection.GetDbHelper();
227+
var table = Helper.CreateSdsCompleteTables(1).First();
228+
229+
// Act
230+
var insertResult = connection.Insert<SdsCompleteTable>(table);
231+
232+
// Assert
233+
Assert.IsTrue(Convert.ToInt64(insertResult) > 0);
234+
Assert.IsTrue(table.Id > 0);
235+
236+
// Act
237+
var result = helper.GetScopeIdentityAsync(connection, null).Result;
238+
239+
// Assert
240+
Assert.AreEqual(insertResult, result);
241+
}
242+
}
243+
244+
#endregion
245+
246+
#endregion
247+
}
248+
}

0 commit comments

Comments
 (0)