@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
JavaScript
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 [0;1mDitto Playground[0m for Node. Use this REPL to play
and interact with Ditto directly. Example:
--------------------------
[0;35m// Create a Ditto instance:[0m
[0;37mconst config = new Ditto.DittoConfig('live.ditto.playground', { mode: 'smallPeersOnly' })[0m
[0;37mconfig.persistenceDirectory = 'playground.ddb'[0m
[0;37mconst ditto = await Ditto.Ditto.open(config)[0m
[0;35m// Set the license token (get yours from portal.ditto.live):[0m
[0;37mditto.setOfflineOnlyLicenseToken('<YOUR_LICENSE_TOKEN_HERE>')[0m
[0;35m// Insert an entry:[0m
[0;37mconst fordBlack = {_id: 'ford-black-123', model: "Ford", color: "black"}[0m
[0;37mawait ditto.store.execute('INSERT INTO cars DOCUMENTS (:doc) ON ID CONFLICT DO UPDATE', { doc: fordBlack })[0m
[0;35m// Find an entry by ID:[0m
[0;37mconst result = await ditto.store.execute('SELECT * FROM cars WHERE _id = :id', { id: 'ford-black-123' })[0m
[0;37mconsole.log(result.items[0]?.value)[0m
[0;35m// Remove an entry:[0m
[0;37mawait ditto.store.execute('DELETE FROM cars WHERE _id = :id', { id: 'ford-black-123' })[0m
----------------------------------------------
`)
var repl = REPL.start(`[0;34mDitto Playground[0m > `)
repl.context.Ditto = require(".")