UNPKG

@dittolive/ditto

Version:

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

43 lines (33 loc) 1.63 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 instance: const config = new Ditto.DittoConfig('live.ditto.playground', { mode: 'smallPeersOnly' }) config.persistenceDirectory = 'playground.ddb' const ditto = await Ditto.Ditto.open(config) // Set the license token (get yours from portal.ditto.live): ditto.setOfflineOnlyLicenseToken('<YOUR_LICENSE_TOKEN_HERE>') // Insert an entry: const fordBlack = {_id: 'ford-black-123', model: "Ford", color: "black"} await ditto.store.execute('INSERT INTO cars DOCUMENTS (:doc) ON ID CONFLICT DO UPDATE', { doc: fordBlack }) // Find an entry by ID: const result = await ditto.store.execute('SELECT * FROM cars WHERE _id = :id', { id: 'ford-black-123' }) console.log(result.items[0]?.value) // Remove an entry: await ditto.store.execute('DELETE FROM cars WHERE _id = :id', { id: 'ford-black-123' }) ---------------------------------------------- `) var repl = REPL.start(`Ditto Playground > `) repl.context.Ditto = require(".")