I don't understand how I can get a value from IndexedDB using Dexie. Database is all good in 'application' tab in inspect tool. Total newbie, so please be understanding.
My db.js
import Dexie from "dexie";
export const db = new Dexie("myDatabase");
db.version(2).stores({
history: "++id, daterange, days",
storage: "id, name, value"
});
db.on("populate", function () {
db.storage.add({
id: 0,
name: "total",
value: 20
});
db.storage.add({
id: 1,
name: "left",
value: 20
});
});
db.open();
App.svelte
<script>
import Counter from "./src/Counter.svelte";
import New from "./src/New.svelte";
import History from "./src/History.svelte";
import { liveQuery } from "dexie";
import { db } from "./src/db";
let total = liveQuery(() =>
db.storage
.where("name")
.equals("total")
.value.then(function(a) {
totals = a;
})
);
let left = 25;
</script>
<style>
main {
width: 100%;
}
</style>
<main>
<Counter daysLeft={left} daysMax={total}/>
<New />
<History />
</main>
Whatever I try, object with daysMax={total}
outputs undefined
, [object Object]
or something like [Dexie object Object]
. I just want to get 20
from db, as seen in db.js:
db.on("populate", function () {
db.storage.add({
id: 0,
name: "total",
value: 20
});
(This all works and is visible in indexedDb)
I also tried daysMax={$total}