Ditto Playground

Try the examples below in your browser console

    // Initialize the Ditto module (loads WebAssembly, etc.):
    await Ditto.init({ webAssemblyModule: '/web/ditto.wasm' })

    // Create a Ditto context:
    const config = new Ditto.DittoConfig('live.ditto.playground', { mode: 'smallPeersOnly' })
    const ditto = await Ditto.Ditto.open(config)

    // 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' }
    )
  

NOTE: not all browsers support await in the console. If you try the above and get a syntax error, use promises directly instead:

    // Init the Ditto module and wait for it to finish.
    Ditto.init({ webAssemblyModule: '/web/ditto.wasm' }).then(() => {
      console.log('Ditto module initialized successfully.')
    })

    const config = new Ditto.DittoConfig('live.ditto.playground', { mode: 'smallPeersOnly' })
    Ditto.Ditto.open(config).then((ditto) => {
      // ...
    })