nestjs-data
Skill12 starsChanged 8 days agoMITView on GitHub
Databases in a NestJS application with the first-party @nestjs/drizzle and @nestjs/typeorm integrations - registering the database, injecting it into services, schemas or entities, migrations, transactions, and writes that stay correct under concurrent requests. Use when adding or changing persistence in a NestJS application.
1 other project uses a version of this, 1 of them edited.
Adopted by
Most recently taken up by
- nestjs/typescript-starteredited, first seen Nov 30, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 1
- nestjs/typescript-starter★ 2.2k99% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository41 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .claude/skills/react-doctor/AGENTS.mdAGENTS.md
- .claude/skills/vercel-react-best-practices/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- ai-agent-developmentSkill
- angular-developerSkill
- api-design-principlesSkill
- aws-serverlessSkill
- brainstormingSkill
- cavemanSkill
- cognitive-doc-designSkill
- diagram-designSkill
- error-handling-patternsSkill
- frontend-designSkill
- golang-proSkill
- gsap-animationSkill
- impeccable-bridgeSkill
- impeccableSkill
- java-springbootSkill
- judgment-daySkill
- kaizenSkill
- nestjs-authSkill
- nestjs-featureSkill
- nestjs-productionSkill
- nestjsSkill
- nestjs-testingSkill
- product-manager-toolkitSkill
- pr-reviewSkill
- react-doctorSkill
- security-auditSkill
- seo-auditSkill
- shadcn-uiSkill
- social-marketingSkill
- software-architectSkill
- stitch-designSkill
- systematic-debuggingSkill
- tailwind-design-systemSkill
- tddSkill
- ui-ux-pro-maxSkill
- vercel-react-best-practicesSkill
- video-productionSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 23
If the project already uses one, keep it.
- Very specific: line 48
Short transactions: Never await an HTTP call, a queue or a user inside a transaction: it holds a pooled connection (and locks) the whole …
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Persistence in a NestJS app
Nest integrates the common ORMs; pick one per app and keep queries in services or repositories, not controllers.
| Package | Docs | |
| Drizzle (SQL-like, schema in TypeScript, no classes) | @nestjs/drizzle + drizzle-orm@rc (v1) | https://docs.nestjs.com/data/drizzle.md |
| TypeORM (entity classes, repositories) | @nestjs/typeorm + typeorm | https://docs.nestjs.com/data/typeorm.md |
| Prisma, MongoDB (Mongoose), Sequelize, MikroORM | /data/prisma, /data/mongodb, ... |
If the project already uses one, keep it.
Drizzle
DrizzleModule.forRoot({ drizzle, connection }) // drizzle(): your driver's, e.g. from 'drizzle-orm/libsql'then @InjectDrizzle() private readonly db: LibSQLDatabase (type from the driver's entry point) in any provider; no forFeature(). The client closes on app.close()/shutdown hooks. Tables are plain objects: sqliteTable('notes', {...}), types from $inferSelect/$inferInsert. Migrations: drizzle-kit generate then drizzle-kit migrate, or migrate() from the driver's /migrator at startup.
TypeORM
TypeOrmModule.forRoot({ type, database, autoLoadEntities: true, synchronize: false }) at the root, TypeOrmModule.forFeature([Note]) in the feature module, @InjectRepository(Note) private readonly notes: Repository<Note>. synchronize: true is for throwaway development databases only: it can drop columns and data. Use migrations otherwise.
Rules
- Don't read, then
save()a whole entity to update it. TypeORM'ssave()inserts the row if it's gone, so a PATCH that loaded a note just before a concurrent DELETE puts it back. Update withrepo.update({ id, userId }, changes)(or a query builder) and checkresult.affected; delete withrepo.delete({ id, userId }). With Drizzle,db.update(notes).set(changes).where(and(eq(notes.id, id), eq(notes.userId, userId))).returning()and treat no row as 404. - Scope by owner in the query, not after loading:
where: { id, userId: user.id }. A row that isn't the caller's is then simply not found. - Map constraint violations, don't pre-check. Insert and catch the unique violation (Drizzle wraps the driver's error: walk
error.cause; SQLiteSQLITE_CONSTRAINT_UNIQUE, PostgreSQL23505) and answer 409; a lookup first lets two concurrent requests both pass. - Page with a cursor (
WHERE id > :after ORDER BY id LIMIT :limit + 1), notOFFSET: noCOUNT(*), stable under inserts. - Check-then-write in one statement or a transaction. "Is the email taken? then insert" needs a unique index (catch the violation and answer 409); "count admins, then demote" needs a transaction (Drizzle
db.transaction(async (tx) => ...), TypeORMdataSource.transaction(async (manager) => ...)). - Cascades in the schema:
onDelete: 'cascade'on the foreign key (Drizzlereferences(() => users.id, { onDelete: 'cascade' }), TypeORM@ManyToOne(() => User, { onDelete: 'CASCADE' })), and for SQLite turn foreign keys on (PRAGMA foreign_keys = ON). - Data that must survive a restart lives in a file or server database from the configured path or URL, never
:memory:. Create the parent directory if needed. - Numbers that come back as strings. PostgreSQL
bigint(int8) andnumeric/decimalarrive as strings throughpg, because JavaScript numbers can't hold them exactly. Convert where you need arithmetic, choose the column mode on purpose (Drizzlebigint({ mode: 'number' })only when values stay below 2^53), and keep money as integer cents ornumerichandled as strings. - Times in UTC. Store timestamps in UTC (
timestamptzin PostgreSQL; epoch milliseconds or ISO strings in SQLite, which has no date type) and convert at the edges. - Short transactions. Never await an HTTP call, a queue or a user inside a transaction: it holds a pooled connection (and locks) the whole time, and a slow third party then exhausts the pool. Call out before or after, or use an outbox (
@nestjs/outbox). - One Prisma client. With Prisma, create one
PrismaService extends PrismaClientprovider, exported from one module, not anew PrismaClient()per service: each client has its own connection pool. - Async drivers yield between statements: two requests can interleave between a read and a write. Synchronous drivers (
better-sqlite3) don't, which hides races in tests that would appear on PostgreSQL.
Recipes, all run on the released packages: schemas and relations, migrations at startup or as a release step, a repository with owner-scoped queries, cursor paging and unique violations mapped to 409, transactions, testing: references/data.md.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

