From 09f7cabcafa071d38e87defd1973804213701489 Mon Sep 17 00:00:00 2001 From: David Gasquez Date: Fri, 3 Jan 2025 11:05:09 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9A=A1=EF=B8=8F=20add=20duckdb=20int?= =?UTF-8?q?egration=20and=20dark=20mode=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Initial setup with DuckDB for data loading and theme toggle component for dark mode --- web/package-lock.json | 81 +++++++++++++++++++++++++++ web/package.json | 1 + web/src/assets/logo.svg | 6 +- web/src/components/ThemeToggle.astro | 79 ++++++++++++++++++++++++++ web/src/content.config.ts | 37 ++++++++++++ web/src/layouts/Layout.astro | 44 +++++++++++---- web/src/pages/countries/[...id].astro | 69 +++++++++++++++++++++++ web/src/pages/countries/index.astro | 46 +++++++++++++++ web/src/pages/index.astro | 24 ++++++-- web/src/styles.css | 48 ++++++++++------ 10 files changed, 402 insertions(+), 33 deletions(-) create mode 100644 web/src/components/ThemeToggle.astro create mode 100644 web/src/content.config.ts create mode 100644 web/src/pages/countries/[...id].astro create mode 100644 web/src/pages/countries/index.astro diff --git a/web/package-lock.json b/web/package-lock.json index 0e26356..38c6d67 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -8,6 +8,7 @@ "name": "datadex", "version": "0.0.1", "dependencies": { + "@duckdb/node-api": "^1.1.3-alpha.8", "astro": "^5.1.1" } }, @@ -126,6 +127,86 @@ "node": ">=6.9.0" } }, + "node_modules/@duckdb/node-api": { + "version": "1.1.3-alpha.8", + "resolved": "https://registry.npmmirror.com/@duckdb/node-api/-/node-api-1.1.3-alpha.8.tgz", + "integrity": "sha512-2cXV/3X3/ocGIoYVe7GkxIsUfHXlQ0THdC/H22KjSLCTBzhEFGJJpOaYCs9u5K532wxs8ogxK79smZPRab6YRQ==", + "dependencies": { + "@duckdb/node-bindings": "1.1.3-alpha.8" + } + }, + "node_modules/@duckdb/node-bindings": { + "version": "1.1.3-alpha.8", + "resolved": "https://registry.npmmirror.com/@duckdb/node-bindings/-/node-bindings-1.1.3-alpha.8.tgz", + "integrity": "sha512-Dda0YePuotBtO9CTfI+vX1NAnRNet3LIcoiTpygTME7emjFi8nLYXz+D7UF78+VdaZZ1AODls9i1m6U2Qxcw1g==", + "optionalDependencies": { + "@duckdb/node-bindings-darwin-arm64": "1.1.3-alpha.8", + "@duckdb/node-bindings-darwin-x64": "1.1.3-alpha.8", + "@duckdb/node-bindings-linux-arm64": "1.1.3-alpha.8", + "@duckdb/node-bindings-linux-x64": "1.1.3-alpha.8", + "@duckdb/node-bindings-win32-x64": "1.1.3-alpha.8" + } + }, + "node_modules/@duckdb/node-bindings-darwin-arm64": { + "version": "1.1.3-alpha.8", + "resolved": "https://registry.npmmirror.com/@duckdb/node-bindings-darwin-arm64/-/node-bindings-darwin-arm64-1.1.3-alpha.8.tgz", + "integrity": "sha512-AG5335Q2MR1oSpE6y9VZc/NhzlxdINNhMKtSJcf4+YZXnIOQgINHw/IMq3g75Mf7wrar1P+dMiSjWdajm/WVpg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@duckdb/node-bindings-darwin-x64": { + "version": "1.1.3-alpha.8", + "resolved": "https://registry.npmmirror.com/@duckdb/node-bindings-darwin-x64/-/node-bindings-darwin-x64-1.1.3-alpha.8.tgz", + "integrity": "sha512-qGOuqgO4Dh8RkDKrQ09L0tXJ/pKAsrfjkuGAhELW7nVmhCpg4TgR78X+heYCdzVMRK8di6om0U5DgMWI0/tbBQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@duckdb/node-bindings-linux-arm64": { + "version": "1.1.3-alpha.8", + "resolved": "https://registry.npmmirror.com/@duckdb/node-bindings-linux-arm64/-/node-bindings-linux-arm64-1.1.3-alpha.8.tgz", + "integrity": "sha512-KXYqqOqFRaQs4C3my13Uc0rNIDv2c+USTK8bQzBkoDjTNZdcktEN4p0/nWtYUgf84VrN5egkPUoMshIOs/EkGw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@duckdb/node-bindings-linux-x64": { + "version": "1.1.3-alpha.8", + "resolved": "https://registry.npmmirror.com/@duckdb/node-bindings-linux-x64/-/node-bindings-linux-x64-1.1.3-alpha.8.tgz", + "integrity": "sha512-czPOTIneSi3LbONByWpVmJjxJvviL8lt4Lhjpt8JR7tzAngVpRiqeys5hNkNjYcvRBP+RXngv4ZXnlfdgTM6lg==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@duckdb/node-bindings-win32-x64": { + "version": "1.1.3-alpha.8", + "resolved": "https://registry.npmmirror.com/@duckdb/node-bindings-win32-x64/-/node-bindings-win32-x64-1.1.3-alpha.8.tgz", + "integrity": "sha512-Kwg1MHShaIfAkdIo60WUgD+7+KZVcBo3Svbq934o6tCzBXPIpkwB2RDYct/FHiyWoCJ2sW4wglfsYEiftLO1ag==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ] + }, "node_modules/@emnapi/runtime": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.3.1.tgz", diff --git a/web/package.json b/web/package.json index 842bbb4..dee97ad 100644 --- a/web/package.json +++ b/web/package.json @@ -9,6 +9,7 @@ "astro": "astro" }, "dependencies": { + "@duckdb/node-api": "^1.1.3-alpha.8", "astro": "^5.1.1" } } diff --git a/web/src/assets/logo.svg b/web/src/assets/logo.svg index c5faecd..40b8257 100644 --- a/web/src/assets/logo.svg +++ b/web/src/assets/logo.svg @@ -1,4 +1,4 @@ - - - + diff --git a/web/src/components/ThemeToggle.astro b/web/src/components/ThemeToggle.astro new file mode 100644 index 0000000..def1290 --- /dev/null +++ b/web/src/components/ThemeToggle.astro @@ -0,0 +1,79 @@ +--- + +--- + + + + + + diff --git a/web/src/content.config.ts b/web/src/content.config.ts new file mode 100644 index 0000000..51949e0 --- /dev/null +++ b/web/src/content.config.ts @@ -0,0 +1,37 @@ +import { DuckDBInstance } from '@duckdb/node-api'; +import { defineCollection, z } from 'astro:content'; + +const countries = defineCollection({ + schema: z.object({ + id: z.string(), + name: z.string(), + data: z.any(), + }), + + loader: async () => { + const instance = await DuckDBInstance.create("/tmp/datadex.duckdb"); + const connection = await instance.connect(); + + await connection.run(` + create table if not exists world_development_indicators as + select * from 'https://huggingface.co/datasets/datonic/world_development_indicators/resolve/main/data/world_development_indicators.parquet' + `); + + const reader = await connection.runAndReadAll(` + select distinct country_code, country_name + from world_development_indicators + where country_code is not null + `); + + const data = reader.getRows(); + + console.log(data); + + return data.map((country: any) => ({ + id: country[0], + name: country[1] + })); + } +}); + +export const collections = { countries }; diff --git a/web/src/layouts/Layout.astro b/web/src/layouts/Layout.astro index 1f70d14..1bfba7c 100644 --- a/web/src/layouts/Layout.astro +++ b/web/src/layouts/Layout.astro @@ -1,23 +1,47 @@ --- import "../styles.css"; +import ThemeToggle from "../components/ThemeToggle.astro"; --- - + + + Datadex + +
+ +
+ - - diff --git a/web/src/pages/countries/[...id].astro b/web/src/pages/countries/[...id].astro new file mode 100644 index 0000000..cdd80e1 --- /dev/null +++ b/web/src/pages/countries/[...id].astro @@ -0,0 +1,69 @@ +--- +import { getCollection, render } from "astro:content"; +import { DuckDBInstance } from "@duckdb/node-api"; +import Layout from "../../layouts/Layout.astro"; + +export async function getStaticPaths() { + const countries = await getCollection("countries"); + return countries.map((country) => ({ + params: { id: country.id }, + props: { country }, + })); +} + +const instance = await DuckDBInstance.create("/tmp/datadex.duckdb"); +const connection = await instance.connect(); + +await connection.run(` + create table if not exists world_development_indicators as + select * from 'https://huggingface.co/datasets/datonic/world_development_indicators/resolve/main/data/world_development_indicators.parquet' +`); + +const reader = await connection.runAndReadAll(` + select + country_name, + country_code, + indicator_name, + year, + indicator_value + from world_development_indicators + where country_code = '${Astro.params.id}' + order by indicator_name desc, year desc + limit 10 +`); +const rows = reader.getRows(); + +const { country } = Astro.props; +const { Content } = await render(country); +--- + + +

{country.data.name}

+ + + + + + + + + + + + + { + rows.map((row) => ( + + + + + + + + )) + } + +
Country NameCountry CodeIndicator NameYearValue
{row[0]}{row[1]}{row[2]}{row[3]}{row[4]}
+ + +
diff --git a/web/src/pages/countries/index.astro b/web/src/pages/countries/index.astro new file mode 100644 index 0000000..e1cde19 --- /dev/null +++ b/web/src/pages/countries/index.astro @@ -0,0 +1,46 @@ +--- +import Layout from "../../layouts/Layout.astro"; +import { getCollection } from "astro:content"; + +const countries = await getCollection("countries"); +--- + + + + +
+

Datadex

+

The Open Data Platform for your Community's Data.

+
+ +
+ +

Countries

+ + +
diff --git a/web/src/pages/index.astro b/web/src/pages/index.astro index f5e1bac..3dce5c9 100644 --- a/web/src/pages/index.astro +++ b/web/src/pages/index.astro @@ -1,12 +1,28 @@ --- import Layout from "../layouts/Layout.astro"; -import { Image } from "astro:assets"; -import logo from "../assets/logo.svg"; +import { getCollection } from "astro:content"; + +const countries = await getCollection("countries"); --- -