Common schema management and DDL utilities.
Common schema management and DDL utilities.
(add-check-if-not-exists! ctx table constraint-name clause)Add the named CHECK clause to table unless a constraint of that name is
there. No engine takes IF NOT EXISTS here, so its duplicate counts as done
(BOU-632).
Add the named CHECK `clause` to `table` unless a constraint of that name is there. No engine takes IF NOT EXISTS here, so its duplicate counts as done (BOU-632).
(add-column-if-not-exists! ctx table column definition)Add column to table unless it is there.
Example: (add-column-if-not-exists! ctx :users :nickname "VARCHAR(50)")
Add `column` to `table` unless it is there. Example: (add-column-if-not-exists! ctx :users :nickname "VARCHAR(50)")
(add-columns-if-not-exist! ctx table columns)(add-columns-if-not-exist! ctx table columns present)Add each [column definition] in columns that table lacks, definition
being what follows the name. Read first because any ALTER locks, even one IF
NOT EXISTS makes a no-op; a duplicate the read missed counts as done (BOU-616).
present, the lower-case column names a caller already read, skips the read.
Example: (add-columns-if-not-exist! ctx :users [[:nickname "VARCHAR(50)"]])
Add each [column definition] in `columns` that `table` lacks, `definition` being what follows the name. Read first because any ALTER locks, even one IF NOT EXISTS makes a no-op; a duplicate the read missed counts as done (BOU-616). `present`, the lower-case column names a caller already read, skips the read. Example: (add-columns-if-not-exist! ctx :users [[:nickname "VARCHAR(50)"]])
(create-index-if-not-exists! ctx index-name table columns)(create-index-if-not-exists! ctx index-name table columns {:keys [unique?]})Create an index unless it is there (BOU-607). A unique index the rows break is a :conflict naming the table and columns.
Example: (create-index-if-not-exists! ctx "idx_users_email" :users [:email]) (create-index-if-not-exists! ctx "uk_users_email" :users [:email] {:unique? true})
Create an index unless it is there (BOU-607). A unique index the rows break
is a :conflict naming the table and columns.
Example:
(create-index-if-not-exists! ctx "idx_users_email" :users [:email])
(create-index-if-not-exists! ctx "uk_users_email" :users [:email] {:unique? true})(drop-column-if-exists! ctx table column)Drop column from table if it is there. No read first, as add does: SQLite
would not list a generated column, so the drop would be skipped.
Drop `column` from `table` if it is there. No read first, as add does: SQLite would not list a generated column, so the drop would be skipped.
(drop-index-if-exists! ctx index-name table)Drop an index if it is there (BOU-607).
Drop an index if it is there (BOU-607).
(execute-ddl! ctx ddl-statement)Execute DDL statement with logging.
Args: ctx: Database context ddl-statement: String DDL statement
Returns: Execution result
Example: (execute-ddl! ctx "CREATE TABLE users (id TEXT PRIMARY KEY)")
Execute DDL statement with logging. Args: ctx: Database context ddl-statement: String DDL statement Returns: Execution result Example: (execute-ddl! ctx "CREATE TABLE users (id TEXT PRIMARY KEY)")
(execute-ddl-if-absent! ctx statement)Run statement, counting "already exists" as done and logging it as
nothing: for boot DDL rewritten for an engine without IF NOT EXISTS, such
as a MySQL CREATE INDEX (BOU-650).
Run `statement`, counting "already exists" as done and logging it as nothing: for boot DDL rewritten for an engine without IF NOT EXISTS, such as a MySQL CREATE INDEX (BOU-650).
(get-table-info ctx table-name)Get column information for a table using adapter-specific introspection.
Args: ctx: Database context table-name: String or keyword table name
Returns: Vector of column info maps
Example: (get-table-info ctx :users)
Get column information for a table using adapter-specific introspection. Args: ctx: Database context table-name: String or keyword table name Returns: Vector of column info maps Example: (get-table-info ctx :users)
(quote-identifier engine ident)ident quoted for engine, as stored: backticks on MySQL, double quotes
elsewhere, so a name with capitals or a reserved word survives.
`ident` quoted for `engine`, as stored: backticks on MySQL, double quotes elsewhere, so a name with capitals or a reserved word survives.
(table-exists? ctx table-name)Check if a table exists using adapter-specific introspection.
Args: ctx: Database context table-name: String or keyword table name
Returns: Boolean - true if table exists
Example: (table-exists? ctx :users)
Check if a table exists using adapter-specific introspection. Args: ctx: Database context table-name: String or keyword table name Returns: Boolean - true if table exists Example: (table-exists? ctx :users)
(widen-column! ctx table column type not-null?)Change column of table to the longer character type, keeping its rows
and its NULL or NOT NULL (BOU-715). A no-op on SQLite, which enforces no
length. MySQL's MODIFY restates the column, so a default it had is dropped:
call this only for columns without one.
Change `column` of `table` to the longer character `type`, keeping its rows and its NULL or NOT NULL (BOU-715). A no-op on SQLite, which enforces no length. MySQL's MODIFY restates the column, so a default it had is dropped: call this only for columns without one.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |