Local Persistence

Persistence API

Persisting data from a client-side app needs to be simple and also easy! This ssampe code lives is on Github.


// Set simple Key/Value pair
db.setItem('key', 'val')

// Set a key to a JSON Object
db.setItem('object', {
  some: "cool",
  json: "node"
})

// That is maybe deeply nested and complex
db.setItem('objectItem', {
  some: "cool",
  json: {
    nested: "thing",
    values: [0, 1, 2, 3],
    deeper: {
      more: "more!"
    }
  }
})

// Or an Array!
db.setItem('arrayItem', [0, 1, 2, 3])

// Or a complicated array!
db.setItem('arrayItem', [0, {key: "value"}, 2])

// What if we want to update object keys?
db.updateItem('objectItem', {
  json: {
    nested: "Thang"
  }
})

// Now we can get items too!
db.getItem('key')
// returns 'val'
db.getItem('objectItem')
// returns {
//   some: "cool",
//   json: {
//     nested: "thang",
//     values: [0, 1, 2, 3],
//     deeper: {
//       more: "more!"
//     }
//   }
// })

// And maybe a way to get em all
db.getItems()
// returns Map([…[id, value]])

// And finally, we can delete things:
db.delItem('key')
db.delItem('objectItem')
db.delItem('arrayItem')

// or ALL the things!
db.clear()