new Database()
Properties:
| Name | Type | Description |
|---|---|---|
DATABASE_NAME |
string
|
The name ('BulletJournal') of the IndexedDB database used by our app |
Stores |
Object.<string, string>
|
Object containing the constant names of the object stores in the database |
- Source:
Example
Example usage of Database
// this sample code would store a daily object in the database and print a success statement when it completes
const id = 'D 20210519';
Database.store(id, { notes: 'this is an example' }, function (stored, id) {
if (stored === true) {
console.log('finished storing object with id ' + id);
} else {
console.log('could not store object with id' + id);
}
}, id);
Members
(static) DATABASE_NAME
Properties:
| Name | Type | Description |
|---|---|---|
DATABASE_NAME |
string
|
The name ('BulletJournal') of the IndexedDB database used by our app |
- Source:
(static) Stores
Properties:
| Name | Type | Description |
|---|---|---|
Stores |
Object.<string, string>
|
Object containing the constant names of the object stores in the database |
- Source:
Methods
(static) delete(id, callbackopt, nullable, …varArgs)
This function deletes a single JSON object with the given ID from the database. It first uses the format of
the given object ID to determine what type of object (ex. bullet, daily, monthly, yearly, etc) is being
deleted. It then makes an asynchronous call to IndexedDB's delete function on the appropriate object store
to delete the desired object, and then passes a boolean (true if the operation succeeds or false if the operation
fails) to the given callback function. In addition to the boolean value, any other given parameters (specified by
varArgs) are also passed to the callback function.
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
id |
string
|
The unique string ID that was used as the object's key in the database | ||
callback |
deleteCallback
|
<optional> <nullable> |
null | Callback function that is run after the database transaction completes (if no callback is provided, nothing is run after the transaction is complete) |
varArgs |
*
|
<repeatable> |
Additional arguments that are passed into callback function (in order) along with a boolean representing the success/failure result of the transaction (which is passed as the first argument to the callback) |
(static) deleteDatabase(callbackopt, nullable)
This function deletes the entire IndexedDB database and all its contents. It makes an
asynchronous call to IndexedDB's deleteDatabase function with the constant database
name 'BulletJournal'. If then runs the given callback function with a true/false parameter
based on whether or not the open operation succeeded.
WARNING: DO NOT CALL UNLESS YOU WISH FOR ALL THE USER'S DATA TO BE DELETED.
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
callback |
deleteCallback
|
<optional> <nullable> |
null | Callback function that is run after the database delete operation completes (if no callback is provided, nothing is run after the transaction is complete) |
(static) fetch(id, callbackopt, nullable, …varArgs)
This function retrieves a single JSON object with the given ID in the database. It first uses the format of
the given object ID to determine what type of object (ex. bullet, daily, monthly, yearly, etc) is being
retrieved. It then makes an asynchronous call to IndexedDB's get function on the appropriate object store
to retrieve the desired object, and then passes the retrieved object to the given callback function if the
retrieval operation succeeded, or passes null to the given callback if the retrieval operation failed. In
addition to the retrieved object, any other given parameters (specified by varArgs) are also passed to the
callback function.
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
id |
string
|
The unique string ID that was used as the object's key in the database | ||
callback |
fetchCallback
|
<optional> <nullable> |
null | Callback function that is run after the database transaction completes (if no callback is provided, nothing is run after the transaction is complete) |
varArgs |
*
|
<repeatable> |
Additional arguments that are passed into callback function (in order) along with the retrieved object (which is passed as the first argument to the callback) |
(static) getEntryKeys(callbackopt, nullable, …varArgs)
This function retrieves the keys of all the daily JSON objects in the database. The function makes an
asynchronous call to IndexedDB's getAllKeys function on the daily object store to retrieve all the keys
of the daily objects in the database, and then passes the retrieved object to the given callback function
if the retrieval operation succeeded, or passes null to the given callback if the retrieval operation
failed. In addition to the retrieved object, any other given parameters (specified by varArgs) are also
passed to the callback function.
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
callback |
fetchCallback
|
<optional> <nullable> |
null | Callback function that is run after the database transaction completes (if no callback is provided, nothing is run after the transaction is complete) |
varArgs |
*
|
<repeatable> |
Additional arguments that are passed into callback function (in order) along with the retrieved object (which is passed as the first argument to the callback) |
(static) getStoreFromID(id) → {string}
This function parses a given ID and determines what type of object (ex. bullet, daily, monthly, yearly,
etc) the ID represents. It returns the object store that stores that type of object. This function is
automatically called as a helper function when the fetch, store, and delete functions are called.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string
|
The unique string ID that was used as the object's key in the database |
Returns:
- Type:
-
string
The name of the object store containing the type of object (ex. bullet, daily, monthly,
yearly, etc) that the given ID represents
(static) openDatabase(callbackopt, nullable)
This function opens the IndexedDB database in order to allow for transactions to be run on the
database. It makes an asynchronous call to IndexedDB's open function with the constant database
name 'BulletJournal' and creates the appropriate object stores if the database doesn't yet exist.
It then runs the given callback function with the resulting database object if the operation
succeeds, or null if the operation fails. This function is automatically called as a helper function
when the fetch, store, and delete functions are called.
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
callback |
openCallback
|
<optional> <nullable> |
null | Callback function that is run after the database open operation completes (if no callback is provided, nothing is run after the transaction is complete) |
(static) store(id, dataObject, callbackopt, nullable, …varArgs)
This function stores a single JSON object in the database using the given ID. It first uses the format of
the given object ID to determine what type of object (ex. bullet, daily, monthly, yearly, etc) is being
stored. It then makes an asynchronous call to IndexedDB's put function on the appropriate object store
to store the given object, and then passes a boolean (true if the operation succeeds or false if the operation
fails) to the given callback function. In addition to the boolean value, any other given parameters (specified by
varArgs) are also passed to the callback function.
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
id |
string
|
The unique string ID that will be used as the object's key in the database | ||
dataObject |
Object
|
The JSON object to be stored | ||
callback |
storeCallback
|
<optional> <nullable> |
null | Callback function that is run after the database transaction completes (if no callback is provided, nothing is run after the transaction is complete) |
varArgs |
*
|
<repeatable> |
Additional arguments that are passed into callback function (in order) along with a boolean representing the success/failure result of the transaction (which is passed as the first argument to the callback) |