org.purefn.sqlium.import

all-ids-query

(all-ids-query spec)
Returns a query that will select all ids in the base table of
spec.

condition-table

(condition-table condition)
Returns the table used in a condition's column.

default-batch-size

delta-condition

(delta-condition field date)
Returns condition map for a delta field.

expiry-condition

(expiry-condition expiry)
Returns condition map for an expiry.

fetch-column

(fetch-column db query column)
Efficient, low-level query function to return a collection of a
single column. Takes a sql query, the column name to fetch, and
returns an ArrayList with the values of that column.

fetch-results

(fetch-results db sql-with-aliases)
Takes the [sql col-aliases] tuple as returned by `sql/select` and
fetches the results, renaming the keys in the returned records
using col-aliases.

id-query

(id-query spec {:keys [limit offset delta expiry], :as opts})
Takes parsed spec (not grouped) and returns query to retrieve the
ids, controlled by opts map.

import-many-relationship

(import-many-relationship db rel data)
Takes a db, a many relationship map and collection of source table data,
retrieves the related data and merges it into the table data.

import-record

(import-record db table-spec entid)
Like import-table, but returns single record from given db.

import-table

(import-table db table-spec)(import-table db table-spec {:keys [limit offset delta expiry batch update-table], :or {batch default-batch-size}, :as opts})
Takes an analyzed DSL spec with a table at the top level, and opts
map, and performs the queries to fetch the table data and its
associated relationships. opts map has keys:

 * :limit   Number of records to retrieve [unlimited]
 * :offset  Starting record [0]
 * :delta   Turns the import into a deltas import. A map with
            parameters for retrieving deltas.
 * :update-table  Also turns into ino a deltas import. Preferred
            over :delta, if present. A map describing the table
            that contains entity ids to update.
 * :expiry  Spec for filter for records older than a specified
            number of days.
 * :batch   Batch size.

If present, the delta map should have keys:
 * :fields  Collection of :table/column (datetime) fields that will
            be used for update detection.
 * :date    Date to be used for comparison. Anything that clj-time can
            coerce to DateTime.

If present, the update-table map should have keys:
 * :table     Name of the update table
 * :id        Name of column with entity ids
 * :updated   Name of column with entity update datetimes.
 * :since     Datetime to return updates since.

If present, the expiry map should have keys:
 * :field   The :table/column (datetime) field that will be used to
            determine record age.
 * :age     DateTime of the cutoff.

The resulting records have keys in the form of :table/column for
each group, and many-relationships
in [:many-relationships :foreign-table/column] keys.

Returns a lazy-seq of results.

join-path

(join-path path)
Takes a path (as from table-paths) and returns collection of maps
describing each join in the path, containing:

`{:base {:name "table-name"
         :alias "optional-alias"
         :join-col "col-name"}
  :target {:name "table-name"
           :alias "table-alias"
           :join-col "col-name"}`

Table aliases are used so that tables can be repeated in a
relationship chain. The aliases are generated by appending an
incrementing number to the table name.

join-results

(join-results rel data rel-data)
Takes a relationship map for a many relationship, table data, and
the relationship's data, and joins the relationship data into the
table data.

path-query

(path-query path conditions)
Takes a path as returned by `table-paths`, and a collection of
conditions, and returns a query to retrieve ids from the base table
in the path.

Each condition is a map of:

`{:column :table/col
  :comparator "comparator-sym"
  :value some-val}`

table-id

(table-id table)
Returns keyword representing a table id field, eg :table/field.

table-paths

(table-paths table-spec)(table-paths paths base-path table-spec)
Returns a map, keyed by table name, with all paths to get to that
table in given compiled spec.

A path is a vector of [table-with-rel* table-without-rel]

Returns  `{table-name #{path}}`

update-table-id-query

(update-table-id-query {:keys [table id updated since], :as update-map})
Takes a map describing update table, and returns a query to
retrieve ids to update. Update map has keys:

  * :table     Name of the update table
  * :id        Name of column with entity ids
  * :updated   Name of column with entity update datetimes.
  * :since     Datetime to return updates since.