Package exports reference
Every export of nestjs-drizzle-crud, the classes, functions, decorators, DI tokens, exceptions, types and Drizzle helpers you can import from the package root.
nestjs-drizzle-crud exports 98 names from its package root: 79 of its own (classes, functions, decorators, DI tokens, exceptions, test helpers and types) and 19 Drizzle helpers re-exported unchanged. Import all of them with import { ... } from "@avytrix/nestjs-drizzle-crud". Anything not listed here is internal and can change in any release.
The root is the only public entry point
src/index.ts is the public surface. Removing or renaming anything on this page is a major
version, so code that imports only from the root survives every minor and patch upgrade.
Core
| Export | Kind | Description |
|---|---|---|
SqlBaseCrudService | abstract class | The base class your services extend. See SqlBaseCrudService API reference. |
DrizzleCrudModule | class | The Nest module, with forRoot, forRootAsync and forFeature. |
CrudService | decorator | @CrudService(config) stores per-entity config on a service class. The forFeature config wins over it. |
parseCrudQuery | function | parseCrudQuery(query, table, options?) turns an HTTP query object into filters, pagination and options. Since 3.4.0. See NestJS query string filters for Drizzle. |
createCrudController | function | createCrudController(Service, options?) returns a controller class with list, trash, get, create, update, delete, soft delete, restore and bulk routes. Since 3.5.0. See NestJS CRUD controller generator. |
CrudContext | object | run(context, fn), current() and middleware(resolve): the per-request context a scope reads, kept in AsyncLocalStorage. Since 3.5.0. See Multi-tenancy. |
CrudEventBus | class | The module-level event bus behind hooks.enableGlobalHooks. forRoot and forRootAsync provide it globally; inject it and call subscribe. Since 3.5.0. See Events. |
DI tokens and connection
| Export | Kind | Description |
|---|---|---|
DRIZZLE_DB | string | Token for the resolved Drizzle instance. Inject it for hand-written queries outside a service. |
DRIZZLE_CONNECTION | string | Token for the DrizzleConnection wrapper. |
DRIZZLE_CRUD_CONFIG | string | Token for the normalized project config. |
DrizzleConnection | class | Holds db. Builds the PostgreSQL connection from a connectionString, or uses the db you passed, and closes only the connection it opened. |
OpenAPI
Both decorators need the optional peer @nestjs/swagger, loaded the first time one runs. Since 3.5.0. See NestJS Drizzle Swagger docs for lists.
| Export | Kind | Description |
|---|---|---|
ApiCrudQuery | decorator | ApiCrudQuery(source, options?) documents every list query parameter and each filterable column. |
ApiCrudList | decorator | ApiCrudQuery plus the 200 page envelope with the row schema. |
Exceptions
Every exception extends a Nest HttpException subclass, so the default exception filter maps it to its status without a custom filter, and you can match it with instanceof. See Error handling.
| Export | HTTP | When |
|---|---|---|
EntityNotFoundException | 404 | update, softDelete, restore or delete on a missing row, and per id in a mass write. |
DuplicateEntityException | 409 | A unique constraint is violated (Postgres 23505). |
StaleVersionException | 409 | Optimistic locking: a write named a version the row is no longer at. Since 3.5.0. |
EntityInUseException | 409 | delete while other rows still reference the row (23503). |
MissingScopeException | 403 | A scoped entity was used without the context value its scope needs. Since 3.5.0. |
ForeignKeyViolationException | 400 | create or update references a parent row that does not exist (23503). Names the column. |
ValidationFailedException | 400 | Bad input: a value the column cannot take, an update with nothing to set, a column outside writableColumns. Throw it from your validation hooks too. |
BulkOperationException | 400 | A bulk method rolled back. The body lists each failed item as { index | id, status, message }; the errors property keeps the original errors. |
DatabaseConnectionException | 500 | Deprecated. Nothing throws it. Removed in the next major version. |
TransactionException | 500 | The driver cannot run the transaction a call needs (Cloudflare D1, synchronous SQLite drivers). Thrown since 3.7.0; it was deprecated before. A failed transaction still rejects with its own error. |
Test utilities
| Export | Kind | Description |
|---|---|---|
TestCrudFactory | class | Static createTestService, createMockDb, createMockTable and createMockEntity. The mocks use jest.fn(), so they need Jest globals. |
BaseCrudSpecHelper | class | Builds a service on a mock database and returns ready-made find, create, update, delete and list scenarios. |
See Testing.
Types
All type-only exports. Import them with import type.
| Export | Description |
|---|---|
DrizzleCrudConfig | The input to forRoot and forRootAsync. |
DrizzleConnectionOptions | connection in DrizzleCrudConfig: { poolSize?, idleTimeout?, ssl? } for the connection the module builds. Since 3.7.0. |
DrizzleCrudAsyncOptions | The argument of forRootAsync: useFactory, useClass or useExisting, with imports and inject. Since 3.7.0. |
DrizzleCrudOptionsFactory | The class shape useClass and useExisting expect: createDrizzleCrudOptions(). Since 3.7.0. |
SqlCrudConfig | The merged per-entity config. |
CrudFeature | One entry of forFeature: { service, table, config? }. |
CrudFeatureConfig | The per-entity config of forFeature. Since 3.3.1. |
SqlOperationOptions | The options argument of every method. |
SqlSearchOptions, SqlSearchMode | options.search: { term, columns, mode?, language?, queryMode? }, and "ilike" | "fullText". Since 3.3.1. |
FullTextOptions, FullTextQueryMode | { language?, queryMode? } and "plain" | "websearch". Since 3.7.0. |
FullTextSearchOptions | The options argument of fullTextSearch: SqlOperationOptions plus filters, language and queryMode. Since 3.7.0. |
PaginationOptions | The pagination argument of findAll and fullTextSearch: { page, limit, sortBy, sortOrder, withCount }. Since 3.3.1. |
ICrudService | The interface SqlBaseCrudService implements. |
OperationOptions | The options type of ICrudService. Since 3.3.1. |
BulkOperationResult | { success, data?, errors? }. Since 3.3.1. |
BulkOperationItemError | One entry of a BulkOperationException body: { index?, id?, status, message }. Since 3.3.1. |
RelationConfig, RelationsConfig, RelationType | One relation, a record of them, and "belongsTo" | "hasMany" | "manyToMany". |
RelationNode, SelectTree | The resolved eager-loading plan and the parsed options.select. |
SqlDialect | "postgresql" | "mysql" | "sqlite". "sqlite" since 3.7.0. |
PrimaryKeyType | "serial" | "bigserial" | "int" | "bigint" | "uuid". The setting that uses it is deprecated. |
SortColumn, SortOrder | { column, order? } and "asc" | "desc". |
SortInput | string | Array<string | SortColumn>, the caller sortBy. Since 3.4.0. |
CrudFilter, FilterGroup | The filter object of findAll, findByCursor and count, and its { and?, or?, not? } groups. Since 3.4.0. |
FilterOperators, FilterOperator | Every filter operator with its operand, and the operator names. Since 3.4.0. |
ColumnFilter, FilterScalar | What one column accepts. Since 3.4.0. |
CursorPaginationOptions, CursorPage | The input and result of findByCursor. 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 | The options and result of parseCrudQuery and parseQuery. 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, and the one with total: null and hasMore. Since 3.5.0. |
RelationCounts | options.counts: string[] | Record<string, true | CrudFilter>. 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. |
ApiCrudSource, ApiCrudQueryOptions | What the OpenAPI decorators describe ({ table, ...allowlists } or a @CrudService class) and their options ({ cursor?, trash? }). Since 3.5.0. |
The full definitions are on Config types reference.
Re-exported Drizzle helpers
These are pass-throughs from drizzle-orm, re-exported so a custom method or mapCreateDtoToEntity override needs one import. The package does not wrap or change them.
import {
and,
asc,
between,
desc,
eq,
gt,
gte,
ilike,
inArray,
isNotNull,
isNull,
like,
lt,
lte,
ne,
not,
notInArray,
or,
sql,
} from "@avytrix/nestjs-drizzle-crud";What is not exported?
The module's internal helpers (normalizeConfig, buildEntityConfig, connectionProviders), the DRIZZLE_RAW_CONFIG token, and the service's private methods are not part of the API. If you need one of them, open an issue on the issue tracker: the public API may need a hook.
Common questions
98: 79 of its own and 19 Drizzle helpers. Of its own, 25 are runtime values (classes, functions, decorators, tokens, exceptions and test helpers) and 54 are types.
No. nestjs-drizzle-crud-mcp is a command-line binary in the package, not an import. Run it with npx -p @avytrix/nestjs-drizzle-crud nestjs-drizzle-crud-mcp.
Deep paths are internal and can change in any release. Import from the package root only.
So code that extends a service can build conditions with eq, and or sql from the same import. They are the drizzle-orm functions themselves, unchanged.
Next steps
SqlBaseCrudService API reference
Every method, its signature and what it throws.
Config types reference
The full definition of every exported type.
For AI agents
The condensed fact sheet for code generation.
Config types reference
The nestjs-drizzle-crud config types, DrizzleCrudConfig for forRoot and SqlCrudConfig per entity, with every option, default and type the methods take.
nestjs-drizzle-crud facts for AI agents
A condensed fact sheet of nestjs-drizzle-crud for AI coding agents, with setup, generics, return shapes, filters, relations, errors and anti-patterns.