wasm-dbms-macros 0.8.1

Runtime-agnostic procedural macros for the wasm-dbms DBMS engine.
Documentation

wasm-dbms-macros

logo

license-mit repo-stars downloads latest-version conventional-commits

ci coveralls docs

Runtime-agnostic procedural macros for the wasm-dbms DBMS engine.

This crate provides procedural macros to automatically implement traits required by the wasm-dbms engine.

Provided Derive Macros

Encode

Automatically implements the Encode trait for structs, generating binary serialization and deserialization methods for memory storage.

use wasm_dbms_macros::Encode;

#[derive(Encode, Debug, PartialEq, Eq)]
struct Position {
    x: Int32,
    y: Int32,
}

Table

Given a struct representing a database table, automatically implements the TableSchema trait with all the necessary types. Generates:

  • ${StructName}Record - implementing TableRecord
  • ${StructName}InsertRequest - implementing InsertRecord
  • ${StructName}UpdateRequest - implementing UpdateRecord
  • ${StructName}ForeignFetcher (only if foreign keys are present)
use wasm_dbms_macros::{Encode, Table};

#[derive(Debug, Table, Clone, PartialEq, Eq)]
#[table = "posts"]
struct Post {
    #[primary_key]
    id: Uint32,
    title: Text,
    content: Text,
    #[foreign_key(entity = "User", table = "users", column = "id")]
    author_id: Uint32,
}

Table Attributes

  • #[table = "table_name"]: Specifies the table name in the database.
  • #[alignment = N]: (optional) Specifies the alignment for table records.
  • #[primary_key]: Marks a field as the primary key.
  • #[foreign_key(entity = "EntityName", table = "table_name", column = "column_name")]: Defines a foreign key relationship.
  • #[sanitizer(SanitizerType)]: Specifies a sanitizer for the field.
  • #[validate(ValidatorType)]: Specifies a validator for the field.
  • #[custom_type]: Marks a field as a custom data type.

CustomDataType

Bridges user-defined types into the Value system. The type must also derive Encode and implement Display.

use wasm_dbms_macros::{Encode, CustomDataType};

#[derive(Encode, CustomDataType)]
#[type_tag = "status"]
enum Status {
    Active,
    Inactive,
}

License

This project is licensed under the MIT License. See the LICENSE file for details.