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;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;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).
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`))"
);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";Clone, Debug.use utopia_query::schema::table::TableDefinition;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.
Clone, Debug.use utopia_query::schema::table::Checks;pub trait Checks: SchemaDialects with named table-level CHECK constraints (and column-level ones).
PHP: Table\Trait\Checks.
use utopia_query::schema::table::ColumnAlterations;pub trait ColumnAlterations: SchemaDialects that drop and rename columns in ALTER TABLE.
PHP: Table\Trait\ColumnAlterations.
use utopia_query::schema::table::CompositePrimary;pub trait CompositePrimary: SchemaDialects with composite primary keys.
PHP: Table\Trait\CompositePrimary.
use utopia_query::schema::table::ForeignKeys;pub trait ForeignKeys: InlineForeignKeyDialects that also add and drop foreign keys in ALTER TABLE.
PHP: Table\Trait\ForeignKeys.
use utopia_query::schema::table::FulltextSpatialIndex;pub trait FulltextSpatialIndex: SchemaDialects with full-text and spatial indexes.
PHP: Table\Trait\FulltextSpatialIndex.
use utopia_query::schema::table::InlineForeignKey;pub trait InlineForeignKey: SchemaDialects with inline foreign keys in CREATE TABLE.
PHP: Table\Trait\InlineForeignKey.
use utopia_query::schema::table::Serial;pub trait Serial: SchemaDialects with SERIAL column factories.
PHP: Table\Trait\Serial.
use utopia_query::schema::table::StandardPartitioning;pub trait StandardPartitioning: SchemaDialects with PARTITION BY RANGE / LIST / HASH.
PHP: Table\Trait\StandardPartitioning.