wasm-dbms-macros 0.6.0

Runtime-agnostic procedural macros for the wasm-dbms DBMS engine.
Documentation
  • Coverage
  • 100%
    5 out of 5 items documented0 out of 4 items with examples
  • Size
  • Source code size: 105.14 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 616.76 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 6s Average build duration of successful builds.
  • all releases: 6s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • veeso/wasm-dbms
    3 0 8
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • veeso

wasm-dbms-macros

logo

license-mit repo-stars downloads latest-version ko-fi 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.