Crates.io | surql-definition |
lib.rs | surql-definition |
version | 0.2.1 |
source | src |
created_at | 2024-05-07 22:36:53.446487 |
updated_at | 2024-05-07 22:46:34.580119 |
description | A Rust procedural macro for generating SurrealDB table and field definitions. |
homepage | https://github.com/kochmaxence/surql-definition-macros |
repository | https://github.com/kochmaxence/surql-definition-macros |
max_upload_size | |
id | 1233141 |
size | 4,624 |
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
.
SurQLDefinition
derive macro from surql-definition-macros
.SurQLSchemaProducer
trait from surql-definition-core
.Add surql-definition
to your Cargo.toml
:
[dependencies]
surql-definition = "0.2.1"
To use surql-definition
, import the relevant items as needed:
use surql_definition::{SurQLDefinition, SurQLSchemaProducer};
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;"
);
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;");
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"] }
This project is licensed under the MIT License. See the LICENSE file for details.