Contents

CloudKit.Database

A Cloudkit.database object represents a public or private database in an app container.

Declaration

interface CloudKit.Database

Overview

Each container has a public database whose data is accessible to all users and, if the current user is signed in, a private database whose data is accessible only by the current user. A database object applies operations to records, subscriptions, and zones within a database.

You do not create database objects yourself, nor should you subclass the CloudKit.Database class. You get a database object using either the publicCloudDatabase or privateCloudDatabase properties in the CloudKit.Container class. You get a CloudKit.Container object using methods in the CloudKit namespace. For example, use CloudKit.getDefaultContainer to get the default container object.

var container = CloudKit.getDefaultContainer();
var publicDatabase = container.publicCloudDatabase;
var privateDatabase = container.privateCloudDatabase;

Read access to the public database doesn’t require that the user sign in. Your web app may fetch records and perform queries on the public database, but by default your app may not save changes to the public database without a signed-in user. Access to the private database requires that the user sign in. To determine whether a user is authenticated, see setUpAuth in CloudKit.Container.

The asynchronous methods in this class return a Promise object that resolves when the operation completes or is rejected due to an error. For a description of the Promise class returned by these methods, go to Mozilla Developer Network: Promise.

This class is similar to the CKDatabase class in the CloudKit framework.

Creating Your Schema

Before you can access records, you must create a schema from your native app using just-in-time schema (see Creating a Database Schema by Saving Records) or using CloudKit Dashboard (see Using CloudKit Dashboard to Manage Databases). Use CloudKit Dashboard to verify that the record types and fields appear in your app’s containers before you test your JavaScript code.

[Image]

Topics

Getting the Container ID

Accessing Records

Accessing Record Zones

Subscribing to Changes

Fetching Changes

Sharing Records

Logging

See Also

Classes