A C# library built using SQLitePCL.raw to use SQLite as a NoSQL database.
The library aims to provide simple low level methods that are used to create your own data access layers. For now the library uses a single connection class which creates/uses tables that have a single column called documents. In reality it should work for other tables with more columns as long as they contain one column called documents but no tests have been made or run for this use case.
Important
To use the library you must ensure you are using an SQLite that contains the JSON1 extension. As of version 3.38.0 (2022-02-22) the JSON functions and operators are built into SQLite by default.
Install some version of SQLitePCL.raw to create your sqlite3 object.
Tip
You can look at the test project for more pragmatic usage. The test project uses SQLitePCLRaw.bundle_e_sqlite3 nuget pacakge to use sqlite.
Using your sqlite3 db create a new instances of the NoSQLiteConnection and optionally pass a JsonSerializerOptions object.
Caution
Once you use the connection be very careful on the consequences of switching your JsonSerializerOptions object.
Note
Disposing NoSQLiteConnection will not close your sqlite3 db or do anything with it. It will just cleanup it's associated table and statement instances.
You get a table using connection.GetTable({TableName})
Note
Tables are created if they do not exist. If you request a table multiple times you will always get the same table instance.
At the table level the following methods are supported:
| Method | Description |
|---|---|
| Count/CountLong | Returns the number of rows in the table. |
| All | Returns all rows in the table. Deserialized to T |
| Clear | Clears the table. |
| Exists | Check if a document exists. |
| Find | Returns the document if it exists or throws. |
| Add | Adds a document. |
| Update | Updates a document (replace). |
| Delete | Deletes a document. |
| IndexExists | Check if an index exists. |
| CreateIndex | Creates an index if it does not exists using "{TableName}_{IndexName}" (can also set unique flag). |
| DeleteIndex | Deletes an index if it does exist. |
At the document level the following methods are supported:
| Method | Description |
|---|---|
| FindProperty | Finds a document by key and returns a property value. |
| Insert | Inserts a property value into a document by key. Overwrite NO, Create YES. |
| Replace | Replaces a property value in a document by key. Overwrite YES, Create NO. |
| Set | Sets a property value in a document by key. Overwrite YES, Create YES. |
- For connection creation look at the TestBase Before and After methods of the _setup.cs file.
- For CRUD examples look at the CRUD method of the Table.cs file.
- For INDEX examples look at the Index and Index_Unique methods of the Table.cs file.
To build this project .NET 10 is needed.
Contributions are welcome and appreciated, before you create a pull request please open a GitHub Issue to discuss what needs changing and or fixing if the issue doesn't exist!