From c4836ce9b613f2ea49b62143d4e10808b1b94ed7 Mon Sep 17 00:00:00 2001 From: SandroMaglione Date: Thu, 9 Jan 2025 06:02:31 +0100 Subject: [PATCH] from `pglite` to `dexie` --- drizzle.config.ts | 7 - package.json | 6 +- pnpm-lock.yaml | 671 +----------------- src/db.ts | 31 - src/drizzle/0000_slow_doctor_faustus.sql | 28 - src/drizzle/meta/0000_snapshot.json | 231 ------ src/drizzle/meta/_journal.json | 13 - src/lib/hooks/use-delete-log.ts | 4 +- ...use-pglite-query.ts => use-dexie-query.ts} | 33 +- src/lib/hooks/use-get-activities.ts | 32 +- src/lib/hooks/use-get-categories.ts | 8 +- src/lib/hooks/use-get-log-by-date.ts | 55 +- src/lib/hooks/use-insert-activity.ts | 4 +- src/lib/hooks/use-insert-category.ts | 4 +- src/lib/hooks/use-insert-log.ts | 4 +- src/lib/hooks/use-pglite-drizzle.ts | 17 - src/lib/runtime-client.ts | 16 +- src/lib/schema.ts | 25 +- src/lib/services/{write-api.ts => dexie.ts} | 50 +- src/lib/services/migrations.ts | 24 - src/lib/services/pglite.ts | 32 - src/routes/__root.tsx | 51 +- 22 files changed, 160 insertions(+), 1186 deletions(-) delete mode 100644 drizzle.config.ts delete mode 100644 src/db.ts delete mode 100644 src/drizzle/0000_slow_doctor_faustus.sql delete mode 100644 src/drizzle/meta/0000_snapshot.json delete mode 100644 src/drizzle/meta/_journal.json rename src/lib/hooks/{use-pglite-query.ts => use-dexie-query.ts} (61%) delete mode 100644 src/lib/hooks/use-pglite-drizzle.ts rename src/lib/services/{write-api.ts => dexie.ts} (50%) delete mode 100644 src/lib/services/migrations.ts delete mode 100644 src/lib/services/pglite.ts diff --git a/drizzle.config.ts b/drizzle.config.ts deleted file mode 100644 index 85e984a..0000000 --- a/drizzle.config.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { defineConfig } from "drizzle-kit"; - -export default defineConfig({ - schema: "./src/db.ts", - out: "./src/drizzle", - dialect: "postgresql", -}); diff --git a/package.json b/package.json index 60ee3d8..2c0ea2f 100644 --- a/package.json +++ b/package.json @@ -16,19 +16,17 @@ "@types/react": "^19.0.2", "@types/react-dom": "^19.0.2", "@vitejs/plugin-react": "^4.3.2", - "drizzle-kit": "^0.30.1", "typescript": "^5.7.2", "vite": "^6.0.3" }, "dependencies": { - "@electric-sql/pglite": "^0.2.15", - "@electric-sql/pglite-react": "^0.2.15", "@tailwindcss/vite": "4.0.0-beta.8", "@tanstack/react-router": "^1.95.0", "@tanstack/router-devtools": "^1.95.0", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", - "drizzle-orm": "^0.38.3", + "dexie": "^4.0.10", + "dexie-react-hooks": "^1.1.7", "effect": "^3.12.0", "lucide-react": "^0.469.0", "react": "^19.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a981fb9..5915802 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,12 +8,6 @@ importers: .: dependencies: - '@electric-sql/pglite': - specifier: ^0.2.15 - version: 0.2.15 - '@electric-sql/pglite-react': - specifier: ^0.2.15 - version: 0.2.15(@electric-sql/pglite@0.2.15)(react@19.0.0) '@tailwindcss/vite': specifier: 4.0.0-beta.8 version: 4.0.0-beta.8(vite@6.0.7(jiti@2.4.2)(lightningcss@1.28.2)(tsx@4.19.2)) @@ -29,9 +23,12 @@ importers: clsx: specifier: ^2.1.1 version: 2.1.1 - drizzle-orm: - specifier: ^0.38.3 - version: 0.38.3(@electric-sql/pglite@0.2.15)(@types/react@19.0.2)(react@19.0.0) + dexie: + specifier: ^4.0.10 + version: 4.0.10 + dexie-react-hooks: + specifier: ^1.1.7 + version: 1.1.7(@types/react@19.0.2)(dexie@4.0.10)(react@19.0.0) effect: specifier: ^3.12.0 version: 3.12.0 @@ -69,9 +66,6 @@ importers: '@vitejs/plugin-react': specifier: ^4.3.2 version: 4.3.4(vite@6.0.7(jiti@2.4.2)(lightningcss@1.28.2)(tsx@4.19.2)) - drizzle-kit: - specifier: ^0.30.1 - version: 0.30.1 typescript: specifier: ^5.7.2 version: 5.7.2 @@ -179,32 +173,6 @@ packages: '@date-fns/tz@1.2.0': resolution: {integrity: sha512-LBrd7MiJZ9McsOgxqWX7AaxrDjcFVjWH/tIKJd7pnR7McaslGYOP1QmmiBXdJH/H/yLCT+rcQ7FaPBUxRGUtrg==} - '@drizzle-team/brocli@0.10.2': - resolution: {integrity: sha512-z33Il7l5dKjUgGULTqBsQBQwckHh5AbIuxhdsIxDDiZAzBOrZO6q9ogcWC65kU382AfynTfgNumVcNIjuIua6w==} - - '@electric-sql/pglite-react@0.2.15': - resolution: {integrity: sha512-u/CA/OM/gYyBIk9jTzy9WWabiK6jR1xPl3IbQ1cRuRFTo57CXh668z3JEJwV19TKzYCsjePB9XIqAh1PNJPN6w==} - peerDependencies: - '@electric-sql/pglite': ^0.2.15 - react: ^18.0.0 - - '@electric-sql/pglite@0.2.15': - resolution: {integrity: sha512-Jiq31Dnk+rg8rMhcSxs4lQvHTyizNo5b269c1gCC3ldQ0sCLrNVPGzy+KnmonKy1ZArTUuXZf23/UamzFMKVaA==} - - '@esbuild-kit/core-utils@3.3.2': - resolution: {integrity: sha512-sPRAnw9CdSsRmEtnsl2WXWdyquogVpB3yZ3dgwJfe8zrOzTsV7cJvmwrKVa+0ma5BoiGJ+BoqkMvawbayKUsqQ==} - deprecated: 'Merged into tsx: https://tsx.is' - - '@esbuild-kit/esm-loader@2.6.5': - resolution: {integrity: sha512-FxEMIkJKnodyA1OaCUoEvbYRkoZlLZ4d/eXFu9Fh8CbBBgP5EmZxrfTRyN0qpXZ4vOvqnE5YdRdcrmUUXuU+dA==} - deprecated: 'Merged into tsx: https://tsx.is' - - '@esbuild/aix-ppc64@0.19.12': - resolution: {integrity: sha512-bmoCYyWdEL3wDQIVbcyzRyeKLgk2WtWLTWz1ZIAZF/EGbNOwSA6ew3PftJ1PqMiOOGu0OyFMzG53L0zqIpPeNA==} - engines: {node: '>=12'} - cpu: [ppc64] - os: [aix] - '@esbuild/aix-ppc64@0.23.1': resolution: {integrity: sha512-6VhYk1diRqrhBAqpJEdjASR/+WVRtfjpqKuNw11cLiaWpAT/Uu+nokB+UJnevzy/P9C/ty6AOe0dwueMrGh/iQ==} engines: {node: '>=18'} @@ -217,18 +185,6 @@ packages: cpu: [ppc64] os: [aix] - '@esbuild/android-arm64@0.18.20': - resolution: {integrity: sha512-Nz4rJcchGDtENV0eMKUNa6L12zz2zBDXuhj/Vjh18zGqB44Bi7MBMSXjgunJgjRhCmKOjnPuZp4Mb6OKqtMHLQ==} - engines: {node: '>=12'} - cpu: [arm64] - os: [android] - - '@esbuild/android-arm64@0.19.12': - resolution: {integrity: sha512-P0UVNGIienjZv3f5zq0DP3Nt2IE/3plFzuaS96vihvD0Hd6H/q4WXUGpCxD/E8YrSXfNyRPbpTq+T8ZQioSuPA==} - engines: {node: '>=12'} - cpu: [arm64] - os: [android] - '@esbuild/android-arm64@0.23.1': resolution: {integrity: sha512-xw50ipykXcLstLeWH7WRdQuysJqejuAGPd30vd1i5zSyKK3WE+ijzHmLKxdiCMtH1pHz78rOg0BKSYOSB/2Khw==} engines: {node: '>=18'} @@ -241,18 +197,6 @@ packages: cpu: [arm64] os: [android] - '@esbuild/android-arm@0.18.20': - resolution: {integrity: sha512-fyi7TDI/ijKKNZTUJAQqiG5T7YjJXgnzkURqmGj13C6dCqckZBLdl4h7bkhHt/t0WP+zO9/zwroDvANaOqO5Sw==} - engines: {node: '>=12'} - cpu: [arm] - os: [android] - - '@esbuild/android-arm@0.19.12': - resolution: {integrity: sha512-qg/Lj1mu3CdQlDEEiWrlC4eaPZ1KztwGJ9B6J+/6G+/4ewxJg7gqj8eVYWvao1bXrqGiW2rsBZFSX3q2lcW05w==} - engines: {node: '>=12'} - cpu: [arm] - os: [android] - '@esbuild/android-arm@0.23.1': resolution: {integrity: sha512-uz6/tEy2IFm9RYOyvKl88zdzZfwEfKZmnX9Cj1BHjeSGNuGLuMD1kR8y5bteYmwqKm1tj8m4cb/aKEorr6fHWQ==} engines: {node: '>=18'} @@ -265,18 +209,6 @@ packages: cpu: [arm] os: [android] - '@esbuild/android-x64@0.18.20': - resolution: {integrity: sha512-8GDdlePJA8D6zlZYJV/jnrRAi6rOiNaCC/JclcXpB+KIuvfBN4owLtgzY2bsxnx666XjJx2kDPUmnTtR8qKQUg==} - engines: {node: '>=12'} - cpu: [x64] - os: [android] - - '@esbuild/android-x64@0.19.12': - resolution: {integrity: sha512-3k7ZoUW6Q6YqhdhIaq/WZ7HwBpnFBlW905Fa4s4qWJyiNOgT1dOqDiVAQFwBH7gBRZr17gLrlFCRzF6jFh7Kew==} - engines: {node: '>=12'} - cpu: [x64] - os: [android] - '@esbuild/android-x64@0.23.1': resolution: {integrity: sha512-nlN9B69St9BwUoB+jkyU090bru8L0NA3yFvAd7k8dNsVH8bi9a8cUAUSEcEEgTp2z3dbEDGJGfP6VUnkQnlReg==} engines: {node: '>=18'} @@ -289,18 +221,6 @@ packages: cpu: [x64] os: [android] - '@esbuild/darwin-arm64@0.18.20': - resolution: {integrity: sha512-bxRHW5kHU38zS2lPTPOyuyTm+S+eobPUnTNkdJEfAddYgEcll4xkT8DB9d2008DtTbl7uJag2HuE5NZAZgnNEA==} - engines: {node: '>=12'} - cpu: [arm64] - os: [darwin] - - '@esbuild/darwin-arm64@0.19.12': - resolution: {integrity: sha512-B6IeSgZgtEzGC42jsI+YYu9Z3HKRxp8ZT3cqhvliEHovq8HSX2YX8lNocDn79gCKJXOSaEot9MVYky7AKjCs8g==} - engines: {node: '>=12'} - cpu: [arm64] - os: [darwin] - '@esbuild/darwin-arm64@0.23.1': resolution: {integrity: sha512-YsS2e3Wtgnw7Wq53XXBLcV6JhRsEq8hkfg91ESVadIrzr9wO6jJDMZnCQbHm1Guc5t/CdDiFSSfWP58FNuvT3Q==} engines: {node: '>=18'} @@ -313,18 +233,6 @@ packages: cpu: [arm64] os: [darwin] - '@esbuild/darwin-x64@0.18.20': - resolution: {integrity: sha512-pc5gxlMDxzm513qPGbCbDukOdsGtKhfxD1zJKXjCCcU7ju50O7MeAZ8c4krSJcOIJGFR+qx21yMMVYwiQvyTyQ==} - engines: {node: '>=12'} - cpu: [x64] - os: [darwin] - - '@esbuild/darwin-x64@0.19.12': - resolution: {integrity: sha512-hKoVkKzFiToTgn+41qGhsUJXFlIjxI/jSYeZf3ugemDYZldIXIxhvwN6erJGlX4t5h417iFuheZ7l+YVn05N3A==} - engines: {node: '>=12'} - cpu: [x64] - os: [darwin] - '@esbuild/darwin-x64@0.23.1': resolution: {integrity: sha512-aClqdgTDVPSEGgoCS8QDG37Gu8yc9lTHNAQlsztQ6ENetKEO//b8y31MMu2ZaPbn4kVsIABzVLXYLhCGekGDqw==} engines: {node: '>=18'} @@ -337,18 +245,6 @@ packages: cpu: [x64] os: [darwin] - '@esbuild/freebsd-arm64@0.18.20': - resolution: {integrity: sha512-yqDQHy4QHevpMAaxhhIwYPMv1NECwOvIpGCZkECn8w2WFHXjEwrBn3CeNIYsibZ/iZEUemj++M26W3cNR5h+Tw==} - engines: {node: '>=12'} - cpu: [arm64] - os: [freebsd] - - '@esbuild/freebsd-arm64@0.19.12': - resolution: {integrity: sha512-4aRvFIXmwAcDBw9AueDQ2YnGmz5L6obe5kmPT8Vd+/+x/JMVKCgdcRwH6APrbpNXsPz+K653Qg8HB/oXvXVukA==} - engines: {node: '>=12'} - cpu: [arm64] - os: [freebsd] - '@esbuild/freebsd-arm64@0.23.1': resolution: {integrity: sha512-h1k6yS8/pN/NHlMl5+v4XPfikhJulk4G+tKGFIOwURBSFzE8bixw1ebjluLOjfwtLqY0kewfjLSrO6tN2MgIhA==} engines: {node: '>=18'} @@ -361,18 +257,6 @@ packages: cpu: [arm64] os: [freebsd] - '@esbuild/freebsd-x64@0.18.20': - resolution: {integrity: sha512-tgWRPPuQsd3RmBZwarGVHZQvtzfEBOreNuxEMKFcd5DaDn2PbBxfwLcj4+aenoh7ctXcbXmOQIn8HI6mCSw5MQ==} - engines: {node: '>=12'} - cpu: [x64] - os: [freebsd] - - '@esbuild/freebsd-x64@0.19.12': - resolution: {integrity: sha512-EYoXZ4d8xtBoVN7CEwWY2IN4ho76xjYXqSXMNccFSx2lgqOG/1TBPW0yPx1bJZk94qu3tX0fycJeeQsKovA8gg==} - engines: {node: '>=12'} - cpu: [x64] - os: [freebsd] - '@esbuild/freebsd-x64@0.23.1': resolution: {integrity: sha512-lK1eJeyk1ZX8UklqFd/3A60UuZ/6UVfGT2LuGo3Wp4/z7eRTRYY+0xOu2kpClP+vMTi9wKOfXi2vjUpO1Ro76g==} engines: {node: '>=18'} @@ -385,18 +269,6 @@ packages: cpu: [x64] os: [freebsd] - '@esbuild/linux-arm64@0.18.20': - resolution: {integrity: sha512-2YbscF+UL7SQAVIpnWvYwM+3LskyDmPhe31pE7/aoTMFKKzIc9lLbyGUpmmb8a8AixOL61sQ/mFh3jEjHYFvdA==} - engines: {node: '>=12'} - cpu: [arm64] - os: [linux] - - '@esbuild/linux-arm64@0.19.12': - resolution: {integrity: sha512-EoTjyYyLuVPfdPLsGVVVC8a0p1BFFvtpQDB/YLEhaXyf/5bczaGeN15QkR+O4S5LeJ92Tqotve7i1jn35qwvdA==} - engines: {node: '>=12'} - cpu: [arm64] - os: [linux] - '@esbuild/linux-arm64@0.23.1': resolution: {integrity: sha512-/93bf2yxencYDnItMYV/v116zff6UyTjo4EtEQjUBeGiVpMmffDNUyD9UN2zV+V3LRV3/on4xdZ26NKzn6754g==} engines: {node: '>=18'} @@ -409,18 +281,6 @@ packages: cpu: [arm64] os: [linux] - '@esbuild/linux-arm@0.18.20': - resolution: {integrity: sha512-/5bHkMWnq1EgKr1V+Ybz3s1hWXok7mDFUMQ4cG10AfW3wL02PSZi5kFpYKrptDsgb2WAJIvRcDm+qIvXf/apvg==} - engines: {node: '>=12'} - cpu: [arm] - os: [linux] - - '@esbuild/linux-arm@0.19.12': - resolution: {integrity: sha512-J5jPms//KhSNv+LO1S1TX1UWp1ucM6N6XuL6ITdKWElCu8wXP72l9MM0zDTzzeikVyqFE6U8YAV9/tFyj0ti+w==} - engines: {node: '>=12'} - cpu: [arm] - os: [linux] - '@esbuild/linux-arm@0.23.1': resolution: {integrity: sha512-CXXkzgn+dXAPs3WBwE+Kvnrf4WECwBdfjfeYHpMeVxWE0EceB6vhWGShs6wi0IYEqMSIzdOF1XjQ/Mkm5d7ZdQ==} engines: {node: '>=18'} @@ -433,18 +293,6 @@ packages: cpu: [arm] os: [linux] - '@esbuild/linux-ia32@0.18.20': - resolution: {integrity: sha512-P4etWwq6IsReT0E1KHU40bOnzMHoH73aXp96Fs8TIT6z9Hu8G6+0SHSw9i2isWrD2nbx2qo5yUqACgdfVGx7TA==} - engines: {node: '>=12'} - cpu: [ia32] - os: [linux] - - '@esbuild/linux-ia32@0.19.12': - resolution: {integrity: sha512-Thsa42rrP1+UIGaWz47uydHSBOgTUnwBwNq59khgIwktK6x60Hivfbux9iNR0eHCHzOLjLMLfUMLCypBkZXMHA==} - engines: {node: '>=12'} - cpu: [ia32] - os: [linux] - '@esbuild/linux-ia32@0.23.1': resolution: {integrity: sha512-VTN4EuOHwXEkXzX5nTvVY4s7E/Krz7COC8xkftbbKRYAl96vPiUssGkeMELQMOnLOJ8k3BY1+ZY52tttZnHcXQ==} engines: {node: '>=18'} @@ -457,18 +305,6 @@ packages: cpu: [ia32] os: [linux] - '@esbuild/linux-loong64@0.18.20': - resolution: {integrity: sha512-nXW8nqBTrOpDLPgPY9uV+/1DjxoQ7DoB2N8eocyq8I9XuqJ7BiAMDMf9n1xZM9TgW0J8zrquIb/A7s3BJv7rjg==} - engines: {node: '>=12'} - cpu: [loong64] - os: [linux] - - '@esbuild/linux-loong64@0.19.12': - resolution: {integrity: sha512-LiXdXA0s3IqRRjm6rV6XaWATScKAXjI4R4LoDlvO7+yQqFdlr1Bax62sRwkVvRIrwXxvtYEHHI4dm50jAXkuAA==} - engines: {node: '>=12'} - cpu: [loong64] - os: [linux] - '@esbuild/linux-loong64@0.23.1': resolution: {integrity: sha512-Vx09LzEoBa5zDnieH8LSMRToj7ir/Jeq0Gu6qJ/1GcBq9GkfoEAoXvLiW1U9J1qE/Y/Oyaq33w5p2ZWrNNHNEw==} engines: {node: '>=18'} @@ -481,18 +317,6 @@ packages: cpu: [loong64] os: [linux] - '@esbuild/linux-mips64el@0.18.20': - resolution: {integrity: sha512-d5NeaXZcHp8PzYy5VnXV3VSd2D328Zb+9dEq5HE6bw6+N86JVPExrA6O68OPwobntbNJ0pzCpUFZTo3w0GyetQ==} - engines: {node: '>=12'} - cpu: [mips64el] - os: [linux] - - '@esbuild/linux-mips64el@0.19.12': - resolution: {integrity: sha512-fEnAuj5VGTanfJ07ff0gOA6IPsvrVHLVb6Lyd1g2/ed67oU1eFzL0r9WL7ZzscD+/N6i3dWumGE1Un4f7Amf+w==} - engines: {node: '>=12'} - cpu: [mips64el] - os: [linux] - '@esbuild/linux-mips64el@0.23.1': resolution: {integrity: sha512-nrFzzMQ7W4WRLNUOU5dlWAqa6yVeI0P78WKGUo7lg2HShq/yx+UYkeNSE0SSfSure0SqgnsxPvmAUu/vu0E+3Q==} engines: {node: '>=18'} @@ -505,18 +329,6 @@ packages: cpu: [mips64el] os: [linux] - '@esbuild/linux-ppc64@0.18.20': - resolution: {integrity: sha512-WHPyeScRNcmANnLQkq6AfyXRFr5D6N2sKgkFo2FqguP44Nw2eyDlbTdZwd9GYk98DZG9QItIiTlFLHJHjxP3FA==} - engines: {node: '>=12'} - cpu: [ppc64] - os: [linux] - - '@esbuild/linux-ppc64@0.19.12': - resolution: {integrity: sha512-nYJA2/QPimDQOh1rKWedNOe3Gfc8PabU7HT3iXWtNUbRzXS9+vgB0Fjaqr//XNbd82mCxHzik2qotuI89cfixg==} - engines: {node: '>=12'} - cpu: [ppc64] - os: [linux] - '@esbuild/linux-ppc64@0.23.1': resolution: {integrity: sha512-dKN8fgVqd0vUIjxuJI6P/9SSSe/mB9rvA98CSH2sJnlZ/OCZWO1DJvxj8jvKTfYUdGfcq2dDxoKaC6bHuTlgcw==} engines: {node: '>=18'} @@ -529,18 +341,6 @@ packages: cpu: [ppc64] os: [linux] - '@esbuild/linux-riscv64@0.18.20': - resolution: {integrity: sha512-WSxo6h5ecI5XH34KC7w5veNnKkju3zBRLEQNY7mv5mtBmrP/MjNBCAlsM2u5hDBlS3NGcTQpoBvRzqBcRtpq1A==} - engines: {node: '>=12'} - cpu: [riscv64] - os: [linux] - - '@esbuild/linux-riscv64@0.19.12': - resolution: {integrity: sha512-2MueBrlPQCw5dVJJpQdUYgeqIzDQgw3QtiAHUC4RBz9FXPrskyyU3VI1hw7C0BSKB9OduwSJ79FTCqtGMWqJHg==} - engines: {node: '>=12'} - cpu: [riscv64] - os: [linux] - '@esbuild/linux-riscv64@0.23.1': resolution: {integrity: sha512-5AV4Pzp80fhHL83JM6LoA6pTQVWgB1HovMBsLQ9OZWLDqVY8MVobBXNSmAJi//Csh6tcY7e7Lny2Hg1tElMjIA==} engines: {node: '>=18'} @@ -553,18 +353,6 @@ packages: cpu: [riscv64] os: [linux] - '@esbuild/linux-s390x@0.18.20': - resolution: {integrity: sha512-+8231GMs3mAEth6Ja1iK0a1sQ3ohfcpzpRLH8uuc5/KVDFneH6jtAJLFGafpzpMRO6DzJ6AvXKze9LfFMrIHVQ==} - engines: {node: '>=12'} - cpu: [s390x] - os: [linux] - - '@esbuild/linux-s390x@0.19.12': - resolution: {integrity: sha512-+Pil1Nv3Umes4m3AZKqA2anfhJiVmNCYkPchwFJNEJN5QxmTs1uzyy4TvmDrCRNT2ApwSari7ZIgrPeUx4UZDg==} - engines: {node: '>=12'} - cpu: [s390x] - os: [linux] - '@esbuild/linux-s390x@0.23.1': resolution: {integrity: sha512-9ygs73tuFCe6f6m/Tb+9LtYxWR4c9yg7zjt2cYkjDbDpV/xVn+68cQxMXCjUpYwEkze2RcU/rMnfIXNRFmSoDw==} engines: {node: '>=18'} @@ -577,18 +365,6 @@ packages: cpu: [s390x] os: [linux] - '@esbuild/linux-x64@0.18.20': - resolution: {integrity: sha512-UYqiqemphJcNsFEskc73jQ7B9jgwjWrSayxawS6UVFZGWrAAtkzjxSqnoclCXxWtfwLdzU+vTpcNYhpn43uP1w==} - engines: {node: '>=12'} - cpu: [x64] - os: [linux] - - '@esbuild/linux-x64@0.19.12': - resolution: {integrity: sha512-B71g1QpxfwBvNrfyJdVDexenDIt1CiDN1TIXLbhOw0KhJzE78KIFGX6OJ9MrtC0oOqMWf+0xop4qEU8JrJTwCg==} - engines: {node: '>=12'} - cpu: [x64] - os: [linux] - '@esbuild/linux-x64@0.23.1': resolution: {integrity: sha512-EV6+ovTsEXCPAp58g2dD68LxoP/wK5pRvgy0J/HxPGB009omFPv3Yet0HiaqvrIrgPTBuC6wCH1LTOY91EO5hQ==} engines: {node: '>=18'} @@ -607,18 +383,6 @@ packages: cpu: [arm64] os: [netbsd] - '@esbuild/netbsd-x64@0.18.20': - resolution: {integrity: sha512-iO1c++VP6xUBUmltHZoMtCUdPlnPGdBom6IrO4gyKPFFVBKioIImVooR5I83nTew5UOYrk3gIJhbZh8X44y06A==} - engines: {node: '>=12'} - cpu: [x64] - os: [netbsd] - - '@esbuild/netbsd-x64@0.19.12': - resolution: {integrity: sha512-3ltjQ7n1owJgFbuC61Oj++XhtzmymoCihNFgT84UAmJnxJfm4sYCiSLTXZtE00VWYpPMYc+ZQmB6xbSdVh0JWA==} - engines: {node: '>=12'} - cpu: [x64] - os: [netbsd] - '@esbuild/netbsd-x64@0.23.1': resolution: {integrity: sha512-aevEkCNu7KlPRpYLjwmdcuNz6bDFiE7Z8XC4CPqExjTvrHugh28QzUXVOZtiYghciKUacNktqxdpymplil1beA==} engines: {node: '>=18'} @@ -643,18 +407,6 @@ packages: cpu: [arm64] os: [openbsd] - '@esbuild/openbsd-x64@0.18.20': - resolution: {integrity: sha512-e5e4YSsuQfX4cxcygw/UCPIEP6wbIL+se3sxPdCiMbFLBWu0eiZOJ7WoD+ptCLrmjZBK1Wk7I6D/I3NglUGOxg==} - engines: {node: '>=12'} - cpu: [x64] - os: [openbsd] - - '@esbuild/openbsd-x64@0.19.12': - resolution: {integrity: sha512-RbrfTB9SWsr0kWmb9srfF+L933uMDdu9BIzdA7os2t0TXhCRjrQyCeOt6wVxr79CKD4c+p+YhCj31HBkYcXebw==} - engines: {node: '>=12'} - cpu: [x64] - os: [openbsd] - '@esbuild/openbsd-x64@0.23.1': resolution: {integrity: sha512-aY2gMmKmPhxfU+0EdnN+XNtGbjfQgwZj43k8G3fyrDM/UdZww6xrWxmDkuz2eCZchqVeABjV5BpildOrUbBTqA==} engines: {node: '>=18'} @@ -667,18 +419,6 @@ packages: cpu: [x64] os: [openbsd] - '@esbuild/sunos-x64@0.18.20': - resolution: {integrity: sha512-kDbFRFp0YpTQVVrqUd5FTYmWo45zGaXe0X8E1G/LKFC0v8x0vWrhOWSLITcCn63lmZIxfOMXtCfti/RxN/0wnQ==} - engines: {node: '>=12'} - cpu: [x64] - os: [sunos] - - '@esbuild/sunos-x64@0.19.12': - resolution: {integrity: sha512-HKjJwRrW8uWtCQnQOz9qcU3mUZhTUQvi56Q8DPTLLB+DawoiQdjsYq+j+D3s9I8VFtDr+F9CjgXKKC4ss89IeA==} - engines: {node: '>=12'} - cpu: [x64] - os: [sunos] - '@esbuild/sunos-x64@0.23.1': resolution: {integrity: sha512-RBRT2gqEl0IKQABT4XTj78tpk9v7ehp+mazn2HbUeZl1YMdaGAQqhapjGTCe7uw7y0frDi4gS0uHzhvpFuI1sA==} engines: {node: '>=18'} @@ -691,18 +431,6 @@ packages: cpu: [x64] os: [sunos] - '@esbuild/win32-arm64@0.18.20': - resolution: {integrity: sha512-ddYFR6ItYgoaq4v4JmQQaAI5s7npztfV4Ag6NrhiaW0RrnOXqBkgwZLofVTlq1daVTQNhtI5oieTvkRPfZrePg==} - engines: {node: '>=12'} - cpu: [arm64] - os: [win32] - - '@esbuild/win32-arm64@0.19.12': - resolution: {integrity: sha512-URgtR1dJnmGvX864pn1B2YUYNzjmXkuJOIqG2HdU62MVS4EHpU2946OZoTMnRUHklGtJdJZ33QfzdjGACXhn1A==} - engines: {node: '>=12'} - cpu: [arm64] - os: [win32] - '@esbuild/win32-arm64@0.23.1': resolution: {integrity: sha512-4O+gPR5rEBe2FpKOVyiJ7wNDPA8nGzDuJ6gN4okSA1gEOYZ67N8JPk58tkWtdtPeLz7lBnY6I5L3jdsr3S+A6A==} engines: {node: '>=18'} @@ -715,18 +443,6 @@ packages: cpu: [arm64] os: [win32] - '@esbuild/win32-ia32@0.18.20': - resolution: {integrity: sha512-Wv7QBi3ID/rROT08SABTS7eV4hX26sVduqDOTe1MvGMjNd3EjOz4b7zeexIR62GTIEKrfJXKL9LFxTYgkyeu7g==} - engines: {node: '>=12'} - cpu: [ia32] - os: [win32] - - '@esbuild/win32-ia32@0.19.12': - resolution: {integrity: sha512-+ZOE6pUkMOJfmxmBZElNOx72NKpIa/HFOMGzu8fqzQJ5kgf6aTGrcJaFsNiVMH4JKpMipyK+7k0n2UXN7a8YKQ==} - engines: {node: '>=12'} - cpu: [ia32] - os: [win32] - '@esbuild/win32-ia32@0.23.1': resolution: {integrity: sha512-BcaL0Vn6QwCwre3Y717nVHZbAa4UBEigzFm6VdsVdT/MbZ38xoj1X9HPkZhbmaBGUD1W8vxAfffbDe8bA6AKnQ==} engines: {node: '>=18'} @@ -739,18 +455,6 @@ packages: cpu: [ia32] os: [win32] - '@esbuild/win32-x64@0.18.20': - resolution: {integrity: sha512-kTdfRcSiDfQca/y9QIkng02avJ+NCaQvrMejlsB3RRv5sE9rRoeBPISaZpKxHELzRxZyLvNts1P27W3wV+8geQ==} - engines: {node: '>=12'} - cpu: [x64] - os: [win32] - - '@esbuild/win32-x64@0.19.12': - resolution: {integrity: sha512-T1QyPSDCyMXaO3pzBkF96E8xMkiRYbUEZADd29SyPGabqxMViNoii+NcK7eWJAEoU6RZyEm5lVSIjTmcdoB9HA==} - engines: {node: '>=12'} - cpu: [x64] - os: [win32] - '@esbuild/win32-x64@0.23.1': resolution: {integrity: sha512-BHpFFeslkWrXWyUPnbKm+xYYVYruCinGcftSBaa8zoF9hZO4BcSCFUvHVTtzpIY6YzUnYtuEhZ+C9iEXjxnasg==} engines: {node: '>=18'} @@ -1623,9 +1327,6 @@ packages: engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} hasBin: true - buffer-from@1.1.2: - resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==} - caniuse-lite@1.0.30001690: resolution: {integrity: sha512-5ExiE3qQN6oF8Clf8ifIDcMRCRE/dMGcETG/XGMD8/XiXm6HXQgQTh1yZYLXXpSOsEUlJm1Xr7kGULZTuGtP/w==} @@ -1672,101 +1373,15 @@ packages: engines: {node: '>=0.10'} hasBin: true - drizzle-kit@0.30.1: - resolution: {integrity: sha512-HmA/NeewvHywhJ2ENXD3KvOuM/+K2dGLJfxVfIHsGwaqKICJnS+Ke2L6UcSrSrtMJLJaT0Im1Qv4TFXfaZShyw==} - hasBin: true - - drizzle-orm@0.38.3: - resolution: {integrity: sha512-w41Y+PquMpSff/QDRGdItG0/aWca+/J3Sda9PPGkTxBtjWQvgU1jxlFBXdjog5tYvTu58uvi3PwR1NuCx0KeZg==} + dexie-react-hooks@1.1.7: + resolution: {integrity: sha512-Lwv5W0Hk+uOW3kGnsU9GZoR1er1B7WQ5DSdonoNG+focTNeJbHW6vi6nBoX534VKI3/uwHebYzSw1fwY6a7mTw==} peerDependencies: - '@aws-sdk/client-rds-data': '>=3' - '@cloudflare/workers-types': '>=4' - '@electric-sql/pglite': '>=0.2.0' - '@libsql/client': '>=0.10.0' - '@libsql/client-wasm': '>=0.10.0' - '@neondatabase/serverless': '>=0.10.0' - '@op-engineering/op-sqlite': '>=2' - '@opentelemetry/api': ^1.4.1 - '@planetscale/database': '>=1' - '@prisma/client': '*' - '@tidbcloud/serverless': '*' - '@types/better-sqlite3': '*' - '@types/pg': '*' - '@types/react': '>=18' - '@types/sql.js': '*' - '@vercel/postgres': '>=0.8.0' - '@xata.io/client': '*' - better-sqlite3: '>=7' - bun-types: '*' - expo-sqlite: '>=14.0.0' - knex: '*' - kysely: '*' - mysql2: '>=2' - pg: '>=8' - postgres: '>=3' - prisma: '*' - react: '>=18' - sql.js: '>=1' - sqlite3: '>=5' - peerDependenciesMeta: - '@aws-sdk/client-rds-data': - optional: true - '@cloudflare/workers-types': - optional: true - '@electric-sql/pglite': - optional: true - '@libsql/client': - optional: true - '@libsql/client-wasm': - optional: true - '@neondatabase/serverless': - optional: true - '@op-engineering/op-sqlite': - optional: true - '@opentelemetry/api': - optional: true - '@planetscale/database': - optional: true - '@prisma/client': - optional: true - '@tidbcloud/serverless': - optional: true - '@types/better-sqlite3': - optional: true - '@types/pg': - optional: true - '@types/react': - optional: true - '@types/sql.js': - optional: true - '@vercel/postgres': - optional: true - '@xata.io/client': - optional: true - better-sqlite3: - optional: true - bun-types: - optional: true - expo-sqlite: - optional: true - knex: - optional: true - kysely: - optional: true - mysql2: - optional: true - pg: - optional: true - postgres: - optional: true - prisma: - optional: true - react: - optional: true - sql.js: - optional: true - sqlite3: - optional: true + '@types/react': '>=16' + dexie: ^3.2 || ^4.0.1-alpha + react: '>=16' + + dexie@4.0.10: + resolution: {integrity: sha512-eM2RzuR3i+M046r2Q0Optl3pS31qTWf8aFuA7H9wnsHTwl8EPvroVLwvQene/6paAs39Tbk6fWZcn2aZaHkc/w==} effect@3.12.0: resolution: {integrity: sha512-b/u9s3b9HfTo0qygVouegP0hkbiuxRIeaCe1ppf8P88hPyl6lKCbErtn7Az4jG7LuU7f0Wgm4c8WXbMcL2j8+g==} @@ -1778,21 +1393,6 @@ packages: resolution: {integrity: sha512-0/r0MySGYG8YqlayBZ6MuCfECmHFdJ5qyPh8s8wa5Hnm6SaFLSK1VYCbj+NKp090Nm1caZhD+QTnmxO7esYGyQ==} engines: {node: '>=10.13.0'} - esbuild-register@3.6.0: - resolution: {integrity: sha512-H2/S7Pm8a9CL1uhp9OvjwrBh5Pvx0H8qVOxNu8Wed9Y7qv56MPtq+GGM8RJpq6glYJn9Wspr8uw7l55uyinNeg==} - peerDependencies: - esbuild: '>=0.12 <1' - - esbuild@0.18.20: - resolution: {integrity: sha512-ceqxoedUrcayh7Y7ZX6NdbbDzGROiyVBgC4PriJThBKSVPWnnFHZAkfI1lJT8QFkOwH4qOS2SJkS4wvpGl8BpA==} - engines: {node: '>=12'} - hasBin: true - - esbuild@0.19.12: - resolution: {integrity: sha512-aARqgq8roFBj054KvQr5f1sFu0D65G+miZRCuJyJ0G13Zwx7vRar5Zhn2tkQNzIXcBrNVsv/8stehpj+GAjgbg==} - engines: {node: '>=12'} - hasBin: true - esbuild@0.23.1: resolution: {integrity: sha512-VVNz/9Sa0bs5SELtn3f7qhJCDPCF5oMEl5cO9/SSinpE9hbPVvxbd572HH5AKiP7WD8INO53GgfDDhRjkylHEg==} engines: {node: '>=18'} @@ -2044,13 +1644,6 @@ packages: resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} engines: {node: '>=0.10.0'} - source-map-support@0.5.21: - resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==} - - source-map@0.6.1: - resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==} - engines: {node: '>=0.10.0'} - tailwind-merge@2.6.0: resolution: {integrity: sha512-P+Vu1qXfzediirmHOC3xKGAYeZtPcV9g76X+xg2FD4tYgR71ewMA35Y3sCz3zhiN/dwefRpJX0yBcgwi1fXNQA==} @@ -2277,220 +1870,102 @@ snapshots: '@date-fns/tz@1.2.0': {} - '@drizzle-team/brocli@0.10.2': {} - - '@electric-sql/pglite-react@0.2.15(@electric-sql/pglite@0.2.15)(react@19.0.0)': - dependencies: - '@electric-sql/pglite': 0.2.15 - react: 19.0.0 - - '@electric-sql/pglite@0.2.15': {} - - '@esbuild-kit/core-utils@3.3.2': - dependencies: - esbuild: 0.18.20 - source-map-support: 0.5.21 - - '@esbuild-kit/esm-loader@2.6.5': - dependencies: - '@esbuild-kit/core-utils': 3.3.2 - get-tsconfig: 4.8.1 - - '@esbuild/aix-ppc64@0.19.12': - optional: true - '@esbuild/aix-ppc64@0.23.1': optional: true '@esbuild/aix-ppc64@0.24.2': optional: true - '@esbuild/android-arm64@0.18.20': - optional: true - - '@esbuild/android-arm64@0.19.12': - optional: true - '@esbuild/android-arm64@0.23.1': optional: true '@esbuild/android-arm64@0.24.2': optional: true - '@esbuild/android-arm@0.18.20': - optional: true - - '@esbuild/android-arm@0.19.12': - optional: true - '@esbuild/android-arm@0.23.1': optional: true '@esbuild/android-arm@0.24.2': optional: true - '@esbuild/android-x64@0.18.20': - optional: true - - '@esbuild/android-x64@0.19.12': - optional: true - '@esbuild/android-x64@0.23.1': optional: true '@esbuild/android-x64@0.24.2': optional: true - '@esbuild/darwin-arm64@0.18.20': - optional: true - - '@esbuild/darwin-arm64@0.19.12': - optional: true - '@esbuild/darwin-arm64@0.23.1': optional: true '@esbuild/darwin-arm64@0.24.2': optional: true - '@esbuild/darwin-x64@0.18.20': - optional: true - - '@esbuild/darwin-x64@0.19.12': - optional: true - '@esbuild/darwin-x64@0.23.1': optional: true '@esbuild/darwin-x64@0.24.2': optional: true - '@esbuild/freebsd-arm64@0.18.20': - optional: true - - '@esbuild/freebsd-arm64@0.19.12': - optional: true - '@esbuild/freebsd-arm64@0.23.1': optional: true '@esbuild/freebsd-arm64@0.24.2': optional: true - '@esbuild/freebsd-x64@0.18.20': - optional: true - - '@esbuild/freebsd-x64@0.19.12': - optional: true - '@esbuild/freebsd-x64@0.23.1': optional: true '@esbuild/freebsd-x64@0.24.2': optional: true - '@esbuild/linux-arm64@0.18.20': - optional: true - - '@esbuild/linux-arm64@0.19.12': - optional: true - '@esbuild/linux-arm64@0.23.1': optional: true '@esbuild/linux-arm64@0.24.2': optional: true - '@esbuild/linux-arm@0.18.20': - optional: true - - '@esbuild/linux-arm@0.19.12': - optional: true - '@esbuild/linux-arm@0.23.1': optional: true '@esbuild/linux-arm@0.24.2': optional: true - '@esbuild/linux-ia32@0.18.20': - optional: true - - '@esbuild/linux-ia32@0.19.12': - optional: true - '@esbuild/linux-ia32@0.23.1': optional: true '@esbuild/linux-ia32@0.24.2': optional: true - '@esbuild/linux-loong64@0.18.20': - optional: true - - '@esbuild/linux-loong64@0.19.12': - optional: true - '@esbuild/linux-loong64@0.23.1': optional: true '@esbuild/linux-loong64@0.24.2': optional: true - '@esbuild/linux-mips64el@0.18.20': - optional: true - - '@esbuild/linux-mips64el@0.19.12': - optional: true - '@esbuild/linux-mips64el@0.23.1': optional: true '@esbuild/linux-mips64el@0.24.2': optional: true - '@esbuild/linux-ppc64@0.18.20': - optional: true - - '@esbuild/linux-ppc64@0.19.12': - optional: true - '@esbuild/linux-ppc64@0.23.1': optional: true '@esbuild/linux-ppc64@0.24.2': optional: true - '@esbuild/linux-riscv64@0.18.20': - optional: true - - '@esbuild/linux-riscv64@0.19.12': - optional: true - '@esbuild/linux-riscv64@0.23.1': optional: true '@esbuild/linux-riscv64@0.24.2': optional: true - '@esbuild/linux-s390x@0.18.20': - optional: true - - '@esbuild/linux-s390x@0.19.12': - optional: true - '@esbuild/linux-s390x@0.23.1': optional: true '@esbuild/linux-s390x@0.24.2': optional: true - '@esbuild/linux-x64@0.18.20': - optional: true - - '@esbuild/linux-x64@0.19.12': - optional: true - '@esbuild/linux-x64@0.23.1': optional: true @@ -2500,12 +1975,6 @@ snapshots: '@esbuild/netbsd-arm64@0.24.2': optional: true - '@esbuild/netbsd-x64@0.18.20': - optional: true - - '@esbuild/netbsd-x64@0.19.12': - optional: true - '@esbuild/netbsd-x64@0.23.1': optional: true @@ -2518,60 +1987,30 @@ snapshots: '@esbuild/openbsd-arm64@0.24.2': optional: true - '@esbuild/openbsd-x64@0.18.20': - optional: true - - '@esbuild/openbsd-x64@0.19.12': - optional: true - '@esbuild/openbsd-x64@0.23.1': optional: true '@esbuild/openbsd-x64@0.24.2': optional: true - '@esbuild/sunos-x64@0.18.20': - optional: true - - '@esbuild/sunos-x64@0.19.12': - optional: true - '@esbuild/sunos-x64@0.23.1': optional: true '@esbuild/sunos-x64@0.24.2': optional: true - '@esbuild/win32-arm64@0.18.20': - optional: true - - '@esbuild/win32-arm64@0.19.12': - optional: true - '@esbuild/win32-arm64@0.23.1': optional: true '@esbuild/win32-arm64@0.24.2': optional: true - '@esbuild/win32-ia32@0.18.20': - optional: true - - '@esbuild/win32-ia32@0.19.12': - optional: true - '@esbuild/win32-ia32@0.23.1': optional: true '@esbuild/win32-ia32@0.24.2': optional: true - '@esbuild/win32-x64@0.18.20': - optional: true - - '@esbuild/win32-x64@0.19.12': - optional: true - '@esbuild/win32-x64@0.23.1': optional: true @@ -3859,8 +3298,6 @@ snapshots: node-releases: 2.0.19 update-browserslist-db: 1.1.1(browserslist@4.24.3) - buffer-from@1.1.2: {} - caniuse-lite@1.0.30001690: {} chokidar@3.6.0: @@ -3899,21 +3336,14 @@ snapshots: detect-libc@1.0.3: {} - drizzle-kit@0.30.1: + dexie-react-hooks@1.1.7(@types/react@19.0.2)(dexie@4.0.10)(react@19.0.0): dependencies: - '@drizzle-team/brocli': 0.10.2 - '@esbuild-kit/esm-loader': 2.6.5 - esbuild: 0.19.12 - esbuild-register: 3.6.0(esbuild@0.19.12) - transitivePeerDependencies: - - supports-color - - drizzle-orm@0.38.3(@electric-sql/pglite@0.2.15)(@types/react@19.0.2)(react@19.0.0): - optionalDependencies: - '@electric-sql/pglite': 0.2.15 '@types/react': 19.0.2 + dexie: 4.0.10 react: 19.0.0 + dexie@4.0.10: {} + effect@3.12.0: dependencies: fast-check: 3.23.2 @@ -3925,64 +3355,6 @@ snapshots: graceful-fs: 4.2.11 tapable: 2.2.1 - esbuild-register@3.6.0(esbuild@0.19.12): - dependencies: - debug: 4.4.0 - esbuild: 0.19.12 - transitivePeerDependencies: - - supports-color - - esbuild@0.18.20: - optionalDependencies: - '@esbuild/android-arm': 0.18.20 - '@esbuild/android-arm64': 0.18.20 - '@esbuild/android-x64': 0.18.20 - '@esbuild/darwin-arm64': 0.18.20 - '@esbuild/darwin-x64': 0.18.20 - '@esbuild/freebsd-arm64': 0.18.20 - '@esbuild/freebsd-x64': 0.18.20 - '@esbuild/linux-arm': 0.18.20 - '@esbuild/linux-arm64': 0.18.20 - '@esbuild/linux-ia32': 0.18.20 - '@esbuild/linux-loong64': 0.18.20 - '@esbuild/linux-mips64el': 0.18.20 - '@esbuild/linux-ppc64': 0.18.20 - '@esbuild/linux-riscv64': 0.18.20 - '@esbuild/linux-s390x': 0.18.20 - '@esbuild/linux-x64': 0.18.20 - '@esbuild/netbsd-x64': 0.18.20 - '@esbuild/openbsd-x64': 0.18.20 - '@esbuild/sunos-x64': 0.18.20 - '@esbuild/win32-arm64': 0.18.20 - '@esbuild/win32-ia32': 0.18.20 - '@esbuild/win32-x64': 0.18.20 - - esbuild@0.19.12: - optionalDependencies: - '@esbuild/aix-ppc64': 0.19.12 - '@esbuild/android-arm': 0.19.12 - '@esbuild/android-arm64': 0.19.12 - '@esbuild/android-x64': 0.19.12 - '@esbuild/darwin-arm64': 0.19.12 - '@esbuild/darwin-x64': 0.19.12 - '@esbuild/freebsd-arm64': 0.19.12 - '@esbuild/freebsd-x64': 0.19.12 - '@esbuild/linux-arm': 0.19.12 - '@esbuild/linux-arm64': 0.19.12 - '@esbuild/linux-ia32': 0.19.12 - '@esbuild/linux-loong64': 0.19.12 - '@esbuild/linux-mips64el': 0.19.12 - '@esbuild/linux-ppc64': 0.19.12 - '@esbuild/linux-riscv64': 0.19.12 - '@esbuild/linux-s390x': 0.19.12 - '@esbuild/linux-x64': 0.19.12 - '@esbuild/netbsd-x64': 0.19.12 - '@esbuild/openbsd-x64': 0.19.12 - '@esbuild/sunos-x64': 0.19.12 - '@esbuild/win32-arm64': 0.19.12 - '@esbuild/win32-ia32': 0.19.12 - '@esbuild/win32-x64': 0.19.12 - esbuild@0.23.1: optionalDependencies: '@esbuild/aix-ppc64': 0.23.1 @@ -4334,13 +3706,6 @@ snapshots: source-map-js@1.2.1: {} - source-map-support@0.5.21: - dependencies: - buffer-from: 1.1.2 - source-map: 0.6.1 - - source-map@0.6.1: {} - tailwind-merge@2.6.0: {} tailwindcss@4.0.0-beta.8: {} diff --git a/src/db.ts b/src/db.ts deleted file mode 100644 index 560abda..0000000 --- a/src/db.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { date, integer, pgEnum, pgTable, varchar } from "drizzle-orm/pg-core"; -import { Color } from "./lib/schema"; - -export const colorColumn = pgEnum("color", Color.literals); - -export const categoryTable = pgTable("category", { - categoryId: integer().primaryKey().generatedAlwaysAsIdentity(), - name: varchar().unique().notNull(), - color: colorColumn().notNull(), -}); - -export const activityTable = pgTable("activity", { - activityId: integer().primaryKey().generatedAlwaysAsIdentity(), - name: varchar().unique().notNull(), - categoryIdRef: integer("category_id") - .references(() => categoryTable.categoryId) - .notNull(), -}); - -export const logTable = pgTable("log", { - logId: integer().primaryKey().generatedAlwaysAsIdentity(), - date: date().notNull(), - note: varchar(), - activityIdRef: integer("activity_id") - .references(() => activityTable.activityId) - .notNull(), -}); - -export const systemTable = pgTable("system", { - version: integer().notNull().default(0), -}); diff --git a/src/drizzle/0000_slow_doctor_faustus.sql b/src/drizzle/0000_slow_doctor_faustus.sql deleted file mode 100644 index eab2511..0000000 --- a/src/drizzle/0000_slow_doctor_faustus.sql +++ /dev/null @@ -1,28 +0,0 @@ -CREATE TYPE "public"."color" AS ENUM('magenta', 'dawn', 'skin', 'emerald', 'sky', 'fuchsia', 'midnight', 'salt');--> statement-breakpoint -CREATE TABLE "activity" ( - "activityId" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "activity_activityId_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1), - "name" varchar NOT NULL, - "category_id" integer NOT NULL, - CONSTRAINT "activity_name_unique" UNIQUE("name") -); ---> statement-breakpoint -CREATE TABLE "category" ( - "categoryId" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "category_categoryId_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1), - "name" varchar NOT NULL, - "color" "color" NOT NULL, - CONSTRAINT "category_name_unique" UNIQUE("name") -); ---> statement-breakpoint -CREATE TABLE "log" ( - "logId" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "log_logId_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1), - "date" date NOT NULL, - "note" varchar, - "activity_id" integer NOT NULL -); ---> statement-breakpoint -CREATE TABLE "system" ( - "version" integer DEFAULT 0 NOT NULL -); ---> statement-breakpoint -ALTER TABLE "activity" ADD CONSTRAINT "activity_category_id_category_categoryId_fk" FOREIGN KEY ("category_id") REFERENCES "public"."category"("categoryId") ON DELETE no action ON UPDATE no action;--> statement-breakpoint -ALTER TABLE "log" ADD CONSTRAINT "log_activity_id_activity_activityId_fk" FOREIGN KEY ("activity_id") REFERENCES "public"."activity"("activityId") ON DELETE no action ON UPDATE no action; \ No newline at end of file diff --git a/src/drizzle/meta/0000_snapshot.json b/src/drizzle/meta/0000_snapshot.json deleted file mode 100644 index e483aaa..0000000 --- a/src/drizzle/meta/0000_snapshot.json +++ /dev/null @@ -1,231 +0,0 @@ -{ - "id": "253b89e5-b1eb-4789-9a58-96a5016fb85a", - "prevId": "00000000-0000-0000-0000-000000000000", - "version": "7", - "dialect": "postgresql", - "tables": { - "public.activity": { - "name": "activity", - "schema": "", - "columns": { - "activityId": { - "name": "activityId", - "type": "integer", - "primaryKey": true, - "notNull": true, - "identity": { - "type": "always", - "name": "activity_activityId_seq", - "schema": "public", - "increment": "1", - "startWith": "1", - "minValue": "1", - "maxValue": "2147483647", - "cache": "1", - "cycle": false - } - }, - "name": { - "name": "name", - "type": "varchar", - "primaryKey": false, - "notNull": true - }, - "category_id": { - "name": "category_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "activity_category_id_category_categoryId_fk": { - "name": "activity_category_id_category_categoryId_fk", - "tableFrom": "activity", - "tableTo": "category", - "columnsFrom": [ - "category_id" - ], - "columnsTo": [ - "categoryId" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "activity_name_unique": { - "name": "activity_name_unique", - "nullsNotDistinct": false, - "columns": [ - "name" - ] - } - }, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.category": { - "name": "category", - "schema": "", - "columns": { - "categoryId": { - "name": "categoryId", - "type": "integer", - "primaryKey": true, - "notNull": true, - "identity": { - "type": "always", - "name": "category_categoryId_seq", - "schema": "public", - "increment": "1", - "startWith": "1", - "minValue": "1", - "maxValue": "2147483647", - "cache": "1", - "cycle": false - } - }, - "name": { - "name": "name", - "type": "varchar", - "primaryKey": false, - "notNull": true - }, - "color": { - "name": "color", - "type": "color", - "typeSchema": "public", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "category_name_unique": { - "name": "category_name_unique", - "nullsNotDistinct": false, - "columns": [ - "name" - ] - } - }, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.log": { - "name": "log", - "schema": "", - "columns": { - "logId": { - "name": "logId", - "type": "integer", - "primaryKey": true, - "notNull": true, - "identity": { - "type": "always", - "name": "log_logId_seq", - "schema": "public", - "increment": "1", - "startWith": "1", - "minValue": "1", - "maxValue": "2147483647", - "cache": "1", - "cycle": false - } - }, - "date": { - "name": "date", - "type": "date", - "primaryKey": false, - "notNull": true - }, - "note": { - "name": "note", - "type": "varchar", - "primaryKey": false, - "notNull": false - }, - "activity_id": { - "name": "activity_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "log_activity_id_activity_activityId_fk": { - "name": "log_activity_id_activity_activityId_fk", - "tableFrom": "log", - "tableTo": "activity", - "columnsFrom": [ - "activity_id" - ], - "columnsTo": [ - "activityId" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.system": { - "name": "system", - "schema": "", - "columns": { - "version": { - "name": "version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - } - }, - "enums": { - "public.color": { - "name": "color", - "schema": "public", - "values": [ - "magenta", - "dawn", - "skin", - "emerald", - "sky", - "fuchsia", - "midnight", - "salt" - ] - } - }, - "schemas": {}, - "sequences": {}, - "roles": {}, - "policies": {}, - "views": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/src/drizzle/meta/_journal.json b/src/drizzle/meta/_journal.json deleted file mode 100644 index a38b2e4..0000000 --- a/src/drizzle/meta/_journal.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "version": "7", - "dialect": "postgresql", - "entries": [ - { - "idx": 0, - "version": "7", - "when": 1736349746144, - "tag": "0000_slow_doctor_faustus", - "breakpoints": true - } - ] -} \ No newline at end of file diff --git a/src/lib/hooks/use-delete-log.ts b/src/lib/hooks/use-delete-log.ts index 0500072..5a769ff 100644 --- a/src/lib/hooks/use-delete-log.ts +++ b/src/lib/hooks/use-delete-log.ts @@ -1,14 +1,14 @@ import { Console, Effect } from "effect"; import { useActionState } from "react"; import { RuntimeClient } from "../runtime-client"; -import { WriteApi } from "../services/write-api"; +import { Dexie } from "../services/dexie"; export const useDeleteLog = () => { return useActionState( (_: null, formData: FormData) => RuntimeClient.runPromise( Effect.gen(function* () { - const api = yield* WriteApi; + const api = yield* Dexie; const logId = formData.get("log-id")! as string; yield* Console.log("Deleting log", { logId }); yield* api.deleteLog({ logId: parseInt(logId) }); diff --git a/src/lib/hooks/use-pglite-query.ts b/src/lib/hooks/use-dexie-query.ts similarity index 61% rename from src/lib/hooks/use-pglite-query.ts rename to src/lib/hooks/use-dexie-query.ts index 4da24b1..dbe4dd0 100644 --- a/src/lib/hooks/use-pglite-query.ts +++ b/src/lib/hooks/use-dexie-query.ts @@ -1,7 +1,7 @@ -import { useLiveQuery } from "@electric-sql/pglite-react"; -import type { Query } from "drizzle-orm"; +import { useLiveQuery } from "dexie-react-hooks"; import { Data, + Effect, Either, flow, Match, @@ -9,22 +9,37 @@ import { Schema, type ParseResult, } from "effect"; -import { usePgliteDrizzle } from "./use-pglite-drizzle"; +import { RuntimeClient } from "../runtime-client"; +import { Dexie } from "../services/dexie"; +class DatabaseError extends Data.TaggedError("DatabaseError")<{ + cause: unknown; +}> {} class MissingData extends Data.TaggedError("MissingData")<{}> {} class InvalidData extends Data.TaggedError("InvalidData")<{ parseError: ParseResult.ParseError; }> {} export const useQuery = ( - query: (orm: ReturnType) => Query, - schema: Schema.Schema + query: (db: (typeof Dexie.Service)["db"]) => Promise, + schema: Schema.Schema, + deps: unknown[] = [] ) => { - const orm = usePgliteDrizzle(); - const { params, sql } = query(orm); - const results = useLiveQuery(sql, params); + const results = useLiveQuery( + () => + RuntimeClient.runPromise( + Effect.gen(function* () { + const { db } = yield* Dexie; + return yield* Effect.tryPromise({ + try: () => query(db), + catch: (error) => new DatabaseError({ cause: error }), + }); + }) + ), + deps + ); return pipe( - results?.rows, + results, Either.fromNullable(() => new MissingData()), Either.flatMap( flow( diff --git a/src/lib/hooks/use-get-activities.ts b/src/lib/hooks/use-get-activities.ts index dfeedb9..3c43505 100644 --- a/src/lib/hooks/use-get-activities.ts +++ b/src/lib/hooks/use-get-activities.ts @@ -1,23 +1,19 @@ -import { eq, sql } from "drizzle-orm"; -import { activityTable, categoryTable } from "../../db"; import { ActivitySelect } from "../schema"; -import { useQuery } from "./use-pglite-query"; +import { useQuery } from "./use-dexie-query"; export const useGetActivities = () => { - return useQuery( - (_) => - _.select({ - activityId: activityTable.activityId, - name: activityTable.name, - categoryName: sql`${categoryTable.name}`.as("categoryName"), - color: categoryTable.color, + return useQuery(async (_) => { + const activities = await _.activity.toArray(); + return Promise.all( + activities.map(async (activity) => { + const category = await _.category.get(activity.categoryIdRef); + return { + activityId: activity.activityId, + name: activity.name, + categoryName: category?.name!, + color: category?.color!, + }; }) - .from(activityTable) - .innerJoin( - categoryTable, - eq(categoryTable.categoryId, activityTable.categoryIdRef) - ) - .toSQL(), - ActivitySelect - ); + ); + }, ActivitySelect); }; diff --git a/src/lib/hooks/use-get-categories.ts b/src/lib/hooks/use-get-categories.ts index a782ccb..eeb6225 100644 --- a/src/lib/hooks/use-get-categories.ts +++ b/src/lib/hooks/use-get-categories.ts @@ -1,10 +1,6 @@ -import { categoryTable } from "../../db"; import { CategorySelect } from "../schema"; -import { useQuery } from "./use-pglite-query"; +import { useQuery } from "./use-dexie-query"; export const useGetCategories = () => { - return useQuery( - (_) => _.select().from(categoryTable).toSQL(), - CategorySelect - ); + return useQuery((_) => _.category.toArray(), CategorySelect); }; diff --git a/src/lib/hooks/use-get-log-by-date.ts b/src/lib/hooks/use-get-log-by-date.ts index f182050..8303323 100644 --- a/src/lib/hooks/use-get-log-by-date.ts +++ b/src/lib/hooks/use-get-log-by-date.ts @@ -1,30 +1,37 @@ -import { eq, sql } from "drizzle-orm"; -import { activityTable, categoryTable, logTable } from "../../db"; import { LogByDateSelect } from "../schema"; -import { useQuery } from "./use-pglite-query"; +import { useQuery } from "./use-dexie-query"; export const useGetLogByDate = (date: string) => { return useQuery( - (_) => - _.select({ - logId: logTable.logId, - date: logTable.date, - note: logTable.note, - name: activityTable.name, - categoryName: sql`${categoryTable.name}`.as("categoryName"), - color: categoryTable.color, - }) - .from(logTable) - .where(eq(logTable.date, date)) - .innerJoin( - activityTable, - eq(logTable.activityIdRef, activityTable.activityId) - ) - .innerJoin( - categoryTable, - eq(categoryTable.categoryId, activityTable.categoryIdRef) - ) - .toSQL(), - LogByDateSelect + async (_) => { + const logs = await _.log.where("date").equals(date).toArray(); + const logsWithActivity = await Promise.all( + logs.map(async (log) => { + const activity = await _.activity.get(log.activityIdRef); + return { + logId: log.logId, + date: log.date, + note: log.note, + name: activity?.name!, + categoryIdRef: activity?.categoryIdRef!, + }; + }) + ); + return Promise.all( + logsWithActivity.map(async (withActivity) => { + const category = await _.category.get(withActivity.categoryIdRef); + return { + logId: withActivity.logId, + date: withActivity.date, + note: withActivity.note, + name: withActivity.name, + categoryName: category?.name!, + color: category?.color!, + }; + }) + ); + }, + LogByDateSelect, + [date] ); }; diff --git a/src/lib/hooks/use-insert-activity.ts b/src/lib/hooks/use-insert-activity.ts index 457130b..35c8ea3 100644 --- a/src/lib/hooks/use-insert-activity.ts +++ b/src/lib/hooks/use-insert-activity.ts @@ -1,14 +1,14 @@ import { Console, Effect } from "effect"; import { useActionState } from "react"; import { RuntimeClient } from "../runtime-client"; -import { WriteApi } from "../services/write-api"; +import { Dexie } from "../services/dexie"; export const useInsertActivity = () => { return useActionState( (_: null, formData: FormData) => RuntimeClient.runPromise( Effect.gen(function* () { - const api = yield* WriteApi; + const api = yield* Dexie; const name = formData.get("name")! as string; const categoryId = formData.get("category-id")! as string; yield* Console.log("Inserting activity", { name, categoryId }); diff --git a/src/lib/hooks/use-insert-category.ts b/src/lib/hooks/use-insert-category.ts index 534d7f8..f2ee62e 100644 --- a/src/lib/hooks/use-insert-category.ts +++ b/src/lib/hooks/use-insert-category.ts @@ -2,14 +2,14 @@ import { Console, Effect } from "effect"; import { useActionState } from "react"; import { RuntimeClient } from "../runtime-client"; import type { Color } from "../schema"; -import { WriteApi } from "../services/write-api"; +import { Dexie } from "../services/dexie"; export const useInsertCategory = () => { return useActionState( (_: null, formData: FormData) => RuntimeClient.runPromise( Effect.gen(function* () { - const api = yield* WriteApi; + const api = yield* Dexie; const name = formData.get("name")! as string; const color = formData.get("color")! as typeof Color.Type; yield* Console.log("Inserting category", { name, color }); diff --git a/src/lib/hooks/use-insert-log.ts b/src/lib/hooks/use-insert-log.ts index 01da775..2b9c36c 100644 --- a/src/lib/hooks/use-insert-log.ts +++ b/src/lib/hooks/use-insert-log.ts @@ -1,14 +1,14 @@ import { Console, Effect } from "effect"; import { useActionState } from "react"; import { RuntimeClient } from "../runtime-client"; -import { WriteApi } from "../services/write-api"; +import { Dexie } from "../services/dexie"; export const useInsertLog = (date: string) => { return useActionState( (_: null, formData: FormData) => RuntimeClient.runPromise( Effect.gen(function* () { - const api = yield* WriteApi; + const api = yield* Dexie; const activityId = formData.get("activity-id")! as string; yield* Console.log("Inserting log", { date, activityId }); yield* api.insertLog({ date, activityId: parseInt(activityId) }); diff --git a/src/lib/hooks/use-pglite-drizzle.ts b/src/lib/hooks/use-pglite-drizzle.ts deleted file mode 100644 index 47e5546..0000000 --- a/src/lib/hooks/use-pglite-drizzle.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Context } from "effect"; -import { createContext, useContext } from "react"; -import { Pglite } from "../services/pglite"; - -export const PgliteDrizzleContext = createContext< - Context.Tag.Service["orm"] | null ->(null); - -export const usePgliteDrizzle = () => { - const orm = useContext(PgliteDrizzleContext); - if (orm === null) { - throw new Error( - "usePgliteDrizzle must be used within PgliteDrizzleProvider" - ); - } - return orm; -}; diff --git a/src/lib/runtime-client.ts b/src/lib/runtime-client.ts index 5a866d4..fac3258 100644 --- a/src/lib/runtime-client.ts +++ b/src/lib/runtime-client.ts @@ -1,16 +1,6 @@ -import { ConfigProvider, Layer, ManagedRuntime } from "effect"; -import { Migrations } from "./services/migrations"; -import { Pglite } from "./services/pglite"; -import { WriteApi } from "./services/write-api"; +import { Layer, ManagedRuntime } from "effect"; +import { Dexie } from "./services/dexie"; -const CustomConfigProvider = Layer.setConfigProvider( - ConfigProvider.fromMap(new Map([["INDEX_DB", "v1"]])) -); - -const MainLayer = Layer.mergeAll( - Migrations.Default, - Pglite.Default, - WriteApi.Default -).pipe(Layer.provide(CustomConfigProvider)); +const MainLayer = Layer.mergeAll(Dexie.Default); export const RuntimeClient = ManagedRuntime.make(MainLayer); diff --git a/src/lib/schema.ts b/src/lib/schema.ts index c49ecf4..26c29fe 100644 --- a/src/lib/schema.ts +++ b/src/lib/schema.ts @@ -11,6 +11,29 @@ export const Color = Schema.Literal( "salt" ); +export class CategoryTable extends Schema.Class("CategoryTable")( + { + categoryId: Schema.Number, + name: Schema.String, + color: Color, + } +) {} + +export class ActivityTable extends Schema.Class("ActivityTable")( + { + activityId: Schema.Number, + name: Schema.String, + categoryIdRef: Schema.Number, + } +) {} + +export class LogTable extends Schema.Class("LogTable")({ + logId: Schema.Number, + date: Schema.DateFromString, + note: Schema.NullOr(Schema.String), + activityIdRef: Schema.Number, +}) {} + export class CategorySelect extends Schema.Class( "CategorySelect" )({ @@ -32,7 +55,7 @@ export class LogByDateSelect extends Schema.Class( "LogByDateSelect" )({ logId: Schema.Number, - date: Schema.DateFromSelf, + date: Schema.DateFromString, note: Schema.NullOr(Schema.String), name: Schema.String, categoryName: Schema.String, diff --git a/src/lib/services/write-api.ts b/src/lib/services/dexie.ts similarity index 50% rename from src/lib/services/write-api.ts rename to src/lib/services/dexie.ts index 5851367..88ae535 100644 --- a/src/lib/services/write-api.ts +++ b/src/lib/services/dexie.ts @@ -1,21 +1,33 @@ -import { eq } from "drizzle-orm"; +import * as _Dexie from "dexie"; import { Data, Effect, flow, Schema } from "effect"; -import { activityTable, categoryTable, logTable } from "../../db"; -import { Color } from "../schema"; -import { Pglite } from "./pglite"; +import { + Color, + type ActivityTable, + type CategoryTable, + type LogTable, +} from "../schema"; class WriteApiError extends Data.TaggedError("WriteApiError")<{ cause: unknown; }> {} -export class WriteApi extends Effect.Service()("WriteApi", { - dependencies: [Pglite.Default], +export class Dexie extends Effect.Service()("Dexie", { effect: Effect.gen(function* () { - const { query } = yield* Pglite; + const db = new _Dexie.Dexie("_db") as _Dexie.Dexie & { + category: _Dexie.EntityTable; + activity: _Dexie.EntityTable; + log: _Dexie.EntityTable; + }; + + db.version(1).stores({ + category: "++categoryId, &name", + activity: "++activityId, &name", + log: "++logId, date", + }); const execute = ( schema: Schema.Schema, - exec: (values: I) => Effect.Effect + exec: (values: I) => Promise ) => flow( Schema.decode(schema), @@ -23,14 +35,20 @@ export class WriteApi extends Effect.Service()("WriteApi", { Effect.tap((encoded) => Effect.log("Insert", encoded)), Effect.tapError((error) => Effect.log("Error", error)), Effect.mapError((error) => new WriteApiError({ cause: error })), - Effect.flatMap(exec) + Effect.flatMap((values) => + Effect.tryPromise({ + try: () => exec(values), + catch: (error) => new WriteApiError({ cause: error }), + }) + ) ); return { + db, + insertCategory: execute( Schema.Struct({ name: Schema.NonEmptyString, color: Color }), - ({ name, color }) => - query((_) => _.insert(categoryTable).values({ name, color })) + ({ name, color }) => db.category.add({ name, color }) ), insertActivity: execute( @@ -39,21 +57,17 @@ export class WriteApi extends Effect.Service()("WriteApi", { categoryId: Schema.Number, }), ({ name, categoryId }) => - query((_) => - _.insert(activityTable).values({ name, categoryIdRef: categoryId }) - ) + db.activity.add({ name, categoryIdRef: categoryId }) ), insertLog: execute( Schema.Struct({ date: Schema.String, activityId: Schema.Number }), ({ date, activityId }) => - query((_) => - _.insert(logTable).values({ date, activityIdRef: activityId }) - ) + db.log.add({ date, activityIdRef: activityId, note: null }) ), deleteLog: execute(Schema.Struct({ logId: Schema.Number }), ({ logId }) => - query((_) => _.delete(logTable).where(eq(logTable.logId, logId))) + db.log.where("logId").equals(logId).delete() ), }; }), diff --git a/src/lib/services/migrations.ts b/src/lib/services/migrations.ts deleted file mode 100644 index ed7147e..0000000 --- a/src/lib/services/migrations.ts +++ /dev/null @@ -1,24 +0,0 @@ -import v0000 from "../../drizzle/0000_slow_doctor_faustus.sql?raw"; - -import type { PGlite } from "@electric-sql/pglite"; -import { Data, Effect } from "effect"; -import { Pglite } from "./pglite"; - -class MigrationsError extends Data.TaggedError("MigrationsError")<{ - cause: unknown; -}> {} - -const execute = (client: PGlite) => (sql: string) => - Effect.tryPromise({ - try: () => client.exec(sql), - catch: (error) => new MigrationsError({ cause: error }), - }); - -export class Migrations extends Effect.Service()("Migrations", { - dependencies: [Pglite.Default], - effect: Effect.gen(function* () { - const db = yield* Pglite; - const migrate = execute(db.client); - return [migrate(v0000)] as const; - }), -}) {} diff --git a/src/lib/services/pglite.ts b/src/lib/services/pglite.ts deleted file mode 100644 index 73ae7ad..0000000 --- a/src/lib/services/pglite.ts +++ /dev/null @@ -1,32 +0,0 @@ -import * as _PGlite from "@electric-sql/pglite"; -import { live } from "@electric-sql/pglite/live"; -import { drizzle } from "drizzle-orm/pglite"; -import { Config, Data, Effect } from "effect"; - -class PgliteError extends Data.TaggedError("PgliteError")<{ - cause: unknown; -}> {} - -export class Pglite extends Effect.Service()("Pglite", { - effect: Effect.gen(function* () { - const indexDb = yield* Config.string("INDEX_DB"); - - const client = yield* Effect.tryPromise({ - try: () => - _PGlite.PGlite.create(`idb://${indexDb}`, { - extensions: { live }, - }), - catch: (error) => new PgliteError({ cause: error }), - }); - - const orm = drizzle({ client }); - - const query = (execute: (_: typeof orm) => Promise) => - Effect.tryPromise({ - try: () => execute(orm), - catch: (error) => new PgliteError({ cause: error }), - }); - - return { client, orm, query }; - }), -}) {} diff --git a/src/routes/__root.tsx b/src/routes/__root.tsx index 6be730a..e27aeab 100644 --- a/src/routes/__root.tsx +++ b/src/routes/__root.tsx @@ -1,62 +1,15 @@ -import { PGliteProvider } from "@electric-sql/pglite-react"; import { Outlet, createRootRoute } from "@tanstack/react-router"; -import { Array, Effect } from "effect"; -import { systemTable } from "../db"; -import { PgliteDrizzleContext } from "../lib/hooks/use-pglite-drizzle"; -import { RuntimeClient } from "../lib/runtime-client"; -import { Migrations } from "../lib/services/migrations"; -import { Pglite } from "../lib/services/pglite"; export const Route = createRootRoute({ component: RootComponent, - loader: () => - RuntimeClient.runPromise( - Effect.gen(function* () { - const migrations = yield* Migrations; - const { query, client, orm } = yield* Pglite; - - const latestVersion = migrations.length; - const { version } = yield* query((_) => - _.select().from(systemTable).limit(1) - ).pipe( - Effect.flatMap(Array.head), - Effect.catchTags({ - PgliteError: () => Effect.succeed({ version: 0 }), - }) - ); - - yield* Effect.all(migrations.slice(version)); - - if (version === 0) { - yield* query((_) => _.insert(systemTable).values({ version: 0 })); - } - - yield* query((_) => - _.update(systemTable).set({ version: latestVersion }) - ); - - yield* Effect.log( - version === latestVersion - ? "Database up to date" - : `Migrations done (from ${version} to ${latestVersion})` - ); - - return { client, orm }; - }).pipe(Effect.tapErrorCause(Effect.logError)) - ), errorComponent: (error) =>
{JSON.stringify(error, null, 2)}
, }); function RootComponent() { - const { client, orm } = Route.useLoaderData(); return (
- - - - {/* */} - - + + {/* */}
); }