dberta.open() - cieszynski/dberta.js GitHub Wiki
Description
The method returns a Promise that resolves to a database connection (db). If the database does not yet exist, a new one is created based on the scheme that is specified with this method. For existing databases, the scheme is only taken into account if the version number is greater than the existing one - so this method can always be called with the scheme without hesitation.
Syntax
dberta.open(dbName, scheme)
Parameters
dbName
The name of the database.
scheme
A common javascript object with version numbers as keys and objects as values to define the stores and indices in this database.
To find out more, read about the scheme used in dberta.js.
Return value
A Promise that resolves to a database connection (db).
Exceptions
AbortError
Version change transaction was aborted in upgradeneeded event handler.
VersionError
Thrown if the requested version is less than the existing version.
TypeError
Thrown if the value of version is not a number greater than zero.
NotFoundError
Thrown if no scheme is given.
NotAllowedError
Thrown if a forbidden storename is used (e.g. "transaction")
Examples
const berta = await dberta.open('my-berta-db', {
3: { // version 3
user: "@id3, firstname, lastname",
events: "@id, date, title"
},
2: { // version 2
user: "@id2, firstname, age, firstname+age"
},
1: { // version 1
user: "@id1, firstname, age, firstname+age"
}
});