surql-definition-macros
A Rust procedural macro for generating SurrealDB table and field definitions.
Overview
surql-definition-macros provides a convenient way to define SurrealDB tables and fields directly from Rust structs. The macro allows you to specify custom attributes, making it easy to set up table schemas and field properties using SurrealQL. It supports both auto-generated and explicitly defined table and field attributes.
Goals
- Provide a user-friendly way to define SurrealDB tables and fields using Rust.
- Offer customization of table and field properties via attributes.
- Generate SurrealQL queries for defining table schemas.
- Allow specifying permissions for tables and fields using SurrealQL syntax.
Non-Goals
- Execute the generated SurrealQL queries.
surql-definition-macrosdoes not depend on SurrealDB or interact with the database directly.
Features
- Auto-generate or explicitly define table definitions from Rust structs.
- Customize field properties using attributes.
- Specify table and field permissions using SurrealQL syntax.
- Easily integrate with SurrealDB to manage your data models.
Usage
Add surql-definition-macros as a dependency in your Cargo.toml file:
[]
= "0.1"
Then, derive SurQLDefinition for your struct:
use SurQLDefinition;
This will generate a SurrealQL query for the User struct:
Attributes
-
surql_table:- Specifies the table name.
-
surql_query:- Specifies a custom SurrealQL query.
-
surql_field:TYPE: Specifies the field type.DEFAULT: Specifies the default value for the field.READONLY: Sets the field as read-only.VALUE: Specifies the value for the field.ASSERT: Specifies a condition for the field.FLEXIBLE: Allows flexible typing for the field.
-
surql_table_permissions/surql_field_permissions:SELECT: Specifies the permissions for the select operation.CREATE: Specifies the permissions for the create operation.UPDATE: Specifies the permissions for the update operation.DELETE: Specifies the permissions for the delete operation.
Examples
Basic Example
use SurQLDefinition;
assert_eq!;
Table Permissions
use SurQLDefinition;
assert_eq!;
Flexible Field
use SurQLDefinition;
assert_eq!;
Readonly Field
use SurQLDefinition;
assert_eq!;
Custom Query
use SurQLDefinition;
assert_eq!;
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
Acknowledgments
Special thanks to the SurrealDB team for their excellent database technology.