use bun sql instead of postgres.js
This commit is contained in:
10
README.md
10
README.md
@@ -20,13 +20,13 @@ bun x sv create --template minimal --types ts --add prettier eslint vitest="usag
|
||||
|
||||
## Developing
|
||||
|
||||
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
||||
This project now requires Bun at runtime because the server uses Bun SQL. Start the development server with:
|
||||
|
||||
```sh
|
||||
npm run dev
|
||||
bun run dev
|
||||
|
||||
# or start the server and open the app in a new browser tab
|
||||
npm run dev -- --open
|
||||
bun run dev -- --open
|
||||
```
|
||||
|
||||
## Building
|
||||
@@ -34,9 +34,9 @@ npm run dev -- --open
|
||||
To create a production version of your app:
|
||||
|
||||
```sh
|
||||
npm run build
|
||||
bun run build
|
||||
```
|
||||
|
||||
You can preview the production build with `npm run preview`.
|
||||
You can preview the production build with `bun run preview`.
|
||||
|
||||
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
|
||||
|
||||
1
bun.lock
1
bun.lock
@@ -7,7 +7,6 @@
|
||||
"dependencies": {
|
||||
"bancho.js": "^0.12.3",
|
||||
"discord.js": "^14.25.1",
|
||||
"postgres": "^3.4.8",
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/compat": "^2.0.2",
|
||||
|
||||
11
package.json
11
package.json
@@ -4,10 +4,10 @@
|
||||
"version": "0.0.1",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
"build": "vite build",
|
||||
"dev": "bun --bun vite dev",
|
||||
"build": "bun --bun vite build",
|
||||
"start": "bun ./build/index.js",
|
||||
"preview": "vite preview",
|
||||
"preview": "bun --bun vite preview",
|
||||
"prepare": "svelte-kit sync || echo ''",
|
||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||
@@ -20,7 +20,7 @@
|
||||
"db:generate": "drizzle-kit generate",
|
||||
"db:migrate": "drizzle-kit migrate",
|
||||
"db:studio": "drizzle-kit studio",
|
||||
"auth:schema": "npx @better-auth/cli generate --config src/lib/server/auth.ts --output src/lib/server/db/auth.schema.ts --yes"
|
||||
"auth:schema": "bun x @better-auth/cli generate --config src/lib/server/auth.ts --output src/lib/server/db/auth.schema.ts --yes"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/compat": "^2.0.2",
|
||||
@@ -57,7 +57,6 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"bancho.js": "^0.12.3",
|
||||
"discord.js": "^14.25.1",
|
||||
"postgres": "^3.4.8"
|
||||
"discord.js": "^14.25.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,16 +5,14 @@
|
||||
* Usage: bun scripts/backfill-personal-team-names.ts
|
||||
*/
|
||||
|
||||
import { drizzle } from 'drizzle-orm/postgres-js';
|
||||
import postgres from 'postgres';
|
||||
import { eq, and } from 'drizzle-orm';
|
||||
import { pgTable, text, uuid, boolean, timestamp } from 'drizzle-orm/pg-core';
|
||||
import { drizzle } from 'drizzle-orm/bun-sql';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { pgTable, text, uuid, boolean } from 'drizzle-orm/pg-core';
|
||||
|
||||
const DATABASE_URL = process.env.DATABASE_URL;
|
||||
if (!DATABASE_URL) throw new Error('DATABASE_URL not set');
|
||||
|
||||
const client = postgres(DATABASE_URL);
|
||||
const db = drizzle(client);
|
||||
const db = drizzle(DATABASE_URL);
|
||||
|
||||
const team = pgTable('team', {
|
||||
id: uuid('id').primaryKey(),
|
||||
|
||||
@@ -11,8 +11,7 @@
|
||||
* then run this script to populate them.
|
||||
*/
|
||||
|
||||
import postgres from 'postgres';
|
||||
import { S3Client } from 'bun';
|
||||
import { SQL, S3Client } from 'bun';
|
||||
|
||||
// ── Config ─────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -130,7 +129,7 @@ async function getBeatmap(beatmapId: string): Promise<BeatmapData | null> {
|
||||
|
||||
// ── Main ───────────────────────────────────────────────────────────────
|
||||
|
||||
const sql = postgres(DATABASE_URL);
|
||||
const sql = new SQL(DATABASE_URL);
|
||||
|
||||
// ════════════════════════════════════════════════════════════════════════
|
||||
// 1. MAPPOOL SLOTS — backfill title/artist/version/coverUrl/listCoverUrl
|
||||
@@ -263,4 +262,4 @@ console.log(` Mappool slots: ${slotOk} backfilled, ${slotFail} failed`);
|
||||
console.log(` User avatars: ${avatarOk} re-proxied, ${avatarSkip} already R2`);
|
||||
console.log(` Team avatars: ${teamOk} re-proxied, ${teamSkip} already R2`);
|
||||
|
||||
await sql.end();
|
||||
await sql.close();
|
||||
|
||||
@@ -4,15 +4,13 @@
|
||||
* Usage: bun scripts/cancel-matches.ts
|
||||
*/
|
||||
|
||||
import { drizzle } from 'drizzle-orm/postgres-js';
|
||||
import postgres from 'postgres';
|
||||
import { drizzle } from 'drizzle-orm/bun-sql';
|
||||
import { sql } from 'drizzle-orm';
|
||||
|
||||
const DATABASE_URL = process.env.DATABASE_URL;
|
||||
if (!DATABASE_URL) throw new Error('DATABASE_URL not set');
|
||||
|
||||
const client = postgres(DATABASE_URL);
|
||||
const db = drizzle(client);
|
||||
const db = drizzle(DATABASE_URL);
|
||||
|
||||
async function main() {
|
||||
const result = await db.execute(sql`
|
||||
|
||||
@@ -7,15 +7,13 @@
|
||||
* --full Nuclear: clear everything except users and personal teams
|
||||
*/
|
||||
|
||||
import { drizzle } from 'drizzle-orm/postgres-js';
|
||||
import postgres from 'postgres';
|
||||
import { drizzle } from 'drizzle-orm/bun-sql';
|
||||
import { sql } from 'drizzle-orm';
|
||||
|
||||
const DATABASE_URL = process.env.DATABASE_URL;
|
||||
if (!DATABASE_URL) throw new Error('DATABASE_URL not set');
|
||||
|
||||
const client = postgres(DATABASE_URL);
|
||||
const db = drizzle(client);
|
||||
const db = drizzle(DATABASE_URL);
|
||||
|
||||
const flag = process.argv[2];
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Run with: bun run scripts/reseed-ratings.ts
|
||||
*/
|
||||
|
||||
import postgres from 'postgres';
|
||||
import { SQL } from 'bun';
|
||||
|
||||
const DATABASE_URL = process.env.DATABASE_URL!;
|
||||
const OSU_CLIENT_ID = process.env.OSU_CLIENT_ID!;
|
||||
@@ -20,7 +20,7 @@ for (const [k, v] of Object.entries({ DATABASE_URL, OSU_CLIENT_ID, OSU_CLIENT_SE
|
||||
}
|
||||
}
|
||||
|
||||
const sql = postgres(DATABASE_URL);
|
||||
const sql = new SQL(DATABASE_URL);
|
||||
|
||||
// ── osu! API ───────────────────────────────────────────────────────────
|
||||
|
||||
@@ -119,7 +119,7 @@ async function main() {
|
||||
}
|
||||
|
||||
console.log(`\nDone: ${updated} updated, ${skipped} skipped`);
|
||||
await sql.end();
|
||||
await sql.close();
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
|
||||
@@ -5,16 +5,14 @@
|
||||
* Usage: bun scripts/seed-db.ts
|
||||
*/
|
||||
|
||||
import { drizzle } from 'drizzle-orm/postgres-js';
|
||||
import postgres from 'postgres';
|
||||
import { drizzle } from 'drizzle-orm/bun-sql';
|
||||
import { sql } from 'drizzle-orm';
|
||||
import { pgTable, text, uuid, boolean, timestamp, integer, real, jsonb } from 'drizzle-orm/pg-core';
|
||||
|
||||
const DATABASE_URL = process.env.DATABASE_URL;
|
||||
if (!DATABASE_URL) throw new Error('DATABASE_URL not set');
|
||||
|
||||
const client = postgres(DATABASE_URL);
|
||||
const db = drizzle(client);
|
||||
const db = drizzle(DATABASE_URL);
|
||||
|
||||
const mappool = pgTable('mappool', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { drizzle } from 'drizzle-orm/postgres-js';
|
||||
import postgres from 'postgres';
|
||||
import * as schema from './schema';
|
||||
import { env } from '$env/dynamic/private';
|
||||
|
||||
if (!env.DATABASE_URL) throw new Error('DATABASE_URL is not set');
|
||||
if (!process.versions.bun) {
|
||||
throw new Error('Bun SQL requires the Bun runtime. If in a dev environment, try running the app with `bun --bun vite dev`.');
|
||||
}
|
||||
|
||||
const client = postgres(env.DATABASE_URL);
|
||||
const { drizzle } = await import('drizzle-orm/bun-sql');
|
||||
|
||||
export const db = drizzle(client, { schema });
|
||||
export const db = drizzle(env.DATABASE_URL, { schema });
|
||||
|
||||
Reference in New Issue
Block a user