Liking cljdoc? Tell your friends :D

asphalt.core


batch-updateclj

(batch-update connection-source sql-source batch-params)
(batch-update params-setter connection-source sql-source batch-params)

Execute a SQL write statement with a batch of parameters returning the number of rows updated as a vector.

Execute a SQL write statement with a batch of parameters returning the number of rows updated as a vector.
sourceraw docstring

compile-sql-templateclj

(compile-sql-template sql-tokens
                      result-types
                      {:keys [result-set-worker param-placeholder params-setter
                              row-maker column-reader conn-worker
                              make-params-setter make-row-maker
                              make-column-reader make-conn-worker sql-name]
                       :or {sql-name (gensym "sql-name-")}
                       :as options})

Given a SQL template (SQL tokens and result types) compile it into a more efficient SQL source with the following enhancements:

  • associated params-setter
  • param placeholder for named, multi-value params
  • associated result-set-worker
  • associated row-maker
  • associated column-reader
  • associated conn-worker
  • act as arity-2 function (f conn-source params) Options: :result-set-worker (fn [sql-source result-set]) - used when :make-conn-worker auto-defaults to query :param-placeholder map {:param-name placeholder-string} - override placeholder ? for named multi-value params :params-setter (fn [prepared-stmt params]) - used when :make-params-setter not specified :row-maker (fn [result-set col-count]) - used when :make-row-maker not specified :column-reader (fn [result-set]) - used when :make-column-reader not specified :conn-worker (fn [conn-source sql-source params]) - used when :make-conn-worker not specified :make-params-setter (fn [param-keys param-types]) -> (fn [prepared-stmt params]) to set params :make-row-maker (fn [result-types]) -> (fn [result-set col-count]) to return row :make-column-reader (fn [result-types]) -> (fn [result-set]) to return column value :make-conn-worker (fn [sql-tokens result-types]) -> (fn [conn-source sql-source params]) :sql-name string (or coerced as string) name for the template See: parse-sql for SQL-template format
Given a SQL template (SQL tokens and result types) compile it into a more efficient SQL source with the following
enhancements:
  * associated params-setter
  * param placeholder for named, multi-value params
  * associated result-set-worker
  * associated row-maker
  * associated column-reader
  * associated conn-worker
  * act as arity-2 function (f conn-source params)
Options:
  :result-set-worker  (fn [sql-source result-set])         - used when :make-conn-worker auto-defaults to query
  :param-placeholder  map {:param-name placeholder-string} - override placeholder ? for named multi-value params
  :params-setter      (fn [prepared-stmt params])          - used when :make-params-setter not specified
  :row-maker          (fn [result-set col-count])          - used when :make-row-maker not specified
  :column-reader      (fn [result-set])                    - used when :make-column-reader not specified
  :conn-worker        (fn [conn-source sql-source params]) - used when :make-conn-worker not specified
  :make-params-setter (fn [param-keys param-types]) -> (fn [prepared-stmt params]) to set params
  :make-row-maker     (fn [result-types]) -> (fn [result-set col-count]) to return row
  :make-column-reader (fn [result-types]) -> (fn [result-set]) to return column value
  :make-conn-worker   (fn [sql-tokens result-types]) -> (fn [conn-source sql-source params])
  :sql-name           string (or coerced as string) name for the template
See:
  `parse-sql` for SQL-template format
sourceraw docstring

defsqlcljmacro

(defsql var-symbol sql)
(defsql var-symbol sql options)
(defsql var-symbol docstring sql options)

Define a parsed/compiled SQL template that can be used to execute the SQL later. The defined template may be invoked like a function (fn [connection-source] [connection-source params]).

Define a parsed/compiled SQL template that can be used to execute the SQL later. The defined template may be invoked
like a function (fn [connection-source] [connection-source params]).
sourceraw docstring

fetch-mapsclj

(fetch-maps sql-source result-set)
(fetch-maps
  {:keys [fetch-size key-maker] :or {key-maker r/label->key} :as options}
  sql-source
  result-set)

Given asphalt.type.ISqlSource and java.sql.ResultSet instances fetch a collection of rows as maps. It is required for asphalt.type.ISqlSource/read-row to return a vector of all column values for the sql-source. Options: Key Type/spec Default Description


:fetch-size positive integer not applied fetch-size to be set on java.sql.ResultSet :key-maker (fn [^String label]) asphalt.result/label->key converts column label to column key

Given asphalt.type.ISqlSource and java.sql.ResultSet instances fetch a collection of rows as maps. It is required
for asphalt.type.ISqlSource/read-row to return a vector of all column values for the sql-source.
Options:
Key          Type/spec            Default                    Description
----         ----------           --------                   ------------
:fetch-size  positive integer     not applied                fetch-size to be set on java.sql.ResultSet
:key-maker   (fn [^String label]) asphalt.result/label->key  converts column label to column key
sourceraw docstring

fetch-optional-rowclj

(fetch-optional-row sql-source result-set)
(fetch-optional-row {:keys [default] :as options} sql-source result-set)

Given asphalt.type.ISqlSource and java.sql.ResultSet instances fetch a single row if one exists, nil (or specified default) otherwise. Options: Key Type/spec Default Description


:default any value nil default value to return when no row is found

See also: fetch-single-row for other options

Given asphalt.type.ISqlSource and java.sql.ResultSet instances fetch a single row if one exists, nil (or specified
default) otherwise.
Options:
Key       Type/spec   Default   Description
----      ----------  --------  ------------
:default  any value   nil       default value to return when no row is found

See also:
`fetch-single-row` for other options
sourceraw docstring

fetch-optional-valueclj

(fetch-optional-value sql-source result-set)
(fetch-optional-value {:keys [default] :as options} sql-source result-set)

Given asphalt.type.ISqlSource and java.sql.ResultSet instances fetch a single column value if one exists, nil (or specified default) otherwise. Options: Key Type/spec Default Description


:default any value nil default value to return when no row is found

See also: fetch-single-value for other supported options

Given asphalt.type.ISqlSource and java.sql.ResultSet instances fetch a single column value if one exists, nil (or
specified default) otherwise.
Options:
Key       Type/spec   Default   Description
----      ----------  --------  ------------
:default  any value   nil       default value to return when no row is found

See also:
`fetch-single-value` for other supported options
sourceraw docstring

fetch-rowsclj

(fetch-rows sql-source result-set)
(fetch-rows
  {:keys [fetch-size max-rows row-maker] :or {row-maker t/read-row} :as options}
  sql-source
  result-set)

Given asphalt.type.ISqlSource and java.sql.ResultSet instances fetch a vector of rows. Options: Key Type/spec Default Description


:fetch-size positive integer not applied fetch-size to set on java.sql.ResultSet :max-rows positive integer not applied max result rows to read :row-maker (fn [sql-source result-set col-count]) returns vector of col values fn to make a row from column values

Given asphalt.type.ISqlSource and java.sql.ResultSet instances fetch a vector of rows.
Options:
Key          Type/spec                               Default      Description
----         ----------                              --------     ------------
:fetch-size  positive integer                        not applied  fetch-size to set on java.sql.ResultSet
:max-rows    positive integer                        not applied  max result rows to read
:row-maker   (fn [sql-source result-set col-count])  returns vector of col values
                                                                  fn to make a row from column values
sourceraw docstring

fetch-single-rowclj

(fetch-single-row sql-source result-set)
(fetch-single-row {:keys [fetch-size on-empty on-multi row-maker]
                   :or {on-empty r/throw-on-empty
                        on-multi r/throw-on-multi
                        row-maker t/read-row}
                   :as options}
                  sql-source
                  result-set)

Given asphalt.type.ISqlSource and java.sql.ResultSet instances fetch a single row. Options: Key Type/spec Default Description


:fetch-size positive integer not applied fetch-size to set on java.sql.ResultSet :on-empty (fn [sql-source result-set]) throws exception fn to handle the :on-empty event :on-multi (fn [sql-source result-set row]) throws exception fn to handle the :on-multi event :row-maker (fn [sql-source result-set col-count]) returns vector of column values fn to make a row from column values

Given asphalt.type.ISqlSource and java.sql.ResultSet instances fetch a single row.
Options:
Key          Type/spec                              Default           Description
----         ----------                             --------          ------------
:fetch-size  positive integer                       not applied       fetch-size to set on java.sql.ResultSet
:on-empty    (fn [sql-source result-set])           throws exception  fn to handle the :on-empty event
:on-multi    (fn [sql-source result-set row])       throws exception  fn to handle the :on-multi event
:row-maker   (fn [sql-source result-set col-count]) returns vector of column values
                                                                      fn to make a row from column values
sourceraw docstring

fetch-single-valueclj

(fetch-single-value sql-source result-set)
(fetch-single-value {:keys [column-reader fetch-size on-empty on-multi]
                     :or {column-reader t/read-col
                          on-empty r/throw-on-empty
                          on-multi r/throw-on-multi}
                     :as options}
                    sql-source
                    result-set)

Given asphalt.type.ISqlSource and java.sql.ResultSet instances fetch a single column value. Options: Key Type/spec Default Description


:column-reader (fn [sql-source result-set]) returns col value fn to extract column value :fetch-size positive integer not applied fetch-size to be set on java.sql.ResultSet :on-empty (fn [sql-source result-set]) throws exception fn to handle the :on-empty event :on-multi (fn [sql-source result-set col-value]) throws exception fn to handle the :on-multi event

Given asphalt.type.ISqlSource and java.sql.ResultSet instances fetch a single column value.
Options:
Key             Type/spec                               Default            Description
----            ----------                              --------           ------------
:column-reader  (fn [sql-source result-set])            returns col value  fn to extract column value
:fetch-size     positive integer                        not applied        fetch-size to be set on java.sql.ResultSet
:on-empty       (fn [sql-source result-set])            throws exception   fn to handle the :on-empty event
:on-multi       (fn [sql-source result-set col-value])  throws exception   fn to handle the :on-multi event
sourceraw docstring

genkeyclj

(genkey connection-source sql-source params)
(genkey result-set-worker connection-source sql-source params)
(genkey params-setter result-set-worker connection-source sql-source params)

Execute an update statement returning the keys generated by the statement. The generated keys are extracted from a java.sql.ResultSet instance using the optional result-set-worker argument.

Execute an update statement returning the keys generated by the statement. The generated keys are extracted from a
java.sql.ResultSet instance using the optional result-set-worker argument.
sourceraw docstring

instrument-connection-sourcecljdeprecated

(instrument-connection-source connection-source
                              {:keys [conn-creation stmt-creation sql-execution]
                               :or {conn-creation JdbcEventListener/NOP
                                    stmt-creation JdbcEventListener/NOP
                                    sql-execution JdbcEventListener/NOP}})

DEPRECATED: Alternate implementation to be provided in a future vesion. Make instrumented connection source using connection-creation, statement-creation and SQL-execution listeners.

Option :conn-creation corresponds to a map containing the following fns, triggered when JDBC connections are created: ;; event = :jdbc-connection-creation-event {:before (fn [event]) :on-success (fn [^String id ^long nanos event]) :on-error (fn [^String id ^long nanos event ^Exception error]) :lastly (fn [^String id ^long nanos event])}

Option :stmt-creation corresponds to a map containing the following fns, triggered when JDBC statements are created: {:before (fn [^asphalt.type.StmtCreationEvent event]) :on-success (fn [^String id ^long nanos ^asphalt.type.StmtCreationEvent event]) :on-error (fn [^String id ^long nanos ^asphalt.type.StmtCreationEvent event ^Exception error]) :lastly (fn [^String id ^long nanos ^asphalt.type.StmtCreationEvent event])}

Option :sql-execution corresponds to a map containing the following fns, triggered when SQL statements are executed: {:before (fn [^asphalt.type.SQLExecutionEvent event]) :on-success (fn [^String id ^long nanos ^asphalt.type.SQLExecutionEvent event]) :on-error (fn [^String id ^long nanos ^asphalt.type.SQLExecutionEvent event ^Exception error]) :lastly (fn [^String id ^long nanos ^asphalt.type.SQLExecutionEvent event])}

DEPRECATED: Alternate implementation to be provided in a future vesion.
Make instrumented connection source using connection-creation, statement-creation and SQL-execution listeners.

Option :conn-creation corresponds to a map containing the following fns, triggered when JDBC connections are created:
;; event = :jdbc-connection-creation-event
{:before     (fn [event])
 :on-success (fn [^String id ^long nanos event])
 :on-error   (fn [^String id ^long nanos event ^Exception error])
 :lastly     (fn [^String id ^long nanos event])}

Option :stmt-creation corresponds to a map containing the following fns, triggered when JDBC statements are created:
{:before     (fn [^asphalt.type.StmtCreationEvent event])
 :on-success (fn [^String id ^long nanos ^asphalt.type.StmtCreationEvent event])
 :on-error   (fn [^String id ^long nanos ^asphalt.type.StmtCreationEvent event ^Exception error])
 :lastly     (fn [^String id ^long nanos ^asphalt.type.StmtCreationEvent event])}

Option :sql-execution corresponds to a map containing the following fns, triggered when SQL statements are executed:
{:before     (fn [^asphalt.type.SQLExecutionEvent event])
 :on-success (fn [^String id ^long nanos ^asphalt.type.SQLExecutionEvent event])
 :on-error   (fn [^String id ^long nanos ^asphalt.type.SQLExecutionEvent event ^Exception error])
 :lastly     (fn [^String id ^long nanos ^asphalt.type.SQLExecutionEvent event])}
sourceraw docstring

instrument-datasourcecljdeprecated

(instrument-datasource ds
                       {:keys [stmt-creation sql-execution]
                        :or {stmt-creation JdbcEventListener/NOP
                             sql-execution JdbcEventListener/NOP}})

DEPRECATED: Use 'instrument-connection-source' instead. Make instrumented javax.sql.DataSource instance using statement-creation and SQL-execution listeners.

Option :stmt-creation corresponds to a map containing the following fns, triggered when JDBC statements are created: {:before (fn [^asphalt.type.StmtCreationEvent event]) :on-success (fn [^String id ^long nanos ^asphalt.type.StmtCreationEvent event]) :on-error (fn [^String id ^long nanos ^asphalt.type.StmtCreationEvent event ^Exception error]) :lastly (fn [^String id ^long nanos ^asphalt.type.StmtCreationEvent event])}

Option :sql-execution corresponds to a map containing the following fns, triggered when SQL statements are executed: {:before (fn [^asphalt.type.SQLExecutionEvent event]) :on-success (fn [^String id ^long nanos ^asphalt.type.SQLExecutionEvent event]) :on-error (fn [^String id ^long nanos ^asphalt.type.SQLExecutionEvent event ^Exception error]) :lastly (fn [^String id ^long nanos ^asphalt.type.SQLExecutionEvent event])}

DEPRECATED: Use 'instrument-connection-source' instead.
Make instrumented javax.sql.DataSource instance using statement-creation and SQL-execution listeners.

Option :stmt-creation corresponds to a map containing the following fns, triggered when JDBC statements are created:
{:before     (fn [^asphalt.type.StmtCreationEvent event])
 :on-success (fn [^String id ^long nanos ^asphalt.type.StmtCreationEvent event])
 :on-error   (fn [^String id ^long nanos ^asphalt.type.StmtCreationEvent event ^Exception error])
 :lastly     (fn [^String id ^long nanos ^asphalt.type.StmtCreationEvent event])}

Option :sql-execution corresponds to a map containing the following fns, triggered when SQL statements are executed:
{:before     (fn [^asphalt.type.SQLExecutionEvent event])
 :on-success (fn [^String id ^long nanos ^asphalt.type.SQLExecutionEvent event])
 :on-error   (fn [^String id ^long nanos ^asphalt.type.SQLExecutionEvent event ^Exception error])
 :lastly     (fn [^String id ^long nanos ^asphalt.type.SQLExecutionEvent event])}
sourceraw docstring

parse-sqlclj

(parse-sql sql)
(parse-sql
  sql
  {:keys [sql-name escape-char param-start-char type-start-char param-types
          result-types]
   :or {sql-name sql escape-char \\ param-start-char \$ type-start-char \^}
   :as options})

Given a SQL statement with embedded parameter names return a two-element vector [sql-tokens result-types] where

  • sql-tokens is a vector of alternating string and param-pair vectors
  • param-pair is a vector of two elements [param-key param-type] (param keys are used to extract map params)
  • result-types is a vector of result types Options: :sql-name (auto generated) name of the SQL statement :escape-char (default: ) escape character in the SQL to avoid interpretation :param-start-char (default: $) character to mark the beginning of a named param :type-start-char (default: ^) character to mark the beginning of a type hint :param-types (parsed from SQL) vector of param-type keywords :result-types (parsed from SQL) vector of result-type keywords See: compile-sql-template to compile a SQL template for efficiency/enhancement asphalt.type for supported SQL types.
Given a SQL statement with embedded parameter names return a two-element vector [sql-tokens result-types] where
* sql-tokens is a vector of alternating string and param-pair vectors
* param-pair is a vector of two elements [param-key param-type] (param keys are used to extract map params)
* result-types is a vector of result types
Options:
:sql-name         (auto generated)  name of the SQL statement
:escape-char      (default: \)     escape character in the SQL to avoid interpretation
:param-start-char (default: $)      character to mark the beginning of a named param
:type-start-char  (default: ^)      character to mark the beginning of a type hint
:param-types      (parsed from SQL) vector of param-type keywords
:result-types     (parsed from SQL) vector of result-type keywords
See:
  `compile-sql-template` to compile a SQL template for efficiency/enhancement
  asphalt.type for supported SQL types.
sourceraw docstring

queryclj

(query connection-source sql-source params)
(query result-set-worker connection-source sql-source params)
(query params-setter result-set-worker connection-source sql-source params)

Execute query with params and process the java.sql.ResultSet instance with result-set-worker. The java.sql.ResultSet instance is closed in the end, so result-set-worker should neither close it nor make a direct/indirect reference to it in the value it returns.

Execute query with params and process the java.sql.ResultSet instance with result-set-worker. The java.sql.ResultSet
instance is closed in the end, so result-set-worker should neither close it nor make a direct/indirect reference to
it in the value it returns.
sourceraw docstring

updateclj

(update connection-source sql-source params)
(update params-setter connection-source sql-source params)

Execute an update statement returning the number of rows impacted.

Execute an update statement returning the number of rows impacted.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close