Docs : SDK : openDatabase
openDatabase lets you retrieve your user's data. You also need to have a database open before storing or modifying user data. This API will return a promise that gets resolved once the database becomes available for use.
userbase.openDatabase({
databaseName: 'example-database-name',
changeHandler: function (items) {
// update your application state with the database items
}
}).then(() => {
// the database can now be used
}).catch((e) => console.error(e))
Parameters
-
databaseName [string | Len: 1-100] - The database name to use.
-
changeHandler [function] - A callback that gets invoked when the database gets modified.
-
items [Array] - The full collection of items in the database, in insertion order.
- itemId [string] - The item's unique identifier.
- item [object] - The stored item.
- fileId [string | optional] - The attached file's unique identifier (if a file has been attached to this item via uploadFile). This can be passed to getFile to retrieve the file.
- fileName [string | optional] - The attached file's name.
- fileSize [number | optional] - The attached file's size in bytes.
-
createdBy [object] - The item creator's attribution data.
- timestamp [date] - The date the item was created.
- username [string | optional] - The item creator's username. Not present if the user has been deleted.
- userDeleted [boolean | optional] - Whether or not the user has been deleted.
-
updatedBy [object | optional] - Attribution data for the latest update.
- timestamp [date] - The date the item was most recently updated.
- username [string | optional] - The item updater's username. Not present if the user has been deleted.
- userDeleted [boolean | optional] - Whether or not the user has been deleted.
-
fileUploadedBy [object | optional] - Attribution data for the attached file.
- timestamp [date] - The date the file was uploaded.
- username [string | optional] - The file uploader's username. Not present if the user has been deleted.
- userDeleted [boolean | optional] - Whether or not the user has been deleted.
-
writeAccess [object | optional] - Access controls set on the item.
- onlyCreator [boolean | optional] - If true, only the item creator or database owner can modify the item.
- users [Array | optional] - If set, these are the users allowed to modify the item.
Advanced Parameters
-
shareToken [string | optional] - This token can only be used to open a database another user shared via shareDatabase.
-
databaseId [string | optional] - The database's unique identifier. This can only be used to open a database the user received access to directly from another user via shareDatabase.
Notes
-
If the user provides a new databaseName for the first time, this will create a new database and the user will be the owner.
-
To interact with a database the user received access to from another user via shareDatabase, you must provide either the databaseId or a shareToken. Providing a databaseName will simply open a new database and the user will be the owner.
-
You can retrieve the databaseId of databases the user received access to from other users via getDatabases.
-
Attribution data provided by the createdBy, updatedBy, and fileUploadedBy fields is only available in newly created databases.
Errors
- ParamsMustBeObject
- DatabaseAlreadyOpening
- DatabaseNameMissing
- DatabaseNameMustBeString
- DatabaseNameCannotBeBlank
- DatabaseNameTooLong
- DatabaseNameRestricted
- DatabaseIdMustBeString
- DatabaseIdCannotBeBlank
- DatabaseIdInvalidLength
- DatabaseIdNotAllowed
- DatabaseIdNotAllowedForOwnDatabase
- ShareTokenInvalid
- ShareTokenNotFound
- ShareTokenNotAllowedForOwnDatabase
- DatabaseNotFound
- ChangeHandlerMissing
- ChangeHandlerMustBeFunction
- UserNotSignedIn
- UserNotFound
- SubscriptionPlanNotSet
- SubscriptionNotFound
- SubscribedToIncorrectPlan
- SubscriptionInactive
- TrialExpired
- TooManyRequests
- ServiceUnavailable