diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index a04d9bb..f193e82 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -31,7 +31,6 @@ dependencies = [ "tauri", "tauri-build", "tauri-plugin-context-menu", - "tauri-plugin-store", "thiserror", ] @@ -1810,17 +1809,6 @@ dependencies = [ "objc_exception", ] -[[package]] -name = "objc-foundation" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" -dependencies = [ - "block", - "objc", - "objc_id", -] - [[package]] name = "objc_exception" version = "0.1.2" @@ -2386,30 +2374,6 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" -[[package]] -name = "rfd" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0149778bd99b6959285b0933288206090c50e2327f47a9c463bfdbf45c8823ea" -dependencies = [ - "block", - "dispatch", - "glib-sys", - "gobject-sys", - "gtk-sys", - "js-sys", - "lazy_static", - "log", - "objc", - "objc-foundation", - "objc_id", - "raw-window-handle", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "windows 0.37.0", -] - [[package]] name = "rustc-demangle" version = "0.1.24" @@ -2902,7 +2866,6 @@ dependencies = [ "rand 0.8.5", "raw-window-handle", "regex", - "rfd", "semver", "serde", "serde_json", @@ -3004,18 +2967,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "tauri-plugin-store" -version = "0.0.0" -source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v1#8244294335a7567fe30b2aa577b764991262b73f" -dependencies = [ - "log", - "serde", - "serde_json", - "tauri", - "thiserror", -] - [[package]] name = "tauri-runtime" version = "0.14.5" @@ -3506,18 +3457,6 @@ dependencies = [ "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "wasm-bindgen-macro" version = "0.2.93" @@ -3547,16 +3486,6 @@ version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" -[[package]] -name = "web-sys" -version = "0.3.70" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - [[package]] name = "webkit2gtk" version = "0.18.2" @@ -3670,7 +3599,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.48.0", ] [[package]] @@ -3679,19 +3608,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows" -version = "0.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57b543186b344cc61c85b5aab0d2e3adf4e0f99bc076eff9aa5927bcc0b8a647" -dependencies = [ - "windows_aarch64_msvc 0.37.0", - "windows_i686_gnu 0.37.0", - "windows_i686_msvc 0.37.0", - "windows_x86_64_gnu 0.37.0", - "windows_x86_64_msvc 0.37.0", -] - [[package]] name = "windows" version = "0.39.0" @@ -3856,12 +3772,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" -[[package]] -name = "windows_aarch64_msvc" -version = "0.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2623277cb2d1c216ba3b578c0f3cf9cdebeddb6e66b1b218bb33596ea7769c3a" - [[package]] name = "windows_aarch64_msvc" version = "0.39.0" @@ -3886,12 +3796,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" -[[package]] -name = "windows_i686_gnu" -version = "0.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3925fd0b0b804730d44d4b6278c50f9699703ec49bcd628020f46f4ba07d9e1" - [[package]] name = "windows_i686_gnu" version = "0.39.0" @@ -3922,12 +3826,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" -[[package]] -name = "windows_i686_msvc" -version = "0.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce907ac74fe331b524c1298683efbf598bb031bc84d5e274db2083696d07c57c" - [[package]] name = "windows_i686_msvc" version = "0.39.0" @@ -3952,12 +3850,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" -[[package]] -name = "windows_x86_64_gnu" -version = "0.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2babfba0828f2e6b32457d5341427dcbb577ceef556273229959ac23a10af33d" - [[package]] name = "windows_x86_64_gnu" version = "0.39.0" @@ -4000,12 +3892,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" -[[package]] -name = "windows_x86_64_msvc" -version = "0.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4dd6dc7df2d84cf7b33822ed5b86318fb1781948e9663bacd047fc9dd52259d" - [[package]] name = "windows_x86_64_msvc" version = "0.39.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 2442200..bb668fb 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -11,9 +11,8 @@ tauri-build = { version = "1", features = [] } bindgen = "0.70.1" [dependencies] -tauri = { version = "1", features = [ "dialog-open", "window-unmaximize", "window-start-dragging", "window-maximize", "shell-open"] } +tauri = { version = "1", features = [ "window-unmaximize", "window-start-dragging", "window-maximize", "shell-open" ] } tauri-plugin-context-menu = "0.8.2" -tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } thiserror = "1" [features] diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index c2debb1..36ea38b 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -20,7 +20,6 @@ struct AppState { fn main() { tauri::Builder::default() - .plugin(tauri_plugin_store::Builder::default().build()) .plugin(tauri_plugin_context_menu::init()) .setup(|app| { let working_dir = app.path_resolver().app_local_data_dir().unwrap(); diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 5751231..78aca34 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -23,10 +23,6 @@ "maximize": true, "unmaximize": true, "startDragging": true - }, - "dialog": { - "all": false, - "open": true } }, "windows": [ diff --git a/src/lib/ch-engine/index.ts b/src/lib/ch-engine/index.ts new file mode 100644 index 0000000..f04deda --- /dev/null +++ b/src/lib/ch-engine/index.ts @@ -0,0 +1,12 @@ +import { exec } from './query'; + +export async function init() { + await exec(` + CREATE DATABASE IF NOT EXISTS agx; + USE agx; + `); +} + +export { Sources } from './sources.svelte'; +export type * from './types'; +export { exec }; diff --git a/src/lib/query.ts b/src/lib/ch-engine/query.ts similarity index 50% rename from src/lib/query.ts rename to src/lib/ch-engine/query.ts index 5e24b2b..65b8749 100644 --- a/src/lib/query.ts +++ b/src/lib/ch-engine/query.ts @@ -1,17 +1,13 @@ import { invoke } from '@tauri-apps/api/tauri'; +import type { CHResponse } from './types'; export async function exec(query: string) { try { - const r: string = await invoke('query', { - query - }); + const r: string = await invoke('query', { query }); + if (!r) return; + return JSON.parse(r) as CHResponse; } catch (e) { console.error(e); } } - -export type CHResponse = { - meta: Array<{ name: string; type: string }>; - data: Array<{ [key: string]: any }>; -}; diff --git a/src/lib/ch-engine/sources.svelte.ts b/src/lib/ch-engine/sources.svelte.ts new file mode 100644 index 0000000..b3cc681 --- /dev/null +++ b/src/lib/ch-engine/sources.svelte.ts @@ -0,0 +1,32 @@ +import { exec } from './query'; +import type { Source } from './types'; + +const LIST_SOURCES_QUERY = `select + t.name as name, + t.engine as engine, + groupArray(map( + 'name', c.name, + 'type', c.type + )) as columns +from system.tables as t +inner join system.columns as c on t.name = c.table +where database = 'agx' +group by t.name, t.engine +`; + +export class Sources { + #tables = $state.raw([]); + + constructor() { + this.fetch(); + } + + public get tables() { + return this.#tables; + } + + async fetch() { + const response = await exec(LIST_SOURCES_QUERY); + if (response) this.#tables = response.data as Source[]; + } +} diff --git a/src/lib/ch-engine/types.d.ts b/src/lib/ch-engine/types.d.ts new file mode 100644 index 0000000..d21a1c1 --- /dev/null +++ b/src/lib/ch-engine/types.d.ts @@ -0,0 +1,15 @@ +export type CHResponse = { + meta: Array; + data: Array<{ [key: string]: any }>; +}; + +export interface ColumnDescriptor { + name: string; + type: string; +} + +export interface Source { + name: string; + engine: string; + columns: ColumnDescriptor[]; +} diff --git a/src/lib/components/ChartContainer.svelte b/src/lib/components/ChartContainer.svelte index 7597687..47b50aa 100644 --- a/src/lib/components/ChartContainer.svelte +++ b/src/lib/components/ChartContainer.svelte @@ -1,6 +1,6 @@ - - - -{#if open} - (open = false)} bind:this={modal}> -
-

Add Source

- - - - -
- {#if error_message} - {error_message} - {/if} -
- -
- - -
-
-
-{/if} - - diff --git a/src/lib/components/Datasets/Datasets.svelte b/src/lib/components/Datasets/Datasets.svelte index 9c97a5a..a1aa87f 100644 --- a/src/lib/components/Datasets/Datasets.svelte +++ b/src/lib/components/Datasets/Datasets.svelte @@ -2,74 +2,45 @@ import SearchBar from '$lib/components/SearchBar.svelte'; import { get_app_context } from '$lib/context'; import Database from '$lib/icons/Database.svelte'; - import Plus from '$lib/icons/Plus.svelte'; import Table from '$lib/icons/Table.svelte'; - import { listen } from '@tauri-apps/api/event'; - import { showMenu } from 'tauri-plugin-context-menu'; - import AddDataset from './AddDataset.svelte'; import { - DATASOURCE_TYPE_COLOR_MAP, - DATASOURCE_TYPE_SHORT_NAME_MAP, - DEFAULT_SOURCE, filter, - remove_nullable + remove_nullable, + SOURCE_TYPE_COLOR_MAP, + SOURCE_TYPE_SHORT_NAME_MAP } from './utils'; - const { datasets } = get_app_context(); + const { sources } = get_app_context(); + + let loading = $state(false); let search = $state(''); - const filtered = $derived(filter(datasets.sources, search)); - - let add_dataset_modal: ReturnType; + const filtered = $derived(filter(sources.tables, search)); +
+ +
- {#each filtered as source, i (source.slug)} + {#each filtered as source, i (source.name)}
- { - e.preventDefault(); - const element = e.currentTarget; - element.classList.add('Selected'); - await showMenu({ - theme: 'dark', - items: [ - { - label: 'Reload', - event: () => datasets.refresh(source) - }, - { - label: 'Copy path', - event: () => navigator.clipboard.writeText(source.path) - }, - { - label: 'Copy alias', - event: () => navigator.clipboard.writeText(source.slug) - }, - { is_separator: true }, - { - label: 'Remove', - event: () => datasets.remove(source), - disabled: source.slug === DEFAULT_SOURCE.slug - } - ] - }); - - const unlistenMenuClose = await listen('menu-did-close', () => { - element.classList.remove('Selected'); - unlistenMenuClose(); - }); - }} - > - {#if source.type === 'MergeTree'} + + {#if source.engine === 'MergeTree'} {:else} {/if}

{source.name}

- - {DATASOURCE_TYPE_SHORT_NAME_MAP[source.type]} + + {SOURCE_TYPE_SHORT_NAME_MAP[source.engine]}
    @@ -82,19 +53,8 @@
{/each} -
- -
- { - const index = datasets.sources.findIndex((s) => s.slug === values.slug); - if (index === -1) datasets.add({ name: values.name, slug: values.slug, path_url: values.path }); - }} -/> - diff --git a/src/lib/components/Datasets/utils.ts b/src/lib/components/Datasets/utils.ts index 2e5eaed..0e788a1 100644 --- a/src/lib/components/Datasets/utils.ts +++ b/src/lib/components/Datasets/utils.ts @@ -1,62 +1,28 @@ -import { exec, type CHResponse } from '$lib/query'; -import type { ColumnDescriptor, Dataset } from '$lib/types'; +import { type Source } from '$lib/ch-engine'; -export function filter(sources: Dataset[], search: string) { +export function filter(sources: Source[], search: string) { if (!search) return sources; const search_ = search.toLowerCase(); return sources.filter( (s) => s.name.toLowerCase().includes(search_) || - s.slug.includes(search_) || s.columns?.some((c) => c.name.toLowerCase().includes(search_)) ); } -export const DATASOURCE_TYPE_COLOR_MAP: Record = { - CSV: 'hsl(58deg 37% 28%)', - Parquet: 'hsl(20deg 37% 28%)', +export const SOURCE_TYPE_COLOR_MAP: Record = { + FILE: 'hsl(58deg 37% 28%)', + S3: 'hsl(20deg 37% 28%)', MergeTree: 'hsl(199deg 37% 28%)' }; -export const DATASOURCE_TYPE_SHORT_NAME_MAP: Record = { - CSV: 'CSV', - Parquet: 'PQT', +export const SOURCE_TYPE_SHORT_NAME_MAP: Record = { + FILE: 'FILE', + S3: 'S3', MergeTree: 'MT' }; export function remove_nullable(type: string) { return type.replace(/Nullable\((.*)\)/, '$1'); } - -export function describe_to_column_descriptors(response: CHResponse): ColumnDescriptor[] { - return response.data.map((d) => { - return { - name: d.name as string, - type: d.type as string - }; - }); -} - -export async function getDefaultSource() { - const defaults: Dataset = { - name: 'Agnostic Logs', - slug: 'agnostic_logs', - path: "s3('https://data.agnostic.dev/ethereum-mainnet-pq/logs/*.parquet', 'Parquet')", - type: 'Parquet', - last_refresh: Date.now() - }; - - const response = await exec(`DESCRIBE TABLE ${defaults.path}`); - if (!response) return; - - defaults.columns = describe_to_column_descriptors(response); - - return defaults; -} - -export const DEFAULT_SOURCE = { - name: 'Agnostic Logs', - slug: 'agnostic_logs', - path_url: 's3://data.agnostic.dev/ethereum-mainnet-pq/logs/*.parquet' -}; diff --git a/src/lib/components/Editor/Editor.svelte b/src/lib/components/Editor/Editor.svelte index 1eaa1b6..ae13e8f 100644 --- a/src/lib/components/Editor/Editor.svelte +++ b/src/lib/components/Editor/Editor.svelte @@ -1,4 +1,5 @@ @@ -57,7 +40,11 @@ {#snippet b()} {#snippet a()} - + {/snippet} {#snippet b()} diff --git a/src/routes/+page.ts b/src/routes/+page.ts index 36f9f58..87c29a8 100644 --- a/src/routes/+page.ts +++ b/src/routes/+page.ts @@ -1,6 +1,8 @@ -import { get_sources_from_store } from '$lib/store'; +import { init } from '$lib/ch-engine'; import type { PageLoad } from './$types'; export const load = (async () => { - return { sources: await get_sources_from_store() }; + await init(); + + return {}; }) satisfies PageLoad;