API FileStore Adapter
Requirements
Install
To use this adapter with your DADI API installation, you'll need to add it to your API's dependencies:
$ npm install @dadi/api-filestore --save
Configure
Configuration Files
Configuration settings are defined in JSON files within a /config
directory at the root of your API application. DADI API has provision for multiple configuration files, one for each environment that your API is expected to run under, for example development
and production
.
A post-install script ran when you installed the package from NPM, creating a development configuration file for you at config/filestore.development.json
.
The naming convention for @dadi/api-filestore
configuration files follows the format filestore.<environment>.json
For example:
filestore.development.json
filestore.production.json
Application Anatomy
my-api/
config/
config.development.json
config.production.json
filestore.development.json
filestore.production.json
main.js
package.json
workspace/
collections/
endpoints/
Configuration
The contents of the configuration file should be similar to the following:
{
"database": {
"path": "path/to/your/database",
"autosaveInterval": 10000,
"serializationMethod": "pretty"
}
}
Property | Description | Default |
---|
path | The relative or absolute path to where your database files will be stored | none |
autosaveInterval | The interval, in milliseconds, between database writes to disk | 5000 (5 seconds) |
serializationMethod | The format of the database file on disk. normal is a condensed version of the JSON, pretty is more readable | normal |
Querying Collections
$eq
{'Name': { '$eq' : 'Odin' }}
{'Name': 'Odin'}
$ne
not equal test
{'legs': { '$ne' : 8 }}
$regex
var results = coll.find({'Name': { '$regex' : /din/ }});
results = coll.find({'Name': { '$regex': 'din' }});
results = coll.find({'Name': { '$regex': ['din', 'i'] }});
If using regex operator within a named transform or dynamic view filter, it is best to use the latter two examples since raw regex does not seem to serialize/deserialize well.
$in
var users = db.addCollection("users");
users.insert({ name : 'odin' });
users.insert({ name : 'thor' });
users.insert({ name : 'svafrlami' });
{ 'name' : { '$in' : ['odin', 'thor'] } }
$between
{ count : { '$between': [50, 75] } }
$contains / $containsAny / $containsNone
var users = db.addCollection("users");
users.insert({ name : 'odin', weapons : ['gungnir', 'draupnir']});
users.insert({ name : 'thor', weapons : ['mjolnir']});
users.insert({ name : 'svafrlami', weapons : ['tyrfing']});
users.insert({ name : 'arngrim', weapons : ['tyrfing']});
{ 'weapons' : { '$contains' : 'tyrfing' } }
{ 'weapons' : { '$containsAny' : ['tyrfing', 'mjolnir'] } }
{ 'weapons' : { '$containsNone' : ['gungnir', 'mjolnir'] } }
Composing Nested Queries
$and
fetch documents matching both sub-expressions
{
'$and': [{
'Age' : {
'$gt': 30
}
},{
'Name' : 'Thor'
}]
}
$or
fetch documents matching any of the sub-expressions
{
'$or': [{
'Age' : {
'$gte': '40'
}
},{
'Name' : 'Thor'
}]
}