refactor(database): ♻️ Use Bun.SQL instead of pg
Some checks failed
CodeQL Scan / Analyze (javascript-typescript) (push) Failing after 1s
Build Docker Images / lint (push) Failing after 7s
Build Docker Images / check (push) Failing after 7s
Build Docker Images / tests (push) Failing after 7s
Deploy Docs to GitHub Pages / build (push) Failing after 0s
Build Docker Images / build (server, Dockerfile, ${{ github.repository_owner }}/server) (push) Has been skipped
Build Docker Images / build (worker, Worker.Dockerfile, ${{ github.repository_owner }}/worker) (push) Has been skipped
Deploy Docs to GitHub Pages / Deploy (push) Has been skipped
Mirror to Codeberg / Mirror (push) Failing after 0s
Nix Build / check (push) Failing after 0s

This commit is contained in:
Jesse Wierzbinski 2025-04-19 14:15:08 +02:00
parent f95f57c4d4
commit 138f4fade3
No known key found for this signature in database
6 changed files with 21 additions and 19 deletions

7
.vscode/launch.json vendored
View file

@ -36,6 +36,13 @@
"program": "${workspaceFolder}/index.ts", "program": "${workspaceFolder}/index.ts",
"cwd": "${workspaceFolder}", "cwd": "${workspaceFolder}",
"watchMode": true "watchMode": true
},
{
"type": "bun",
"internalConsoleOptions": "neverOpen",
"request": "launch",
"name": "Run tests",
"program": "test"
} }
] ]
} }

View file

@ -88,7 +88,7 @@ export default apiRoute((app) =>
AND "IdsFollowers"."following" = true AND "IdsFollowers"."following" = true
) )
`) `)
).rows.map((u) => u.id as string), ).map((u) => u.id as string),
), ),
})), })),
); );

View file

@ -48,7 +48,6 @@
"mitata": "^1.0.34", "mitata": "^1.0.34",
"oauth4webapi": "^3.5.0", "oauth4webapi": "^3.5.0",
"ora": "^8.2.0", "ora": "^8.2.0",
"pg": "^8.14.1",
"qs": "^6.14.0", "qs": "^6.14.0",
"sharp": "^0.34.1", "sharp": "^0.34.1",
"sonic-channel": "^1.3.1", "sonic-channel": "^1.3.1",
@ -68,7 +67,6 @@
"@types/html-to-text": "^9.0.4", "@types/html-to-text": "^9.0.4",
"@types/markdown-it-container": "^2.0.10", "@types/markdown-it-container": "^2.0.10",
"@types/mime-types": "^2.1.4", "@types/mime-types": "^2.1.4",
"@types/pg": "^8.11.13",
"@types/qs": "^6.9.18", "@types/qs": "^6.9.18",
"@types/web-push": "^3.6.4", "@types/web-push": "^3.6.4",
"bun-bagel": "^1.2.0", "bun-bagel": "^1.2.0",

View file

@ -1,13 +1,13 @@
import { getLogger } from "@logtape/logtape"; import { getLogger } from "@logtape/logtape";
import { SQL } from "bun";
import chalk from "chalk"; import chalk from "chalk";
import { drizzle, type NodePgDatabase } from "drizzle-orm/node-postgres"; import { type BunSQLDatabase, drizzle } from "drizzle-orm/bun-sql";
import { withReplicas } from "drizzle-orm/pg-core"; import { withReplicas } from "drizzle-orm/pg-core";
import { migrate } from "drizzle-orm/postgres-js/migrator"; import { migrate } from "drizzle-orm/postgres-js/migrator";
import { Pool } from "pg";
import { config } from "~/config.ts"; import { config } from "~/config.ts";
import * as schema from "./schema.ts"; import * as schema from "./schema.ts";
const primaryDb = new Pool({ const primaryDb = new SQL({
host: config.postgres.host, host: config.postgres.host,
port: config.postgres.port, port: config.postgres.port,
user: config.postgres.username, user: config.postgres.username,
@ -17,7 +17,7 @@ const primaryDb = new Pool({
const replicas = config.postgres.replicas.map( const replicas = config.postgres.replicas.map(
(replica) => (replica) =>
new Pool({ new SQL({
host: replica.host, host: replica.host,
port: replica.port, port: replica.port,
user: replica.username, user: replica.username,
@ -32,9 +32,9 @@ export const db =
drizzle(primaryDb, { schema }), drizzle(primaryDb, { schema }),
replicas.map((r) => drizzle(r, { schema })) as [ replicas.map((r) => drizzle(r, { schema })) as [
// biome-ignore lint/style/useNamingConvention: <explanation> // biome-ignore lint/style/useNamingConvention: <explanation>
NodePgDatabase<typeof schema> & { $client: Pool }, BunSQLDatabase<typeof schema> & { $client: SQL },
// biome-ignore lint/style/useNamingConvention: <explanation> // biome-ignore lint/style/useNamingConvention: <explanation>
...(NodePgDatabase<typeof schema> & { $client: Pool })[], ...(BunSQLDatabase<typeof schema> & { $client: SQL })[],
], ],
) )
: drizzle(primaryDb, { schema }); : drizzle(primaryDb, { schema });

View file

@ -65,7 +65,6 @@
"@types/html-to-text": "^9.0.4", "@types/html-to-text": "^9.0.4",
"@types/markdown-it-container": "^2.0.10", "@types/markdown-it-container": "^2.0.10",
"@types/mime-types": "^2.1.4", "@types/mime-types": "^2.1.4",
"@types/pg": "^8.11.13",
"@types/qs": "^6.9.18", "@types/qs": "^6.9.18",
"@types/web-push": "^3.6.4", "@types/web-push": "^3.6.4",
"bun-bagel": "^1.2.0", "bun-bagel": "^1.2.0",
@ -127,7 +126,6 @@
"mitata": "^1.0.34", "mitata": "^1.0.34",
"oauth4webapi": "^3.5.0", "oauth4webapi": "^3.5.0",
"ora": "^8.2.0", "ora": "^8.2.0",
"pg": "^8.14.1",
"qs": "^6.14.0", "qs": "^6.14.0",
"sharp": "^0.34.1", "sharp": "^0.34.1",
"sonic-channel": "^1.3.1", "sonic-channel": "^1.3.1",

View file

@ -140,9 +140,6 @@ importers:
ora: ora:
specifier: ^8.2.0 specifier: ^8.2.0
version: 8.2.0 version: 8.2.0
pg:
specifier: ^8.14.1
version: 8.14.1
qs: qs:
specifier: ^6.14.0 specifier: ^6.14.0
version: 6.14.0 version: 6.14.0
@ -195,9 +192,6 @@ importers:
'@types/mime-types': '@types/mime-types':
specifier: ^2.1.4 specifier: ^2.1.4
version: 2.1.4 version: 2.1.4
'@types/pg':
specifier: ^8.11.13
version: 8.11.13
'@types/qs': '@types/qs':
specifier: ^6.9.18 specifier: ^6.9.18
version: 6.9.18 version: 6.9.18
@ -5871,7 +5865,8 @@ snapshots:
pg-cloudflare@1.1.1: pg-cloudflare@1.1.1:
optional: true optional: true
pg-connection-string@2.7.0: {} pg-connection-string@2.7.0:
optional: true
pg-int8@1.0.1: {} pg-int8@1.0.1: {}
@ -5880,6 +5875,7 @@ snapshots:
pg-pool@3.8.0(pg@8.14.1): pg-pool@3.8.0(pg@8.14.1):
dependencies: dependencies:
pg: 8.14.1 pg: 8.14.1
optional: true
pg-protocol@1.8.0: {} pg-protocol@1.8.0: {}
@ -5910,10 +5906,12 @@ snapshots:
pgpass: 1.0.5 pgpass: 1.0.5
optionalDependencies: optionalDependencies:
pg-cloudflare: 1.1.1 pg-cloudflare: 1.1.1
optional: true
pgpass@1.0.5: pgpass@1.0.5:
dependencies: dependencies:
split2: 4.2.0 split2: 4.2.0
optional: true
picocolors@1.1.1: {} picocolors@1.1.1: {}
@ -6175,7 +6173,8 @@ snapshots:
wicked-good-xpath: 1.3.0 wicked-good-xpath: 1.3.0
optional: true optional: true
split2@4.2.0: {} split2@4.2.0:
optional: true
sprintf-js@1.0.3: {} sprintf-js@1.0.3: {}