Nestjs Drizzle
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.
parseCrudQueryfunctionparseCrudQuery(query, table, options?) turns an HTTP query object into filters, pagination and options. Since 3.4.0. See Parse query strings.
createCrudControllerfunctioncreateCrudController(Service, options?) returns a controller class with list, get, create, update, delete, soft delete, restore, trash and bulk routes. Since 3.5.0. See CRUD controller factory.
CrudContextobjectrun(context, fn), current() and middleware(resolve): the per-request context a scope reads, in AsyncLocalStorage. Since 3.5.0. See Multi-tenancy.
CrudEventBusclassThe module-level event bus behind hooks.enableGlobalHooks. Inject it and call subscribe. Since 3.5.0. See Global hooks and write events.

OpenAPI

Both need the optional peer @nestjs/swagger, loaded only when a decorator runs. Since 3.5.0. See OpenAPI docs for list queries.

ExportKindDescription
ApiCrudQuerydecoratorDocuments every list query parameter and each filterable column.
ApiCrudListdecoratorApiCrudQuery plus the 200 page envelope with the row schema.
ApiCrudSource, ApiCrudQueryOptionstypesThe decorators' source ({ table, ...allowlists } or a @CrudService class) and options ({ cursor?, trash? }).

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.
CrudEventBusclassAlso a provider: forRoot / forRootAsync register and export it globally.
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.
StaleVersionException409Optimistic locking: a write named a version the row is no longer at. Since 3.5.0. See Optimistic locking.
MissingScopeException403A scoped entity was used without the context value its scope needs. Since 3.5.0. See Multi-tenancy.
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. The response body lists each failed item as { index | id, status, message }; errors keeps the original errors.
DatabaseConnectionException500Deprecated. Nothing in the package throws it. Removed in the next major version.
TransactionException500Deprecated. Nothing in the package throws it; a failed transaction rejects with its own error. Removed in the next major version.

Types

ExportKind
ICrudServiceinterface, the abstract shape SqlBaseCrudService implements.
CrudFeaturetype, the input to forFeature.
CrudFeatureConfigtype, the per-entity config of forFeature. Since 3.3.1.
DrizzleCrudConfigtype, input to forRoot / forRootAsync.
SqlCrudConfiginterface, the per-entity merged config.
SqlOperationOptionsinterface, the third argument to most methods, including search for findAll and count.
OperationOptionsinterface, the options type used by ICrudService. Since 3.3.1.
PaginationOptionsinterface, the second argument of findAll and fullTextSearch: { page, limit, sortBy, sortOrder, withCount }. Since 3.3.1; withCount since 3.5.0.
SqlSearchOptionsinterface, options.search: { term, columns, mode }. Since 3.3.1.
SqlSearchMode'ilike' | 'fullText'. Since 3.3.1.
BulkOperationResultinterface, { success, data?, errors? }. Since 3.3.1.
BulkOperationItemErrorinterface, one entry of a BulkOperationException body: { index?, id?, status, message }. Since 3.3.1.
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'. The primaryKeyType setting that uses it is deprecated.
SortColumn{ column, order }.
SortOrder'asc' | 'desc'.
SortInputstring | Array<string | SortColumn>, the caller sortBy. Since 3.4.0.
CrudFilterthe filter object of findAll, findByCursor and count, groups included. Since 3.4.0.
FilterGroup{ and?, or?, not? }. Since 3.4.0.
FilterOperatorsevery filter operator and its operand. Since 3.4.0.
FilterOperatorkeyof FilterOperators. Since 3.4.0.
ColumnFilter, FilterScalarwhat one column accepts. Since 3.4.0.
CursorPaginationOptionsthe second argument of findByCursor. Since 3.4.0.
CursorPage{ data, limit, nextCursor, total? }. Since 3.4.0.
CrudAllowliststhe allowlist keys of SqlCrudConfig. Since 3.4.0; writableRelations since 3.5.0.
UpsertOptions{ conflictTarget?, update? }. Since 3.4.0.
BulkMode'set' | 'perItem'. Since 3.4.0.
ParseCrudQueryOptions, ParsedCrudQueryinput and output of parseCrudQuery. Since 3.4.0.
CollectionFilter, CollectionQuantifier{ some?, none?, every? } on a collection filter, and its keys. Since 3.5.0.
CrudPage, UncountedCrudPagethe findAll envelope; with withCount: false, total: null and hasMore. Since 3.5.0.
RelationCountsstring[] | Record<string, true | CrudFilter>, options.counts. Since 3.5.0.
CountByRow{ value, count }, one group of countBy. Since 3.5.0.
CrudScope, CrudScopeValues, CrudContextValuethe scope config, its column: value pairs, and the context it reads. Since 3.5.0.
CrudEvent, CrudEventPhase, CrudSubscriber, CrudWriteOperationwrite events and their subscribers. Since 3.5.0.
CrudControllerOptions, CrudControllerInstance, CrudRouteName, CrudRouteOptionsthe controller factory's options and result. Since 3.5.0.

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,
  between,
  desc,
  eq,
  gt,
  gte,
  ilike,
  inArray,
  isNotNull,
  isNull,
  like,
  lt,
  lte,
  ne,
  not,
  notInArray,
  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