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

ExportKindDescription
SqlBaseCrudServiceabstract classThe base class your services extend. See SqlBaseCrudService API reference.
DrizzleCrudModuleclassThe Nest module, with forRoot, forRootAsync and forFeature.
CrudServicedecorator@CrudService(config) stores per-entity config on a service class. The forFeature config wins over it.
parseCrudQueryfunctionparseCrudQuery(query, table, options?) turns an HTTP query object into filters, pagination and options. Since 3.4.0. See NestJS query string filters for Drizzle.
createCrudControllerfunctioncreateCrudController(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.
CrudContextobjectrun(context, fn), current() and middleware(resolve): the per-request context a scope reads, kept in AsyncLocalStorage. Since 3.5.0. See Multi-tenancy.
CrudEventBusclassThe 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

ExportKindDescription
DRIZZLE_DBstringToken for the resolved Drizzle instance. Inject it for hand-written queries outside a service.
DRIZZLE_CONNECTIONstringToken for the DrizzleConnection wrapper.
DRIZZLE_CRUD_CONFIGstringToken for the normalized project config.
DrizzleConnectionclassHolds 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.

ExportKindDescription
ApiCrudQuerydecoratorApiCrudQuery(source, options?) documents every list query parameter and each filterable column.
ApiCrudListdecoratorApiCrudQuery 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.

ExportHTTPWhen
EntityNotFoundException404update, softDelete, restore or delete on a missing row, and per id in a mass write.
DuplicateEntityException409A unique constraint is violated (Postgres 23505).
StaleVersionException409Optimistic locking: a write named a version the row is no longer at. Since 3.5.0.
EntityInUseException409delete while other rows still reference the row (23503).
MissingScopeException403A scoped entity was used without the context value its scope needs. Since 3.5.0.
ForeignKeyViolationException400create or update references a parent row that does not exist (23503). Names the column.
ValidationFailedException400Bad input: a value the column cannot take, an update with nothing to set, a column outside writableColumns. Throw it from your validation hooks too.
BulkOperationException400A bulk method rolled back. The body lists each failed item as { index | id, status, message }; the errors property keeps the original errors.
DatabaseConnectionException500Deprecated. Nothing throws it. Removed in the next major version.
TransactionException500The 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

ExportKindDescription
TestCrudFactoryclassStatic createTestService, createMockDb, createMockTable and createMockEntity. The mocks use jest.fn(), so they need Jest globals.
BaseCrudSpecHelperclassBuilds 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.

ExportDescription
DrizzleCrudConfigThe input to forRoot and forRootAsync.
DrizzleConnectionOptionsconnection in DrizzleCrudConfig: { poolSize?, idleTimeout?, ssl? } for the connection the module builds. Since 3.7.0.
DrizzleCrudAsyncOptionsThe argument of forRootAsync: useFactory, useClass or useExisting, with imports and inject. Since 3.7.0.
DrizzleCrudOptionsFactoryThe class shape useClass and useExisting expect: createDrizzleCrudOptions(). Since 3.7.0.
SqlCrudConfigThe merged per-entity config.
CrudFeatureOne entry of forFeature: { service, table, config? }.
CrudFeatureConfigThe per-entity config of forFeature. Since 3.3.1.
SqlOperationOptionsThe options argument of every method.
SqlSearchOptions, SqlSearchModeoptions.search: { term, columns, mode?, language?, queryMode? }, and "ilike" | "fullText". Since 3.3.1.
FullTextOptions, FullTextQueryMode{ language?, queryMode? } and "plain" | "websearch". Since 3.7.0.
FullTextSearchOptionsThe options argument of fullTextSearch: SqlOperationOptions plus filters, language and queryMode. Since 3.7.0.
PaginationOptionsThe pagination argument of findAll and fullTextSearch: { page, limit, sortBy, sortOrder, withCount }. Since 3.3.1.
ICrudServiceThe interface SqlBaseCrudService implements.
OperationOptionsThe options type of ICrudService. Since 3.3.1.
BulkOperationResult{ success, data?, errors? }. Since 3.3.1.
BulkOperationItemErrorOne entry of a BulkOperationException body: { index?, id?, status, message }. Since 3.3.1.
RelationConfig, RelationsConfig, RelationTypeOne relation, a record of them, and "belongsTo" | "hasMany" | "manyToMany".
RelationNode, SelectTreeThe 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".
SortInputstring | Array<string | SortColumn>, the caller sortBy. Since 3.4.0.
CrudFilter, FilterGroupThe filter object of findAll, findByCursor and count, and its { and?, or?, not? } groups. Since 3.4.0.
FilterOperators, FilterOperatorEvery filter operator with its operand, and the operator names. Since 3.4.0.
ColumnFilter, FilterScalarWhat one column accepts. Since 3.4.0.
CursorPaginationOptions, CursorPageThe input and result of findByCursor. 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, ParsedCrudQueryThe 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, UncountedCrudPageThe findAll envelope, and the one with total: null and hasMore. Since 3.5.0.
RelationCountsoptions.counts: string[] | Record<string, true | CrudFilter>. 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.
ApiCrudSource, ApiCrudQueryOptionsWhat 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.

users.service.ts
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

Next steps

Last updated View change history

On this page