diff --git a/package-lock.json b/package-lock.json index f0804028a..4cb811bf3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,9 @@ "": { "name": "appbuilder-pwa", "version": "0.0.1", + "dependencies": { + "sql.js": "^1.12.0" + }, "devDependencies": { "@esbuild-plugins/node-globals-polyfill": "^0.2.3", "@esbuild-plugins/node-modules-polyfill": "^0.2.2", @@ -8840,6 +8843,11 @@ "integrity": "sha512-zC8zGoGkmc8J9ndvml8Xksr1Amk9qBujgbF0JAIWO7kXr43w0h/0GJNM/Vustixu+YE8N/MTrQ7N31FvHUACxQ==", "dev": true }, + "node_modules/sql.js": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/sql.js/-/sql.js-1.12.0.tgz", + "integrity": "sha512-Bi+43yMx/tUFZVYD4AUscmdL6NHn3gYQ+CM+YheFWLftOmrEC/Mz6Yh7E96Y2WDHYz3COSqT+LP6Z79zgrwJlA==" + }, "node_modules/stackback": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz", diff --git a/package.json b/package.json index 309eaaf1f..43941cf5d 100644 --- a/package.json +++ b/package.json @@ -69,5 +69,8 @@ }, "volta": { "node": "20.9.0" + }, + "dependencies": { + "sql.js": "^1.12.0" } } diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 7389d479d..33f782db6 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -6,18 +6,24 @@ import contents from '$lib/data/contents'; import { isFirstLaunch, audioActive } from '$lib/data/stores'; import { navigateToTextReference } from '$lib/navigate'; + import config from '$lib/data/config'; + + onMount(async () => { + if (config.programType === 'DAB') { + await goto(`${base}/lexicon`); + return; + } - onMount(() => { const launchAction = contents?.features?.['launch-action']; if ($page.data?.audio) { $audioActive = $page.data.audio === '1'; } if ($page.data?.ref) { - navigateToTextReference($page.data.ref); + await navigateToTextReference($page.data.ref); } else if (launchAction === 'contents' || ($isFirstLaunch && launchAction)) { - goto(`${base}/contents/1`); + await goto(`${base}/contents/1`); } else { - goto(`${base}/text`); + await goto(`${base}/text`); } }); diff --git a/src/routes/lexicon/+page.js b/src/routes/lexicon/+page.js new file mode 100644 index 000000000..711bbc52e --- /dev/null +++ b/src/routes/lexicon/+page.js @@ -0,0 +1,37 @@ +import { base } from '$app/paths'; +import initSqlJs from 'sql.js'; + +export async function load({ fetch }) { + const SQL = await initSqlJs({ + locateFile: (file) => `https://sql.js.org/dist/${file}` + }); + + // Fetch the database file + const response = await fetch(`${base}/data.sqlite`); + const buffer = await response.arrayBuffer(); + + // Load the database into sql.js + const db = new SQL.Database(new Uint8Array(buffer)); + console.log('Database loaded:', db); + + // Example: Running a simple query + const results = db.exec( + 'SELECT id, name, homonym_index, type, num_senses, summary FROM entries' + ); + const result = results[0]; + console.log(result); + + const entries = []; + for (let value of result.values) { + const entry = {}; + for (let i = 0; i < result.columns.length; ++i) { + entry[result.columns[i]] = value[i]; + } + entries.push(entry); + } + console.log(entries); + + return { + entries + }; +} diff --git a/src/routes/lexicon/+page.svelte b/src/routes/lexicon/+page.svelte new file mode 100644 index 000000000..bc9bae766 --- /dev/null +++ b/src/routes/lexicon/+page.svelte @@ -0,0 +1,32 @@ + + +
+ +
+
+
    + {#if entries.length > 0} + {#each entries as entry} +
  • {entry.name}
  • + {/each} + {:else} +
  • No entries available or table 'entries' not found.
  • + {/if} +
+
+
+