diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2025-05-03 10:31:06 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2025-05-03 10:31:06 +0300 |
| commit | e04a63a4e0f35da7a61acca0b1b2ae0d12568d91 (patch) | |
| tree | 362d5b8c4df57b90348daacccae38b87657c722a /README.md | |
| parent | 84ac3652415b662aae9580c008a5aa996d58c9f4 (diff) | |
Update README
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 80 |
1 files changed, 45 insertions, 35 deletions
@@ -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`. @@ -43,6 +49,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::*; // Define a type that represents your fields (columns) @@ -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 |
