Skip to content

Commit ba76df7

Browse files
committed
Refactor the whole API
- Change the connection so it only manages tables and the `sqlite3` db connection. - Create `NoSQLiteTable` that manages a specific table. - Refactor some API names on the `NoSQLiteTable` class. - Update README.md to reflect the changes and better describe the library. - Update tests to use new names. - Bump version to `0.2 ...`
1 parent 7104008 commit ba76df7

File tree

6 files changed

+475
-367
lines changed

6 files changed

+475
-367
lines changed

README.md

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,31 @@
44
[![NuGet](https://buildstats.info/nuget/P41.NoSQLite?includePreReleases=true)](https://www.nuget.org/packages/P41.NoSQLite)
55
[![MIT License](https://img.shields.io/apm/l/atomic-design-ui.svg?)](https://github.com/panoukos41/NoSQLite/blob/main/LICENSE.md)
66

7-
A thin wrapper above sqlite to use it as a nosql database.
7+
A thin wrapper above sqlite using the [`JSON1`](https://www.sqlite.org/json1.html) apis turn it into a [`NOSQL`](https://en.wikipedia.org/wiki/NoSQL) database.
8+
9+
This library references and uses [`SQLitePCLRaw.bundle_e_sqlite3`](https://www.nuget.org/packages/SQLitePCLRaw.bundle_e_sqlite3) version `2.1.2` and later witch ensures that the [`JSON1 APIS`](https://www.sqlite.org/json1.html) are present.
10+
11+
The library executes `Batteries.Init();` for you when a connection is first initialized.
812

913
## Getting Started
1014

11-
All you need is an instance of `NoSQLiteConnection`. The instance requires a `string` that is a fully qualified path to the database file and you can also optionally provide your own `JsonSerializerOptions` to configure the JSON serialization/deserialization.
15+
Create an instance of `NoSQLiteConnection`.
16+
```csharp
17+
var connection = new NoSQLiteConnection(
18+
"path to database file", // Required
19+
json_options) // Optional JsonSerializerOptions
20+
```
1221

13-
`NoSQLiteConnection` creates and opens a connection when initialized so keep in mind that you will have to dispose it when you are done. Use the `Dispose` method of the `IDisposable interface`.
22+
The connection configures the `PRAGMA journal_mode` to be [`WAL`](https://www.sqlite.org/wal.html)
1423
15-
In most scenarios you will create it and store it for use until you shutdown your application.
24+
The connection manages an `sqlite3` object when initialized. *You should always dispose it when you are done so that the databases flashes `WAL` files* but you can also ignore it ¯\ (ツ)/¯.
1625

17-
The `sqlite` database is configured with `journal_mode` set to `WAL`.
26+
## Tables
1827

19-
## How It Works
28+
You get a table using `connection.GetTable()` you can optionaly provide a table name or leave it as it is to get the default `documents` table.
29+
> Tables are created if they do not exist.
2030

21-
It works by taking advantage of the [JSON1](https://www.sqlite.org/json1.html) through the [SQLitePCLRaw.bundle_e_sqlite3](https://www.nuget.org/packages/SQLitePCLRaw.bundle_e_sqlite3) nuget package that forces the correct version of sqlite to manipulate the documents, create indexes and more in the future!
31+
Tables are managed by their connections so you don't have to worry about disposing. If you request a table multiple times *(eg: the same name)* you will always get the same `Instance`.
2232

2333
## Document Management
2434

@@ -31,15 +41,16 @@ public class Person
3141
public string? Description { get; set; }
3242
}
3343
```
34-
35-
and the same connection:
3644
```csharp
37-
var db = new NoSQLiteConnection("path to database file", "json options or null");
45+
var connection = new NoSQLiteConnection("path to database file", "json options or null");
46+
```
47+
```csharp
48+
var docs = connection.GetTable();
3849
```
3950

4051
### Create/Update documents.
4152

42-
Creating or Updating a document happens from the same `insert` method, keep in mind that this always replaces the document with the new one.
53+
Creating or Updating a document happens from the same `Insert` method, keep in mind that this always replaces the document with the new one.
4354
```csharp
4455
var panos = new Person
4556
{
@@ -48,18 +59,18 @@ var panos = new Person
4859
Description = "C# dev"
4960
}
5061

51-
db.Insert("panos", panos); // If it exists it is now replaced/updated.
62+
docs.Insert("panos", panos); // If it exists it is now replaced/updated.
5263
```
5364

5465
### Get documents.
5566
```csharp
56-
var doc = db.Get<Person>("panos");
67+
var doc = docs.Get<Person>("panos"); // Get the document or null.
5768
```
5869

5970
#### Delete documents.
6071
```csharp
61-
db.Remove("panos"); // Will remove the document.
62-
db.Remove("panos"); // Will still succeed even if the document doesn't exist.
72+
docs.Remove("panos"); // Will remove the document.
73+
docs.Remove("panos"); // Will still succeed even if the document doesn't exist.
6374
```
6475

6576
## Build

0 commit comments

Comments
 (0)