Skip to Content
This documentation is still under construction
Rust APIBuild From Directory

Building a version source from a directory

Instead of maintaining one large JSON file, you can split a version source across many small files in a directory and let AlphaDB combine them into a single version source at runtime. This lives in the alphadb::version_source module, which is gated behind the version-source crate feature.

[dependencies] alphadb = { version = "...", features = ["version-source"] }

Directory layout

A version source directory contains one config file and one file per version.

my-version-source/ ├── adb-config.json ├── 1.0.0-create-users.json ├── 1.1.0-add-index.json └── 1.2.0-add-email.json

The config file must be named adb-config.json or _adb-config.json (exactly one must be present). It defines the root-level name and engine:

{ "name": "example-db", "engine": "mysql" }

Every other file is a version file. Its name must start with a valid version number followed by a hyphen (<version>-<description>.json); the leading version number becomes the version’s _id. The file itself is a JSON object of methods, without an _id key:

{ "createtable": { "users": { "primary_key": "id", "id": { "type": "INT", "auto_increment": true }, "name": { "type": "VARCHAR", "length": 100 } } } }

Usage

build_version_source_from_dir reads the directory and returns the combined version source as a serde_json::Value, ready to pass to update.

use std::path::PathBuf; use alphadb::version_source::build_version_source_from_dir; let version_source = build_version_source_from_dir(&PathBuf::from("path/to/my-version-source")) .expect("Failed to build version source"); // Hand it to the database as a string let version_source_string = serde_json::to_string(&version_source).unwrap();

The result is a normal version source with the name and engine taken from the config file, and one entry in version per version file:

{ "name": "example-db", "engine": "mysql", "version": [ { "_id": "1.0.0", "createtable": { "users": { /* ... */ } } }, { "_id": "1.1.0", "altertable": { "users": { /* ... */ } } }, { "_id": "1.2.0", "altertable": { "users": { /* ... */ } } } ] }
Last updated on