surql-definition-macros
surql-definition-macros is a Rust procedural macro crate that simplifies the process of generating SurrealDB table and field definitions. The crate provides the SurQLDefinition derive macro, which automatically creates SurrealDB schema queries based on annotated Rust structs.
Table of Contents
Features
- Automatically generates SurrealDB table and field definitions from Rust structs.
- Supports flexible types, default values, assertions, and permissions.
- Provides runtime and compile-time query validation options.
Installation
Add surql-definition-macros to your Cargo.toml:
[]
= "0.2.1"
Usage
To use surql-definition-macros, simply derive SurQLDefinition on your struct and optionally use the provided attributes for customization:
surql_table: Specifies the table name.surql_field: Configures field properties like type, default value, and assertions.surql_field_permissions: Sets field-level permissions.surql_table_permissions: Sets table-level permissions.surql_query: Defines a custom SurrealDB query.
Examples
Simple Usage
Here’s a basic example showcasing the use of SurQLDefinition to generate SurrealDB schema queries for a struct with various primitive types:
use SurQLDefinition;
assert_eq!;
Advanced Usage
In this example, the ComplexStruct demonstrates more advanced features like flexible types, custom field types, and default values:
use SurQLDefinition;
assert_eq!;
Validation
surql-definition-macros supports runtime and compile-time validation of generated queries using the runtime_query_validation and compile_query_validation features, respectively. These features rely on the surrealdb-core crate for query parsing.
To enable validation, update your Cargo.toml:
[]
= { = "0.2.1", = ["runtime_query_validation"] }
License
This project is licensed under the MIT License. See the LICENSE file for details.