move to dexie es nedb does not support multiple isntances

This commit is contained in:
2020-10-08 20:03:09 +02:00
parent 56cd2a3e7c
commit 3f77bcf1e0
9 changed files with 40 additions and 101 deletions

View File

@@ -3,7 +3,7 @@
import day from 'dayjs'
import { range, random } from 'lodash'
import { insertLog, normalizeTimestamp, clear as clearDB } from '../../shared/db'
import { insertLog, normalizeTimestamp, DB } from '../../shared/db'
let loading = false
@@ -29,7 +29,8 @@
async function clear() {
try {
loading = true
await clearDB()
await DB.limits.clear()
await DB.logs.clear()
} finally {
loading = false
}

View File

@@ -2,7 +2,7 @@
import { createEventDispatcher } from 'svelte'
import { cloneDeep } from 'lodash'
import { Limits } from '../../shared/db'
import { DB } from '../../shared/db'
const dispatch = createEventDispatcher()
const init = { limit: ['1', 'h'], every: [1, 'd'] }
@@ -23,8 +23,7 @@
}
async function save() {
const { _id, ...rest } = limit
await Limits.update({ _id }, rest, { upsert: true })
await DB.limits.put(limit)
dispatch('update')
close()
}
@@ -41,7 +40,8 @@
<div class="content">
{#if limit}
<label class="form-label">
Host <input type="text" class="form-input" placeholder="google.com" bind:value={limit.host} />
Host
<input type="text" class="form-input" placeholder="google.com" bind:value={limit.host} />
</label>
<div class="form-label">Rules</div>

View File

@@ -4,7 +4,7 @@
import RulesEditor from '../components/RulesEditor.svelte'
import Rules from '../components/Rules.svelte'
import { Limits } from '../../shared/db.js'
import { DB } from '../../shared/db.js'
import { longPress } from '../../shared/lib'
let limits = null
@@ -15,15 +15,15 @@
}
function edit(id) {
limit = limits.find((limit) => limit._id === id)
limit = limits.find((limit) => limit.id === id)
}
async function load() {
limits = await Limits.find()
limits = await DB.limits.toArray()
}
async function del(id) {
await Limits.remove({ _id: id })
await DB.limits.delete(id)
await load()
}
@@ -50,7 +50,7 @@
<th>Rules</th>
<th class="text-right w-32">Actions</th>
</tr>
{#each limits as { host, rules, _id }}
{#each limits as { host, rules, id }}
<tr>
<td>{host}</td>
<td>
@@ -58,8 +58,8 @@
</td>
<td class="text-right">
<div class="btn-group">
<button class="btn btn-sm btn-primary" on:click={() => edit(_id)}>Edit</button>
<button class="btn btn-sm btn-error tooltip" data-tooltip="Hold to delete" use:longPress={() => del(_id)}>
<button class="btn btn-sm btn-primary" on:click={() => edit(id)}>Edit</button>
<button class="btn btn-sm btn-error tooltip" data-tooltip="Hold to delete" use:longPress={() => del(id)}>
Delete
</button>
</div>