surql-definition-core

Crates.iosurql-definition-core
lib.rssurql-definition-core
version0.2.1
sourcesrc
created_at2024-05-07 22:34:14.134393
updated_at2024-05-07 22:45:45.140589
descriptionA Rust procedural macro for generating SurrealDB table and field definitions.
homepagehttps://github.com/kochmaxence/surql-definition-macros
repositoryhttps://github.com/kochmaxence/surql-definition-macros
max_upload_size
id1233138
size4,574
MK (kochmaxence)

documentation

README

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.

Links

Commit count: 16

cargo fmt