#surrealdb #schema #surreal #snake-case #derive #proc-macro

surql-definition-core

A Rust procedural macro for generating SurrealDB table and field definitions

2 releases

0.2.1 May 7, 2024
0.2.0 May 7, 2024

#2777 in Database interfaces


Used in 2 crates

MIT license

5KB

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.

Table of Contents

  1. Features
  2. Installation
  3. Usage
  4. Examples
    1. Generating a SurrealDB Schema Query
    2. Converting Strings to Snake Case
  5. License
  6. Links

Features

  • Provides a SurQLSchemaProducer trait for generating SurrealDB schema queries.
  • Includes a utility function to_snake_case for converting strings to snake case.

Installation

Add surql-definition-core to your Cargo.toml:

[dependencies]
surql-definition-core = "0.2.1"

Usage

To use surql-definition-core, import the trait or utility function as needed:

use surql_definition_core::{SurQLSchemaProducer, to_snake_case};

Examples

Generating a SurrealDB Schema Query

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;");

Converting Strings to Snake Case

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");

License

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

No runtime deps