UNPKG

@dittolive/ditto

Version:

Ditto is a cross-platform SDK that allows apps to sync with and even without internet connectivity.

45 lines (34 loc) 1.5 kB
const REPL = require('repl') const BOLD = '\x1B[0;1m' const RESET = '\x1B[0m' const BLACK = '\x1B[0;30m' const RED = '\x1B[0;31m' const GREEN = '\x1B[0;32m' const YELLOW = '\x1B[0;33m' const BLUE = '\x1B[0;34m' const MAGENTA = '\x1B[0;35m' const CYAN = '\x1B[0;36m' const WHITE = '\x1B[0;37m' console.log(` Welcome to the Ditto Playground for Node. Use this REPL to play and interact with Ditto directly, Example: -------------------------- // Create a Ditto context: const identity = { type: 'offlinePlayground', appID: 'live.ditto.playground' } const ditto = new Ditto.Ditto(identity, 'playground.ddb') // Set the license token (get yours from portal.ditto.live): ditto.setOfflineOnlyLicenseToken('<YOUR_LICENSE_TOKEN_HERE>') // Get hold of a collection: const cars = ditto.store.collection('cars') // Insert an entry: const fordBlack = {_id: 'ford-black-123', model: "Ford", color: "black"} await cars.upsert(fordBlack) // Find an entry by ID: const foundFordBlack = await cars.findByID('ford-black-123') console.log(foundFordBlack) // Remove an entry: await cars.findByID('ford-black-123').remove() ---------------------------------------------- `) var repl = REPL.start(`Ditto Playground > `) repl.context.Ditto = require(".")