dexie-cloud-addon
Add-on (plugin) for connecting Dexie database with a database in the cloud, Dexie Cloud. The add-on is loaded on the client and integrates with Dexie to track changes, sync, authenticate and observe remote changes.
Installation
Install dexie-cloud-addon
npm install dexie@latest
npm install dexie-cloud-addon@latest
Create a cloud database to sync with
Use dexie-cloud (another package) to create a database in the cloud, so that dexie-cloud-addon will have a database URL to sync with. Dexie Cloud has a forever free edition for 3 production users, unlimited devices and unlimited evaluation users.
npx dexie-cloud create
Usage
import Dexie from 'dexie';
import dexieCloud from 'dexie-cloud-addon'; // Import the addon
const db = new Dexie('mydb', {
addons: [dexieCloud] // Include addon in your Dexie instance
});
db.version(1).stores({
myTable: '@myId, myIndex1, myIndex2, ...'
});
db.cloud.configure({
databaseUrl: 'https://xxxxxxx.dexie.cloud', // URL from `npx dexie-cloud create`
...otherOptions
});
API
Methods
Method | Description |
---|---|
db.cloud.configure() | Connect your client to the cloud |
db.cloud.login() | Authenticate user. Useful in combination with option {requireAuth: false} |
db.cloud.logout() | Logout current user. |
db.cloud.sync() | Force a sync. Useful in combination with option {disableWebSocket: true} and {disableEagerSync: true} |
db.cloud.permissions() | Observe access permissions for given object - see also usePermission() |
Properties
Property | Type | Description |
---|---|---|
db.cloud.version | string | Version of dexie-cloud-addon |
db.cloud.options | DexieCloudOptions | Options configured using db.cloud.configure() |
db.cloud.schema | DexieCloudSchema | Dexie-Cloud specific schema (complementary to dexie schema) |
db.cloud.currentUserId | string | UserID of the currently logged in user |
db.cloud.currentUser | Observable<UserLogin> | Observable of currently logged in user. |
db.cloud.webSocketStatus | Observable<string> | Observable of websocket status: “not-started”, “connecting”, “connected”, “disconnected” or “error” |
db.cloud.syncState | Observable<SyncState> | Observable of sync state |
db.cloud.persistedSyncState | Observable<PersistedSyncState> | Observable of persisted sync state |
db.cloud.events.syncComplete | Observable<void> | Observable of persisted sync state |
db.cloud.userInteraction | Observable<DXCUserInteraction> | Observable of login GUI. Use in combination with option {customLoginGui: true} |
db.cloud.invites | Observable<Invite[]> | Observable of invites from other users to their realms |
db.cloud.roles | Observable<Role[]> | Observable of global roles in your database |
db.cloud.usingServiceWorker | boolean | Whether service worker is used or not. Depends on a combination of config options and whether a service worker that imports dexie-cloud’s service worker module was found |
Consuming Observable<T>
Many properties in db.cloud are Observables and the method db.cloud.permissions() returns an Observable. Observables represents reactive data and allows your app to subscribe to them and re-render whenever they emit a value. Observables can be consumed in any GUI framework and we give two samples below.
Example (React)
import { useObservable } from 'dexie-react-hooks';
import { db } from './db.js';
function MyComponent() {
// db.cloud.invites is an Observable of Invite[] array.
const invites = useObservable(db.cloud.invites);
return (
<>
<h1>Invites</h1>
<ul>
{invites.map((invite) => (
<li key={invite.id}>
You are invited to act as {invite.roles?.join(', ')}
in the realm {invite.realm.name}
<button onClick={() => invite.accept()}>Accept</button>
<button onClick={() => invite.reject()}>Reject</button>
</li>
))}
</ul>
</>
);
}
This component would render the current invites for your user at any time and re-render whenever an invite is added, updated or removed.
See useObservable()
Example (Svelte)
<script>
import { db } from "./db.js";
let oInvites = db.cloud.invites;
</script>
<div>
<h1>Invites</h1>
{#each $oInvites as invite (invite.id)}
<li>{invite.realm.name}</li>
{/each}
</div>
For more samples, see also db.cloud.currentUser and db.cloud.permissions()
Table of Contents
- API Reference
- Access Control in Dexie Cloud
- Add demo users
- Add public data
- Authentication in Dexie Cloud
- Best Practices
- Building Addons
- Collection
- Collection.and()
- Collection.clone()
- Collection.count()
- Collection.delete()
- Collection.desc()
- Collection.distinct()
- Collection.each()
- Collection.eachKey()
- Collection.eachPrimaryKey()
- Collection.eachUniqueKey()
- Collection.filter()
- Collection.first()
- Collection.keys()
- Collection.last()
- Collection.limit()
- Collection.modify()
- Collection.offset()
- Collection.or()
- Collection.primaryKeys()
- Collection.raw()
- Collection.reverse()
- Collection.sortBy()
- Collection.toArray()
- Collection.uniqueKeys()
- Collection.until()
- Compound Index
- Consistency in Dexie Cloud
- Consistent add() operator
- Consistent remove() operator
- Consistent replacePrefix() operator
- Consuming Dexie as a module
- Custom Emails in Dexie Cloud
- DBCore
- DBCoreAddRequest
- DBCoreCountRequest
- DBCoreCursor
- DBCoreDeleteRangeRequest
- DBCoreDeleteRequest
- DBCoreGetManyRequest
- DBCoreGetRequest
- DBCoreIndex
- DBCoreKeyRange
- DBCoreMutateRequest
- DBCoreMutateResponse
- DBCoreOpenCursorRequest
- DBCorePutRequest
- DBCoreQuery
- DBCoreQueryRequest
- DBCoreQueryResponse
- DBCoreRangeType
- DBCoreSchema
- DBCoreTable
- DBCoreTableSchema
- DBCoreTransaction
- DBCoreTransactionMode
- DBPermissionSet
- Deprecations
- Derived Work
- Design
- Dexie Cloud API
- Dexie Cloud API Limits
- Dexie Cloud Best Practices
- Dexie Cloud CLI
- Dexie Cloud Docs
- Dexie Cloud REST API
- Dexie Cloud Web Hooks
- Dexie Constructor
- Dexie.AbortError
- Dexie.BulkError
- Dexie.ConstraintError
- Dexie.DataCloneError
- Dexie.DataError
- Dexie.DatabaseClosedError
- Dexie.IncompatiblePromiseError
- Dexie.InternalError
- Dexie.InvalidAccessError
- Dexie.InvalidArgumentError
- Dexie.InvalidStateError
- Dexie.InvalidTableError
- Dexie.MissingAPIError
- Dexie.ModifyError
- Dexie.NoSuchDatabaseErrorError
- Dexie.NotFoundError
- Dexie.Observable
- Dexie.Observable.DatabaseChange
- Dexie.OpenFailedError
- Dexie.PrematureCommitError
- Dexie.QuotaExceededError
- Dexie.ReadOnlyError
- Dexie.SchemaError
- Dexie.SubTransactionError
- Dexie.Syncable
- Dexie.Syncable.IDatabaseChange
- Dexie.Syncable.IPersistentContext
- Dexie.Syncable.ISyncProtocol
- Dexie.Syncable.StatusTexts
- Dexie.Syncable.Statuses
- Dexie.Syncable.registerSyncProtocol()
- Dexie.TimeoutError
- Dexie.TransactionInactiveError
- Dexie.UnknownError
- Dexie.UnsupportedError
- Dexie.UpgradeError()
- Dexie.VersionChangeError
- Dexie.VersionError
- Dexie.[table]
- Dexie.addons
- Dexie.async()
- Dexie.backendDB()
- Dexie.close()
- Dexie.currentTransaction
- Dexie.debug
- Dexie.deepClone()
- Dexie.defineClass()
- Dexie.delByKeyPath()
- Dexie.delete()
- Dexie.derive()
- Dexie.events()
- Dexie.exists()
- Dexie.extend()
- Dexie.fakeAutoComplete()
- Dexie.getByKeyPath()
- Dexie.getDatabaseNames()
- Dexie.hasFailed()
- Dexie.ignoreTransaction()
- Dexie.isOpen()
- Dexie.js
- Dexie.name
- Dexie.on()
- Dexie.on.blocked
- Dexie.on.close
- Dexie.on.error
- Dexie.on.populate
- Dexie.on.populate-(old-version)
- Dexie.on.ready
- Dexie.on.storagemutated
- Dexie.on.versionchange
- Dexie.open()
- Dexie.override()
- Dexie.semVer
- Dexie.setByKeyPath()
- Dexie.shallowClone()
- Dexie.spawn()
- Dexie.table()
- Dexie.tables
- Dexie.transaction()
- Dexie.transaction()-(old-version)
- Dexie.use()
- Dexie.verno
- Dexie.version
- Dexie.version()
- Dexie.vip()
- Dexie.waitFor()
- DexieCloudOptions
- DexieError
- Docs Home
- Download
- EntityTable
- Export and Import Database
- Get started with Dexie in Angular
- Get started with Dexie in React
- Get started with Dexie in Svelte
- Get started with Dexie in Vue
- Hello World
- How To Use the StorageManager API
- Inbound
- IndexSpec
- Indexable Type
- IndexedDB on Safari
- Invite
- Member
- Migrating existing DB to Dexie
- MultiEntry Index
- PersistedSyncState
- Privacy Policy
- Promise
- Promise.PSD
- Promise.catch()
- Promise.finally()
- Promise.on.error
- Promise.onuncatched
- Questions and Answers
- Realm
- Releasing Dexie
- Road Map
- Road Map: Dexie 5.0
- Road Map: Dexie Cloud
- Role
- Run Dexie Cloud on Own Servers
- Sharding and Scalability
- Simplify with yield
- Support Ukraine
- SyncState
- Table
- Table Schema
- Table.add()
- Table.bulkAdd()
- Table.bulkDelete()
- Table.bulkGet()
- Table.bulkPut()
- Table.bulkUpdate()
- Table.clear()
- Table.count()
- Table.defineClass()
- Table.delete()
- Table.each()
- Table.filter()
- Table.get()
- Table.hook('creating')
- Table.hook('deleting')
- Table.hook('reading')
- Table.hook('updating')
- Table.limit()
- Table.mapToClass()
- Table.name
- Table.offset()
- Table.orderBy()
- Table.put()
- Table.reverse()
- Table.schema
- Table.toArray()
- Table.toCollection()
- Table.update()
- Table.where()
- The main limitations of IndexedDB
- Transaction
- Transaction.abort()
- Transaction.on.abort
- Transaction.on.complete
- Transaction.on.error
- Transaction.table()
- Tutorial
- Typescript
- Typescript (old)
- Understanding the basics
- UserLogin
- Version
- Version.stores()
- Version.upgrade()
- WhereClause
- WhereClause.above()
- WhereClause.aboveOrEqual()
- WhereClause.anyOf()
- WhereClause.anyOfIgnoreCase()
- WhereClause.below()
- WhereClause.belowOrEqual()
- WhereClause.between()
- WhereClause.equals()
- WhereClause.equalsIgnoreCase()
- WhereClause.inAnyRange()
- WhereClause.noneOf()
- WhereClause.notEqual()
- WhereClause.startsWith()
- WhereClause.startsWithAnyOf()
- WhereClause.startsWithAnyOfIgnoreCase()
- WhereClause.startsWithIgnoreCase()
- db.cloud.configure()
- db.cloud.currentUser
- db.cloud.currentUserId
- db.cloud.events.syncComplete
- db.cloud.invites
- db.cloud.login()
- db.cloud.logout()
- db.cloud.options
- db.cloud.permissions()
- db.cloud.persistedSyncState
- db.cloud.roles
- db.cloud.schema
- db.cloud.sync()
- db.cloud.syncState
- db.cloud.userInteraction
- db.cloud.usingServiceWorker
- db.cloud.version
- db.cloud.webSocketStatus
- db.members
- db.realms
- db.roles
- db.syncable.connect()
- db.syncable.delete()
- db.syncable.disconnect()
- db.syncable.getOptions()
- db.syncable.getStatus()
- db.syncable.list()
- db.syncable.on('statusChanged')
- db.syncable.setFilter()
- dexie-cloud-addon
- dexie-react-hooks
- liveQuery()
- unhandledrejection-event
- useLiveQuery()
- useObservable()
- usePermissions()