@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
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 context:[0m
[0;37mconst identity = { type: 'offlinePlayground', appID: 'live.ditto.playground' }[0m
[0;37mconst ditto = new Ditto.Ditto(identity, 'playground.ddb')[0m
[0;35m// Set the license token (get yours from portal.ditto.live):[0m
[0;37mditto.setOfflineOnlyLicenseToken('<YOUR_LICENSE_TOKEN_HERE>')[0m
[0;35m// Get hold of a collection:[0m
[0;37mconst cars = ditto.store.collection('cars')[0m
[0;35m// Insert an entry:[0m
[0;37mconst fordBlack = {_id: 'ford-black-123', model: "Ford", color: "black"}[0m
[0;37mawait cars.upsert(fordBlack)[0m
[0;35m// Find an entry by ID:[0m
[0;37mconst foundFordBlack = await cars.findByID('ford-black-123')[0m
[0;37mconsole.log(foundFordBlack)[0m
[0;35m// Remove an entry:[0m
[0;37mawait cars.findByID('ford-black-123').remove()[0m
----------------------------------------------
`)
var repl = REPL.start(`[0;34mDitto Playground[0m > `)
repl.context.Ditto = require(".")