Skip to main content

hyperdb_api/
table.rs

1// Copyright (c) 2026, Salesforce, Inc. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3
4//! Runtime `Table` trait emitted by `#[derive(Table)]`.
5
6/// Describes a database table derived from a Rust struct.
7///
8/// Implemented by `#[derive(Table)]`. Provides the SQL `CREATE TABLE`
9/// statement as a `const`, which can be used at runtime for migrations,
10/// test fixtures, or compile-time validation (via `#[hyperdb(register)]`).
11///
12/// # Example
13///
14/// ```rust,ignore
15/// use hyperdb_api::{Table};
16///
17/// #[derive(Table)]
18/// #[hyperdb(table = "users")]
19/// struct User {
20///     #[hyperdb(primary_key)]
21///     id: i64,
22///     name: String,
23///     email: Option<String>,
24/// }
25///
26/// println!("{}", User::CREATE_SQL);
27/// // CREATE TABLE users (id BIGINT NOT NULL, name TEXT NOT NULL, email TEXT)
28/// ```
29pub trait Table {
30    /// The SQL table name (lower-snake-case of the struct name by default,
31    /// or the value of `#[hyperdb(table = "...")]`).
32    const NAME: &'static str;
33
34    /// The full `CREATE TABLE` SQL statement for this struct's schema.
35    const CREATE_SQL: &'static str;
36}