new IndexDB( [dbName] [, storeName])
Create a new simple document store using IndexedDB.
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
dbName |
string |
<optional> |
The name of the database to create/open, defaults to 'DocumentStore'. |
storeName |
string |
<optional> |
The name of the object store to create/open, defaults to 'Documents'. |
Members
-
:IDBDatabase
db
-
The IndexedDB database instance.
Type
- IDBDatabase
-
:string
dbName
-
The name of the database.
NOTE: The actual name of the database is prefixed with the
PD.appIDapplication identifier to make it unique from other apps delivered by the same server. The name is also sanitized to remove any whitespace.Type
- string
-
:boolean
isIndexDB <readonly>
-
A flag indicating that this object is a custom IndexDB wrapper instance.
Type
- boolean
-
:string
storeName
-
The name of the object store or table within the database.
Type
- string
Methods
-
delete(id) <async>
-
Deletes a document from the database.
Parameters:
Name Type Description idstring The database key associated with the document to remove.
Returns:
Returns
trueif the document was successfully deleted, otherwisefalse.- Type
- boolean
-
dispose() <async>
-
Disposes of the database and frees resources.
Returns:
Returns
trueif the database was successfully destroyed.- Type
- boolean
-
get(id) <async>
-
Retrieve a document from the database.
Parameters:
Name Type Description idstring The database key associated with a document.
Returns:
Returns the document if found, otherwise null.
- Type
- object | null
-
keys() <async>
-
Retrieves a list of keys for documents in the database.
Returns:
Returns an array of document keys.
- Type
- Array.<string>
-
open() <async>
-
Open the database and create the object store if it doesn't exist.
Returns:
Returns
trueif the database was opened successfully, otherwisefalse.- Type
- boolean
-
rename(oldId, newId) <async>
-
Renames a document in the database.
Parameters:
Name Type Description oldIdstring The current ID of the document.
newIdstring The new ID to assign to the document.
Returns:
Returns
trueif the document was successfully renamed.- Type
- boolean
-
set(id, data) <async>
-
Saves a document to the database with the given name.
Parameters:
Name Type Description idstring The new database key to associate with the document.
dataobject The JSON object or string to store in the database.
Returns:
Returns
trueif the document was successfully saved, otherwisefalse.- Type
- boolean
-
isSupported() <static>
-
Checks if the browser/client supports IndexedDB.
Returns:
Returns
trueif IndexedDB is supported, otherwisefalse.- Type
- boolean