grounddb-codegen 1.0.0

Compile-time code generation for GroundDB schemas
Documentation

grounddb-codegen

Crates.io docs.rs

Compile-time code generation for GroundDB.

Reads a schema.yaml and generates a complete Rust source file with:

  • Typed structs for each collection (e.g., User, Post)
  • Enums for fields with enum constraints (e.g., UserRole, PostStatus)
  • Partial-update structs where all fields are Option (e.g., UserPartial)
  • View row structs derived from SQL SELECT columns (e.g., PostFeedRow)
  • Query parameter structs for parameterized views (e.g., PostCommentsParams)
  • StoreExt trait with typed collection accessors and view methods

Setup

Add to your Cargo.toml:

[build-dependencies]
grounddb-codegen = "1"

Create a build.rs:

fn main() {
    grounddb_codegen::generate_from_schema(
        "data/schema.yaml",
        "src/generated.rs",
    ).expect("codegen failed");
}

Include the generated module:

mod generated;
use generated::*;

What Gets Generated

Given a schema with a users collection:

collections:
  users:
    path: "users/{name}.md"
    fields:
      name: { type: string, required: true }
      email: { type: string, required: true }
      role: { type: string, enum: [admin, member, guest], default: member }

The codegen produces:

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct User {
    pub name: String,
    pub email: String,
    #[serde(default)]
    pub role: UserRole,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum UserRole { Admin, Member, Guest }

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct UserPartial {
    pub name: Option<String>,
    pub email: Option<String>,
    pub role: Option<UserRole>,
}

For full documentation, see the repository README.