A thin wrapper above sqlite using the JSON1
apis turn it into a NOSQL
database.
This library references and uses SQLitePCLRaw.bundle_e_sqlite3
version 2.1.2
and later witch ensures that the JSON1 APIS
are present.
The library executes Batteries.Init();
for you when a connection is first initialized.
Create an instance of NoSQLiteConnection
.
var connection = new NoSQLiteConnection(
"path to database file", // Required
json_options) // Optional JsonSerializerOptions
The connection configures the PRAGMA journal_mode
to be WAL
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 ¯\ (ツ)/¯.
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.
Tables are created if they do not exist.
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
.
Example class that will be used below:
public class Person
{
public string Name { get; set; }
public string Surname { get; set; }
public string? Description { get; set; }
}
var connection = new NoSQLiteConnection("path to database file", "json options or null");
var docs = connection.GetTable();
Creating or Updating a document happens from the same Insert
method, keep in mind that this always replaces the document with the new one.
var panos = new Person
{
Name = "panoukos",
Surname = "41",
Description = "C# dev"
}
docs.Insert("panos", panos); // If it exists it is now replaced/updated.
var doc = docs.Get<Person>("panos"); // Get the document or null.
docs.Remove("panos"); // Will remove the document.
docs.Remove("panos"); // Will still succeed even if the document doesn't exist.
To build this project .NET 7 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!