Crates.io | surql-definition-core |
lib.rs | surql-definition-core |
version | 0.2.1 |
source | src |
created_at | 2024-05-07 22:34:14.134393 |
updated_at | 2024-05-07 22:45:45.140589 |
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 | 1233138 |
size | 4,574 |
surql-definition-core
surql-definition-core
is a Rust library that provides core utilities and traits for generating SurrealDB schema queries. The crate includes a trait for schema generation and a utility function for converting strings to snake case.
This crate is used by the surql-definition-macros
crate to generate SurrealDB table and field definitions.
SurQLSchemaProducer
trait for generating SurrealDB schema queries.to_snake_case
for converting strings to snake case.Add surql-definition-core
to your Cargo.toml
:
[dependencies]
surql-definition-core = "0.2.1"
To use surql-definition-core
, import the trait or utility function as needed:
use surql_definition_core::{SurQLSchemaProducer, to_snake_case};
Implement the SurQLSchemaProducer
trait to define a schema query for a struct:
use surql_definition_core::SurQLSchemaProducer;
struct MyTable;
impl SurQLSchemaProducer for MyTable {
fn schema_query() -> &'static str {
"DEFINE TABLE my_table;"
}
}
assert_eq!(MyTable::schema_query(), "DEFINE TABLE my_table;");
Use the to_snake_case
function to convert a string to snake case:
use surql_definition_core::to_snake_case;
assert_eq!(to_snake_case("HelloWorld"), "hello_world");
assert_eq!(to_snake_case("snake_case"), "snake_case");
assert_eq!(to_snake_case("CamelCase123"), "camel_case_123");
This project is licensed under the MIT License. See the LICENSE file for details.