new LocalDatabaseTransport(config)
Database transport for IndexedDB.
Database transport for IndexedDB
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
object | Transport configuration
Properties
|
- Source:
- See:
-
- The Data Transport is set into the
Foundation
stack and it is consumed insideDataEntity
to persist data locally. LocalDatabaseTransport
extends Dexie as database handler for IndexedDB. See Dexie
- The Data Transport is set into the
Example
import LocalDatabaseTransport from './LocalDatabaseTransport' import { Schema } from './utils' const UserSchema = new Schema({ name: { type: String, required: true }, username: { type: String, required: true } }) const ProductSchema = new Schema({ // ... }) const dbName = 'MyDatabaseName' const localDataTransport = new LocalDatabaseTransport({ version: 1, // default 1 tables: {}, // default {} dbName }) // or const localDataTransport = new LocalDatabaseTransport({ dbName }) localDataTransport.addSchema('User', UserSchema) localDataTransport.addSchema('Product', ProductSchema) await localDataTransport.connect() const Biden = await localDataTransport.table('User').add({ name: 'Joe Biden', username: 'biden'}) const Ferrari = await localDataTransport.table('Product').add({ name: 'Ferrari', vendor: 'Ferrari', price_cost: 3000000})
Extends
- dexie
Methods
-
<static> addSchema(schemaName, schema)
A a Data Schema into the Schema tree.
-
A a Data Schema into the Schema tree
Parameters:
Name Type Description schemaName
string The schema name. Same as Entity name. schema
object A valid mongoose like schema - Source:
Returns:
schema - The schema enty from inside the Schema tree- Type
- object
Example
const UserSchema = new Schema({ name: { type: String, required: true }, username: { type: String, required: true } }) localDataTransport.addSchema('User', UserSchema)
-
<async, static> connect()
Setup connection to local database.
-
Setup connection to local database
- Source:
Returns:
-
Foundation uuid saved on localStorage
-
signature - Default methods signature format { error, data }
- Type
- object
-
signature.error - Execution error information
- Type
- string | object
-
signature.data - Connection information
- Type
- object
Example
await localDataTransport.connect()