Liking cljdoc? Tell your friends :D

fulcro-sql.core


build-db-managerclj

(build-db-manager config)

Build a component that can manage you SQL database startup and stop.

Build a component that can manage you SQL database startup and stop.
sourceraw docstring

column-specclj

(column-spec schema sqlprop)

Returns a database-specific SQL property selection and AS clause for the given sql prop.

E.g.: (column-spec schema :account/name) => account.name AS "account/name"

Returns a database-specific SQL property selection and AS clause for the given sql prop.

E.g.: (column-spec schema :account/name) => account.name AS "account/name"
sourceraw docstring

column-spec*cljmultimethod

Get the database-specific column query specification for a given SQL prop.

Get the database-specific column query specification for a given SQL prop.
sourceraw docstring

columns-forclj

(columns-for schema graph-query)

Returns an SQL-centric set of properties at the top level of the given graph query. It does not follow joins, but does include any columns that would be necessary to process the given joins. It will always include the row ID.

Returns an SQL-centric set of properties at the top level of the given graph query. It does not follow joins, but
does include any columns that would be necessary to process the given joins. It will always include the row ID.
sourceraw docstring

create-drop*cljmultimethod

source

create-poolclj

(create-pool properties-file)

Create a HikariDataSource for connection pooling from a properties filename.

Create a HikariDataSource for connection pooling from a properties filename.
sourceraw docstring

filter-params->filtersclj

(filter-params->filters schema params)

Convert filter parameters like {:item/deleted {:eq false :max-depth 3}} into filters suitable for run-query.

Convert filter parameters like {:item/deleted {:eq false :max-depth 3}} into filters suitable for run-query.
sourceraw docstring

filter-whereclj

(filter-where expr params)
(filter-where expr params min-depth max-depth)

Creates a filter usable on the graph:

expr - An SQL boolean expression usable within a WHERE clause params - A vector of values to plug into any ? of expr min-depth - The starting depth at which this expression applies. Defaults to 1 (top level) max-depth - The ending depth (inclusive) at which this expression applies. Must be >= min depth

Creates a filter usable on the graph:

expr - An SQL boolean expression usable within a WHERE clause
params - A vector of values to plug into any ? of expr
min-depth - The starting depth at which this expression applies. Defaults to 1 (top level)
max-depth - The ending depth (inclusive) at which this expression applies. Must be >= min depth
sourceraw docstring

forward?clj

(forward? schema graph-join)

Returns true if the join key is on the source table (as opposed to the target table)

Returns true if the join key is on the source table (as opposed to the target table)
sourceraw docstring

graphprop->sqlpropclj

(graphprop->sqlprop schema kw)

Convert a keyword in clojure-form to sql-form. E.g. :account-id to :account_id

Convert a keyword in clojure-form to sql-form. E.g. :account-id to :account_id
sourceraw docstring

graphprop->sqlprop*cljmultimethod

source

id-columnsclj

(id-columns {:keys [:fulcro-sql.core/pks] :as schema})

Returns a set of table-namespaced keywords that are the ID columns for all tables.

Returns a set of table-namespaced keywords that are the ID columns for all tables.
sourceraw docstring

id-propclj

(id-prop schema table)

Returns the SQL-centric property for the PK in a result set map (before conversion back to Om)

Returns the SQL-centric property for the PK in a result set map (before conversion back to Om)
sourceraw docstring

join-keyclj

(join-key join)

Returns the key in a join. E.g. for {:k [...]} it returns :k

Returns the key in a join. E.g. for {:k [...]} it returns :k
sourceraw docstring

join-queryclj

(join-query join)

Returns the subquery of a join. E.g. for {:k [:data]} it returns [:data].

Returns the subquery of a join. E.g. for {:k [:data]} it returns [:data].
sourceraw docstring

next-idclj

(next-id db schema table-kw)

Get the next generated ID for the given table.

NOTE: IF you specify the Java System Property dev, then this function will assume you are writing tests and will allocate extra IDs in order to prevent assertions on your generated IDs across tables from giving false positives (since all tables will start from ID 1). It does this by throwing away a random number of IDs, so that IDs across tables are less likely to be identical when an equal number of rows are inserted.

Get the next generated ID for the given table.

NOTE: IF you specify the Java System Property `dev`, then this function will assume you are writing tests and will
allocate extra IDs in order to prevent assertions on your generated IDs across
tables from giving false positives (since all tables will start from ID 1). It does this by throwing away a
random number of IDs, so that IDs across tables are less likely to be identical when an equal number of rows
are inserted.
sourceraw docstring

next-id*cljmultimethod

source

omprop->sqlpropclj

(omprop->sqlprop {:keys [:fulcro-sql.core/graph->sql] :as schema} p)

Derive an sqlprop from an om query element (prop or join)

Derive an sqlprop from an om query element (prop or join)
sourceraw docstring

pk-columnclj

(pk-column schema table)

Returns the SQL column for a given table's primary key

Returns the SQL column for a given table's primary key
sourceraw docstring

query-element->sqlpropclj

(query-element->sqlprop {:keys [:fulcro-sql.core/joins] :as schema} element)
source

query-forclj

(query-for schema graph-join-prop graph-query id-set)
(query-for {:keys [:fulcro-sql.core/joins] :as schema}
           graph-join-prop
           graph-query
           id-set
           filtering)

Returns an SQL query to get the true data columns that exist for the graph-query. Joins will contribute to this query iff there is a column on the target table that is needed in order to process the join.

graph-join-prop : nil if the id-set is on the table of this query itself, otherwise the fulcro query keyword that was used to follow a join. graph-query : the things to pull from the databsae. Table will be derived from this, so you must pull more than just the ID. id-set : The ids of the rows you want to pull. If join-col is set, that will be the join column matched against these. Otherwise the PK of the table.

Returns an SQL query to get the true data columns that exist for the graph-query. Joins will contribute to this
query iff there is a column on the target table that is needed in order to process the join.

graph-join-prop : nil if the id-set is on the table of this query itself, otherwise the fulcro query keyword that was used to follow a join.
graph-query : the things to pull from the databsae. Table will be derived from this, so you must pull more than just the ID.
id-set : The ids of the rows you want to pull. If join-col is set, that will be the join column matched against these. Otherwise the PK of the table.
sourceraw docstring

recursive?clj

(recursive? {:keys [:fulcro-sql.core/joins] :as schema} graph-key-or-join)

Is this a self-reference join?

Is this a self-reference join?
sourceraw docstring

reverse?clj

(reverse? {:keys [:fulcro-sql.core/joins] :as schema} graph-key-or-join)

Opposite of forward?

Opposite of forward?
sourceraw docstring

run-queryclj

(run-query db
           {:keys [:fulcro-sql.core/joins :fulcro-sql.core/graph->sql]
            :as schema}
           join-or-id-column
           query
           root-id-set)
(run-query db
           {:keys [:fulcro-sql.core/joins :fulcro-sql.core/graph->sql]
            :as schema}
           join-or-id-column
           query
           root-id-set
           filtering)

Run a graph query against an SQL database.

db - the database schema - the schema join-or-id-column - The ID column of the table (being queried) corresponding to root-id-set OR the join column whose second join component corresponds to the IDs in root-id-set. query - The query to run root-id-set - A set of PK values that identify the row(s) that root your graph query filters - A map of filters, keyed by table, whose values are vectors of filter expressions generated by filter-where.

(let [filters {:account [(filter-where "account.id IS NOT NULL AND account.deleted = ?" [false])]}] (run-query db schema :account/id #{2} filters))

There is a helper filter-params->filters for converting simple parameters into these more general filters:

(let [filters (filter-params->filters schema {:account/id {:null false} :account/deleted {:eq false})] (run-query db schema :account/id #{2} filters))

The former are fully general (since any number of expressions can apply to a single table, and the expression can be arbitrary), whereas the latter are less prone to errors. You should not accept the former from clients, but the latter can be easily checked for security since they have limited scope, are keyed by column, and are immune from SQL injection.

Returns:

  • IF the join-or-id-column is a to-one join: returns a map
  • Otherwise returns a vector of maps, one entry for each ID in root-id-set
Run a graph query against an SQL database.

db - the database
schema - the schema
join-or-id-column - The ID column of the table (being queried) corresponding to root-id-set OR the join column
                    whose second join component corresponds to the IDs in root-id-set.
query - The query to run
root-id-set - A set of PK values that identify the row(s) that root your graph query
filters - A map of filters, keyed by table, whose values are vectors of filter expressions generated by `filter-where`.

(let [filters {:account [(filter-where "account.id IS NOT NULL AND account.deleted = ?" [false])]}]
  (run-query db schema :account/id #{2} filters))

There is a helper `filter-params->filters` for converting simple parameters into these more general filters:

(let [filters (filter-params->filters schema {:account/id {:null false} :account/deleted {:eq false})]
  (run-query db schema :account/id #{2} filters))

The former are fully general (since any number of expressions can apply to a single table, and the expression can be
arbitrary), whereas the latter are less prone to errors. You should not accept the former from clients, but the latter
can be easily checked for security since they have limited scope, are keyed by column, and are immune from SQL injection.

Returns:
- IF the join-or-id-column is a to-one join: returns a map
- Otherwise returns a vector of maps, one entry for each ID in root-id-set
sourceraw docstring

seed!clj

(seed! db schema rows)

Seed the given seed-row and seed-update items into the given database. Returns a map whose values will be the keyword placeholders for generated PK ids, and whose values are the real numeric generated ID:

(let [{:keys [id/sam id/joe]} (seed! db schema [(seed-row :account {:id :id/joe ...})
                                                (seed-row :account {:id :id/sam ...})]
  ...)
Seed the given seed-row and seed-update items into the given database. Returns a map whose values will be the
keyword placeholders for generated PK ids, and whose values are the real numeric generated ID:

```
(let [{:keys [id/sam id/joe]} (seed! db schema [(seed-row :account {:id :id/joe ...})
                                                (seed-row :account {:id :id/sam ...})]
  ...)
```
sourceraw docstring

seed-rowclj

(seed-row table value)

Generate an instruction to insert a seed row for a table, which can contain keyword placeholders for IDs. It is recommended you namespace your generated IDs into id so that substitution during seeding doesn't cause surprises. For example:

(seed-row :account {:id :id/joe ...})

If the generated IDs appear in a PK location, they will be generated (must be unique per seed set). If they are in a value column, then the current generated value (which must have already been seeded) will be used.

See also seed-update for resolving circular references.

Generate an instruction to insert a seed row for a table, which can contain keyword placeholders for IDs. It is
 recommended you namespace your generated IDs into `id` so that substitution during seeding doesn't cause surprises.
 For example:

```
(seed-row :account {:id :id/joe ...})
```

If the generated IDs appear in a PK location, they will be generated (must be unique per seed set). If they
are in a value column, then the current generated value (which must have already been seeded) will be used.

See also `seed-update` for resolving circular references.
sourceraw docstring

seed-updateclj

(seed-update table id value)

Generates an instruction to update a seed row (in the same seed set) that already appeared. This may be necessary if your database has referential loops.

(seed-row :account {:id :id/joe ...})
(seed-row :account {:id :id/sam ...})
(seed-update :account :id/joe {:last_edited_by :id/sam })

table should be a keyword form of the table in your database. id can be a real ID or a generated ID placeholder keyword (recommended: namespace it with id). value is a map of col/value pairs to update on the row.

Generates an instruction to update a seed row (in the same seed set) that already appeared. This may be necessary if your database has
referential loops.

```
(seed-row :account {:id :id/joe ...})
(seed-row :account {:id :id/sam ...})
(seed-update :account :id/joe {:last_edited_by :id/sam })
```

`table` should be a keyword form of the table in your database.
`id` can be a real ID or a generated ID placeholder keyword (recommended: namespace it with `id`).
`value` is a map of col/value pairs to update on the row.
sourceraw docstring

SQLDatabaseManagercljprotocol

get-dbspecclj

(get-dbspec this database-kw)

Get a clojure jdbc dbspec for the given database-kw.

Get a clojure jdbc dbspec for the given database-kw.

start-databasesclj

(start-databases this)

Create the connection pools and (optionally) run the migrations.

Create the connection pools and (optionally) run the migrations.
source

sqlprop->graphpropclj

(sqlprop->graphprop schema kw)

Convert a keyword in clojure-form to sql-form. E.g. :account-id to :account_id

Convert a keyword in clojure-form to sql-form. E.g. :account-id to :account_id
sourceraw docstring

sqlprop->graphprop*cljmultimethod

source

sqlprop-for-joinclj

(sqlprop-for-join {:keys [:fulcro-sql.core/joins] :as schema} join)

Returns the sqlprop column needed from the source table.

Returns the sqlprop column needed from the source table.
sourceraw docstring

str-colclj

(str-col prop)

Returns the SQL string for the given sqlprop. E.g. :a/b -> a.b

Returns the SQL string for the given sqlprop. E.g. :a/b -> a.b
sourceraw docstring

str-idcolclj

(str-idcol schema table)

Returns the SQL string for the ID column of the given (keyword) table. E.g. :account -> account.id

Returns the SQL string for the ID column of the given (keyword) table. E.g. :account -> account.id
sourceraw docstring

strip-join-columnsclj

(strip-join-columns query graph-result)

Walk the query and graph result, removing any join columns that were part of query processing, but were not asked for in the original query.

Walk the query and graph result, removing any join columns that were part of query processing, but were not asked
for in the original query.
sourceraw docstring

table-forclj

(table-for schema query)

Scans the given Om query and tries to determine which table is to be used for the props within it.

Scans the given Om query and tries to determine which table is to be used for the props within it.
sourceraw docstring

table-for*cljmultimethod

source

to-manyclj

(to-many join-seq)
source

to-many?clj

(to-many? join)

Is the given join to-many? Returns true if the join is marked to many, or if the join is unmarked (e.g. default)

Is the given join to-many? Returns true if the join is marked to many, or if the join is unmarked (e.g. default)
sourceraw docstring

to-oneclj

(to-one join-seq)
source

to-one?clj

(to-one? join)

Is the give join to-one? Returns true iff the join is marked to-one.

Is the give join to-one? Returns true iff the join is marked to-one.
sourceraw docstring

uses-join-table?clj

(uses-join-table? {:keys [:fulcro-sql.core/joins] :as schema} graph-key-or-join)

Returns true if the join has a join table

Returns true if the join has a join table
sourceraw docstring

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

× close