Namespace

offline

kiss.db.offline

Offline database wrapper with Nedb

View Source client/core/db/offline.js, line 8

Methods

# async static copyManyToTrash(modelId, query, dbModeopt) → {object}

Copy many records to the "trash" collection (recycle bin)

This is useful if you want to implement soft deletion

Parameters:
Name Type Attributes Description
modelId string
query string
dbMode string <optional>

Use "memory" to work with an in-memory collection

View Source client/core/db/offline.js, line 626

The records copied to the trash with extra informations

object

# async static copyOneToTrash(modelId, recordId, dbModeopt) → {object}

Copy a record to the "trash" collection (recycle bin)

This is useful if you want to implement soft deletion

Parameters:
Name Type Attributes Description
modelId string
recordId string
dbMode string <optional>

Use "memory" to work with an in-memory collection

View Source client/core/db/offline.js, line 597

The record copied to the trash with extra informations

object

# async static count(modelId, query, dbModeopt) → {number}

Count the number of records that match a query.

Parameters:
Name Type Attributes Description
modelId string
query object

Use same query format as for find() method

dbMode string <optional>

Use "memory" to work with an in-memory collection

View Source client/core/db/offline.js, line 579

The number of records

number

# async static createCollectionIndex(modelId, fieldName, dbModeopt) → {promise}

Create an index for a collection

According to NeDb, this can give a significant performance boost when reading data.

Parameters:
Name Type Attributes Description
modelId string
fieldName string
dbMode string <optional>

Use "memory" to work with an in-memory collection

View Source client/core/db/offline.js, line 125

Promise to have a collection index created

promise
Example
await db.offline.createCollectionIndex("users", {fieldName: "firstName"})

# async static deleteCollection(modelId) → {promise}

Delete the local NeDb collection (memory or offline)

Parameters:
Name Type Description
modelId string

View Source client/core/db/offline.js, line 94

Promise to have a the collection deleted

promise

# static deleteMany(modelId, query, sendToTrashopt, dbModeopt)

Delete many records from a collection

Parameters:
Name Type Attributes Description
modelId string
query object
sendToTrash boolean <optional>

If true, keeps the original records in a "trash" collection

dbMode string <optional>

Use "memory" to work with an in-memory collection

TODO: NOT TESTED YET

View Source client/core/db/offline.js, line 540

# async static deleteOne(modelId, recordId, sendToTrashopt, dbModeopt) → {boolean}

Delete an element from a collection. See db.delete

Parameters:
Name Type Attributes Description
modelId string
recordId string
sendToTrash boolean <optional>

If true, keeps the original record in a "trash" collection

dbMode string <optional>

Use "memory" to work with an in-memory collection

View Source client/core/db/offline.js, line 482

boolean

# async static find(modelId, queryopt, dbModeopt) → {Array.<object>}

Find documents in a collection. See db.find

Parameters:
Name Type Attributes Description
modelId string
query object <optional>

Query object

filter * <optional>

The query

filterSyntax string <optional>

The query syntax. By default, passed as a normalized object

sort * <optional>

Sort fields

sortSyntax string <optional>

The sort syntax. By default, passed as a normalized array

group Array.<string> <optional>

Array of fields to group by: ["country", "city"]

groupUnwind boolean <optional>

true to unwind the fields for records that belongs to multiple groups

projection object <optional>

{firstName: 1, lastName: 1, password: 0}

skip object <optional>

Number of records to skip

limit object <optional>

Number of records to return

dbMode string <optional>

Use "memory" to work with an in-memory collection

View Source client/core/db/offline.js, line 428

An array containing the records data

Array.<object>

# async static findById(modelId, ids, sortopt, sortSyntaxopt, dbModeopt) → {Array.<object>}

Find multiple records by id

Parameters:
Name Type Attributes Description
modelId string
ids Array.<string>

ids of the records to retrieve

sort Array.<object> | object <optional>

Sort options, as a normalized array or a Mongo object. Normalized example: [{fieldA: "asc"}, {fieldB: "desc"}]. Mongo example: {fieldA: 1, fieldB: -1}

sortSyntax string <optional>

Sort syntax: "nomalized" | "mongo". Default is normalized

dbMode string <optional>

Use "memory" to work with an in-memory collection

View Source client/core/db/offline.js, line 385

The found records

Array.<object>

# async static findOne(modelId, recordId, dbModeopt) → {object}

Find a single record in a collection. See db.findOne

Parameters:
Name Type Attributes Description
modelId string
recordId string
dbMode string <optional>

Use "memory" to work with an in-memory collection

View Source client/core/db/offline.js, line 362

The found record

object

# async static insertMany(modelId, records, dbModeopt) → {Array.<object>}

Insert many records in a collection. See db.insertMany

Parameters:
Name Type Attributes Description
modelId string
records Array.<object>

An array of records [{...}, {...}] for bulk insert

dbMode string <optional>

Use "memory" to work with an in-memory collection

View Source client/core/db/offline.js, line 175

The array of inserted records data

Array.<object>

# async static insertOne(modelId, record, dbModeopt) → {object}

Insert one record in a collection. See db.insertOne

Parameters:
Name Type Attributes Description
modelId string
record object

A single record

dbMode string <optional>

Use "memory" to work with an in-memory collection

View Source client/core/db/offline.js, line 141

The inserted record data

object

# async static updateBulk(operations, dbModeopt) → {object}

Update many records in multiple collections. See db.updateBulk TODO: group operations by collection to avoid reseting the collection in the loop TODO: use PromiseAll to parallelize update operations

Parameters:
Name Type Attributes Description
operations Array.<object>

The list of updates to perform

dbMode string <optional>

Use "memory" to work with an in-memory collection

View Source client/core/db/offline.js, line 321

response - Empty object for offline/memory database

object

Update the 2 records connected by a link

Parameters:
Name Type Description
linkRecord object

View Source client/core/db/offline.js, line 229

The transaction result

# async static updateMany(modelId, query, update, dbModeopt)

Update many records in a single collection. See db.updateMany

Parameters:
Name Type Attributes Description
modelId string
query object
update object
dbMode string <optional>

Use "memory" to work with an in-memory collection

TODO: NOT USED / NOT TESTED YET

View Source client/core/db/offline.js, line 285

# async static updateOne(modelId, recordId, update, dbModeopt) → {object}

Update a single record in a collection. See db.updateOne

Parameters:
Name Type Attributes Description
modelId string
recordId string
update string

Specifies how the record should be updated

dbMode string <optional>

Use "memory" to work with an in-memory collection

View Source client/core/db/offline.js, line 245

The updated record

object

# async static updateOneDeep(modelId, recordId, updateopt, dbModeopt) → {boolean}

Update a record then propagate the mutation to foreign records. Note: it will generate a transaction processed with kiss.db.updateBulk

Parameters:
Name Type Attributes Description
modelId string
recordId string
update string <optional>

If not specified, re-compute all the computed fields

dbMode string <optional>

Use "memory" to work with an in-memory collection

View Source client/core/db/offline.js, line 214

true if the update is successful

boolean
Example
await kiss.db.updateOneDeep("company", "f07xF008d", {"name": "pickaform"})