Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bun.lock

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

10 changes: 6 additions & 4 deletions lib/credits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import crypto from "node:crypto";
import { createRequire } from "node:module";
import { Credits, postgresStore as creditsPg, sqliteStore as creditsSqlite } from "@profullstack/redeem-credits";
import { Affiliates, postgresStore as affPg, sqliteStore as affSqlite } from "@profullstack/affiliates";
import { connectionSettings } from "@profullstack/libsql-pg";
import pg from "pg";
import { databaseUrl, db, ensureSchema, getAccountById, type Account } from "./db";
import { grantPaidDays, toMs } from "./plan";
import { sqlTime } from "./sql-time";
Expand Down Expand Up @@ -56,11 +58,11 @@ function rawConnection(): { kind: "pg"; pool: any } | { kind: "sqlite"; db: any
const url = databaseUrl();
if (POSTGRES_URL.test(url)) {
if (!_pool) {
const { Pool } = require_("pg");
// The same sslmode handling as the app's own client (libsql-pg), so both
// connections reach the database the same way.
const { connectionSettings } = require_("@profullstack/libsql-pg");
_pool = new Pool({ ...connectionSettings(url), max: 4 });
// connections reach the database the same way. A static import: libsql-pg
// is ESM and a server external, and require() of it from the Next bundle
// returned no connectionSettings (prod 500 "i is not a function").
_pool = new pg.Pool({ ...connectionSettings(url), max: 4 });
_pool.on("error", () => {});
}
return { kind: "pg", pool: _pool };
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"devDependencies": {
"@libsql/client": "^0.18.0",
"@types/node": "^26.6.5",
"@types/pg": "^8.23.1",
"@types/react": "^19.3.0",
"@types/react-dom": "^19.3.0",
"typescript": "^7.0.2"
Expand Down
Loading