Skip to main content

Table

Trait Table 

Source
pub trait Table {
    const NAME: &'static str;
    const CREATE_SQL: &'static str;
}
Expand description

Describes a database table derived from a Rust struct.

Implemented by #[derive(Table)]. Provides the SQL CREATE TABLE statement as a const, which can be used at runtime for migrations, test fixtures, or compile-time validation (via #[hyperdb(register)]).

§Example

use hyperdb_api::{Table};

#[derive(Table)]
#[hyperdb(table = "users")]
struct User {
    #[hyperdb(primary_key)]
    id: i64,
    name: String,
    email: Option<String>,
}

println!("{}", User::CREATE_SQL);
// CREATE TABLE users (id BIGINT NOT NULL, name TEXT NOT NULL, email TEXT)

Required Associated Constants§

Source

const NAME: &'static str

The SQL table name (lower-snake-case of the struct name by default, or the value of #[hyperdb(table = "...")]).

Source

const CREATE_SQL: &'static str

The full CREATE TABLE SQL statement for this struct’s schema.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§