-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Prisma TypedSQL #377
base: dev
Are you sure you want to change the base?
Changes from all commits
0f567fb
2fce855
976a488
22760df
289bab9
4b9645b
22a6b40
a342d98
18150a3
6e7d3f6
7e2d731
a2940bd
6522b6d
16fc961
7ef8c1e
10e9b96
e200a87
df1f59a
76ce3ec
259a780
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,9 @@ | |
"build-self-host-seed-script": "tsup --config prisma/tsup.config.ts", | ||
"analyze-bundle": "ANALYZE_BUNDLE=1 pnpm run build", | ||
"start": "next start --port 8102", | ||
"codegen-prisma": "pnpm run prisma generate", | ||
"codegen-prisma:watch": "pnpm run prisma generate --watch", | ||
"codegen": "pnpm run with-env bash -c 'if [ \"$STACK_ACCELERATE_ENABLED\" = \"true\" ]; then pnpm run prisma generate --no-engine && pnpm run generate-docs; else pnpm run codegen-prisma && pnpm run generate-docs; fi'", | ||
"codegen-prisma": "concurrently -k -s first \"tsx scripts/mock-postgres.mjs\" \"node -e \\\"setTimeout(() => process.exit(0), 2000)\\\" && cross-env STACK_DATABASE_CONNECTION_STRING=\\\"postgres://postgres@localhost:8118/postgres?pgbouncer=true&connection_limit=1\\\" STACK_DIRECT_DATABASE_CONNECTION_STRING=\\\"postgres://postgres@localhost:8118/postgres?connection_limit=1\\\" STACK_SEED_INTERNAL_PROJECT_PUBLISHABLE_CLIENT_KEY=\\\"test_key\\\" STACK_SEED_INTERNAL_PROJECT_SECRET_SERVER_KEY=\\\"test_secret\\\" STACK_SEED_INTERNAL_PROJECT_SUPER_SECRET_ADMIN_KEY=\\\"test_admin\\\" sh -c \\\"pnpm run prisma migrate reset --force && pnpm run prisma generate --sql\\\"\"", | ||
"codegen-prisma:watch": "pnpm run codegen-prisma && chokidar \"prisma/**/*\" -c \"pnpm run codegen-prisma\"", | ||
"codegen": "pnpm run with-env bash -c 'if [ \"$STACK_ACCELERATE_ENABLED\" = \"true\" ]; then pnpm run prisma generate --sql --no-engine && pnpm run generate-docs; else pnpm run codegen-prisma && pnpm run generate-docs; fi'", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change? Why |
||
"codegen:watch": "concurrently -n \"prisma,docs\" -k \"pnpm run codegen-prisma:watch\" \"pnpm run watch-docs\"", | ||
"psql-inner": "psql $STACK_DATABASE_CONNECTION_STRING", | ||
"psql": "pnpm run with-env pnpm run psql-inner", | ||
|
@@ -31,6 +31,7 @@ | |
"seed": "pnpm run db-seed-script" | ||
}, | ||
"dependencies": { | ||
"@electric-sql/pglite": "0.2.7", | ||
"@next/bundle-analyzer": "15.0.3", | ||
"@node-oauth/oauth2-server": "^5.1.0", | ||
"@opentelemetry/api": "^1.9.0", | ||
|
@@ -44,7 +45,7 @@ | |
"@opentelemetry/sdk-trace-base": "^1.26.0", | ||
"@opentelemetry/sdk-trace-node": "^1.26.0", | ||
"@opentelemetry/semantic-conventions": "^1.27.0", | ||
"@prisma/client": "^6.0.1", | ||
"@prisma/client": "^6.1.0", | ||
"@prisma/extension-accelerate": "^1.2.1", | ||
"@prisma/instrumentation": "^5.19.1", | ||
"@sentry/nextjs": "^8.40.0", | ||
|
@@ -55,6 +56,7 @@ | |
"@vercel/functions": "^1.4.2", | ||
"@vercel/otel": "^1.10.0", | ||
"bcrypt": "^5.1.1", | ||
"chokidar-cli": "^3.0.0", | ||
"dotenv-cli": "^7.3.0", | ||
"jose": "^5.2.2", | ||
"next": "15.0.3", | ||
|
@@ -63,6 +65,7 @@ | |
"openid-client": "^5.6.4", | ||
"oslo": "^1.2.1", | ||
"pg": "^8.11.3", | ||
"pg-gateway": "0.3.0-beta.3", | ||
"posthog-node": "^4.1.0", | ||
"react": "^19.0.0", | ||
"react-dom": "^19.0.0", | ||
|
@@ -82,9 +85,10 @@ | |
"@types/react-dom": "^19.0.0", | ||
"@types/semver": "^7.5.8", | ||
"concurrently": "^8.2.2", | ||
"cross-env": "^7.0.3", | ||
"glob": "^10.4.1", | ||
"import-in-the-middle": "^1.12.0", | ||
"prisma": "^6.0.1", | ||
"prisma": "^6.1.0", | ||
"require-in-the-middle": "^7.4.0", | ||
"rimraf": "^5.0.5", | ||
"tsup": "^8.3.0", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
SELECT data->>'userId' as "userId", MAX("createdAt") as "lastActiveAt" | ||
FROM "Event" | ||
WHERE data->>'userId' = ANY($1) | ||
GROUP BY data->>'userId' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { PGlite } from '@electric-sql/pglite'; | ||
import net from 'node:net'; | ||
import { fromNodeSocket } from 'pg-gateway/node'; | ||
|
||
const db = new PGlite(); | ||
|
||
const server = net.createServer(async (socket) => { | ||
let activeDb; | ||
|
||
console.info(`Client connected: ${socket.remoteAddress}:${socket.remotePort}`) | ||
await fromNodeSocket(socket, { | ||
serverVersion: '16.3', | ||
|
||
auth: { | ||
// No password required | ||
method: 'trust', | ||
}, | ||
|
||
async onStartup({ clientParams }) { | ||
console.info(`Connecting client to ${clientParams?.database}`) | ||
// If the DB is the Prisma shadow DB, create a temp in-memory instance | ||
if (clientParams?.database === 'prisma-shadow') { | ||
activeDb = new PGlite() | ||
} else { | ||
activeDb = db | ||
} | ||
|
||
// Wait for PGlite to be ready before further processing | ||
await activeDb.waitReady | ||
}, | ||
|
||
async onMessage(data, { isAuthenticated }) { | ||
if (!isAuthenticated) { | ||
// currently we have no authentication, but let's keep it for the future | ||
return | ||
} | ||
|
||
// Forward raw message to PGlite and send response to client | ||
return await activeDb.execProtocolRaw(data) | ||
}, | ||
}) | ||
|
||
socket.on('end', () => { | ||
console.info('Client disconnected') | ||
}) | ||
}) | ||
|
||
server.listen(8118, () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you document this in the dev launchpad? |
||
console.info('Postgres server listening on port 8118') | ||
}) |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we put this into a JS file instead (you can merge it with mock-postgres.mjs)