1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-07-14 04:34:04 +00:00

Save queries

This commit is contained in:
2023-02-15 17:00:53 +01:00
parent 3291bc845f
commit 5f358885a3
12 changed files with 419 additions and 37 deletions

View File

@ -0,0 +1,45 @@
import { get, writable } from 'svelte/store';
import { RemoveQuery, SavedQueries, SaveQuery, UpdateQueries } from '../../../wailsjs/go/app/App';
const { set, subscribe } = writable({});
let skipUpdate = true;
async function reload() {
const newViewStore = await SavedQueries();
set(newViewStore);
return newViewStore;
}
function forCollection(hostKey, dbKey, collKey) {
const allViews = get({ subscribe });
const entries = Object.entries(allViews).filter(v => (
v[1].hostKey === hostKey &&
v[1].dbKey === dbKey &&
v[1].collKey === collKey
));
return Object.fromEntries(entries);
}
async function create(query) {
const newId = await SaveQuery(JSON.stringify(query));
await reload();
return newId;
}
async function remove(id) {
await RemoveQuery(id);
await reload();
}
reload();
subscribe(newViewStore => {
if (skipUpdate) {
skipUpdate = false;
return;
}
UpdateQueries(JSON.stringify(newViewStore));
});
const queries = { reload, create, remove, set, subscribe, forCollection };
export default queries;