Skip to content
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

add parameterized queries to typesql #7498

Merged
merged 1 commit into from
Feb 7, 2025
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
7 changes: 7 additions & 0 deletions orm/typedsql/prisma/sql/filterTrackingEvents.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- @param {String} $1:types
-- @param {String} $2:variants
SELECT te."id", te."type", te."variant"
FROM "TrackingEvent" te
WHERE
($1 IS NULL OR te."type" IN (SELECT value FROM json_each($1)))
AND ($2 IS NULL OR te."variant" IN (SELECT value FROM json_each($2)))
7 changes: 7 additions & 0 deletions orm/typedsql/prisma/sql/getTrackingEvents.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT
id,
type,
variant
FROM "TrackingEvent"
LIMIT
:limit ;
13 changes: 12 additions & 1 deletion orm/typedsql/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import { PrismaClient } from '@prisma/client'
import { conversionByVariant } from '@prisma/client/sql'
import { filterTrackingEvents } from '@prisma/client/sql'
import { getTrackingEvents } from '@prisma/client/sql'

async function main() {
const prisma = new PrismaClient()

const stats = await prisma.$queryRawTyped(conversionByVariant())

console.log(stats)

const rows = await prisma.$queryRawTyped(filterTrackingEvents(
JSON.stringify(['PageOpened', 'ButtonClicked']),
JSON.stringify(['BlueBuyButton', 'RedBuyButton'])
))
console.log(rows)

const result = await prisma.$queryRawTyped(getTrackingEvents(5))
console.log(result)

}

main()