Skip to main content

PostgreSql

Struct PostgreSql 

Source
pub struct PostgreSql { /* private fields */ }
Expand description

The PostgreSQL schema: double-quote quoting, identity columns, SERIAL types, CHECK-emulated enums, standalone index statements, PL/pgSQL procedures and triggers, types, sequences, extensions and collations.

use utopia_query::schema::{PostgreSql, Schema};

let mut table = PostgreSql::new().table("users");
table.add_column("bio", utopia_query::schema::ColumnType::Text, None).nullable();
table.drop_column("legacy");
table.index(["email"])?;
assert_eq!(
    table.alter()?.query,
    "ALTER TABLE \"users\" ADD COLUMN \"bio\" TEXT NULL, DROP COLUMN \"legacy\"; \
     CREATE INDEX \"idx_email\" ON \"users\" (\"email\")"
);
use Utopia\Query\Schema\ColumnType;
use Utopia\Query\Schema\PostgreSQL;

$table = (new PostgreSQL())->table('users');
$table->addColumn('bio', ColumnType::Text)->nullable();
$table->dropColumn('legacy');
$table->index(['email']);
echo $table->alter()->query, "\n";

PHP: Utopia\Query\Schema\PostgreSQL.

Implementations§

Source§

impl PostgreSql

Source

pub fn new() -> Self

A PostgreSQL schema without an executor.

PHP: new PostgreSQL().

Source

pub fn create_extension(&self, name: &str) -> Result<Statement>

CREATE EXTENSION IF NOT EXISTS name.

PHP: createExtension().

Source

pub fn drop_extension(&self, name: &str) -> Result<Statement>

DROP EXTENSION IF EXISTS name.

PHP: dropExtension().

Source

pub fn create_collation( &self, name: &str, options: &[(&str, &str)], deterministic: bool, ) -> Result<Statement>

CREATE COLLATION IF NOT EXISTS name (key = 'value', ..., deterministic = ...); option keys are identifiers (PHP’s default for deterministic is true).

PHP: createCollation().

Source

pub fn alter_column_type( &self, table: &str, column: &str, kind: &str, using: &str, ) -> Result<Statement>

ALTER TABLE table ALTER COLUMN column TYPE type [USING expr]: the type is a type declaration, the cast expression has no ;, -- or /* (PHP’s default for using is empty).

PHP: alterColumnType().

Source

pub fn alter_column_nullable( &self, table: &str, column: &str, nullable: bool, ) -> Result<Statement>

ALTER TABLE table ALTER COLUMN column DROP NOT NULL / SET NOT NULL.

PHP: alterColumnNullable().

Source

pub fn drop_index_concurrently(&self, name: &str) -> Result<Statement>

DROP INDEX CONCURRENTLY name.

PHP: dropIndexConcurrently().

Trait Implementations§

Source§

impl AnalyzeTable for PostgreSql

Source§

fn analyze_table(&self, table: &str) -> Result<Statement>

Analyzes table. Read more
Source§

impl AutoIncrement for PostgreSql

Source§

impl Checks for PostgreSql

Source§

impl Clone for PostgreSql

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Collation for PostgreSql

Source§

impl ColumnAlterations for PostgreSql

Source§

impl ColumnComments for PostgreSql

Source§

fn comment_on_column( &self, table: &str, column: &str, comment: &str, ) -> Result<Statement>

Sets the comment of column of table. Read more
Source§

impl CompositePrimary for PostgreSql

Source§

impl CreatePartition for PostgreSql

Source§

fn create_partition( &self, parent: &str, name: &str, expression: &str, ) -> Result<Statement>

CREATE TABLE name PARTITION OF parent FOR VALUES expression; the expression has no ;, -- or /*.

Source§

impl Databases for PostgreSql

Source§

fn create_database(&self, name: &str) -> Result<Statement>

CREATE SCHEMA name: PostgreSQL namespaces with schemas.

Source§

fn drop_database(&self, name: &str) -> Result<Statement>

Drops database name. Read more
Source§

impl Debug for PostgreSql

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PostgreSql

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Dimensions for PostgreSql

Source§

impl DropPartition for PostgreSql

Source§

fn drop_partition(&self, _table: &str, name: &str) -> Result<Statement>

Drops partition name of table. Read more
Source§

impl ForeignKeys for PostgreSql

Source§

impl ForeignKeys for PostgreSql

Source§

fn add_foreign_key( &self, table: &str, name: &str, key: &ForeignKey, ) -> Result<Statement>

ALTER TABLE table ADD CONSTRAINT name FOREIGN KEY ... for key. Read more
Source§

fn drop_foreign_key(&self, table: &str, name: &str) -> Result<Statement>

Drops the foreign key name of table. Read more
Source§

impl FulltextSpatialIndex for PostgreSql

Source§

impl Generated for PostgreSql

Source§

impl InlineForeignKey for PostgreSql

Source§

impl Partitioning for PostgreSql

Source§

fn compile_create_partitioning(&self, table: &Table<Self>) -> String

PARTITION BY kind(expression), without a partition count.

Source§

impl Procedures for PostgreSql

Source§

fn create_procedure( &self, name: &str, params: &[(ParameterDirection, &str, &str)], body: &str, ) -> Result<Statement>

A PL/pgSQL function returning VOID; the body must not contain $$.

Source§

fn drop_procedure(&self, name: &str) -> Result<Statement>

Drops procedure name. Read more
Source§

impl RenameIndex for PostgreSql

Source§

fn rename_index(&self, _table: &str, from: &str, to: &str) -> Result<Statement>

Renames index from of table to to. Read more
Source§

impl ReplaceView for PostgreSql

Source§

fn create_or_replace_view( &self, name: &str, query: &mut dyn AnyBuilder, ) -> Result<Statement>

Creates or replaces view name of the query query builds. Read more
Source§

impl Schema for PostgreSql

Source§

fn compile_column_definition(&self, column: &Column<Self>) -> Result<String>

Identity instead of AUTO_INCREMENT (none for SERIAL types), enums as a CHECK (... IN (...)), no inline comment.

Source§

fn compile_generated_clause(&self, column: &Column<Self>) -> String

Always STORED: PostgreSQL has no virtual generated columns.

Source§

fn compile_alter(&self, table: &Table<Self>) -> Result<Statement>

Column changes in one ALTER TABLE, indexes as separate CREATE / DROP INDEX statements, joined by ; .

Source§

fn create_index( &self, table: &str, name: &str, columns: &[&str], options: &IndexOptions, ) -> Result<Statement>

CREATE [UNIQUE] INDEX [CONCURRENTLY] name ON table [USING method] (...).

Source§

fn executor(&self) -> Option<&Executor>

The executor statements carry, if any.
Source§

fn set_executor(&mut self, executor: Executor) -> &mut Self

Sets the executor every statement compiled from now on carries (Statement::execute runs it). Read more
Source§

fn literal(&self) -> StringLiteral

How the dialect writes a string literal: comments, defaults and enum values are inlined, since DDL takes no bound parameters. Read more
Source§

fn quote(&self, identifier: &str) -> Result<String>

Quotes a possibly qualified identifier. Read more
Source§

fn quote_literal(&self, identifier: &str) -> Result<String>

Quotes one identifier, dots included. Read more
Source§

fn compile_column_type(&self, column: &Column<Self>) -> Result<String>

The SQL type of column. Read more
Source§

fn compile_auto_increment(&self) -> &'static str

The auto-increment keyword. Read more
Source§

fn quote_collation(&self, collation: &str) -> Result<String>

A collation name as COLLATE takes it. Read more
Source§

fn compile_unsigned(&self) -> &'static str

The unsigned keyword, or empty where there is none. Read more
Source§

fn compile_create_suffix(&self, table: &Table<Self>) -> String

Clauses after the column list of CREATE TABLE (partitioning). Read more
Source§

fn compile_rename(&self, from: &str, to: &str) -> Result<Statement>

Renames table from to to. Read more
Source§

fn drop_index(&self, _table: &str, name: &str) -> Result<Statement>

Drops index name of table. Read more
Source§

fn table(&self, name: impl Into<String>) -> Table<Self>

A blueprint of table name compiled by this schema. Read more
Source§

fn compile_create( &self, table: &Table<Self>, if_not_exists: bool, ) -> Result<Statement>

CREATE TABLE [IF NOT EXISTS] for table. Read more
Source§

fn compile_drop(&self, name: &str, if_exists: bool) -> Result<Statement>

DROP TABLE [IF EXISTS] name. Read more
Source§

fn compile_truncate(&self, name: &str) -> Result<Statement>

Empties table name. Read more
Source§

fn compile_index_columns(&self, index: &Index) -> Result<String>

The column list of an index: lengths, collations, operator class, orders and raw expressions. Read more
Source§

impl Sequences for PostgreSql

Source§

fn create_sequence( &self, name: &str, start: i64, increment_by: i64, ) -> Result<Statement>

Creates sequence name starting at start, stepping by increment_by (PHP’s defaults are 1 and 1). Read more
Source§

fn drop_sequence(&self, name: &str) -> Result<Statement>

Drops sequence name. Read more
Source§

fn next_val(&self, name: &str) -> Result<Statement>

Reads the next value of sequence name. Read more
Source§

impl Serial for PostgreSql

Source§

impl Srid for PostgreSql

Source§

impl StandardPartitioning for PostgreSql

Source§

impl TableComments for PostgreSql

Source§

fn comment_on_table(&self, table: &str, comment: &str) -> Result<Statement>

Sets the comment of table. Read more
Source§

impl Triggers for PostgreSql

Source§

fn create_trigger( &self, name: &str, table: &str, timing: TriggerTiming, event: TriggerEvent, body: &str, ) -> Result<Statement>

A trigger function <name>_func and the trigger executing it; the body must not contain $$.

Source§

fn drop_trigger(&self, name: &str, table: Option<&str>) -> Result<Statement>

Drops the trigger and its function; the table is required.

Source§

impl Types for PostgreSql

Source§

fn create_type(&self, name: &str, values: &[&str]) -> Result<Statement>

CREATE TYPE name AS ENUM (values...). Read more
Source§

fn drop_type(&self, name: &str) -> Result<Statement>

Drops type name. Read more
Source§

impl Unique for PostgreSql

Source§

impl Views for PostgreSql

Source§

fn create_view( &self, name: &str, query: &mut dyn AnyBuilder, ) -> Result<Statement>

Creates view name of the query query builds (its bindings ride along). Read more
Source§

fn drop_view(&self, name: &str) -> Result<Statement>

Drops view name. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for PostgreSql

§

impl !UnwindSafe for PostgreSql

§

impl Forget for PostgreSql

§

impl Freeze for PostgreSql
where *const ArcInner<dyn Fn(&Statement) -> Result<Value<Object>, Error> + Sync + Send> is !null: Freeze, PhantomData<ArcInner<dyn Fn(&Statement) -> Result<Value<Object>, Error> + Sync + Send>>: Freeze,

§

impl Move for PostgreSql

§

impl Send for PostgreSql
where Arc<dyn Fn(&Statement) -> Result<Value<Object>, Error> + Sync + Send>: Send,

§

impl Sync for PostgreSql
where Arc<dyn Fn(&Statement) -> Result<Value<Object>, Error> + Sync + Send>: Sync,

§

impl Unpin for PostgreSql
where Arc<dyn Fn(&Statement) -> Result<Value<Object>, Error> + Sync + Send>: Unpin,

§

impl UnsafeUnpin for PostgreSql
where *const ArcInner<dyn Fn(&Statement) -> Result<Value<Object>, Error> + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&Statement) -> Result<Value<Object>, Error> + Sync + Send>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.