surql-definition

Crates.iosurql-definition
lib.rssurql-definition
version0.2.1
sourcesrc
created_at2024-05-07 22:36:53.446487
updated_at2024-05-07 22:46:34.580119
descriptionA Rust procedural macro for generating SurrealDB table and field definitions.
homepagehttps://github.com/kochmaxence/surql-definition-macros
repositoryhttps://github.com/kochmaxence/surql-definition-macros
max_upload_size
id1233141
size4,624
MK (kochmaxence)

documentation

README

surql-definition

surql-definition is a Rust crate that provides a unified interface for generating SurrealDB table and field definitions. It re-exports functionality from surql-definition-macros and surql-definition-core.

Table of Contents

  1. Features
  2. Installation
  3. Usage
  4. Examples
  5. Validation
  6. License
  7. Links

Features

  • Re-exports the SurQLDefinition derive macro from surql-definition-macros.
  • Re-exports the SurQLSchemaProducer trait from surql-definition-core.
  • Simplifies the process of defining and validating SurrealDB schemas.

Installation

Add surql-definition to your Cargo.toml:

[dependencies]
surql-definition = "0.2.1"

Usage

To use surql-definition, import the relevant items as needed:

use surql_definition::{SurQLDefinition, SurQLSchemaProducer};

Examples

Defining a SurrealDB Table

The following example demonstrates how to use the SurQLDefinition macro to define a SurrealDB table:

use surql_definition::SurQLDefinition;

#[derive(SurQLDefinition)]
struct User {
    id: u64,
    name: String,
    email: String,
}

assert_eq!(
    User::schema_query(),
    "DEFINE TABLE user; DEFINE FIELD id ON user TYPE int; DEFINE FIELD name ON user TYPE string; DEFINE FIELD email ON user TYPE string;"
);

Using SurQLSchemaProducer

The SurQLSchemaProducer trait allows you to manually implement a schema query for a struct:

use surql_definition::SurQLSchemaProducer;

struct Product;

impl SurQLSchemaProducer for Product {
    fn schema_query() -> &'static str {
        "DEFINE TABLE product;"
    }
}

assert_eq!(Product::schema_query(), "DEFINE TABLE product;");

Validation

surql-definition supports runtime and compile-time validation of generated queries through the features provided by surql-definition-macros.

To enable validation, update your Cargo.toml:

[dependencies]
surql-definition = { version = "0.2.1", features = ["runtime_query_validation"] }

License

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

Links

Commit count: 16

cargo fmt