Module to manage the sqlite database.
- Source:
Methods
(async, static) addData(db, data) → {Promise.<object.<string, int>>}
Add data to a dataset resource.
Parameters:
Name | Type | Description |
---|---|---|
db |
object | The sqlite3 db object from module node-sqlite3. |
data |
DataRow | Array.<DataRow> | The data to add. Must conform to the schema defined by the resource metadata. Supports creating an individual document or many documents. |
- Source:
Returns:
- The promise with the total count of rows added.
- Type
- Promise.<object.<string, int>>
Examples
create an individual document
// returns {"count": 1} if successful
manager.addData(db, {lsoa: "E0000001", count: 398});
create multiple documents
manager.addData(db, [
{lsoa: "E0000001", count: 398},
{lsoa: "E0000002", count: 1775},
{lsoa: "E0000005", count: 4533},
]);
add a 2D ndarray
buffer = Buffer.alloc(23*34);
manager.addData(db, {id: 1, array: manager.getNdarrayMeta(buffer, "float64", [23, 34])});
(static) closeDatabase(db) → {Promise.<object>}
Closes a sqlite database.
Parameters:
Name | Type | Description |
---|---|---|
db |
object | The sqlite3 db object from module node-sqlite3 |
- Source:
Returns:
- The empty promise or error
- Type
- Promise.<object>
(static) createDataset(db, options) → {Promise.<string>}
Creates a dataset in the sqlite database.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
db |
object | The sqlite3 db object from module node-sqlite3 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
options |
object | details of the dataset to be added Properties
|
- Source:
Returns:
- The id of the dataset created
- Type
- Promise.<string>
Example
create a dataset with give id and schema
manager.createDataset(db, {
"id": "12345",
"schema": {
"dataSchema": {
"prop1": {"__tdxType": ["number"]}
},
"uniqueIndex": [{"asc": "prop1"}]
}
});
(async, static) deleteData(db, data, doNotThrowopt)
Deletes data from a dataset-based resource.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
db |
object | The sqlite3 db object from module node-sqlite3. |
||
data |
DataRow | Array.<DataRow> | The primary key data to delete. |
||
doNotThrow |
boolean |
<optional> |
false | set to override default error handling. |
- Source:
(static) getData(db, filteropt, projectionopt, optionsopt) → {Promise.<DatasetData>}
Gets all data from the given dataset that matches the filter provided.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
db |
object | The sqlite3 db object from module node-sqlite3. |
|||||||||||||||||||||
filter |
object |
<optional> |
A mongodb filter object. If omitted, all data will be retrieved. |
||||||||||||||||||||
projection |
object |
<optional> |
A mongodb projection object. Should be used to restrict the payload to the minimum properties needed if a lot of data is being retrieved. |
||||||||||||||||||||
options |
object |
<optional> |
A mongodb options object. Can be used to limit, skip, sort etc. Note a default
Properties
|
- Source:
Returns:
- Type
- Promise.<DatasetData>
(static) getDatasetData(db, filteropt, projectionopt, optionsopt) → {Promise.<DatasetData>}
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
db |
object | The id of the dataset-based resource. |
|||||||||
filter |
object |
<optional> |
A mongodb filter object. If omitted, all data will be retrieved. |
||||||||
projection |
object |
<optional> |
A mongodb projection object. Should be used to restrict the payload to the minimum properties needed if a lot of data is being retrieved. |
||||||||
options |
object |
<optional> |
A mongodb options object. Can be used to limit, skip, sort etc. Note a default
Properties
|
- Deprecated:
- use getData() Gets all data from the given dataset that matches the filter provided.
- Source:
Returns:
- Type
- Promise.<DatasetData>
(static) getDatasetDataCount(db, filter) → {object}
Gets a count of the data in a dataset-based resource, after applying the given filter.
Parameters:
Name | Type | Description |
---|---|---|
db |
object | The sqlite3 db object from module node-sqlite3. |
filter |
object | An optional mongodb filter to apply before counting the data. |
- Source:
Returns:
- The promise with the total count of rows.
- Type
- object
(static) getDistinct(db, key, filteropt) → {Promise.<Array.<object>>}
Gets a list of distinct values for a given property in a dataset-based resource.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
db |
object | The sqlite3 db object from module node-sqlite3. |
|
key |
string | The name of the property to use. Can be a property path, e.g. "address.postcode". |
|
filter |
object |
<optional> |
An optional mongodb filter to apply. |
- Source:
Returns:
- Type
- Promise.<Array.<object>>
(static) getGeneralSchema(db) → {object}
Returns the general schema.
Parameters:
Name | Type | Description |
---|---|---|
db |
object | The sqlite3 db object from module node-sqlite3. |
- Source:
Returns:
- The general schema object
- Type
- object
(async, static) getResource(db, noThrowopt) → {Promise.<Resource>}
Gets the details for a given database.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
db |
object | The sqlite3 db object from module node-sqlite3. |
||
noThrow |
boolean |
<optional> |
false | If set, the call won't reject or throw if the resource doesn't exist. |
- Source:
Throws:
Will throw/reject if the resource is not found (see noThrow
flag) or permission is denied.
Returns:
- Type
- Promise.<Resource>
(async, static) openDatabase(path, type, mode) → {Promise.<object>}
Opens a sqlite database. Creates if none exists.
Parameters:
Name | Type | Description |
---|---|---|
path |
string | The path of the db |
type |
string | The type of the db: "file" or "memory" |
mode |
string | The open mode of the db: "w+" or "rw" or "r" |
- Source:
Returns:
Returns the sqlite3 db object from module node-sqlite3
- Type
- Promise.<object>
(static) setGeneralSchema(db, schema)
Sets the general schema and the default NULL array.
Parameters:
Name | Type | Description |
---|---|---|
db |
object | The sqlite3 db object from module node-sqlite3. |
schema |
object | The general schema. |
- Source:
(static) truncateResource(db) → {object}
Truncates the dataset resource.
Parameters:
Name | Type | Description |
---|---|---|
db |
object | The sqlite3 db object from module node-sqlite3. |
- Source:
Returns:
- The promise with the total count of rows deleted.
- Type
- object
(async, static) updateData(db, data, upsertopt, throwsopt) → {Promise.<CommandResult>}
Updates data in a dataset resource.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
db |
object | The sqlite3 db object from module node-sqlite3. |
||
data |
DataRow | Array.<DataRow> | The data to update. Must conform to the schema defined by the resource metadata. Supports updating individual or multiple rows. |
||
upsert |
boolean |
<optional> |
false | Indicates the data should be created if no document/row is found matching the primary key. |
throws |
boolean |
<optional> |
true | Indicates whether this function should reject if there is an error. The TDX-API doesn't, as it returns a field which states if there has been an error. |
- Source:
Returns:
- Use the result property to check for errors.
- Type
- Promise.<CommandResult>
(static) updateDataByQuery(db, query, update) → {Promise.<object>}
Updates data in a dataset-based resource using a query to specify the documents to be updated.
Parameters:
Name | Type | Description |
---|---|---|
db |
object | The sqlite3 db object from module node-sqlite3. |
query |
object | The query that specifies the data to update. All documents matching the query will be updated. |
update |
object | The update object with field data to be replaced. |
- Source:
Returns:
The promise with the total count of rows updated.
- Type
- Promise.<object>
Example
updates multiple documents
// Update all documents with English lsoa, setting `count` to 1000.
manager.updateDataByQuery(db, {lsoa: {$regex: "E*"}}, {count: 1000});