Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
use @mattrax/mysql-planetscale
Brendan Allan66ae6da1a98d
diff --git a/.env.example b/.env.exampleindex f2af00b7d..1381da5c6 100644--- a/.env.example+++ b/.env.example@@ -26,10 +26,7 @@ NEXT_PUBLIC_TASKS_URL=http://localhost:3002NEXT_PUBLIC_LOCAL_MODE=false# -- database ****************-DB_PLANETSCALE_HOST=localhost:3900-DB_PLANETSCALE_DATABASE=planetscale-DB_PLANETSCALE_USERNAME=root-DB_PLANETSCALE_PASSWORD=planetscale+DATABASE_URL=mysql://root@localhost:3900/cap# Generate a secret with `openssl rand -base64 32`NEXTAUTH_SECRET=@@ -51,4 +48,4 @@ RESEND_API_KEY=# - MISC, NOT REQUIRED FOR DEV ****************-NEXT_LOOPS_KEY=\ No newline at end of file+NEXT_LOOPS_KEY=diff --git a/packages/database/drizzle.config.ts b/packages/database/drizzle.config.tsindex b9259e3ff..437960ba0 100644--- a/packages/database/drizzle.config.ts+++ b/packages/database/drizzle.config.ts@@ -1,9 +1,14 @@import type { Config } from "drizzle-kit";+if (!process.env.DATABASE_URL?.startsWith("mysql://"))+ throw new Error(+ "DATABASE_URL must be a 'mysql://' URI. Drizzle Kit doesn't support the fetch adapter!"+ );+export default {schema: "./schema.ts",dbCredentials: {- uri: `mysql://${process.env.DB_PLANETSCALE_USERNAME}:${process.env.DB_PLANETSCALE_PASSWORD}@${process.env.DB_PLANETSCALE_HOST}/${process.env.DB_PLANETSCALE_DATABASE}?ssl={"rejectUnauthorized":false}`,+ uri: process.env.DATABASE_URL,},driver: "mysql2",} satisfies Config;diff --git a/packages/database/index.ts b/packages/database/index.tsindex 43088b561..25166107c 100644--- a/packages/database/index.ts+++ b/packages/database/index.ts@@ -1,8 +1,24 @@import { drizzle } from "drizzle-orm/planetscale-serverless";-import { Client } from "@planetscale/database";+import { Client, Config } from "@planetscale/database";++const URL = process.env.DATABASE_URL!;++let fetchHandler: Config["fetch"] = undefined;export const connection = new Client({- url: `mysql://${process.env.DB_PLANETSCALE_USERNAME}:${process.env.DB_PLANETSCALE_PASSWORD}@${process.env.DB_PLANETSCALE_HOST}/${process.env.DB_PLANETSCALE_DATABASE}?ssl={"rejectUnauthorized":false}`,+ url: URL,+ fetch: async (input, init) => {+ if (+ process.env.NEXT_PUBLIC_ENVIRONMENT === "development" &&+ URL.startsWith("mysql://")+ ) {+ fetchHandler = (+ await import("@mattrax/mysql-planetscale")+ ).createFetchHandler(URL);+ }++ return await (fetchHandler || fetch)(input, init);+ },});export const db = drizzle(connection);diff --git a/packages/database/package.json b/packages/database/package.jsonindex 45075435a..3fa5ab64b 100644--- a/packages/database/package.json+++ b/packages/database/package.json@@ -11,6 +11,7 @@"db:drop": "drizzle-kit drop --config=drizzle.config.ts"},"dependencies": {+ "@mattrax/mysql-planetscale": "^0.0.2","@paralleldrive/cuid2": "^2.2.2","@planetscale/database": "^1.13.0","@react-email/components": "^0.0.13",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 4331d5acc..d5ee8221f 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -532,6 +532,9 @@ importers:packages/database:dependencies:+ '@mattrax/mysql-planetscale':+ specifier: ^0.0.2+ version: 0.0.2'@paralleldrive/cuid2':specifier: ^2.2.2version: 2.2.2@@ -3849,6 +3852,13 @@ packages:read-yaml-file: 1.1.0dev: false+ /@mattrax/[email protected]:+ resolution: {integrity: sha512-wrbsQ8c5FOcicJV1VgV791MWRDkNOpMZapmKAUzXWRMfZrmm7msHZ8IcL78BtTBSUXKf+VvE9zN+qg4p/LafWw==}+ dependencies:+ '@planetscale/database': 1.18.0+ mysql2: 3.9.7+ dev: false+/@mdx-js/[email protected]:resolution: {integrity: sha512-jLuwRlz8DQfQNiUCJR50Y09CGPq3fLtmtUQfVrj79E0JWu3dvsVcxVIcfhR5h0iXu+/z++zDrYeiJqifRynJkA==}dependencies:@@ -4358,6 +4368,11 @@ packages:engines: {node: '>=16'}dev: false+ /@planetscale/[email protected]:+ resolution: {integrity: sha512-t2XdOfrVgcF7AW791FtdPS27NyNqcE1SpoXgk3HpziousvUMsJi4Q6NL3JyOBpsMOrvk94749o8yyonvX5quPw==}+ engines: {node: '>=16'}+ dev: false+/@radix-ui/[email protected]:resolution: {integrity: sha512-3e7rn8FDMin4CgeL7Z/49smCA3rFYY3Ha2rUQ7HRWFadS5iCRw08ZgVT1LaNTCNqgvrUiyczLflrVrF0SRQtNA==}dependencies:@@ -10018,7 +10033,7 @@ packages:doctrine: 2.1.0eslint: 8.57.0eslint-import-resolver-node: 0.3.9- eslint-module-utils: 2.8.0(@typescript-eslint/[email protected])([email protected])([email protected])([email protected])+ eslint-module-utils: 2.8.0(@typescript-eslint/[email protected])([email protected])([email protected])([email protected])hasown: 2.0.0is-core-module: 2.13.1is-glob: 4.0.3