Query builders and ORM boundaries
A query builder composes SQL operations through an API; an object-relational mapper (ORM) also maps data between application objects and relational tables. Both still depend on database constraints and query behavior. A repository exposes an application-level operation, for example finding a book by ID. Drizzle expresses a selection and predicate in SQL-like TypeScript; Prisma uses a generated client and model operations; TypeORM offers entity mappings and repositories. Their transaction and migration APIs differ. The example uses a narrow repository over a real SQLite statement. The separate Drizzle function illustrates the same contract with an already configured PostgreSQL database and schema. Verify emitted SQL and parameter handling rather than trusting a library name. Client generation, package setup and database-specific behavior need separate tests. Do not return whole entities when the caller only needs a public projection. ORM type inference does not replace database constraints or resource authorization. Evidence: Actual local SQLite 3.49.1 via experimental node:sqlite. Source: https://orm.drizzle.team/docs/select
Formal Syntax & Structure
See example for the scoped contractWorking Example
import {DatabaseSync} from 'node:sqlite';const db=new DatabaseSync(':memory:');try { db.exec("CREATE TABLE book(id INTEGER PRIMARY KEY,title TEXT, internal_note TEXT); INSERT INTO book VALUES(1,'Rivers','staff only')"); const repository={find(id){const row=db.prepare('SELECT id,title FROM book WHERE id=?').get(id);return row?{id:row.id,title:row.title}:null;}}; console.log(JSON.stringify(repository.find(1))); console.log(repository.find(2));}finally{db.close();}