forest.repository

->FoxxRepository

(->FoxxRepository repo schema)

A repository is a gateway to the database. It gets data from the database, updates it or adds brand-new data. Conversion between Javascript and Clojure datastructure is done automatically.

app-repository

(app-repository repo schema)(app-repository repo schema indexes)

Creates a new instance of Repo inside current application context.

Repository can take care of ensuring the existence of collection indexes for you. If you define indexes for a repository, instances of the repository will have access to additional index-specific methods like range or fulltext.

Parameters:

  • repo: name of the repo, as string
  • schema: the schema against which entries will be validated and coerced.
  • indexes (optional): a vector of indexes.
    • For example: [{:type :fulltext, :fields [:text], :minLength 3}]

ArangoCollection

protocol

ArangoDB collection

members

add

(add this entry)

Saves an entry into the database. This entry can be any Clojure data structure. Will set the :_id and :_rev on the entry. Returns the entry.

by-example

(by-example this example)

Returns a vector of entries for the given example.

replace-by-id

(replace-by-id this id entry)

Finds the entry in the database by the given :_id and replaces it with the given entry. Sets the :_id and :_rev of the entry. Returns nil.

replace-by-example

(replace-by-example this example entry)

Finds the entry in the database by the given example and replaces it with the given entry. Sets the :_id and :_rev of the entry. Returns nil.

update-by-id

(update-by-id this id data)

Finds an entry by :_id and update it with the keys/values in the provided data. Returns nil.

remove-by-id

(remove-by-id this id)

Removes the entry with the given :_id. Expects an :_id of an existing entry.

update-by-example

(update-by-example this example data)

Finds an entry by example and update it with the key/values in the provided data. Returns nil.

key-range

(key-range this key left right)

Returns all entries in the repository such that the key is greater than or equal to left and strictly less than right.

For range queries it is required that a skiplist index is present for the queried key. If no skiplist index is present on the key, the method will not be available.

Parameters:

  • key: key to query.
  • left: lower bound of the value range (inclusive).
  • right: upper bound of the value range (exclusive).

by-id

(by-id this id)

Returns the entry for the given :_id.

remove-entry

(remove-entry this entry)

Removes the entry from the repository.

fulltext

(fulltext this key text)(fulltext this key text limit)

Returns all entries whose key value matches the search query text.

In order to use the fulltext method, a fulltext index must be defined on the repository. If multiple fulltext indexes are defined on the repository for the key, the most capable one will be selected. If no fulltext index is present, the method will not be available.

Parameter:

  • key: entry key to perform a search on.
  • text: text query to match the key’s value against.
  • limit (optional): number of entries to return. Defaults to all.

remove-by-example

(remove-by-example this example)

Finds all entries that fit this example and removes them.

all

(all this)(all this options)

Returns a vector of entries that matches the given example. You can provide both a skip and a limit value.

Parameters:

  • options (optional):
    • skip (optional): skips the first given number of entries.
    • limit (optional): only returns at most the given number of entries.

count-all

(count-all this)

Returns the number of entries in this collection.

replace-entry

(replace-entry this entry)

Finds the entry in the database by its :_id and replace it with this version. Expects an entry. Sets the :_rev of the entry. Returns nil.

first-example

(first-example this example)

Returns the first entry that matches the given example.

within

(within this lat lng radius)(within this lat lng radius options)

Finds entries within the distance radius from the coordinate (latitude, longitude). The returned vector is sorted by distance with the nearest entry coming first.

For geo queries it is required that a geo index is present in the repository. If no geo index is present, the methods will not be available.

Parameters:

  • lat: latitude of the coordinate.
  • lng: longitude of the coordinate.
  • radius: maximum distance from the coordinate.
  • options (optional):
    • :geo (optional): name of the specific geo index to use.
    • :distance (optional): If set to a truthy value, the returned entries will have an additional key containing the distance between the given coordinate and the entry. If the value is a keyword, that value will be used as the key name, otherwise the name defaults to :distance.
    • :limit (optional): number of entries to return. Defaults to 100.

near

(near this lat lng)(near this lat lng options)

Finds entries near the coordinate (latitude, longitude). The returned vector is sorted by distance with the nearest entry coming first.

For geo queries it is required that a geo index is present in the repository. If no geo index is present, the methods will not be available.

Parameters:

  • lat: latitude of the coordinate.
  • lng: longitude of the coordinate.
  • options (optional):
    • :geo (optional): name of the specific geo index to use.
    • :distance (optional): If set to a truthy value, the returned models will have an additional key containing the distance between the given coordinate and the entry. If the value is a string, that value will be used as the key name, otherwise the name defaults to :distance.
    • :limit (optional): number of entries to return. Defaults to 100.

create-collection!

(create-collection! coll-name)

Creates a new collection with given name for current application context. Returns true if created successfully. Otherwise returns nil.

drop-collection!

(drop-collection! coll-name)

Deletes a new collection with given name for current application context. Returns true if deleted successfully. Otherwise returns nil.

FoxxRepository

A repository is a gateway to the database. It gets data from the database, updates it or adds brand-new data. Conversion between Javascript and Clojure datastructure is done automatically.

map->FoxxRepository

(map->FoxxRepository G__7894)

A repository is a gateway to the database. It gets data from the database, updates it or adds brand-new data. Conversion between Javascript and Clojure datastructure is done automatically.

truncate-collection!

(truncate-collection! coll-name)

Truncates a collection with given name for current application context, removing all documents but keeping all its indexes. Returns true if deleted successfully. Otherwise returns nil.