(as expr alias & [columns])
Parse expr
and return an expr with and AS clause using alias
.
Parse `expr` and return an expr with and AS clause using `alias`.
(asc expr)
Parse expr
and return an ORDER BY expr using ascending order.
Parse `expr` and return an ORDER BY expr using ascending order.
(ast stmt)
Returns the abstract syntax tree of stmt
.
Returns the abstract syntax tree of `stmt`.
(auto-commit? db)
Returns true if the current database connection is in auto commit mode, otherwise false.
Returns true if the current database connection is in auto commit mode, otherwise false.
(cascade condition)
Add a CASCADE clause to an SQL statement.
Add a CASCADE clause to an SQL statement.
(check expr)
Add a CHECK clause to an SQL statement.
Add a CHECK clause to an SQL statement.
(column name type & {:as options})
Add a column to stmt
.
Add a column to `stmt`.
(columns table)
Returns the columns of table
.
Returns the columns of `table`.
(compose stmt & body)
Compose multiple SQL statements.
Compose multiple SQL statements.
(concurrently condition)
Add a CONCURRENTLY clause to a SQL statement.
Add a CONCURRENTLY clause to a SQL statement.
(connect db & [opts])
Connect to db
using opts
.
Connect to `db` using `opts`.
(connected? db)
Returns true if db
is connected, otherwise false.
Returns true if `db` is connected, otherwise false.
(connection db)
Return the current connection to db
.
Return the current connection to `db`.
(continue-identity condition)
Add a CONTINUE IDENTITY clause to an SQL statement.
Add a CONTINUE IDENTITY clause to an SQL statement.
(copy db table columns & body)
Build a COPY statement.
Examples:
(copy db :country [] (from :stdin))
(copy db :country [] (from "/usr1/proj/bray/sql/country_data"))
Build a COPY statement. Examples: (copy db :country [] (from :stdin)) (copy db :country [] (from "/usr1/proj/bray/sql/country_data"))
(count-all db table)
Count all rows in the database table
.
Count all rows in the database `table`.
(create-materialized-view db view columns & body)
Build a CREATE MATERIALIZED VIEW statement.
Examples:
(sql/create-materialized-view db :pseudo-source [:key :value] (sql/values [["a" 1] ["a" 2] ["a" 3] ["a" 4] ["b" 5] ["c" 6] ["c" 7]]))
Build a CREATE MATERIALIZED VIEW statement. Examples: (sql/create-materialized-view db :pseudo-source [:key :value] (sql/values [["a" 1] ["a" 2] ["a" 3] ["a" 4] ["b" 5] ["c" 6] ["c" 7]]))
(create-schema db schema & body)
Build a CREATE SCHEMA statement.
Build a CREATE SCHEMA statement.
(create-table db table & body)
Build a CREATE TABLE statement.
Build a CREATE TABLE statement.
(create-type db type & body)
Build a CREATE TYPE sql statement.
Build a CREATE TYPE sql statement.
(db spec & [opts])
Return a new database from spec
.
Return a new database from `spec`.
(db? x)
Return true if x
is a database, otherwise false.
Return true if `x` is a database, otherwise false.
(deftable table-name doc & body)
Define a database table.
Define a database table.
(delete db table & body)
Build a DELETE statement.
Examples:
(delete db :continents)
(delete db :continents (where '(= :id 1)))
Build a DELETE statement. Examples: (delete db :continents) (delete db :continents (where '(= :id 1)))
(delimiter delimiter)
Add a DELIMITER clause to an SQL statement.
Add a DELIMITER clause to an SQL statement.
(desc expr)
Parse expr
and return an ORDER BY expr using descending order.
Parse `expr` and return an ORDER BY expr using descending order.
(distinct exprs & {:keys [on]})
Parse exprs
and return a DISTINCT clause.
Parse `exprs` and return a DISTINCT clause.
(do-constraint constraint)
Add a DO CONSTRAINT clause to a SQL statement.
Add a DO CONSTRAINT clause to a SQL statement.
(do-nothing)
Add a DO NOTHING clause to a SQL statement.
Add a DO NOTHING clause to a SQL statement.
(do-update expr)
Add a DO UPDATE clause to a SQL statement.
Add a DO UPDATE clause to a SQL statement.
(drop-materialized-view db view & body)
Build a DROP MATERIALIZED VIEW statement.
Examples:
(drop-materialized-view db :order-summary)
Build a DROP MATERIALIZED VIEW statement. Examples: (drop-materialized-view db :order-summary)
(drop-schema db schemas & body)
Build a DROP SCHEMA statement.
Examples:
(drop-schema db [:my-schema])
Build a DROP SCHEMA statement. Examples: (drop-schema db [:my-schema])
(drop-table db tables & body)
Build a DROP TABLE statement.
Examples:
(drop-table db [:continents])
(drop-table db [:continents :countries])
Build a DROP TABLE statement. Examples: (drop-table db [:continents]) (drop-table db [:continents :countries])
(drop-type db types & body)
Build a DROP TYPE statement.
Examples:
(drop-type db [:mood])
(drop-table db [:my-schema.mood])
Build a DROP TYPE statement. Examples: (drop-type db [:mood]) (drop-table db [:my-schema.mood])
(drop-view db view & body)
Build a DROP VIEW statement.
Examples:
(drop-view db :order-summary)
Build a DROP VIEW statement. Examples: (drop-view db :order-summary)
(encoding encoding)
Add a ENCODING clause to an SQL statement.
Add a ENCODING clause to an SQL statement.
(except & args)
Build an EXCEPT statement.
Examples:
(except (select db [1]) (select db [2]))
(except {:all true} (select db [1]) (select db [2]))
Build an EXCEPT statement. Examples: (except (select db [1]) (select db [2])) (except {:all true} (select db [1]) (select db [2]))
(excluded-keyword k)
Returns the keyword k
, prefixed with "EXCLUDED.".
Returns the keyword `k`, prefixed with "EXCLUDED.".
(excluded-keyword? k)
Returns true if the keyword k
is prefixed with "EXCLUDED.",
otherwise false.
Returns true if the keyword `k` is prefixed with "EXCLUDED.", otherwise false.
(excluded-kw-map ks)
Returns a map of EXCLUDED ks
indexed by ks
.
Returns a map of EXCLUDED `ks` indexed by `ks`.
(execute stmt & [opts])
Execute stmt
against a database.
Execute `stmt` against a database.
(explain db stmt & [opts])
Return an EXPLAIN statement for stmt
. opts
can be a map with
the following key/value pairs:
Examples:
(explain db (select db [:*] (from :foo)))
(explain db (select db [:*] (from :foo)) {:analyze true})
Return an EXPLAIN statement for `stmt`. `opts` can be a map with the following key/value pairs: - :analyze boolean - :buffers boolean - :costs boolean - :format :json, :text, :yaml, :xml - :timing boolean - :verbose boolean Examples: (explain db (select db [:*] (from :foo))) (explain db (select db [:*] (from :foo)) {:analyze true})
(from & from)
Add a FROM clause to an SQL statement. The from
forms can be one
or more tables, :stdin, a filename or an other sub query.
Examples:
(select db [:*] (from :continents))
(select db [:*] (from :continents :countries) (where '(= :continents.id :continent-id)))
(select db [:*] (from (as (select [1 2 3]) :x)))
(copy db :country [] (from :stdin))
(copy db :country [] (from "/usr1/proj/bray/sql/country_data"))
Add a FROM clause to an SQL statement. The `from` forms can be one or more tables, :stdin, a filename or an other sub query. Examples: (select db [:*] (from :continents)) (select db [:*] (from :continents :countries) (where '(= :continents.id :continent-id))) (select db [:*] (from (as (select [1 2 3]) :x))) (copy db :country [] (from :stdin)) (copy db :country [] (from "/usr1/proj/bray/sql/country_data"))
(group-by & exprs)
Add a GROUP BY clause to an SQL statement.
Add a GROUP BY clause to an SQL statement.
(having condition & [combine])
Add a HAVING clause to an SQL statement.
Examples:
(select db [:city '(max :temp-lo)] (from :weather) (group-by :city) (having '(< (max :temp-lo) 40)))
Add a HAVING clause to an SQL statement. Examples: (select db [:city '(max :temp-lo)] (from :weather) (group-by :city) (having '(< (max :temp-lo) 40)))
(if-exists condition)
Add a IF EXISTS clause to an SQL statement.
Add a IF EXISTS clause to an SQL statement.
(if-not-exists condition)
Add a IF EXISTS clause to an SQL statement.
Add a IF EXISTS clause to an SQL statement.
(inherits & tables)
Add an INHERITS clause to an SQL statement.
Add an INHERITS clause to an SQL statement.
(inline-str s)
Compile s
as an inline string, instead of a prepared statement
parameter.
WARNING: You have to make sure the string s
is safe against SQL
injection attacks yourself.
Compile `s` as an inline string, instead of a prepared statement parameter. WARNING: You have to make sure the string `s` is safe against SQL injection attacks yourself.
(insert db table columns & body)
Build a INSERT statement.
Build a INSERT statement.
(intersect & args)
Build an INTERSECT statement.
Examples:
(intersect (select db [1]) (select db [2]))
(intersect {:all true} (select db [1]) (select db [2]))
Build an INTERSECT statement. Examples: (intersect (select db [1]) (select db [2])) (intersect {:all true} (select db [1]) (select db [2]))
(join from condition & {:keys [type outer pk]})
Add a JOIN clause to a statement.
Examples:
(select db [:*] (from :countries) (join :continents '(using :id)))
(select db [:*] (from :continents) (join :countries.continent-id :continents.id))
(select db [:*] (from :countries) (join :continents '(on (= :continents.id :countries.continent-id))))
Add a JOIN clause to a statement. Examples: (select db [:*] (from :countries) (join :continents '(using :id))) (select db [:*] (from :continents) (join :countries.continent-id :continents.id)) (select db [:*] (from :countries) (join :continents '(on (= :continents.id :countries.continent-id))))
(like table & {:as opts})
Add a LIKE clause to an SQL statement.
Add a LIKE clause to an SQL statement.
(limit expr)
Add a LIMIT clause to an SQL statement.
Add a LIMIT clause to an SQL statement.
Make a new instance of class
using attrs
.
Make a new instance of `class` using `attrs`.
(make-instances db class records)
Convert all records
into instances of class
.
Convert all `records` into instances of `class`.
(nulls expr where)
Parse expr
and return an NULLS FIRST/LAST expr.
Parse `expr` and return an NULLS FIRST/LAST expr.
(offset expr)
Add a OFFSET clause to an SQL statement.
Add a OFFSET clause to an SQL statement.
(on-conflict target & body)
Add a ON CONFLICT clause to a SQL statement.
Add a ON CONFLICT clause to a SQL statement.
(on-conflict-on-constraint target & body)
Add a ON CONFLICT ON CONSTRAINT clause to a SQL statement.
Add a ON CONFLICT ON CONSTRAINT clause to a SQL statement.
(or-replace condition)
Add an OR REPLACE clause to an SQL statement.
Add an OR REPLACE clause to an SQL statement.
(order-by & exprs)
Add a ORDER BY clause to an SQL statement.
Add a ORDER BY clause to an SQL statement.
(page-info db target & [params])
Returns the page info for query
and params
.
Returns the page info for `query` and `params`.
(paginate page & [limit per-page])
Add LIMIT and OFFSET clauses to query
calculated from page
and
per-page.
Add LIMIT and OFFSET clauses to `query` calculated from `page` and `per-page.`
(prepare db sql & [opts])
Return a prepared statement for sql
.
Return a prepared statement for `sql`.
(primary-key & keys)
Add a PRIMARY KEY clause to a table.
Add a PRIMARY KEY clause to a table.
(print-explain query)
Print the execution plan of query
.
Print the execution plan of `query`.
(refresh-materialized-view db view & body)
Build a REFRESH MATERIALIZED VIEW statement.
Examples:
(refresh-materialized-view db :order-summary)
Build a REFRESH MATERIALIZED VIEW statement. Examples: (refresh-materialized-view db :order-summary)
(restart-identity condition)
Add a RESTART IDENTITY clause to an SQL statement.
Add a RESTART IDENTITY clause to an SQL statement.
(restrict condition)
Add a RESTRICT clause to an SQL statement.
Add a RESTRICT clause to an SQL statement.
(returning & exprs)
Add a RETURNING clause to an SQL statement.
Examples:
(insert db :distributors [] (values [{:did 106 :dname "XYZ Widgets"}]) (returning :*))
(update db :films {:kind "Dramatic"} (where '(= :kind "Drama")) (returning :*))
Add a RETURNING clause to an SQL statement. Examples: (insert db :distributors [] (values [{:did 106 :dname "XYZ Widgets"}]) (returning :*)) (update db :films {:kind "Dramatic"} (where '(= :kind "Drama")) (returning :*))
(select db exprs & body)
Build a SELECT statement.
Examples:
(select db [1])
(select db [:*] (from :continents))
(select db [:id :name] (from :continents))
Build a SELECT statement. Examples: (select db [1]) (select db [:*] (from :continents)) (select db [:id :name] (from :continents))
(set-savepoint! db & [name])
Set a savepoint on the current connection.
Set a savepoint on the current connection.
(sql stmt)
Compile stmt
into a clojure.java.jdbc compatible vector.
Compile `stmt` into a clojure.java.jdbc compatible vector.
(sql-str stmt)
Prepare stmt
using the database and return the raw SQL as a string.
Prepare `stmt` using the database and return the raw SQL as a string.
(temporary condition)
Add a TEMPORARY clause to an SQL statement.
Add a TEMPORARY clause to an SQL statement.
(transact db f & [opts])
Run f
within a database transaction on db
.
Run `f` within a database transaction on `db`.
(truncate db tables & body)
Build a TRUNCATE statement.
Examples:
(truncate db [:continents])
(truncate db [:continents :countries])
Build a TRUNCATE statement. Examples: (truncate db [:continents]) (truncate db [:continents :countries])
(union & args)
Build a UNION statement.
Examples:
(union (select db [1]) (select db [2]))
(union {:all true} (select db [1]) (select db [2]))
Build a UNION statement. Examples: (union (select db [1]) (select db [2])) (union {:all true} (select db [1]) (select db [2]))
(update db table row & body)
Build a UPDATE statement.
Examples:
(update db :films {:kind "Dramatic"} (where '(= :kind "Drama")))
Build a UPDATE statement. Examples: (update db :films {:kind "Dramatic"} (where '(= :kind "Drama")))
(values vals)
(values db vals)
Return a VALUES statement or clause.
Examples:
(values db [[1 "one"] [2 "two"] [3 "three"]])
(insert db :distributors [] (values [{:did 106 :dname "XYZ Widgets"}]))
Return a VALUES statement or clause. Examples: (values db [[1 "one"] [2 "two"] [3 "three"]]) (insert db :distributors [] (values [{:did 106 :dname "XYZ Widgets"}]))
(where condition & [combine])
Add a WHERE clause to an SQL statement.
Examples:
(select db [1] (where '(in 1 (1 2 3))))
(select db [*] (from :continents) (where '(= :name "Europe")))
(delete db :continents (where '(= :id 1)))
Add a WHERE clause to an SQL statement. Examples: (select db [1] (where '(in 1 (1 2 3)))) (select db [*] (from :continents) (where '(= :name "Europe"))) (delete db :continents (where '(= :id 1)))
(window & exprs)
Add a WINDOW clause to an SQL statement.
Add a WINDOW clause to an SQL statement.
(with db bindings query)
Build a WITH (common table expressions) query.
Build a WITH (common table expressions) query.
(with-connection [db-sym db & [opts]] & body)
Open a database connection, bind the connected db
to db-sym
,
evaluate body
and close the connection again.
Open a database connection, bind the connected `db` to `db-sym`, evaluate `body` and close the connection again.
(with-data data?)
Add a WITH [NO] DATA clause to a SQL statement.
Add a WITH [NO] DATA clause to a SQL statement.
(with-db [db-sym config & [opts]] & body)
Start a database component using config
bind it to db-sym
,
evaluate body
and close the database connection again.
Start a database component using `config` bind it to `db-sym`, evaluate `body` and close the database connection again.
(with-rollback [db-sym db] & body)
Start a transaction, evaluate body
and rollback.
Start a transaction, evaluate `body` and rollback.
(with-savepoint [db-sym db opts] & body)
Start a transaction, evaluate body
and rollback.
Start a transaction, evaluate `body` and rollback.
(with-transaction [db-sym db & [opts]] & body)
Start a new db
transaction, bind db
to db-sym
and evaluate
body
within the transaction.
Start a new `db` transaction, bind `db` to `db-sym` and evaluate `body` within the transaction.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close