Skip to content

Commit

Permalink
feat: Use hosted db
Browse files Browse the repository at this point in the history
  • Loading branch information
sebald committed Oct 25, 2023
1 parent 4982df2 commit 1bd4704
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 48 deletions.
15 changes: 11 additions & 4 deletions lib/db/db.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { type ColumnType, type Generated, Kysely } from 'kysely';
import { PlanetScaleDialect } from 'kysely-planetscale';
import { Kysely, MysqlDialect } from 'kysely';
import { type ColumnType, type Generated } from 'kysely';

import type { GameRecord, XWSFaction, XWSSquad } from '@/lib/types';
import { createPool } from 'mysql2';

// Types
// ---------------
Expand Down Expand Up @@ -43,8 +44,14 @@ export interface Database {
// Database
// ---------------
export const db = new Kysely<Database>({
dialect: new PlanetScaleDialect({
url: process.env.DATABASE_URL,
dialect: new MysqlDialect({
pool: async () =>
createPool({
host: process.env.DATABASE_HOST,
user: process.env.DATABASE_USERNAME,
password: process.env.DATABASE_PASSWORD,
database: 'main',
}),
}),
// log: ['query'],
});
Expand Down
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,6 @@
"repository": "github:sebald/pattern-analyzer",
"sideEffects": false,
"packageManager": "[email protected]",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"format": "prettier . --write",
"typecheck": "tsc --noEmit",
"test": "jest",
"clean": "rm -rf .next",
"db:setup": "tsx ./scripts/setup-database.ts",
"db:query": "tsx ./scripts/query-database.ts",
"update:xwing": "zx scripts/update-xwing-data.mjs",
"update:yasb": "zx scripts/update-yasb-data.mjs"
},
"dependencies": {
"@nivo/axes": "0.83.0",
"@nivo/bar": "0.83.0",
Expand All @@ -34,18 +20,18 @@
"class-variance-authority": "0.7.0",
"clsx": "2.0.0",
"dayjs": "1.11.10",
"kysely": "^0.26.3",
"kysely-planetscale": "^1.4.0",
"kysely": "0.26.3",
"mysql2": "3.6.2",
"next": "13.5.4",
"p-limit": "^4.0.0",
"p-limit": "4.0.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-is": "18.2.0",
"react-use": "17.4.0",
"react-use-clipboard": "1.0.9",
"swr": "2.2.4",
"tailwind-merge": "1.14.0",
"tailwindcss-animate": "^1.0.7",
"tailwindcss-animate": "1.0.7",
"use-debounce": "9.0.4",
"zod": "3.22.4"
},
Expand Down Expand Up @@ -75,5 +61,19 @@
"xwing-data2": "github:danrs/xwing-data2#6735cf4",
"yasb": "github:raithos/xwing#cbb7ab9",
"zx": "7.2.3"
},
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"format": "prettier . --write",
"typecheck": "tsc --noEmit",
"test": "jest",
"clean": "rm -rf .next",
"db:setup": "tsx ./scripts/setup-database.ts",
"db:query": "tsx ./scripts/query-database.ts",
"update:xwing": "zx scripts/update-xwing-data.mjs",
"update:yasb": "zx scripts/update-yasb-data.mjs"
}
}
91 changes: 65 additions & 26 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions scripts/setup-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@ void (async () => {
} catch (err: any) {
console.log(chalk.red.bold(err?.body?.message || err.message || err));
}
process.exit(0); // Weird 🤷‍♂️
})();

0 comments on commit 1bd4704

Please sign in to comment.