Liking cljdoc? Tell your friends :D

oc.lib.db.common

CRUD functions on resources stored in RethinkDB.

CRUD functions on resources stored in RethinkDB.
raw docstring

add-to-setclj

(add-to-set conn table-name primary-key-value field element)

For the resource specified by the primary key, add the element to the set of elements with the specified field name. Return the updated resource if a change is made, and an exception on DB error.

For the resource specified by the primary key, add the element to the set of elements with the specified field
name. Return the updated resource if a change is made, and an exception on DB error.
sourceraw docstring

build-filter-fnclj

(build-filter-fn filter-map)
source

conn?clj

(conn? conn)

Check if a var is a valid RethinkDB connection map/atom.

Check if a var is a valid RethinkDB connection map/atom.
sourceraw docstring

create-resourceclj

(create-resource conn table-name resource timestamp)

Create a resource in the DB, returning the property map for the resource.

Create a resource in the DB, returning the property map for the resource.
sourceraw docstring

current-timestampclj

source

default-timeoutclj

source

delete-all-resources!clj

(delete-all-resources! conn table-name)

Use with caution! Failure can result in partial deletes of just some resources. Returns true if successful.

Use with caution! Failure can result in partial deletes of just some resources. Returns `true` if successful.
sourceraw docstring

delete-resourceclj

(delete-resource conn table-name primary-key-value)
(delete-resource conn table-name key-name key-value)

Delete the specified resource and return true.

Delete the specified resource and return `true`.
sourceraw docstring

drain-cursorclj

(drain-cursor result)

If the result is a cursor, drain it into a Clojure sequence.

If the result is a cursor, drain it into a Clojure sequence.
sourceraw docstring

filter-resourcesclj

(filter-resources conn table-name filter-map)
(filter-resources conn table-name filter-map fields)
(filter-resources conn table-name index-name index-value filter-map fields)

Given a table name, and a filter map in the form of:

  • a filter-map A sequence of filters used to filter results. example: [{:fn :ne :value 'blah' :field 'foo'} {:fn :eq :value true :field 'bar'}]

Return the resources which pass the provided filter(s).

Valid filters are: :eq, :ne, :gt, :ge, :lt, :le

All filters are AND'ed together if more than one is provided.

Given a table name, and a filter map in the form of:

- a `filter-map` A sequence of filters used to filter results.
  example: [{:fn :ne :value 'blah' :field 'foo'}
            {:fn :eq :value true :field 'bar'}]

Return the resources which pass the provided filter(s).

Valid filters are: :eq, :ne, :gt, :ge, :lt, :le

All filters are AND'ed together if more than one is provided.
sourceraw docstring

grouped-resources-by-most-commonclj

(grouped-resources-by-most-common conn
                                  table-name
                                  index-name
                                  index-value
                                  group-field)
(grouped-resources-by-most-common conn
                                  table-name
                                  index-name
                                  index-value
                                  group-field
                                  limit)

Given a table name, an index name and value, a grouping field, return an sequence of the grouping field, and a count of how many were in the group. Sequence is ordered, most common to least. Optionally specify a limit on how many to return.

Response:

[['😜' 3] ['👌' 2] ['💥' 1]]

Given a table name, an index name and value, a grouping field, return an sequence of the grouping field,
and a count of how many were in the group. Sequence is ordered, most common to least. Optionally specify
a limit on how many to return.

Response:

[['😜' 3] ['👌' 2] ['💥' 1]]
sourceraw docstring

months-with-resourceclj

(months-with-resource conn table-name index-name index-value date-field)

Given a table name, an index name and value, and an ISO8601 date field, return an ordered sequence of all the months that have at least one resource.

Response:

[['2017' '06'] ['2017' '01'] [2016 '05']]

Sequence is ordered, newest to oldest.

Given a table name, an index name and value, and an ISO8601 date field, return an ordered sequence of all the months 
that have at least one resource.

Response:

[['2017' '06'] ['2017' '01'] [2016 '05']]

Sequence is ordered, newest to oldest.
sourceraw docstring

read-all-resources-and-relationsclj

(read-all-resources-and-relations conn
                                  table-name
                                  index-name
                                  index-value
                                  order-by
                                  order
                                  start
                                  direction
                                  relation-name
                                  relation-table-name
                                  relation-field-name
                                  relation-index-name
                                  relation-fields
                                  {:keys [count] :or {count false}})
(read-all-resources-and-relations conn
                                  table-name
                                  index-name
                                  index-value
                                  order-by
                                  order
                                  start
                                  direction
                                  filter-map
                                  relation-name
                                  relation-table-name
                                  relation-field-name
                                  relation-index-name
                                  relation-fields
                                  {:keys [count] :or {count false}})

Like read-resources-and-relations but doesn't apply limit.

Like `read-resources-and-relations` but doesn't apply limit.
sourceraw docstring

read-resourceclj

(read-resource conn table-name primary-key-value)

Given a table name and a primary key value, retrieve the resource from the database, or return nil if it doesn't exist.

Given a table name and a primary key value, retrieve the resource from the database,
or return nil if it doesn't exist.
sourceraw docstring

read-resourcesclj

(read-resources conn table-name)
(read-resources conn table-name fields)
(read-resources conn table-name index-name index-value)
(read-resources conn table-name index-name index-value fields)
(read-resources conn table-name index-name index-value fields limit)

Given a table name, and an optional index name and value, an optional set of fields, and an optional limit, retrieve the resources from the database.

Given a table name, and an optional index name and value, an optional set of fields, and an optional limit, retrieve
the resources from the database.
sourceraw docstring

read-resources-and-relationsclj

(read-resources-and-relations conn
                              table-name
                              index-name
                              index-value
                              relation-name
                              relation-table-name
                              relation-field-name
                              relation-index-name
                              relation-fields
                              {:keys [count] :or {count false}})
(read-resources-and-relations conn
                              table-name
                              index-name
                              index-value
                              order-by
                              order
                              start
                              direction
                              relation-name
                              relation-table-name
                              relation-field-name
                              relation-index-name
                              relation-fields
                              {:keys [count] :or {count false}})
(read-resources-and-relations conn
                              table-name
                              index-name
                              index-value
                              order-by
                              order
                              start
                              direction
                              limit
                              relation-name
                              relation-table-name
                              relation-field-name
                              relation-index-name
                              relation-fields
                              {:keys [count] :or {count false}})
(read-resources-and-relations conn
                              table-name
                              index-name
                              index-value
                              order-by
                              order
                              start
                              direction
                              limit
                              filter-map
                              relation-name
                              relation-table-name
                              relation-field-name
                              relation-index-name
                              relation-fields
                              {:keys [count] :or {count false}})

In the first arity (9): Given a table name, an index name and value, and what amounts to a document key, foreign table, foreign key, foreign key index and the fields of the foreign table that are interesting, return all the resources that match the index, and any related resources in the other table in an array in each resource.

E.g.

Table A: foo, bar Table B: blat, a-bar, blu

Here bar and a-bar have the same value, with a-bar acting as a foreign key pointing each B at an A.

(read-resources-and-relations conn 'A' :foo-index '1234' :my-bees 'B' :bar :a-bar-index ['blat', 'blu'])

will return something like:

[ { :foo '1234' :bar 'abcd' :my-bees [{:blat 'ferret' :blu 42} {:blat 'monkey' :blu 7}] } { :foo '1234' :bar 'efgh' :my-bees [{:blat 'mouse' :blu 77} {:blat 'mudskipper' :blu 17}] } ]

The second arity (14) is largely the same functionality as the first, but with more control over the selection and order of the returned resources in the form of:

  • an order-by field for the order of the returned resources
  • an order, one of either :desc or :asc
  • an initial value of the order-by field to start the limited set from
  • a direction, one of either :before or :after the start value
  • limit, a numeric limit to the number returned

The third arity (15) is largely the same functionality as the second, but with an additonal filter map in the form of:

  • a filter-map A sequence of filters used to filter results. example: [{:fn :ne :value 'blah' :field 'foo'} {:fn :eq :value true :field 'bar'}]

Valid filters are: :eq, :ne, :gt, :ge, :lt, :le

All filters are AND'ed together if more than one is provided.

In the first arity (9): Given a table name, an index name and value, and what amounts to a document key, foreign table,
foreign key, foreign key index and the fields of the foreign table that are interesting, return all the resources
that match the index, and any related resources in the other table in an array in each resource.

E.g.

Table A: foo, bar
Table B: blat, a-bar, blu

Here `bar` and `a-bar` have the same value, with `a-bar` acting as a foreign key pointing each B at an A.

(read-resources-and-relations conn 'A' :foo-index '1234' :my-bees 'B' :bar :a-bar-index ['blat', 'blu'])

will return something like:

[
  {
    :foo '1234'
    :bar 'abcd'
    :my-bees [{:blat 'ferret' :blu 42} {:blat 'monkey' :blu 7}]
  }
  {
    :foo '1234'
    :bar 'efgh'
    :my-bees [{:blat 'mouse' :blu 77} {:blat 'mudskipper' :blu 17}]
  }
]

The second arity (14) is largely the same functionality as the first, but with more control over the selection and
order of the returned resources in the form of:

- an `order-by` field for the order of the returned resources
- an `order`, one of either `:desc` or `:asc`
- an initial value of the order-by field to `start` the limited set from
- a `direction`, one of either `:before` or `:after` the `start` value
- `limit`, a numeric limit to the number returned

The third arity (15) is largely the same functionality as the second, but with an additonal filter map
in the form of:

- a `filter-map` A sequence of filters used to filter results.
  example: [{:fn :ne :value 'blah' :field 'foo'}
            {:fn :eq :value true :field 'bar'}]

Valid filters are: :eq, :ne, :gt, :ge, :lt, :le

All filters are AND'ed together if more than one is provided.
sourceraw docstring

read-resources-by-primary-keysclj

(read-resources-by-primary-keys conn table-name primary-keys)
(read-resources-by-primary-keys conn table-name primary-keys fields)

Given a table name, a sequence of primary keys, and an optional set of fields, retrieve the resources from the database.

Given a table name, a sequence of primary keys, and an optional set of fields, retrieve the
resources from the database.
sourceraw docstring

read-resources-in-orderclj

(read-resources-in-order conn table-name index-name index-value)
(read-resources-in-order conn table-name index-name index-value fields)

Given a table name, an index name and value, and an optional set of fields, retrieve the resources from the database in updated-at property order.

Given a table name, an index name and value, and an optional set of fields, retrieve
the resources from the database in updated-at property order.
sourceraw docstring

remove-from-setclj

(remove-from-set conn table-name primary-key-value field element)

For the resource specified by the primary key, remove the element to the set of elements with the specified field name. Return the updated resource if a change is made, nil if not, and an exception on DB error.

For the resource specified by the primary key, remove the element to the set of elements with the specified
field name. Return the updated resource if a change is made, nil if not, and an exception on DB error.
sourceraw docstring

remove-propertyclj

(remove-property conn table-name primary-key-value property-name)
(remove-property conn table-name primary-key-value property-name timestamp)

Given a table name, the name of the primary key, and a property to remove, update a resource in the DB, removing the specified property of the resource.

Given a table name, the name of the primary key, and a property to remove,
update a resource in the DB, removing the specified property of the resource.
sourceraw docstring

s-or-k?clj

(s-or-k? value)

Truthy if the provided value is a string or a keyword.

Truthy if the provided value is a string or a keyword.
sourceraw docstring

timestamp-formatclj

source

unique-idclj

(unique-id)

Return a 12 character fragment from a UUID e.g. 51ab-4c86-a474

Return a 12 character fragment from a UUID e.g. 51ab-4c86-a474
sourceraw docstring

update-resourceclj

(update-resource conn
                 table-name
                 primary-key-name
                 primary-key-value
                 new-resource)
(update-resource conn
                 table-name
                 primary-key-name
                 original-resource
                 :guard
                 map?
                 new-resource)
(update-resource conn
                 :guard
                 conn?
                 table-name
                 :guard
                 s-or-k?
                 primary-key-name
                 :guard
                 s-or-k?
                 original-resource
                 :guard
                 map?
                 new-resource
                 :guard
                 map?
                 timestamp
                 :guard
                 string?)

Given a table name, the name of the primary key, an optional original resource (for efficiency if it's already been retrieved) and the updated resource, update the resource in the DB, returning the property map for the updated resource.

Given a table name, the name of the primary key, an optional original resource (for efficiency if it's already
been retrieved) and the updated resource, update the resource in the DB, returning the property map for the
updated resource.
sourceraw docstring

updated-at-orderclj

(updated-at-order coll)

Return items in a sequence sorted by their :updated-at key. Newest first.

Return items in a sequence sorted by their :updated-at key. Newest first.
sourceraw docstring

with-timeoutcljmacro

(with-timeout ms & body)

A basic macro to wrap things in a timeout. Will throw an exception if the operation times out. Note: This is a simplistic approach and piggybacks on core.asyncs executor-pool. Read this discussion for more info: https://gist.github.com/martinklepsch/0caf92b5e42eefa3a894

A basic macro to wrap things in a timeout.
Will throw an exception if the operation times out.
Note: This is a simplistic approach and piggybacks on core.asyncs executor-pool.
Read this discussion for more info: https://gist.github.com/martinklepsch/0caf92b5e42eefa3a894
sourceraw docstring

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

× close