(->db-connection conn backend)
Positional factory function for class sqlosure.db_connection.db-connection.
Positional factory function for class sqlosure.db_connection.db-connection.
(db-connection-backend rec__2313__auto__)
(db-connection-backend data__2314__auto__ v__2315__auto__)
Lens for the backend
field from a [[db-connection]] record. See sqlosure.db-connection/make-db-connection
.
Lens for the `backend` field from a [[db-connection]] record. See [[sqlosure.db-connection/make-db-connection]].
(db-connection-conn rec__2313__auto__)
(db-connection-conn data__2314__auto__ v__2315__auto__)
Lens for the conn
field (The database connection map as used by jdbc.) from a [[db-connection]] record. See sqlosure.db-connection/make-db-connection
.
Lens for the `conn` field (The database connection map as used by jdbc.) from a [[db-connection]] record. See [[sqlosure.db-connection/make-db-connection]].
(db-connection? thing)
Is object a db-connection
record? See sqlosure.db-connection/make-db-connection
.
Is object a `db-connection` record? See [[sqlosure.db-connection/make-db-connection]].
(delete! conn sql-table criterion-proc)
delete!
takes a db-connection, a sql-table and a criterion function and
deletes all entries in sql-table
that satisfy the criteria.
criterion-proc
is a function that takes as many arguments as the relation
has fields. In it's body one can specify the criteria in the same manner as
in regular sqlosure queries.
Example:
(def db-spec { ... }) ;; Your db-connection map.
(def kv-table (table "kv" {"key" $integer-t
"value" $string-t}))
;; Delete all records where key > 10.
(delete! (db-connect db-spec) kv-table
(fn [k v]
($> k ($integer 10))))
`delete!` takes a db-connection, a sql-table and a criterion function and deletes all entries in `sql-table` that satisfy the criteria. `criterion-proc` is a function that takes as many arguments as the relation has fields. In it's body one can specify the criteria in the same manner as in regular sqlosure queries. Example: (def db-spec { ... }) ;; Your db-connection map. (def kv-table (table "kv" {"key" $integer-t "value" $string-t})) ;; Delete all records where key > 10. (delete! (db-connect db-spec) kv-table (fn [k v] ($> k ($integer 10))))
(insert! conn sql-table & args)
insert!
takes a db-connection and an sql-table and some rest args
and
attempts to insert them into the connected databases table.
The table to insert into is the relational-algebra/base-relation-handle
of
sql-table
.
args
can either be:
Example:
(def db-spec { ... }) ;; Your db-connection map.
;; For inserts that contain every column of the specified table:
(insert! (db-connect db-spec) some-table arg1 arg2 ... argN)
;; For inserts that only specify a subset of all columns:
(insert! (db-connect db-spec) some-table
(alist->rel-scheme {"foo" $integer-t
"bar" $string-t}
integer-value string-value))
`insert!` takes a db-connection and an sql-table and some rest `args` and attempts to insert them into the connected databases table. The table to insert into is the `relational-algebra/base-relation-handle` of `sql-table`. `args` can either be: - a set of values to insert if there is a value for each column. Those must be in the order of the columns in the table. - a rel-scheme, specifying the columns to insert the values into follwed by the desired values. Example: (def db-spec { ... }) ;; Your db-connection map. ;; For inserts that contain every column of the specified table: (insert! (db-connect db-spec) some-table arg1 arg2 ... argN) ;; For inserts that only specify a subset of all columns: (insert! (db-connect db-spec) some-table (alist->rel-scheme {"foo" $integer-t "bar" $string-t} integer-value string-value))
(make-db-connection conn backend)
Construct a db-connection
(db-connection
serves as a container for storing the current
db-connection as well as backend specific conversion and printer
functions.) record.
conn
(The database connection map as used by jdbc.): access via sqlosure.db-connection/db-connection-conn
backend
: access via sqlosure.db-connection/db-connection-backend
Construct a `db-connection` (`db-connection` serves as a container for storing the current db-connection as well as backend specific conversion and printer functions.) record. `conn` (The database connection map as used by jdbc.): access via [[sqlosure.db-connection/db-connection-conn]] `backend`: access via [[sqlosure.db-connection/db-connection-backend]]
(map->db-connection m__2330__auto__)
Factory function for class sqlosure.db_connection.db-connection, taking a map of keywords to field values.
Factory function for class sqlosure.db_connection.db-connection, taking a map of keywords to field values.
(result-set-seq rs col-types backend)
Creates and returns a lazy sequence of maps corresponding to the rows in the java.sql.ResultSet rs.
Creates and returns a lazy sequence of maps corresponding to the rows in the java.sql.ResultSet rs.
(run-query conn q & {:keys [optimize?] :or {optimize? true} :as opts-map})
Takes a database connection and a query and runs it against the database.
Example:
(def db-spec { ... }) ;; Your db-connection map.
(def kv-table (table "kv" {"key" $integer-t
"value" $string-t}))
;; Get all records from kv-table where "key" is less than 10.
(run-query (db-connect db-spec)
(query [kv (<- kv-table)]
(restrict ($> (! k "key")
($integer 10)))
(project {"value" (! kv "value")})))
Takes a database connection and a query and runs it against the database. Example: (def db-spec { ... }) ;; Your db-connection map. (def kv-table (table "kv" {"key" $integer-t "value" $string-t})) ;; Get all records from kv-table where "key" is less than 10. (run-query (db-connect db-spec) (query [kv (<- kv-table)] (restrict ($> (! k "key") ($integer 10))) (project {"value" (! kv "value")})))
(update! conn sql-table criterion-proc alist-first & args)
update!
takes a db-connection, a sql-table, a criterion-proc and and map
and updates all entries of sql-table
that satisfy criterion-proc
with the
new key->value pairs specified in alist-first
function.
Example:
(def db-spec { ... }) ;; Your db-connection map.
(def kv-table (table "kv" {"key" $integer-t
"value" $string-t}))
;; Update the "value" field all records where key > 10 to "NEWVAL".
(update! (db-connect db-spec) kv-table
(fn [k v]
($> k ($integer 10))) ;; Read: "key" > 10
(fn [k v]
{"value" ($string "NEWVAL")})
`update!` takes a db-connection, a sql-table, a criterion-proc and and map and updates all entries of `sql-table` that satisfy `criterion-proc` with the new key->value pairs specified in `alist-first` function. Example: (def db-spec { ... }) ;; Your db-connection map. (def kv-table (table "kv" {"key" $integer-t "value" $string-t})) ;; Update the "value" field all records where key > 10 to "NEWVAL". (update! (db-connect db-spec) kv-table (fn [k v] ($> k ($integer 10))) ;; Read: "key" > 10 (fn [k v] {"value" ($string "NEWVAL")})
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close