Skip to main content

API Reference

This page lists the first-version public API. The package may add APIs as samples and driver coverage grow, but this surface is the supported baseline.

Modules​

DrizzleModule.forRoot(options)​

Registers a Drizzle client and optional schema.

DrizzleModule.forRoot({
schema,
connection: db,
shutdown: client => client.$client.close(),
});

Options:

OptionPurpose
connectionExisting Drizzle client or a factory returning one
schemaStandard Drizzle schema object, stored as-is
connectionNameOptional name for multi-database applications
isGlobalDefaults to true; set false for module-scoped registration
shutdownOptional hook called during Nest module destruction

DrizzleModule.forRootAsync(options)​

Registers a Drizzle client from an async or provider-backed factory.

DrizzleModule.forRootAsync({
inject: [ConfigService],
useFactory: async config => ({
schema,
connection: createDb(config),
}),
});

DrizzleModule.forFeature(repositories)​

Registers repository classes as providers and exports them from the dynamic module.

Decorators​

@InjectDrizzle(connectionName?)​

Injects a registered Drizzle client.

@DrizzleRepository(options?)​

Marks a class as a Drizzle repository. The class is still a normal Nest provider and should be registered through forFeature().

@Transactional(options?)​

Re-exports the transaction decorator from the CLS transaction stack.

@InjectTransaction(connectionName?)​

Injects the active transaction object from the CLS transaction stack.

Testing​

DrizzleTestModule.forRoot(options)​

Registers a test client under the same tokens as DrizzleModule.

DrizzleTestModule.forFeature(repositories)​

Registers repository providers for tests.

createDrizzleMockClient(overrides)​

Creates a shallow typed object mock for direct client injection tests.

createDrizzleRepositoryMock(methods)​

Creates a shallow typed repository mock for service tests.

Token Helpers​

getDrizzleClientToken(), getDrizzleSchemaToken(), getDrizzleOptionsToken(), and getDrizzleConnectionManagerToken() are exported for advanced integration and testing scenarios. Prefer decorators in application code unless an external integration needs the exact provider token.