No description
Find a file
Markus Scully ff57ee8deb
📝 cli, vanth, meta, flake: Simplify dependencies, add meta crate, and improve docs
- Removed dependencies `sqlx` and `bevy_app` to simplify the project.
- Added new crate `vanth_meta` for generating example SVGs.
- Updated CLI tests to use `assert_cmd` for better test assertions.
- Enhanced README with comprehensive library and CLI usage documentation.
- Modified `Store::write` in `vanth` crate to return the content hash.
- Set `checkPhase` to empty in Nix flake configuration.
2025-08-11 12:59:29 +03:00
.cargo ♻️🍱💩👷 crates/vanth, project: Refactor entity system and setup; migrate to Nix flakes 2025-08-04 21:03:15 +03:00
crates 📝 cli, vanth, meta, flake: Simplify dependencies, add meta crate, and improve docs 2025-08-11 12:59:29 +03:00
.gitignore Init commit 2024-11-14 23:24:15 +00:00
Cargo.lock 📝 cli, vanth, meta, flake: Simplify dependencies, add meta crate, and improve docs 2025-08-11 12:59:29 +03:00
Cargo.toml 📝 cli, vanth, meta, flake: Simplify dependencies, add meta crate, and improve docs 2025-08-11 12:59:29 +03:00
flake.lock ♻️🍱💩👷 crates/vanth, project: Refactor entity system and setup; migrate to Nix flakes 2025-08-04 21:03:15 +03:00
flake.nix 📝 cli, vanth, meta, flake: Simplify dependencies, add meta crate, and improve docs 2025-08-11 12:59:29 +03:00
LICENSE Refactor: Convert project to a Bevy-based workspace and node 2025-07-12 22:59:41 +03:00
README.md 📝 cli, vanth, meta, flake: Simplify dependencies, add meta crate, and improve docs 2025-08-11 12:59:29 +03:00
rustfmt.toml ♻️🍱 config, cli, vanth, vanth_derive, varo: Reformatted code and added editor configuration files 2025-08-07 12:49:33 +03:00

Vanth

Vanth is a content-addressed database as a library designed for entity-component-system (ECS) applications.

It is currently experimental and should not be used for anything.

Library usage

Any type that implements serde::Serialize can be hashed using vanth::hash to produce a vanth::ContentHash.

let x = "hello";
assert_eq!(vanth::hash(&x).hex(), "ea8f163db38682925e4491c5e58d4bb3506ef8c14eb78a86e908c5624a67200f");

Derive or implement the vanth::Vanth trait for types you want to store in the database.

use serde::{Deserialize, Serialize};
use vanth::Vanth;

#[derive(Deserialize, Serialize, Vanth)]
struct Data {
    value: u32,
}

This generates a method Vanth::ty() which returns a vanth::Ty. This should represent the type's fully qualified name - its module path followed by the type itself and any generics it has. E.g. Data::<ty().to_string() could return my::crate::module::Data.

The derivation only works for basic types right now and is not implemented for std types. Moving or renaming types or modules will change the type name, necessitating a database migration. This is not supported yet.

This should be used with caution. There are good reasons why std::any::TypeId is opaque.

Database storage

use vanth::store::{Store, StoreParams};

// Or use `Store::in_memory`.
let mut store = Store::sqlite_from_path(
    "path/to/my_database.sqlite".into(),
    StoreParams { create_if_not_exists: true, ..Default::default() },
);
let hash = store.write(Data { value: 5 }).unwrap();
let my_data: Data = store.get_from_hash(hash).unwrap();

CLI usage

You can run the Vanth CLI with Nix using nix run https://git.mascully.com/mascully/vanth.

Use -- to pass arguments, e.g. nix run https://git.mascully.com/mascully/vanth -- --help.

Syntax

Write a component to the database:

$ vanth write --db /path/to/db.sqlite --ty my::type::Name --value '{ "field": "value" }'
a1cf81d8afe4e72604ea5c13bbd9b6cce14bd98c3a2f036f7156c4464a88ec09

Get a component from the database:

$ vanth get --db /path/to/db.sqlite --ty my::type::Name a1cf81d8afe4e72604ea5c13bbd9b6cce14bd98c3a2f036f7156c4464a88ec09
{"field":"value"}

Get all components of a type from the database:

$ vanth get-all --db /path/to/db.sqlite --ty my::type::Name
{"field":"value1"}
{"field":"value2"}
{"field":"value3"}

Delete a component by its content hash:

$ vanth delete --db /path/to/db.sqlite ea8f163db38682925e4491c5e58d4bb3506ef8c14eb78a86e908c5624a67200f

Delete all components of a type:

$ vanth delete-all --db /path/to/db.sqlite --ty my::type::Name