nnestjs-drizzle-crud
Reference

Exports

The full public API surface of nestjs-drizzle-crud, grouped by category.

Every export below is available from the package root: import { ... } from 'nestjs-drizzle-crud'.

Core

ExportKindDescription
SqlBaseCrudServiceclassThe base class your services extend. See API reference.

Module & DI tokens

ExportKindDescription
DrizzleCrudModuleclassThe Nest module. Has forRoot, forRootAsync, forFeature static methods.
DRIZZLE_DBstringDI token for the resolved Drizzle instance.
DRIZZLE_CONNECTIONstringDI token for the connection wrapper.
DRIZZLE_CRUD_CONFIGstringDI token for the normalized global config.
DrizzleConnectionclassThe internal connection wrapper. Exposed for advanced use.

Decorators

ExportKindDescription
CrudServicedecoratorAttach per-entity config to a service class. The forFeature config field still wins.

Exceptions

All exceptions extend @nestjs/common's HttpException, so Nest's default exception filter maps them to HTTP status codes automatically. They are real classes. Use instanceof checks in your exception filters. See Errors for the per-method reference.

ExportHTTPDescription
EntityNotFoundException404Thrown by update, restore, massUpdate, massRestore when the row doesn't exist.
DuplicateEntityException409Thrown by create / update when a unique constraint is violated (Postgres SQLSTATE 23505).
ForeignKeyViolationException400Thrown by create / update when a supplied foreign key references no existing row (23503). Names the offending column.
EntityInUseException409Thrown by delete when other rows still reference this one (23503, ON DELETE RESTRICT or NO ACTION).
ValidationFailedException400Throw this from your validateCreate / validateUpdate hooks to reject bad input.
BulkOperationException400Thrown by any bulk method when the transaction rolls back. Carries per-row errors.
DatabaseConnectionException500Thrown when the connection can't be established.
TransactionException500Thrown by executeSqlTransaction on transaction-level errors.

Types

ExportKind
ICrudServiceinterface, the abstract shape SqlBaseCrudService implements.
CrudFeaturetype, the input to forFeature.
DrizzleCrudConfigtype, input to forRoot / forRootAsync.
SqlCrudConfiginterface, the per-entity merged config.
SqlOperationOptionsinterface, the third argument to most methods, including search for findAll and count.
RelationConfiginterface, describes one relation in relations.
RelationsConfigtype, a record of RelationConfig.
RelationType'belongsTo' | 'hasMany' | 'manyToMany'.
RelationNodeinterface, one resolved node in an eager-loading plan.
SelectTreeinterface, the parsed options.select.
SqlDialect'postgresql' | 'mysql'.
PrimaryKeyType'serial' | 'bigserial' | 'int' | 'bigint' | 'uuid'.
SortColumn{ column, order }.
SortOrder'asc' | 'desc'.

Re-exported Drizzle helpers

For convenience, the package re-exports the Drizzle helpers most commonly used in mapCreateDtoToEntity, custom methods, and filter construction:

import {
  and,
  asc,
  desc,
  eq,
  gt,
  gte,
  ilike,
  inArray,
  isNotNull,
  isNull,
  like,
  lt,
  lte,
  ne,
  or,
  sql,
} from 'nestjs-drizzle-crud';

All of these are pass-throughs to drizzle-orm. The package doesn't wrap or extend them.

Test utilities

ExportDescription
TestCrudFactoryClass with createMockDb, createMockTable, createMockEntity, createTestService.
BaseCrudSpecHelperA higher-level helper that builds a full service + fixtures.

See Testing for usage.

Binaries

CommandDescription
nestjs-drizzle-crud-mcpMCP server over stdio that serves the package docs to any AI agent. Run it with npx nestjs-drizzle-crud-mcp. See AI agents and MCP.

What's not exported

The following are internal to the package and should not be imported directly:

  • DrizzleCrudModule's internal connectionProviders / buildEntityConfig / normalizeConfig helpers.
  • The internal DRIZZLE_RAW_CONFIG token.

If you find yourself reaching for these, open a feature request. The public API may need a hook.

Next

On this page