intense-visions/harness-engineering/prisma-raw-queries
Claude Code and agent skill by intense-visions/harness-engineering
- community
Checking that the SKILL.md file is still in the repository.
Install
npx vskill@latest install intense-visions/harness-engineering/prisma-raw-queriesSKILL.md
The same SKILL.md was published earlier as intense-visions/harness-engineering/prisma-raw-queries.
Prisma Raw Queries
Execute type-safe raw SQL with $queryRaw, $executeRaw, and Prisma.sql template tag
When to Use
- Running SQL queries that Prisma Client cannot express (CTEs, window functions, complex joins)
- Performing bulk operations more efficiently than Prisma's generated queries
- Calling database-specific features (full-text search, advisory locks, lateral joins)
- Executing data migrations or one-off scripts
Instructions
- Read query — use
$queryRawwith a tagged template literal. Always parameterize inputs:
The template tag automatically parameterizes ${role} as a prepared statement parameter — never string-interpolated.
- Write query — use
$executeRawfor INSERT, UPDATE, DELETE. Returns the affected row count:
- Dynamic table or column names — use
Prisma.raw()for identifiers that cannot be parameterized:
Validate columnName against an allowlist before using Prisma.raw() to prevent SQL injection.
- Build dynamic queries with
Prisma.sqlandPrisma.join:
- Compose query fragments with
Prisma.sql:
- Type the result —
$queryRawreturnsunknown[]by default. Pass a generic type or validate with Zod:
- Use raw queries inside transactions:
Details
Raw queries bypass Prisma's query engine and type generation. The SQL runs directly against the database connection, but parameter binding still uses prepared statements for safety.
Table and column naming: Prisma maps model names to table names via @@map and field names to column names via @map. In raw SQL, you must use the actual database names, not the Prisma model names. Check with prisma migrate diff --from-empty --to-schema-datamodel prisma/schema.prisma --script to see the real table names.
Return type caveats:
$queryRawreturns rows with exact database column names (not Prisma field names)BigIntcolumns return JavaScriptBigInt, which is not JSON-serializable — convert toNumberorStringbefore sending to clientsDecimalcolumns returnPrisma.Decimalobjects, notnumberDateTimecolumns returnDateobjects
`$queryRawUnsafe` / `$executeRawUnsafe`: Accept a plain string instead of a tagged template. These do NOT parameterize — you are responsible for preventing SQL injection. Avoid unless you are building a query builder that handles parameterization itself.
Performance advantages of raw SQL:
- CTEs and window functions are impossible with Prisma Client but often the most efficient solution
INSERT ... ON CONFLICT(upsert) on multiple rows is significantly faster than loopingprisma.model.upsert()- Bulk updates with CASE expressions are faster than individual
updatecalls
Source
https://prisma.io/docs/orm/prisma-client/queries/raw-database-access
Process
- Read the instructions and examples in this document.
- Apply the patterns to your implementation, adapting to your specific context.
- Verify your implementation against the details and edge cases listed above.
Harness Integration
- Type: knowledge — this skill is a reference document, not a procedural workflow.
- No tools or state — consumed as context by other skills and agents.
Success Criteria
- The patterns described in this document are applied correctly in the implementation.
- Edge cases and anti-patterns listed in this document are avoided.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingagents/skills/gemini-cli/prisma-raw-queries/SKILL.md
Popularity
- Repository stars
- 14
- Repository forks
- 7
- 7-day trend score
- 14
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/intense-visions/harness-engineering/prisma-raw-queries)