Skip to content

Latest commit

 

History

History
82 lines (60 loc) · 3.13 KB

README.md

File metadata and controls

82 lines (60 loc) · 3.13 KB

NoSQLite: NoSQL on top of SQLite

Release NuGet MIT License

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.

Getting Started

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 ¯\ (ツ)/¯.

Tables

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.

Document Management

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();

Create/Update documents.

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.

Get documents.

var doc = docs.Get<Person>("panos"); // Get the document or null.

Delete documents.

docs.Remove("panos"); // Will remove the document.
docs.Remove("panos"); // Will still succeed even if the document doesn't exist.

Build

To build this project .NET 7 is needed.

Contribute

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!