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
| Export | Kind | Description |
|---|---|---|
SqlBaseCrudService | class | The base class your services extend. See API reference. |
parseCrudQuery | function | parseCrudQuery(query, table, options?) turns an HTTP query object into filters, pagination and options. Since 3.4.0. See Parse query strings. |
createCrudController | function | createCrudController(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. |
CrudContext | object | run(context, fn), current() and middleware(resolve): the per-request context a scope reads, in AsyncLocalStorage. Since 3.5.0. See Multi-tenancy. |
CrudEventBus | class | The 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.
| Export | Kind | Description |
|---|---|---|
ApiCrudQuery | decorator | Documents every list query parameter and each filterable column. |
ApiCrudList | decorator | ApiCrudQuery plus the 200 page envelope with the row schema. |
ApiCrudSource, ApiCrudQueryOptions | types | The decorators' source ({ table, ...allowlists } or a @CrudService class) and options ({ cursor?, trash? }). |
Module & DI tokens
| Export | Kind | Description |
|---|---|---|
DrizzleCrudModule | class | The Nest module. Has forRoot, forRootAsync, forFeature static methods. |
DRIZZLE_DB | string | DI token for the resolved Drizzle instance. |
DRIZZLE_CONNECTION | string | DI token for the connection wrapper. |
DRIZZLE_CRUD_CONFIG | string | DI token for the normalized global config. |
CrudEventBus | class | Also a provider: forRoot / forRootAsync register and export it globally. |
DrizzleConnection | class | The internal connection wrapper. Exposed for advanced use. |
Decorators
| Export | Kind | Description |
|---|---|---|
CrudService | decorator | Attach 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.
| Export | HTTP | Description |
|---|---|---|
EntityNotFoundException | 404 | Thrown by update, restore, massUpdate, massRestore when the row doesn't exist. |
DuplicateEntityException | 409 | Thrown by create / update when a unique constraint is violated (Postgres SQLSTATE 23505). |
ForeignKeyViolationException | 400 | Thrown by create / update when a supplied foreign key references no existing row (23503). Names the offending column. |
StaleVersionException | 409 | Optimistic locking: a write named a version the row is no longer at. Since 3.5.0. See Optimistic locking. |
MissingScopeException | 403 | A scoped entity was used without the context value its scope needs. Since 3.5.0. See Multi-tenancy. |
EntityInUseException | 409 | Thrown by delete when other rows still reference this one (23503, ON DELETE RESTRICT or NO ACTION). |
ValidationFailedException | 400 | Throw this from your validateCreate / validateUpdate hooks to reject bad input. |
BulkOperationException | 400 | Thrown 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. |
DatabaseConnectionException | 500 | Deprecated. Nothing in the package throws it. Removed in the next major version. |
TransactionException | 500 | Deprecated. Nothing in the package throws it; a failed transaction rejects with its own error. Removed in the next major version. |
Types
| Export | Kind |
|---|---|
ICrudService | interface, the abstract shape SqlBaseCrudService implements. |
CrudFeature | type, the input to forFeature. |
CrudFeatureConfig | type, the per-entity config of forFeature. Since 3.3.1. |
DrizzleCrudConfig | type, input to forRoot / forRootAsync. |
SqlCrudConfig | interface, the per-entity merged config. |
SqlOperationOptions | interface, the third argument to most methods, including search for findAll and count. |
OperationOptions | interface, the options type used by ICrudService. Since 3.3.1. |
PaginationOptions | interface, the second argument of findAll and fullTextSearch: { page, limit, sortBy, sortOrder, withCount }. Since 3.3.1; withCount since 3.5.0. |
SqlSearchOptions | interface, options.search: { term, columns, mode }. Since 3.3.1. |
SqlSearchMode | 'ilike' | 'fullText'. Since 3.3.1. |
BulkOperationResult | interface, { success, data?, errors? }. Since 3.3.1. |
BulkOperationItemError | interface, one entry of a BulkOperationException body: { index?, id?, status, message }. Since 3.3.1. |
RelationConfig | interface, describes one relation in relations. |
RelationsConfig | type, a record of RelationConfig. |
RelationType | 'belongsTo' | 'hasMany' | 'manyToMany'. |
RelationNode | interface, one resolved node in an eager-loading plan. |
SelectTree | interface, 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'. |
SortInput | string | Array<string | SortColumn>, the caller sortBy. Since 3.4.0. |
CrudFilter | the filter object of findAll, findByCursor and count, groups included. Since 3.4.0. |
FilterGroup | { and?, or?, not? }. Since 3.4.0. |
FilterOperators | every filter operator and its operand. Since 3.4.0. |
FilterOperator | keyof FilterOperators. Since 3.4.0. |
ColumnFilter, FilterScalar | what one column accepts. Since 3.4.0. |
CursorPaginationOptions | the second argument of findByCursor. Since 3.4.0. |
CursorPage | { data, limit, nextCursor, total? }. Since 3.4.0. |
CrudAllowlists | the 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, ParsedCrudQuery | input 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, UncountedCrudPage | the findAll envelope; with withCount: false, total: null and hasMore. Since 3.5.0. |
RelationCounts | string[] | Record<string, true | CrudFilter>, options.counts. Since 3.5.0. |
CountByRow | { value, count }, one group of countBy. Since 3.5.0. |
CrudScope, CrudScopeValues, CrudContextValue | the scope config, its column: value pairs, and the context it reads. Since 3.5.0. |
CrudEvent, CrudEventPhase, CrudSubscriber, CrudWriteOperation | write events and their subscribers. Since 3.5.0. |
CrudControllerOptions, CrudControllerInstance, CrudRouteName, CrudRouteOptions | the 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
| Export | Description |
|---|---|
TestCrudFactory | Class with createMockDb, createMockTable, createMockEntity, createTestService. |
BaseCrudSpecHelper | A higher-level helper that builds a full service + fixtures. |
See Testing for usage.
Binaries
| Command | Description |
|---|---|
nestjs-drizzle-crud-mcp | MCP 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 internalconnectionProviders/buildEntityConfig/normalizeConfighelpers.- The internal
DRIZZLE_RAW_CONFIGtoken.
If you find yourself reaching for these, open a feature request. The public API may need a hook.