BoxDB
The class for IndexedDB and object stores management.
|
|
Parameters
- databaseName:
string
- Name of the database
- version:
number
- Version to open the database with
Properties
- BoxDB.Types
static
- BoxDB.Range
static
- BoxDB.Order
static
- databaseName:
string
- Database name
- version:
number
- Database version
- ready:
boolean
- Database ready status
Methods
BoxDB.Types
The
BoxDB.Types
is a set of defined data types.
|
|
Properties
- BoxDB.Types.BOOLEAN: for Boolean value
- BoxDB.Types.NUMBER: for Number value
- BoxDB.Types.STRING: for String value
- BoxDB.Types.DATE: for Date value
- BoxDB.Types.ARRAY: for Array value
- BoxDB.Types.OBJECT: for Object value
- BoxDB.Types.REGEXP: for RegExp value
- BoxDB.Types.FILE: for File value
- BoxDB.Types.BLOB: for Blob value
- BoxDB.Types.ANY: for any value (Skip type checking)
BoxDB.Range
The
BoxDB.Range
is a set of IDBKeyRange.
|
|
Methods
- BoxDB.Range.equal: returns a new key range containing a single value.
- Using IDBKeyRange.only
- Returns: IDBKeyRange
- BoxDB.Range.upper: returns a new upper-bound key range
- Using IDBKeyRange.upperBound
- Returns: IDBKeyRange
- BoxDB.Range.lower: returns a new key range with only a lower bound.
- Using IDBKeyRange.lowerBound
- Returns: IDBKeyRange
- BoxDB.Range.bound: returns a new key range with the specified upper and lower bounds
- Using IDBKeyRange.bound
- Returns: IDBKeyRange
BoxDB.Order
The
BoxDB.Order
is a set of IDBCursor.direction.
|
|
- BoxDB.Order.ASC: for using IDBCursor with
next
direction - BoxDB.Order.ASC_UNIQUE: for using IDBCursor with
nextunique
direction - BoxDB.Order.DESC: for using IDBCursor with
prev
direction - BoxDB.Order.DESC_UNIQUE: for using IDBCursor with
prevunique
direction
BoxDB.interrupt()
The
interrupt()
method of the BoxDB interface returns a TransactionTask to abort transaction.
|
|
BoxDB.create()
The
create()
method of the BoxDB interface returns new Box.
|
|
Parameters
- storeName:
string
- Name of the object store
- schema: BoxSchema
- Data schema of the data to store
- options: BoxOption (
optional
)- Object store options
Return value
BoxDB.open()
The
open()
method of the BoxDB interface open IndexedDB and create/update/delete object store based on created boxes.
|
|
Return value
- Promise<Event>
BoxDB.transaction()
The
BoxDB.transaction()
method takes an list of TransactionTask as an input, and perform tasks sequentially in one transaction.
Most important, if an error occurs during transaction, rolled back to the previous state.
|
|
Parameters
- task: …TransactionTask[]
- Transaction tasks
Return value
- Promise<
void
>
BoxSchema
The
BoxSchema
is an object that for data model. It’s includes field name with data type, and detailed options(key/index).
|
|
|
|
Options
- type: BoxDB.Types
- Type of this property (used by type checking)
- key:
boolean
(optional
)- Set this property as in-line key
- Can be set in-line key only once each object store
- If you want change, create new box after drop ( re-create box with
force
option)
- If you want change, create new box after drop ( re-create box with
- index:
boolean
(optional
) - unique:
boolean
(optional
)- Add unique constraint to this property’s index
- Must have use with
index
option
- Must have use with
- Add unique constraint to this property’s index
BoxOption
Box creation options
|
|
- autoIncrement:
boolean
(default:false
)- Use out-of-line key for this object store
- For autoIncrement flag
- force:
boolean
(default:false
)- Force update when versionchange event
- WARNING: This option will be drop exist object store before create
BoxData
Data of based on BoxSchema.
|
|
OptionalBoxData
|
|
BoxRange
The
BoxRange
is an object for query with value or IDBKeyRange.
|
|
Properties
- value: BoxDB.Range or IDBValidKey value
- index:
string
(optional
)- Indexed field name in schema (
index: true
option) - If you don’t serve index name, follows in-line key as default.
- Indexed field name in schema (
FilterFunction
The
FilterFunction
is a function to evaluate each record. This function receives BoxData and returns a boolean value.
|
|
Box
A
Box
is an abstraction that represents a object store. and also can generate data in a defined form (schema).
|
|
Parameters
- storeName:
string
- Name of the object store
- schema: BoxSchema
- Data schema of the data to store
- options: BoxOption (
optional
)- Object store options
Methods
- Box.getName(): Returns object store name
- Box.getVersion(): Returns target database version
- Box.add(value, key): Add record to object store
- Box.get(key): Get record from object store
- Box.put(value[, key]): Put record to object store
- Box.delete(key): Delete record from object store
- Box.count(key): Get records count
- Box.clear(): Drop the object store
- Box.find(range, …predicate): Returns
BoxCursorHandler
, Transaction by IDBCursor- find().get(): Get records
- find().update(updateValue): Update records
- find().delete(): Delete records
- Box.$add(): Returns TransactionTask that add record.
- Box.$put(): Returns TransactionTask that update record.
- Box.$delete(): Returns TransactionTask that delete record.
- Box.$find(): Returns TransactionCursorHandler.
Box.getName()
The
getName()
methods returns current object store name
|
|
Return value
- string
Box.getVersion()
The
getVersion()
methods returns version of database
|
|
Return value
- number
Box.add()
The
add()
method of the Box interface stores the data in the target object store.
|
|
Parameters
- value: BoxData
- The data to be stored.
- key: IDBValidKey (
optional
)- The key to use to identify the record. (default:
null
) - Using this parameter when box defined with
autoIncrement
option.
- The key to use to identify the record. (default:
Return value
- Promise<IDBValidKey>
- Returns added record’s key (both in/out-of-line key)
Box.get()
The
get()
method of the Box interface returns an specific record data from object store
|
|
Parameters
- key: IDBValidKey
- The key or key range that identifies the record to be retrieved.
Return value
- Promise<BoxData>
Box.put()
The
put()
method of the Box interface updates a given record in a database, or inserts a new record if the given item does not already exist.
|
|
Parameters
- value: BoxData
- The data you wish to update.
- key: IDBValidKey (
optional
)- The key that identifies the record to be updated.
- Using this parameter when box defined with
autoIncrement
option.
Return value
- Promise<
void
>
Box.delete()
The
delete()
method of the Box interface deletes target record
|
|
Parameters
- key: IDBValidKey
- The key that identifies the record to be deleted.
Return value
- Promise<
void
>
Box.find()
The
find()
method of the Box interface selects all records that are retrieved by BoxRange and passed the provided FilterFunction.
Parameters
- range: BoxRange (
optional
) - pridicate: …FilterFunction (
optional
)
Return value
Box.count()
The
BoxMode.count()
method returns all records count in object store.
|
|
Return value
- Promise<
number
>
Box.clear()
The
BoxMode.clear()
method clears all of data in object store.
|
|
Return value
- Promise<
void
>
Box.$add()
The
$add()
of the Box interface returns TransactionTask to add record.
$
Prefixed methods returns TransactionTask
|
|
Parameters
- value: BoxData
- The data to be stored.
- key: IDBValidKey (
optional
)- The key to use to identify the record. (default:
null
) - Using this parameter when box defined with
autoIncrement
option.
- The key to use to identify the record. (default:
Return value
Box.$put()
The
$put()
of the Box interface returns a TransactionTask to update or insert record.
|
|
Parameters
- value: BoxData
- The data you wish to update.
- key: IDBValidKey (
optional
)- The key that identifies the record to be updated.
- Using this parameter when box defined with
autoIncrement
option.
Return value
Box.$delete()
The
$delete()
of the Box interface returns a TransactionTask to delete record.
|
|
Parameters
- key: IDBValidKey (
optional
)- The key that identifies the record to be deleted.
- Using this parameter when box defined with
autoIncrement
option.
Return value
Box.$find()
The
find()
method of the Box interface selects all records that are retrieved by BoxRange and passed the provided FilterFunction.
Different from
find()
,$find()
returns TransactionCursorHandler.
|
|
Parameters
- range: BoxRange (
optional
) - pridicate: …FilterFunction (
optional
)
Return value
BoxCursorHandler
The
BoxCursorHandler
interface uses IDBCursor to control data.
|
|
Methods
- BoxCursorHandler.get(): Get records from object store
- BoxCursorHandler.update(): Update records in object store
- BoxCursorHandler.delete(): Delete records in object store
BoxCursorHandler.get()
The
get()
method of the BoxCursorHandler interface returns a filtered list of record data from object store.
|
|
Parameters
- order: BoxDB.Order (
optional
)- Default: BoxDB.Order.ASC
- Uses in open IDBCursor
- Ordering based on specified index (default: in-line key)
- limit:
number
(optional
)- Default: unlimited
Return value
BoxCursorHandler.update()
The
update()
method of the BoxCursorHandler interface updates filtered records data from object store.
|
|
Parameters
- updateValue: OptionalBoxData
Return value
- Promise<
void
>
BoxCursorHandler.delete()
The
delete()
method of the BoxCursorHandler interface deletes filtered records data from object store.
|
|
Return value
- Promise<
void
>
TransactionCursorHandler
|
|
Methods
TransactionCursorHandler.update()
The
TransactionCursorHandler.update()
interface behaves the same as BoxCursorHandler.update(), but returns TransactionTask.
|
|
Parameters
- updateValue: OptionalBoxData
Return value
TransactionCursorHandler.delete()
The
TransactionCursorHandler.delete()
interface behaves the same as BoxCursorHandler.delete(), but returns TransactionTask.
|
|
Return value
TransactionTask
The
TransactionTask
is a value object for using in transaction(). It can be created with$
prefixed methods like $get(), $delete().