Members
-
connected
-
Description
Get the database connection state.
Returns
Details
-
filepath
-
Description
Get the filepath of the database.
Returns
Details
-
created
-
Description
Get the date and time of creation of the database.
Returns
Details
-
collections
-
Description
Get all collections of the database.
Returns
Details
-
size
-
Description
Get the amount of collections of the database.
Returns
Details
-
totalSize
-
Description
Get the amount of documents of all collections.
Returns
Details
-
settings
-
Description
Get all database related settings.
Returns
Details
-
autosave
-
Description
Get the current state of autosave.
Returns
Details
-
autosaveInterval
-
Description
Get the current autosave interval.
Returns
Details
-
autosave
-
Description
Enable or disable autosave.
Parameters
Name Type Description value
boolean Whether to enable or disable autosave.
Details
-
autosaveInterval
-
Description
Set a new autosave interval.
Parameters
Name Type Description value
number New interval in milliseconds.
Details
Methods
-
<async> connect( [ settings ] ) → {Promise.<void>}
-
Description
Create a connection to a new database. If the file already exists, it will be loaded and the collections (and optionally the settings, too) will be applied to this instance, unless the setting
overwriteExisting
is set to true.Parameters
Name Type Attributes Default Description settings
object <optional> {} Optional settings related to the database.
Name Type Attributes Description filepath
string <optional> Filepath for the database.
autosave
boolean <optional> Whether the database should be automatically saved.
autosaveInterval
number <optional> Interval for the autosave in milliseconds.
restoreSettings
boolean <optional> Whether it should restore settings from the loaded database, if it exists.
overwriteExisting
boolean <optional> Whether the existing database (same filepath) should be overwritten.
Returns
Details
-
<async> disconnect( [ save ] )
-
Description
Close the database connection.
Disables autosave, removes the event listeners for the database and its collections, clears all documents and collections.
Parameters
Name Type Attributes Default Description save
boolean <optional> true Whether to save the database before disconnecting.
Details
-
createCollection( name ) → {Collection}
-
Description
Create a collection with the given name. Returns an existing collection in case a collection with the same name already eixists in this database.
Use TrustDB#deleteCollection before creating or adding a collection with the same name.
Parameters
Name Type Description name
string Name of the collection.
Returns
Details
-
addCollection( collection ) → {Collection}
-
Description
IMPORTANT: This function does not create a new collection. Use TrustDB#createCollection to create a new collection.
Add a collection to the database. Returns an existing collection in case a collection with the same name already eixists in this database.
Use TrustDB#deleteCollection before creating or adding a collection with the same name.
Parameters
Name Type Description collection
Collection Collection instance to add.
Returns
Details
-
deleteCollection( collection ) → {Collection}
-
Description
Delete a collection with the given name or using a Collection instance.
Parameters
Name Type Description collection
Collection | string Name of the collection or a Collection instance.
Returns
Details
-
getCollection( name ) → {Collection}
-
Description
Retrieve a collection by name.
Parameters
Name Type Description name
string Name of the collection.
Returns
Details
-
<async> saveDatabase() → {Promise.<void>}
-
Description
Save the database with its collections, settings and metadata to the specified filepath.
Returns
Details
-
<async> save() → {Promise.<void>}
-
Description
Save the database with its collections, settings and metadata to the specified filepath.
Returns
Details
-
<async> save() → {Promise.<void>}
-
Description
Save the database with its collections, settings and metadata to the specified filepath.
Returns
Details
-
<async> deleteDatabase() → {Promise.<void>}
-
Description
Delete the database from the filesystem, if it exists.
Returns
Details
-
<async> moveDatabase( filepath ) → {Promise.<void>}
-
Description
Move the database to the new path on the filesystem.
Parameters
Name Type Description filepath
string New path for the database file.
Returns
Details
-
configureSettings( [ settings ] )
-
Description
(Re-)configure the settings.
Parameters
Name Type Attributes Default Description settings
object <optional> {} Optional settings related to the database.
Name Type Attributes Description filepath
string <optional> Filepath for the database. Only applies if there is no filepath set.
autosave
boolean <optional> Whether the database should be automatically saved.
autosaveInterval
number <optional> Interval for the autosave in milliseconds.
Details
-
clear() → {Array.<Collection>}
-
Description
Clear the database by deleting all of its collections.
Returns
Details