Constructor
new db(dbName, listenersopt) → {db}
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
dbName |
string | The name of the database to initialize. Connects to an existing database if localStorage already has it. | |
listeners |
object |
<optional> |
Object that contains functions that fire on certain events such as 'onChange'. |
Returns:
databaseInstance - The object that contains all data about the database that has been initialized.
- Type
- db
Methods
abortTransaction()
Aborts a transaction.
Any changes made after starting a transaction will be discarded and the database is started afresh from the last saved state from persisted storage.
add(newRow) → {db}
Adds a new entry/row to the current active table in this database instance.
Parameters:
| Name | Type | Description |
|---|---|---|
newRow |
Object | The object to insert as an entry. A new 'entryId' field is automatically added to it. |
Returns:
DoggoDB Database Instance
- Type
- db
commitTransaction()
Commits a transaction.
Any changes made after starting a transaction will be saved to storage.
create(tableName) → {db}
Function to create a new table. This is equivalent to db.table(tableName) because the table function also creates a new table if it does not exist.
Parameters:
| Name | Type | Description |
|---|---|---|
tableName |
String | The name of the new table to create. |
Returns:
DoggoDB Database Instance
- Type
- db
delete(filters, deleteOnlyOne) → {Boolean}
Deletes certain set of rows from currently active table based on filters.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
filters |
Object | The Map of filters that you would use in the "find" function. | |
deleteOnlyOne |
Boolean | true | If true it stops deleting at the first match. |
Returns:
- Type
- Boolean
drop(tableName) → {db}
Drops a table in the database.
Parameters:
| Name | Type | Description |
|---|---|---|
tableName |
String | Name of the table to delete. |
Returns:
DoggoDB Database Instance
- Type
- db
find(filters, limitersopt)
Returns a result set from the active table.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
filters |
Object | Key value pair to query a table by. | |
limiters |
Object |
<optional> |
{ offset: Number, limit: Number } |
findAndUpdate(filters, updates, updateOnlyOne) → {Boolean}
Updates certain set of rows from currently active table based on filters.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
filters |
Object | The Map of filters that you would use in the "find" function. | |
updates |
Object | The Map of updates. | |
updateOnlyOne |
Boolean | true | If true it stops deleting at the first match. |
Returns:
- Type
- Boolean
get() → {Array}
Gets all contents of a table as an array of Objects.
Returns:
- Type
- Array
list() → {Object}
List all tables in the database as an object along with their contents and metadata.
Returns:
- Type
- Object
restoreToPreviousState()
Restores the database to previous/persisted state.
Can be used on start or during aborting a transaction.
save() → {undefined}
Saves the current database instance to localstorage.
Returns:
- Type
- undefined
startTransaction()
Starts a transaction.
Any changes made after starting a transaction will only be committed to storage in case the commitTransaction function is called.
table(tableName) → {db}
Sets a table as the current active table for the database instance, before that it creates a new one if it doesn't already exist.
Parameters:
| Name | Type | Description |
|---|---|---|
tableName |
String | The name of the table. |
Returns:
DoggoDB Database Instance
- Type
- db
updateAt(rowIndex, updates) → {Boolean}
Updates a row at a given position.
Parameters:
| Name | Type | Description |
|---|---|---|
rowIndex |
Number | The index (Starting from 0) of the row to update. |
updates |
Object | The Map of updates. |
Returns:
- Type
- Boolean