View in English

  • Apple Developer
    • Get Started

    Explore Get Started

    • Overview
    • Learn
    • Apple Developer Program

    Stay Updated

    • Latest News
    • Hello Developer
    • Platforms

    Explore Platforms

    • Apple Platforms
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store

    Featured

    • Design
    • Distribution
    • Games
    • Accessories
    • Web
    • Home
    • CarPlay
    • Technologies

    Explore Technologies

    • Overview
    • Xcode
    • Swift
    • SwiftUI

    Featured

    • Accessibility
    • App Intents
    • Apple Intelligence
    • Games
    • Machine Learning & AI
    • Security
    • Xcode Cloud
    • Community

    Explore Community

    • Overview
    • Meet with Apple events
    • Community-driven events
    • Developer Forums
    • Open Source

    Featured

    • WWDC
    • Swift Student Challenge
    • Developer Stories
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Centers
    • Documentation

    Explore Documentation

    • Documentation Library
    • Technology Overviews
    • Sample Code
    • Human Interface Guidelines
    • Videos

    Release Notes

    • Featured Updates
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • tvOS
    • Xcode
    • Downloads

    Explore Downloads

    • All Downloads
    • Operating Systems
    • Applications
    • Design Resources

    Featured

    • Xcode
    • TestFlight
    • Fonts
    • SF Symbols
    • Icon Composer
    • Support

    Explore Support

    • Overview
    • Help Guides
    • Developer Forums
    • Feedback Assistant
    • Contact Us

    Featured

    • Account Help
    • App Review Guidelines
    • App Store Connect Help
    • Upcoming Requirements
    • Agreements and Guidelines
    • System Status
  • Quick Links

    • Events
    • News
    • Forums
    • Sample Code
    • Videos
 

Videos

Abrir menú Cerrar menú
  • Colecciones
  • Todos los videos
  • Información

Más videos

  • Información
  • Código
  • Meet CKTool JS

    Discover how you can manage and automate your iCloud containers using CKTool JS. We'll show you how to configure CKTool JS to manage your containers' schemas, modify records with ease, and manipulate data on the fly. We'll also explore how you can integrate CKTool JS into your automation and tooling workflows.

    To get the most out of this session, we recommend familiarity with CloudKit schemas, JavaScript, and npm.

    Recursos

    • CloudKit Samples: Tooling
    • CKTool JS
    • Integrating a Text-Based Schema into Your Workflow
      • Video HD
      • Video SD

    Videos relacionados

    WWDC22

    • What’s new in CloudKit Console

    WWDC21

    • Automate CloudKit tests with cktool and declarative schema
    • Meet CloudKit Console
  • Buscar este video…
    • 6:43 - Create security and default arguments objects

      // Create security object and setup default args
      
      const { CKEnvironment } = require("@apple/cktool.database");
      
      const security = {
          "ManagementTokenAuth": "<YOUR_MANAGEMENT_TOKEN>",
          "UserTokenAuth": "<YOUR_USER_TOKEN>"
      };
      
      const defaultArgs = {
          "teamId": "<YOUR_TEAM_ID>",
          "containerId": "<YOUR_CONTAINER_ID>",
          "environment": CKEnvironment.DEVELOPMENT
      };
    • 7:17 - Create configuration and API objects

      // Create configuration and API objects
      
      const { createConfiguration } = require("@apple/cktool.target.nodejs");
      const { PromisesApi } = require("@apple/cktool.database");
      
      const configuration = createConfiguration();
      const api = new PromisesApi({
          "configuration": configuration,
          "security": security
      });
    • 10:00 - Reset to production and import schema

      // Create a function to apply a schema
      
      const { File } = require("@apple/cktool.target.nodejs");
      const fs = require("fs/promises");
      const path = require("path");
      
      const importMySchema = async () => {
          const schemaPath = "<YOUR_SCHEMA_FILE>.ckdb";
          const buffer = await fs.readFile(schemaPath);
          const file = new File([buffer], schemaPath);
          await api.importSchema({ ...defaultArgs, "file": file });
      }
      
      // Chain the calls
      api.resetToProduction(defaultArgs)
        .then(() => importMySchema());
    • 11:36 - Factory functions

      // Create fields with factory functions.
      
      const {
          makeRecordFieldValue
      } = require("@apple/cktool.database");
      
      const value = makeRecordFieldValue.int64(2007);
    • 12:02 - Create database arguments object

      // Create a database arguments object.
      
      const {
          CKDatabaseType, CKEnvironment
      } = require("@apple/cktool.database");
      
      const databaseArgs = {
          "containerID": "<YOUR_CONTAINER_ID>",
          "environment": CKEnvironment.DEVELOPMENT,
          "databaseType": CKDatabaseType.PRIVATE,
          "zoneName": "_defaultZone"
      };
    • 12:16 - Query for records

      // Define helper function for querying records
      
      const { CKDBQueryFilterType } = require("@apple/cktool.database");
      const countryQueryRecordForCountryCode3 = async (countryCode3) => {
          const response = await api.queryRecords({
              ...databaseArgs,
              "body": {
                  "query": {
                      "recordType": "Countries",
                      "filters": [{
                          "fieldName": "isoCode3",
                          "fieldValue": makeRecordFieldValue.string(countryCode3),
                          "type": CKDBQueryFilterType.EQUALS
                      }]
                  }
              }
          });
          return response.result.records[0];
      }
    • 12:58 - Create field values

      // Define a helper function for creating field values
      
      const {
          makeRecordFieldValue, CKDBRecordReferenceAction
      } = require("@apple/cktool.database");
      
      const makeCoinFieldValues = ({ countryRecordName, issueYear, nominalValue }) => ({
          "country": makeRecordFieldValue.reference({
              recordName: countryRecordName,
              action: CKDBRecordReferenceAction.DELETE_SELF
          }),
          "issueYear": makeRecordFieldValue.int64(issueYear),
          "nominalValue": makeRecordFieldValue.double(nominalValue)
      });
    • 13:26 - Create a record

      // Define helper method for creating coins
      
      const coinCreateRecord = async (fields) => {
          const response = await api.createRecord({
              ...databaseArgs,
              "body": {
                  "recordType": "Coins",
                  "fields": fields
              },
          });
          return response.result.record;
      }
    • 13:48 - Call record creation helper method

      // Call coin creation method with field values
      
      const countryRecord = await countryQueryRecordForCountryCode3("USA");
      
      const coinRecord1 = await coinCreateRecord(
          makeCoinFieldValues({
              "countryRecordName": countryRecord.recordName,
              "issueYear": 2007,
              "nominalValue": 0.10
          })
      );
    • 14:16 - Define update record helper function

      // Define helper method for updating coins.
      // Note that recordChangeTag is required
      
      const coinUpdate =
          async (recordName, recordChangeTag, fields) => {
              const response = await api.updateRecord({
                  ...databaseArgs,
                  "recordName": recordName,
                  "body": {
                      "recordType": "Coins",
                      "recordChangeTag": recordChangeTag,
                      "fields": fields
                  }
              });
              return response.result.record;
          }
    • 14:44 - Update a record with field values

      // Call coin updating method with field values.
      // Note that the recordChangeTag of the record
      // to update is passed to the coin update function.
      
      const countryRecord = await countryQueryRecordForCountryCode3("USA");
      const updatedCoinRecord1 = await coinUpdate(
          coinRecord1.recordName,
          coinRecord1.recordChangeTag,
          makeCoinFieldValues({
              "countryRecordName": countryRecord.recordName,
              "issueYear": 2010,
              "nominalValue": 0.10
          });
      );
    • 14:57 - Delete a record

      // Deleting a record
      
      await api.deleteRecord({
          ...databaseArgs,
         "recordName": coinRecord1.recordName
      });

Developer Footer

  • Videos
  • WWDC22
  • Meet CKTool JS
  • Open Menu Close Menu
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store
    Open Menu Close Menu
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • Icon Composer
    • SF Symbols
    Open Menu Close Menu
    • Accessibility
    • Accessories
    • Apple Intelligence
    • Audio & Video
    • Augmented Reality
    • Business
    • Design
    • Distribution
    • Education
    • Games
    • Health & Fitness
    • In-App Purchase
    • Localization
    • Maps & Location
    • Machine Learning & AI
    • Security
    • Safari & Web
    Open Menu Close Menu
    • Documentation
    • Downloads
    • Sample Code
    • Videos
    Open Menu Close Menu
    • Help Guides & Articles
    • Contact Us
    • Forums
    • Feedback & Bug Reporting
    • System Status
    Open Menu Close Menu
    • Apple Developer
    • App Store Connect
    • Certificates, IDs, & Profiles
    • Feedback Assistant
    Open Menu Close Menu
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program
    • Mini Apps Partner Program
    • News Partner Program
    • Video Partner Program
    • Security Bounty Program
    • Security Research Device Program
    Open Menu Close Menu
    • Meet with Apple
    • Apple Developer Centers
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Academies
    • WWDC
    Read the latest news.
    Get the Apple Developer app.
    Copyright © 2026 Apple Inc. All rights reserved.
    Terms of Use Privacy Policy Agreements and Guidelines