{"success":true,"name":"orm-or-raw-queries-in-node-decide-by-your-queries-not-by-com","description":"Starting database code in a Node project and picking ORM vs raw queries by habit","category":"ai-brimind","path":"ai-brimind/orm-or-raw-queries-in-node-decide-by-your-queries-not-by-com/SKILL.md","file":"SKILL.md","content":"---\nname: orm-or-raw-queries-in-node-decide-by-your-queries-not-by-com\ndescription: \"Starting database code in a Node project and picking ORM vs raw queries by habit\"\n---\n\n# ORM or Raw Queries in Node? Decide by Your Queries, Not by Comfort\n\n## When to use\nProject is Node.js/Next.js with a database, and you are choosing between an ORM (Prisma, Mongoose...) and raw queries without looking at what the app's queries will actually be.\n\n## Example request\nApp is mostly simple CRUD (create user, list bookings) → an ORM writes the boring 90% safely and gives types; standard shapes love ORMs. One report needs a heavy query with joins and grouping → the ORM version is unreadable and slow; ORMs allow raw escape hatches for exactly this. Writing raw string queries with user input glued in → injection risk the ORM would have blocked; safety is part of the choice. Fighting the ORM for hours to express a simple SQL idea → the tool became the obstacle; mixing (ORM for CRUD, raw for the hard 10%) is a valid answer.\n\n## Instructions\nAct as a database-layer chooser who looks at the actual queries the app will run before picking the tool that writes them. First list the app's real database work in plain words: how much is simple CRUD (create, read one, list, update, delete) versus complex reads (multi-table joins, aggregations, reports, search)? Then match: mostly CRUD → an ORM earns its place — it generates the repetitive queries, keeps types in sync with the schema, and blocks injection by default; heavy analytical queries → plan for raw SQL where the ORM gets awkward, using the ORM's own raw escape hatch so both live together safely. Never treat it as religion: 'ORM for the standard 90%, raw for the hard 10%' is a normal, healthy answer — but say which parts fall in which bucket. If choosing raw queries, state how injection is prevented (parameterized queries, never string-gluing user input). If the app's query shapes are still unknown, sketch the 5 most important screens and what each asks the database — that sketch decides better than any benchmark blog. Only settle the choice once you can point at the app's real queries and say which tool writes each kind best — picking by comfort or by trend means discovering the mismatch after a hundred queries are already written.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #318\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}