Back to the Solid State KV Docs
To create a local database, call the SolidState()
function.
import SolidState from '$lib/solidstate-kv'
const db = SolidState()
This will return
// db { version: "0.0.1", persister: fn, getter: fn, post: fn, put: fn, get: fn }
db.post()
let ref = await db.post({
"@type": "Food",
"name": "Hummus",
"ingredient": [
"Garbanzo Beans",
"Lemon"
]
})
This will return a copy of the document.
// ref
undefined
Note that we have a new property, @id
. This is a generated UUID, but you can also provide your own, so long as it's unique to this entity.
let ref = await db.post({
"@id": "chickpeas",
"@type": "Ingredient",
"name": "Chickpeas"
})
// ref
undefined
db.put()
function, passing the Entities @id
as the first parameter, and the new keys as the second.
This will return the entire updated Entity:
// ref
"…"
Add to the existing value of an Entity with db.patch()
.
This will return the entire updated Entity:
// ref
"…"
Delete a key/value off an Entity with db.delete()
.
This will return the entire updated Entity:
// ref
"…"
Or delete the entire entity:
Which will return null
// ref
…
@id
with db.get()
Get a all items with db.getAll()
let ref = await db.getAll()
"…"