Rust

table

Module

[Table]: a fluent table blueprint, compiled by its schema into CREATE TABLE, ALTER TABLE and the other table statements; and ForeignKey, a foreign key declared on it.

Factories and alterations every dialect has are inherent methods; the others are gated by marker traits the dialects implement (Serial, Checks, InlineForeignKey, ...), as PHP's dialect table classes each use only the traits they support.

Contents

use utopia_query::schema::table::ForeignKey;
Rust
pub struct ForeignKey {
    pub column: String,
    pub ref_table: String,
    pub ref_column: String,
    pub on_delete: Option<ForeignKeyAction>,
    pub on_update: Option<ForeignKeyAction>,
}

A foreign key: FOREIGN KEY (column) REFERENCES table (column) with optional ON DELETE / ON UPDATE actions.

PHP: Utopia\Query\Schema\ForeignKey and its dialect classes.

use utopia_query::schema::table::Table;
Rust
pub struct Table<S> {
    // private fields
}

A table blueprint for the dialect S: columns, indexes, keys and alterations, compiled by the schema it came from.

PHP: Utopia\Query\Schema\Table and its dialect classes (Table\MySQL, Table\PostgreSQL, Table\SQLite, Table\ClickHouse, Table\MongoDB).

Rust
use utopia_query::schema::{MySql, Schema};

let mut users = MySql::new().table("users");
users.id("id");
users.string("email", 255).unique();
users.foreign_key("team_id").references("id").on("teams");
assert_eq!(
    users.create()?.query,
    "CREATE TABLE `users` (`id` BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, `email` VARCHAR(255) NOT NULL, \
     PRIMARY KEY (`id`), UNIQUE (`email`), FOREIGN KEY (`team_id`) REFERENCES `teams` (`id`))"
);
PHP
use Utopia\Query\Schema\MySQL;

$users = (new MySQL())->table('users');
$users->id();
$users->string('email')->unique();
$users->foreignKey('team_id')->references('id')->on('teams');
echo $users->create()->query, "\n";
Also implements Clone, Debug.
use utopia_query::schema::table::TableDefinition;
Rust
pub struct TableDefinition<S> {
    pub name: String,
    pub columns: Vec<Column<S>>,
    pub indexes: Vec<Index>,
    pub foreign_keys: Vec<ForeignKey>,
    pub drop_columns: Vec<String>,
    pub rename_columns: Vec<RenameColumn>,
    pub drop_indexes: Vec<String>,
    pub drop_foreign_keys: Vec<String>,
    pub raw_column_defs: Vec<String>,
    pub raw_index_defs: Vec<String>,
    pub checks: Vec<CheckConstraint>,
    pub composite_primary_key: Vec<String>,
    pub order_by: Vec<String>,
    pub partition_type: Option<PartitionType>,
    pub partition_expression: String,
    pub partition_count: Option<i64>,
    pub engine: Option<Engine>,
    pub engine_args: Vec<String>,
    pub ttl: Option<String>,
    pub settings: Vec<(String, String)>,
    pub sample_by: Option<String>,
    pub order_by_raw: Option<String>,
}

Everything a table blueprint holds: added columns, indexes, keys, and the alterations, partitioning and engine options set on it.

PHP: the public properties of Utopia\Query\Schema\Table.

Also implements Clone, Debug.
use utopia_query::schema::table::Checks;
Rust
pub trait Checks: Schema

Dialects with named table-level CHECK constraints (and column-level ones).

PHP: Table\Trait\Checks.

use utopia_query::schema::table::ColumnAlterations;
Rust
pub trait ColumnAlterations: Schema

Dialects that drop and rename columns in ALTER TABLE.

PHP: Table\Trait\ColumnAlterations.

use utopia_query::schema::table::CompositePrimary;
Rust
pub trait CompositePrimary: Schema

Dialects with composite primary keys.

PHP: Table\Trait\CompositePrimary.

use utopia_query::schema::table::ForeignKeys;
Rust
pub trait ForeignKeys: InlineForeignKey

Dialects that also add and drop foreign keys in ALTER TABLE.

PHP: Table\Trait\ForeignKeys.

Implemented byMySqlPostgreSql
use utopia_query::schema::table::FulltextSpatialIndex;
Rust
pub trait FulltextSpatialIndex: Schema

Dialects with full-text and spatial indexes.

PHP: Table\Trait\FulltextSpatialIndex.

use utopia_query::schema::table::InlineForeignKey;
Rust
pub trait InlineForeignKey: Schema

Dialects with inline foreign keys in CREATE TABLE.

PHP: Table\Trait\InlineForeignKey.

use utopia_query::schema::table::Serial;
Rust
pub trait Serial: Schema

Dialects with SERIAL column factories.

PHP: Table\Trait\Serial.

use utopia_query::schema::table::StandardPartitioning;
Rust
pub trait StandardPartitioning: Schema

Dialects with PARTITION BY RANGE / LIST / HASH.

PHP: Table\Trait\StandardPartitioning.