From e04a63a4e0f35da7a61acca0b1b2ae0d12568d91 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sat, 3 May 2025 10:31:06 +0300 Subject: Update README --- README.md | 80 +++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 45 insertions(+), 35 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 5d0e82c..16407c6 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,12 @@ The most significant sources of inspiration for AutereDB are: for its excellent overview of database internals and in-depth analysis of log-structured storage. AutereDB is heavily based on the design outlined in chapter 3. +## In this repository + +- `autere_db`: The core Rust library +- `py_bindings`: Python bindings for the Rust library API +- `demo`: A simple Python chat app that demonstrates the usage of AutereDB + ## Usage in Rust Add AutereDB as a dependency in your `Cargo.toml`. @@ -42,6 +48,45 @@ autere_db = { git = "https://github.com/jantuomi/autere_db.git" } Then use it in your code like so: +```rust +fn example() -> DBResult<()> { + // Initialize the database + let mut db = DB::configure() + // Set the directory where the database files are stored. + .data_dir("data") + + // Select the database fields, i.e. columns. + .fields(vec![Field::Id, Field::Name]) + + // Select the primary key field. + .primary_key(Field::Id) + + // Select the secondary key fields. All queries must be + // based on the primary key or secondary keys. + .secondary_keys(vec![Field::Name]) + + // Define the conversion functions between the data type and database values. + .from_record(Inst::from_record) + .into_record(Inst::into_record) + + // Finish the builder pattern and initialize the database. + .initialize()?; + + // Insert or update the record based on the primary key + db.upsert(Inst { + id: 1, + name: Some("Alice".to_string()), + })?; + + // Get the record by primary key + let found = db.get(&Value::Int(1))?; + + ... +} +``` + +With `Inst` etc. being defined like so: + ```rust use autere_db::*; @@ -89,41 +134,6 @@ impl Inst { inst } } - -fn example() -> DBResult<()> { - // Initialize the database - let mut db = DB::configure() - // Set the directory where the database files are stored. - .data_dir("data") - - // Select the database fields, i.e. columns. - .fields(vec![Field::Id, Field::Name]) - - // Select the primary key field. - .primary_key(Field::Id) - - // Select the secondary key fields. All queries must be - // based on the primary key or secondary keys. - .secondary_keys(vec![Field::Name]) - - // Define the conversion functions between the data type and database values. - .from_record(Inst::from_record) - .into_record(Inst::into_record) - - // Finish the builder pattern and initialize the database. - .initialize()?; - - // Insert or update the record based on the primary key - db.upsert(Inst { - id: 1, - name: Some("Alice".to_string()), - })?; - - // Get the record by primary key - let found = db.get(&Value::Int(1))?; - - ... -} ``` ## Tests -- cgit v1.3