hono-crud 0.1.4 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +71 -0
  3. package/dist/adapters/drizzle/index.d.ts +443 -270
  4. package/dist/adapters/drizzle/index.js +441 -156
  5. package/dist/adapters/memory/index.d.ts +82 -39
  6. package/dist/adapters/memory/index.js +5 -1247
  7. package/dist/adapters/prisma/index.d.ts +107 -155
  8. package/dist/adapters/prisma/index.js +382 -366
  9. package/dist/auth/index.d.ts +478 -0
  10. package/dist/auth/index.js +4 -0
  11. package/dist/bulk-patch-C1j76FUv.d.ts +141 -0
  12. package/dist/cache/index.d.ts +425 -0
  13. package/dist/cache/index.js +5 -0
  14. package/dist/chunk-6LS3LNIH.js +158 -0
  15. package/dist/chunk-CNE7UR5E.js +175 -0
  16. package/dist/chunk-FST5S5UY.js +304 -0
  17. package/dist/chunk-IPGNLIJV.js +199 -0
  18. package/dist/chunk-MANRQHEB.js +330 -0
  19. package/dist/{chunk-U3LNOTK5.js → chunk-NTQNZZSH.js} +153 -1066
  20. package/dist/chunk-OKVSQZMU.js +1695 -0
  21. package/dist/chunk-SCC4CBTS.js +142 -0
  22. package/dist/chunk-U3SUUXJK.js +770 -0
  23. package/dist/chunk-WOFE46VS.js +1214 -0
  24. package/dist/chunk-XYVTFG7O.js +947 -0
  25. package/dist/chunk-YJMGFVHZ.js +220 -0
  26. package/dist/chunk-ZCHXXN7T.js +44 -0
  27. package/dist/{import-C5LLxomK.d.ts → import-C4cjkYZ1.d.ts} +42 -1316
  28. package/dist/index-BVaCSKwG.d.ts +272 -0
  29. package/dist/index-Dm8-ODYA.d.ts +420 -0
  30. package/dist/index.d.ts +1997 -3718
  31. package/dist/index.js +2014 -3584
  32. package/dist/logging/index.d.ts +299 -0
  33. package/dist/logging/index.js +5 -0
  34. package/dist/memory-B_NZbOQP.d.ts +462 -0
  35. package/dist/rate-limit/index.d.ts +6 -0
  36. package/dist/rate-limit/index.js +5 -0
  37. package/dist/route-BCROG0Mx.d.ts +64 -0
  38. package/dist/storage/index.d.ts +368 -0
  39. package/dist/storage/index.js +5 -0
  40. package/dist/types-B8CWg4nO.d.ts +327 -0
  41. package/dist/types-Bc7ebF5x.d.ts +236 -0
  42. package/dist/types-CwJSGrCj.d.ts +982 -0
  43. package/dist/types-DlIkjpdK.d.ts +139 -0
  44. package/dist/ui-CNJUoCg1.d.ts +148 -0
  45. package/dist/ui.d.ts +2 -0
  46. package/dist/ui.js +1 -0
  47. package/dist/versioning-4Pn5V1ed.d.ts +291 -0
  48. package/package.json +32 -6
@@ -1,288 +1,186 @@
1
+ import { Table, SQL, Column } from 'drizzle-orm';
2
+ import { M as MetaInput, I as IncludeOptions, F as FilterCondition, g as RelationConfig, h as NestedUpdateInput, i as NestedWriteResult, L as ListFilters, P as PaginatedResult, j as AggregateOptions, k as AggregateResult, S as SearchOptions, l as SearchResult } from '../../types-CwJSGrCj.js';
1
3
  import { Env } from 'hono';
2
- import { Table, SQL, InferSelectModel, Column } from 'drizzle-orm';
4
+ import { C as CreateEndpoint, M as ModelObject, R as ReadEndpoint, U as UpdateEndpoint, D as DeleteEndpoint, L as ListEndpoint, a as RestoreEndpoint, B as BatchCreateEndpoint, b as BatchDeleteEndpoint, c as BatchRestoreEndpoint, d as BatchUpdateEndpoint, e as BatchUpdateItem, A as AggregateEndpoint, f as BatchUpsertEndpoint, g as UpsertEndpoint, E as ExportEndpoint, I as ImportEndpoint, S as SearchEndpoint, V as VersionCompareEndpoint, h as VersionHistoryEndpoint, i as VersionReadEndpoint, j as VersionRollbackEndpoint } from '../../import-C4cjkYZ1.js';
5
+ import { A as AdapterBundle } from '../../index-BVaCSKwG.js';
3
6
  import { z } from 'zod';
4
- import { M as MetaInput, d as AggregateEndpoint, g as AggregateOptions, h as AggregateResult, B as BatchCreateEndpoint, ak as ModelObject, n as BatchDeleteEndpoint, p as BatchRestoreEndpoint, r as BatchUpdateEndpoint, s as BatchUpdateItem, u as BatchUpsertEndpoint, F as CreateEndpoint, aA as RelationConfig, L as DeleteEndpoint, P as ExportEndpoint, af as ListFilters, ax as PaginatedResult, a2 as ImportEndpoint, ad as ListEndpoint, az as ReadEndpoint, a9 as IncludeOptions, aE as RestoreEndpoint, aI as SearchEndpoint, aJ as SearchOptions, aK as SearchResult, aP as UpdateEndpoint, ap as NestedUpdateInput, ar as NestedWriteResult, aR as UpsertEndpoint, aU as VersionCompareEndpoint, aV as VersionHistoryEndpoint, aY as VersionReadEndpoint, aZ as VersionRollbackEndpoint } from '../../import-C5LLxomK.js';
5
- import 'hono/utils/http-status';
6
7
  import '@hono/zod-openapi';
8
+ import '../../route-BCROG0Mx.js';
9
+ import 'hono/utils/http-status';
10
+ import '../../versioning-4Pn5V1ed.js';
7
11
 
8
12
  /**
9
- * Drizzle-Zod schema utilities.
10
- *
11
- * This module provides helpers for generating Zod schemas from Drizzle tables
12
- * using drizzle-zod. This allows automatic schema generation for CRUD operations.
13
- *
14
- * Note: drizzle-zod is an optional peer dependency. These utilities will only
15
- * work if drizzle-zod is installed.
16
- *
17
- * @example
18
- * ```ts
19
- * import { pgTable, text, timestamp, uuid } from 'drizzle-orm/pg-core';
20
- * import { createDrizzleSchemas } from 'hono-crud/adapters/drizzle';
21
- *
22
- * const users = pgTable('users', {
23
- * id: uuid('id').primaryKey().defaultRandom(),
24
- * name: text('name').notNull(),
25
- * email: text('email').notNull().unique(),
26
- * createdAt: timestamp('created_at').defaultNow(),
27
- * });
28
- *
29
- * const { select: UserSchema, insert: CreateUserSchema } = createDrizzleSchemas(users);
30
- * ```
13
+ * Internal query builder interface used for type-safe method calls.
14
+ * All Drizzle query builders satisfy this interface at runtime.
15
+ */
16
+ interface QueryBuilder extends PromiseLike<unknown[]> {
17
+ where(condition: unknown): QueryBuilder;
18
+ limit(n: number): QueryBuilder;
19
+ offset(n: number): QueryBuilder;
20
+ orderBy(...columns: unknown[]): QueryBuilder;
21
+ set(data: Record<string, unknown>): QueryBuilder;
22
+ values(data: Record<string, unknown> | Record<string, unknown>[]): QueryBuilder;
23
+ returning(): QueryBuilder;
24
+ onConflictDoUpdate(config: {
25
+ target: unknown[];
26
+ set: Record<string, unknown>;
27
+ where?: unknown;
28
+ }): QueryBuilder;
29
+ onConflictDoNothing(config?: {
30
+ target?: unknown[];
31
+ }): QueryBuilder;
32
+ onDuplicateKeyUpdate(config: {
33
+ set: Record<string, unknown>;
34
+ }): QueryBuilder;
35
+ }
36
+ /**
37
+ * Internal database interface used for type-safe method calls.
38
+ * All Drizzle databases (PostgreSQL, MySQL, SQLite) satisfy this interface at runtime.
31
39
  */
32
-
40
+ interface Database {
41
+ select(fields?: Record<string, unknown>): {
42
+ from(table: Table): QueryBuilder;
43
+ };
44
+ insert(table: Table): QueryBuilder;
45
+ update(table: Table): QueryBuilder;
46
+ delete(table: Table): QueryBuilder;
47
+ transaction<T>(fn: (tx: Database) => Promise<T>): Promise<T>;
48
+ }
33
49
  /**
34
- * Re-export createSelectSchema from drizzle-zod.
35
- * Creates a Zod schema for SELECT queries (all columns as required/optional based on table definition).
36
- *
37
- * @param table - Drizzle table definition
38
- * @param refine - Optional refinements for specific columns
39
- * @returns Zod schema for the table's select type
40
- *
41
- * @example
42
- * ```ts
43
- * import { users } from './schema';
44
- * import { createSelectSchema } from 'hono-crud/adapters/drizzle';
45
- *
46
- * const UserSchema = createSelectSchema(users);
47
- * type User = z.infer<typeof UserSchema>;
48
- * ```
50
+ * Casts a database to the internal Database interface for method calls.
51
+ * This is safe because all Drizzle databases have these methods at runtime.
49
52
  */
50
- declare function createSelectSchema<T extends Table>(table: T, refine?: Record<string, z.ZodTypeAny>): z.ZodObject<Record<string, z.ZodTypeAny>>;
53
+ declare function cast<T>(instance: T): Database;
51
54
  /**
52
- * Re-export createInsertSchema from drizzle-zod.
53
- * Creates a Zod schema for INSERT queries (columns with defaults become optional).
54
- *
55
- * @param table - Drizzle table definition
56
- * @param refine - Optional refinements for specific columns
57
- * @returns Zod schema for the table's insert type
55
+ * Base constraint for Drizzle database types.
56
+ * Your database type must have select, insert, update, delete, and transaction methods.
58
57
  *
59
58
  * @example
60
59
  * ```ts
61
- * import { users } from './schema';
62
- * import { createInsertSchema } from 'hono-crud/adapters/drizzle';
60
+ * import { drizzle } from 'drizzle-orm/postgres-js';
61
+ * import * as schema from './schema';
63
62
  *
64
- * const CreateUserSchema = createInsertSchema(users);
65
- * type CreateUser = z.infer<typeof CreateUserSchema>;
63
+ * const database = drizzle(client, { schema });
64
+ *
65
+ * // Pass typeof database as the DB generic parameter
66
+ * class UserCreate extends DrizzleCreateEndpoint<Env, UserMeta, typeof database> {
67
+ * db = database; // Full type safety!
68
+ * }
66
69
  * ```
67
70
  */
68
- declare function createInsertSchema<T extends Table>(table: T, refine?: Record<string, z.ZodTypeAny>): z.ZodObject<Record<string, z.ZodTypeAny>>;
71
+ interface DrizzleDatabaseConstraint {
72
+ select: unknown;
73
+ insert: unknown;
74
+ update: unknown;
75
+ delete: unknown;
76
+ transaction: unknown;
77
+ }
69
78
  /**
70
- * Re-export createUpdateSchema from drizzle-zod (if available).
71
- * Creates a Zod schema for UPDATE queries (all columns become optional).
72
- *
73
- * Note: createUpdateSchema may not be available in older versions of drizzle-zod.
74
- * Use createInsertSchema(table).partial() as an alternative.
75
- *
76
- * @param table - Drizzle table definition
77
- * @param refine - Optional refinements for specific columns
78
- * @returns Zod schema for the table's update type
79
- *
80
- * @example
81
- * ```ts
82
- * import { users } from './schema';
83
- * import { createUpdateSchema } from 'hono-crud/adapters/drizzle';
84
- *
85
- * const UpdateUserSchema = createUpdateSchema(users);
86
- * type UpdateUser = z.infer<typeof UpdateUserSchema>;
87
- * ```
79
+ * @deprecated Pass your database type as a generic parameter instead
88
80
  */
89
- declare function createUpdateSchema<T extends Table>(table: T, refine?: Record<string, z.ZodTypeAny>): z.ZodObject<Record<string, z.ZodTypeAny>>;
81
+ type DrizzleDatabase = DrizzleDatabaseConstraint;
90
82
  /**
91
- * Result of createDrizzleSchemas helper.
83
+ * @deprecated Pass your database type as a generic parameter instead
92
84
  */
93
- interface DrizzleSchemas {
94
- /** Schema for SELECT queries (full record) */
95
- select: z.ZodObject<Record<string, z.ZodTypeAny>>;
96
- /** Schema for INSERT queries (required fields only) */
97
- insert: z.ZodObject<Record<string, z.ZodTypeAny>>;
98
- /** Schema for UPDATE queries (all fields optional) */
99
- update: z.ZodObject<Record<string, z.ZodTypeAny>>;
100
- }
85
+ type DrizzleDB = DrizzleDatabaseConstraint;
101
86
  /**
102
- * Creates all three common schemas (select, insert, update) for a Drizzle table.
103
- *
104
- * This is a convenience helper that generates:
105
- * - `select`: Full record schema for reading data
106
- * - `insert`: Schema for creating new records
107
- * - `update`: Partial schema for updating records
108
- *
109
- * @param table - Drizzle table definition
110
- * @param options - Optional configuration
111
- * @param options.insertRefine - Refinements for insert schema
112
- * @param options.selectRefine - Refinements for select schema
113
- * @param options.updateRefine - Refinements for update schema
114
- * @returns Object containing select, insert, and update schemas
87
+ * Type helper for defining Hono Env with database in Variables.
88
+ * Use this when injecting the database via middleware.
115
89
  *
116
90
  * @example
117
91
  * ```ts
118
- * import { pgTable, text, uuid } from 'drizzle-orm/pg-core';
119
- * import { createDrizzleSchemas, defineModel, defineMeta } from 'hono-crud/adapters/drizzle';
120
- * import { z } from 'zod';
92
+ * import { DrizzleEnv } from 'hono-crud/adapters/drizzle';
121
93
  *
122
- * const users = pgTable('users', {
123
- * id: uuid('id').primaryKey().defaultRandom(),
124
- * name: text('name').notNull(),
125
- * email: text('email').notNull().unique(),
126
- * });
94
+ * type AppEnv = DrizzleEnv<typeof db>;
127
95
  *
128
- * // Generate schemas from table
129
- * const schemas = createDrizzleSchemas(users, {
130
- * insertRefine: {
131
- * email: z.string().email(), // Add email validation
132
- * },
133
- * });
96
+ * const app = new Hono<AppEnv>();
134
97
  *
135
- * // Use with hono-crud model
136
- * const UserModel = defineModel({
137
- * tableName: 'users',
138
- * schema: schemas.select,
139
- * primaryKeys: ['id'],
140
- * table: users,
98
+ * app.use('*', async (c, next) => {
99
+ * c.set('db', db);
100
+ * await next();
141
101
  * });
142
- * ```
143
- */
144
- declare function createDrizzleSchemas<T extends Table>(table: T, options?: {
145
- insertRefine?: Record<string, z.ZodTypeAny>;
146
- selectRefine?: Record<string, z.ZodTypeAny>;
147
- updateRefine?: Record<string, z.ZodTypeAny>;
148
- }): DrizzleSchemas;
149
- /**
150
- * Async version of createDrizzleSchemas that handles lazy loading.
151
- * Use this if you're not sure drizzle-zod is already loaded.
152
102
  *
153
- * @param table - Drizzle table definition
154
- * @param options - Optional configuration
155
- * @returns Promise resolving to schemas object
156
- */
157
- declare function createDrizzleSchemasAsync<T extends Table>(table: T, options?: {
158
- insertRefine?: Record<string, z.ZodTypeAny>;
159
- selectRefine?: Record<string, z.ZodTypeAny>;
160
- updateRefine?: Record<string, z.ZodTypeAny>;
161
- }): Promise<DrizzleSchemas>;
162
- /**
163
- * Checks if drizzle-zod is available.
164
- * @returns true if drizzle-zod can be imported
165
- */
166
- declare function isDrizzleZodAvailable(): boolean;
167
-
168
- /**
169
- * Query builder type returned by select().from()
103
+ * // Endpoints can now access db from context automatically
104
+ * class ProjectCreate extends DrizzleCreateEndpoint<AppEnv, typeof projectMeta> {
105
+ * _meta = projectMeta;
106
+ * // No db property needed - comes from context!
107
+ * }
108
+ * ```
170
109
  */
171
- interface DrizzleSelectQuery<T = unknown> {
172
- where(condition?: SQL): DrizzleSelectQuery<T>;
173
- limit(n: number): DrizzleSelectQuery<T>;
174
- offset(n: number): DrizzleSelectQuery<T>;
175
- orderBy(...columns: SQL[]): DrizzleSelectQuery<T>;
176
- from(table: Table): DrizzleSelectQuery<T>;
177
- then<TResult>(onfulfilled?: (value: T[]) => TResult | PromiseLike<TResult>): Promise<TResult>;
178
- }
110
+ type DrizzleEnv<DB = DrizzleDatabaseConstraint> = {
111
+ Variables: {
112
+ db: DB;
113
+ };
114
+ };
179
115
  /**
180
- * Configuration for ON CONFLICT DO UPDATE (PostgreSQL/SQLite)
116
+ * Gets the Drizzle table from the model.
181
117
  */
182
- interface OnConflictDoUpdateConfig<T = unknown> {
183
- /** Target columns for conflict detection */
184
- target: Column[];
185
- /** Data to set on conflict */
186
- set: Record<string, unknown>;
187
- /** Optional where clause for conditional update */
188
- where?: SQL;
189
- }
118
+ declare function getTable<M extends MetaInput>(meta: M): Table;
190
119
  /**
191
- * Insert query builder type with upsert support
120
+ * Gets a column from the table with proper type safety.
121
+ * Uses drizzle-orm's getTableColumns for type-safe column access.
122
+ *
123
+ * @param table - The Drizzle table
124
+ * @param field - The field/column name
125
+ * @returns The column
126
+ * @throws Error if the column is not found in the table
192
127
  */
193
- interface DrizzleInsertQuery<T = unknown> {
194
- values(data: Record<string, unknown> | Record<string, unknown>[]): DrizzleInsertQuery<T>;
195
- returning(): Promise<T[]>;
196
- /**
197
- * PostgreSQL/SQLite: ON CONFLICT DO UPDATE
198
- */
199
- onConflictDoUpdate(config: OnConflictDoUpdateConfig<T>): DrizzleInsertQuery<T>;
200
- /**
201
- * PostgreSQL/SQLite: ON CONFLICT DO NOTHING
202
- */
203
- onConflictDoNothing(config?: {
204
- target?: Column[];
205
- }): DrizzleInsertQuery<T>;
206
- /**
207
- * MySQL: ON DUPLICATE KEY UPDATE
208
- */
209
- onDuplicateKeyUpdate(config: {
210
- set: Record<string, unknown>;
211
- }): DrizzleInsertQuery<T>;
212
- }
128
+ declare function getColumn(table: Table, field: string): Column;
213
129
  /**
214
- * Update query builder type
130
+ * Loads related records for a given item using Drizzle queries.
215
131
  */
216
- interface DrizzleUpdateQuery<T = unknown> {
217
- set(data: Record<string, unknown>): DrizzleUpdateQuery<T>;
218
- where(condition?: SQL): DrizzleUpdateQuery<T>;
219
- returning(): Promise<T[]>;
220
- }
132
+ declare function loadDrizzleRelation<T extends Record<string, unknown>>(db: DrizzleDatabase, item: T, relationName: string, relationConfig: RelationConfig<Table>): Promise<T>;
221
133
  /**
222
- * Delete query builder type
134
+ * Loads all requested relations for an item.
135
+ * Note: For multiple items, use `batchLoadDrizzleRelations` to avoid N+1 queries.
223
136
  */
224
- interface DrizzleDeleteQuery<T = unknown> {
225
- where(condition?: SQL): DrizzleDeleteQuery<T>;
226
- returning(): Promise<T[]>;
227
- }
137
+ declare function loadDrizzleRelations<T extends Record<string, unknown>, M extends MetaInput>(db: DrizzleDatabase, item: T, meta: M, includeOptions?: IncludeOptions): Promise<T>;
228
138
  /**
229
- * Generic Drizzle database interface that works with any dialect.
230
- * This type provides strong typing while remaining dialect-agnostic.
231
- *
232
- * @example
233
- * ```ts
234
- * import { drizzle } from 'drizzle-orm/node-postgres';
235
- *
236
- * const db = drizzle(pool);
237
- *
238
- * class UserCreate extends DrizzleCreateEndpoint<Env, UserMeta> {
239
- * db: DrizzleDatabase = db;
240
- * }
241
- * ```
139
+ * Batch loads relations for multiple items to avoid N+1 queries.
140
+ * Instead of N queries per relation, this uses 1 query per relation using inArray().
242
141
  */
243
- interface DrizzleDatabase {
244
- /**
245
- * Create a SELECT query
246
- */
247
- select<T extends Record<string, unknown> = Record<string, unknown>>(fields?: T): {
248
- from<TTable extends Table>(table: TTable): DrizzleSelectQuery<InferSelectModel<TTable>>;
249
- };
250
- /**
251
- * Create an INSERT query
252
- */
253
- insert<TTable extends Table>(table: TTable): DrizzleInsertQuery<InferSelectModel<TTable>>;
254
- /**
255
- * Create an UPDATE query
256
- */
257
- update<TTable extends Table>(table: TTable): DrizzleUpdateQuery<InferSelectModel<TTable>>;
258
- /**
259
- * Create a DELETE query
260
- */
261
- delete<TTable extends Table>(table: TTable): DrizzleDeleteQuery<InferSelectModel<TTable>>;
262
- /**
263
- * Execute operations within a transaction
264
- */
265
- transaction<T>(fn: (tx: DrizzleDatabase) => Promise<T>): Promise<T>;
266
- }
142
+ declare function batchLoadDrizzleRelations<T extends Record<string, unknown>, M extends MetaInput>(db: DrizzleDatabase, items: T[], meta: M, includeOptions?: IncludeOptions): Promise<T[]>;
267
143
  /**
268
- * @deprecated Use DrizzleDatabase instead
144
+ * Builds a where condition from filter conditions.
269
145
  */
270
- type DrizzleDB = DrizzleDatabase;
146
+ declare function buildWhereCondition(table: Table, filter: FilterCondition): SQL | undefined;
147
+
271
148
  /**
272
149
  * Drizzle Create endpoint.
273
150
  * Works with any Drizzle dialect (PostgreSQL, MySQL, SQLite).
274
151
  *
152
+ * The database can be provided in three ways:
153
+ * 1. Direct property: `db = myDb;`
154
+ * 2. Context injection via middleware: `c.set('db', myDb)`
155
+ * 3. Factory function: `createDrizzleCrud(db, meta)`
156
+ *
275
157
  * @example
276
158
  * ```ts
159
+ * // Pattern 1: Direct property (backward compatible)
277
160
  * class UserCreate extends DrizzleCreateEndpoint<Env, typeof userMeta> {
278
161
  * _meta = userMeta;
279
- * db = db; // Your Drizzle instance
162
+ * db = db;
163
+ * }
164
+ *
165
+ * // Pattern 2: Context injection (cleanest - no db property needed)
166
+ * class UserCreate extends DrizzleCreateEndpoint<AppEnv, typeof userMeta> {
167
+ * _meta = userMeta;
168
+ * // db comes from c.set('db', myDb) in middleware
169
+ * }
170
+ *
171
+ * // Pattern 3: Factory function (no _meta or db needed)
172
+ * const User = createDrizzleCrud(db, userMeta);
173
+ * class UserCreate extends User.Create {
174
+ * schema = { tags: ['Users'] };
280
175
  * }
281
176
  * ```
282
177
  */
283
178
  declare abstract class DrizzleCreateEndpoint<E extends Env = Env, M extends MetaInput = MetaInput> extends CreateEndpoint<E, M> {
284
- /** Drizzle database instance */
285
- abstract db: DrizzleDatabase;
179
+ /**
180
+ * Drizzle database instance.
181
+ * Can be undefined if using context-based injection via middleware.
182
+ */
183
+ db?: DrizzleDatabase;
286
184
  /**
287
185
  * Whether to wrap create and nested operations in a transaction.
288
186
  * When true, the entire create operation (including nested writes) will be atomic.
@@ -292,7 +190,10 @@ declare abstract class DrizzleCreateEndpoint<E extends Env = Env, M extends Meta
292
190
  /** Current transaction context (set during transaction execution) */
293
191
  private _tx?;
294
192
  /**
295
- * Gets the database instance to use (transaction or main db).
193
+ * Gets the database instance to use. Checks in order:
194
+ * 1. Transaction context (if in transaction)
195
+ * 2. Direct property
196
+ * 3. Context variables (if middleware injected)
296
197
  */
297
198
  protected getDb(): DrizzleDatabase;
298
199
  protected getTable(): Table;
@@ -321,7 +222,9 @@ declare abstract class DrizzleCreateEndpoint<E extends Env = Env, M extends Meta
321
222
  */
322
223
  declare abstract class DrizzleReadEndpoint<E extends Env = Env, M extends MetaInput = MetaInput> extends ReadEndpoint<E, M> {
323
224
  /** Drizzle database instance */
324
- abstract db: DrizzleDatabase;
225
+ db?: DrizzleDatabase;
226
+ /** Gets the database instance from property or context */
227
+ protected getDb(): DrizzleDatabase;
325
228
  protected getTable(): Table;
326
229
  protected getColumn(field: string): Column;
327
230
  read(lookupValue: string, additionalFilters?: Record<string, string>, includeOptions?: IncludeOptions): Promise<ModelObject<M['model']> | null>;
@@ -335,7 +238,7 @@ declare abstract class DrizzleReadEndpoint<E extends Env = Env, M extends MetaIn
335
238
  */
336
239
  declare abstract class DrizzleUpdateEndpoint<E extends Env = Env, M extends MetaInput = MetaInput> extends UpdateEndpoint<E, M> {
337
240
  /** Drizzle database instance */
338
- abstract db: DrizzleDatabase;
241
+ db?: DrizzleDatabase;
339
242
  /**
340
243
  * Whether to wrap update and nested operations in a transaction.
341
244
  * When true, the entire update operation (including nested writes) will be atomic.
@@ -344,9 +247,7 @@ declare abstract class DrizzleUpdateEndpoint<E extends Env = Env, M extends Meta
344
247
  protected useTransaction: boolean;
345
248
  /** Current transaction context (set during transaction execution) */
346
249
  private _tx?;
347
- /**
348
- * Gets the database instance to use (transaction or main db).
349
- */
250
+ /** Gets the database instance from property, transaction, or context */
350
251
  protected getDb(): DrizzleDatabase;
351
252
  protected getTable(): Table;
352
253
  protected getColumn(field: string): Column;
@@ -377,7 +278,7 @@ declare abstract class DrizzleUpdateEndpoint<E extends Env = Env, M extends Meta
377
278
  */
378
279
  declare abstract class DrizzleDeleteEndpoint<E extends Env = Env, M extends MetaInput = MetaInput> extends DeleteEndpoint<E, M> {
379
280
  /** Drizzle database instance */
380
- abstract db: DrizzleDatabase;
281
+ db?: DrizzleDatabase;
381
282
  /**
382
283
  * Whether to wrap delete and cascade operations in a transaction.
383
284
  * When true, the entire delete operation (including cascade deletes) will be atomic.
@@ -386,9 +287,7 @@ declare abstract class DrizzleDeleteEndpoint<E extends Env = Env, M extends Meta
386
287
  protected useTransaction: boolean;
387
288
  /** Current transaction context (set during transaction execution) */
388
289
  private _tx?;
389
- /**
390
- * Gets the database instance to use (transaction or main db).
391
- */
290
+ /** Gets the database instance from property, transaction, or context */
392
291
  protected getDb(): DrizzleDatabase;
393
292
  protected getTable(): Table;
394
293
  protected getColumn(field: string): Column;
@@ -429,7 +328,9 @@ declare abstract class DrizzleDeleteEndpoint<E extends Env = Env, M extends Meta
429
328
  */
430
329
  declare abstract class DrizzleListEndpoint<E extends Env = Env, M extends MetaInput = MetaInput> extends ListEndpoint<E, M> {
431
330
  /** Drizzle database instance */
432
- abstract db: DrizzleDatabase;
331
+ db?: DrizzleDatabase;
332
+ /** Gets the database instance from property or context */
333
+ protected getDb(): DrizzleDatabase;
433
334
  protected getTable(): Table;
434
335
  protected getColumn(field: string): Column;
435
336
  list(filters: ListFilters): Promise<PaginatedResult<ModelObject<M['model']>>>;
@@ -443,7 +344,7 @@ declare abstract class DrizzleListEndpoint<E extends Env = Env, M extends MetaIn
443
344
  */
444
345
  declare abstract class DrizzleRestoreEndpoint<E extends Env = Env, M extends MetaInput = MetaInput> extends RestoreEndpoint<E, M> {
445
346
  /** Drizzle database instance */
446
- abstract db: DrizzleDatabase;
347
+ db?: DrizzleDatabase;
447
348
  /**
448
349
  * Whether to wrap restore operation in a transaction.
449
350
  * Useful when combined with hooks that perform additional operations.
@@ -452,9 +353,7 @@ declare abstract class DrizzleRestoreEndpoint<E extends Env = Env, M extends Met
452
353
  protected useTransaction: boolean;
453
354
  /** Current transaction context (set during transaction execution) */
454
355
  private _tx?;
455
- /**
456
- * Gets the database instance to use (transaction or main db).
457
- */
356
+ /** Gets the database instance from property, transaction, or context */
458
357
  protected getDb(): DrizzleDatabase;
459
358
  protected getTable(): Table;
460
359
  protected getColumn(field: string): Column;
@@ -464,13 +363,16 @@ declare abstract class DrizzleRestoreEndpoint<E extends Env = Env, M extends Met
464
363
  */
465
364
  handle(): Promise<Response>;
466
365
  }
366
+
467
367
  /**
468
368
  * Drizzle Batch Create endpoint.
469
369
  * Works with any Drizzle dialect (PostgreSQL, MySQL, SQLite).
470
370
  */
471
371
  declare abstract class DrizzleBatchCreateEndpoint<E extends Env = Env, M extends MetaInput = MetaInput> extends BatchCreateEndpoint<E, M> {
472
372
  /** Drizzle database instance */
473
- abstract db: DrizzleDatabase;
373
+ db?: DrizzleDatabase;
374
+ /** Gets the database instance from property or context */
375
+ protected getDb(): DrizzleDatabase;
474
376
  protected getTable(): Table;
475
377
  batchCreate(items: Partial<ModelObject<M['model']>>[]): Promise<ModelObject<M['model']>[]>;
476
378
  }
@@ -482,7 +384,9 @@ declare abstract class DrizzleBatchCreateEndpoint<E extends Env = Env, M extends
482
384
  */
483
385
  declare abstract class DrizzleBatchUpdateEndpoint<E extends Env = Env, M extends MetaInput = MetaInput> extends BatchUpdateEndpoint<E, M> {
484
386
  /** Drizzle database instance */
485
- abstract db: DrizzleDatabase;
387
+ db?: DrizzleDatabase;
388
+ /** Gets the database instance from property or context */
389
+ protected getDb(): DrizzleDatabase;
486
390
  protected getTable(): Table;
487
391
  protected getColumn(field: string): Column;
488
392
  batchUpdate(items: BatchUpdateItem<ModelObject<M['model']>>[]): Promise<{
@@ -497,8 +401,10 @@ declare abstract class DrizzleBatchUpdateEndpoint<E extends Env = Env, M extends
497
401
  * Supports soft delete when the model has `softDelete` configured.
498
402
  */
499
403
  declare abstract class DrizzleBatchDeleteEndpoint<E extends Env = Env, M extends MetaInput = MetaInput> extends BatchDeleteEndpoint<E, M> {
500
- /** Drizzle database instance */
501
- abstract db: DrizzleDatabase;
404
+ /** Drizzle database instance. Can be undefined if using context injection. */
405
+ db?: DrizzleDatabase;
406
+ /** Gets the database instance from property or context. */
407
+ protected getDb(): DrizzleDatabase;
502
408
  protected getTable(): Table;
503
409
  protected getColumn(field: string): Column;
504
410
  batchDelete(ids: string[]): Promise<{
@@ -513,8 +419,10 @@ declare abstract class DrizzleBatchDeleteEndpoint<E extends Env = Env, M extends
513
419
  * Only works with models that have `softDelete` enabled.
514
420
  */
515
421
  declare abstract class DrizzleBatchRestoreEndpoint<E extends Env = Env, M extends MetaInput = MetaInput> extends BatchRestoreEndpoint<E, M> {
516
- /** Drizzle database instance */
517
- abstract db: DrizzleDatabase;
422
+ /** Drizzle database instance. Can be undefined if using context injection. */
423
+ db?: DrizzleDatabase;
424
+ /** Gets the database instance from property or context. */
425
+ protected getDb(): DrizzleDatabase;
518
426
  protected getTable(): Table;
519
427
  protected getColumn(field: string): Column;
520
428
  batchRestore(ids: string[]): Promise<{
@@ -522,13 +430,16 @@ declare abstract class DrizzleBatchRestoreEndpoint<E extends Env = Env, M extend
522
430
  notFound: string[];
523
431
  }>;
524
432
  }
433
+
525
434
  /**
526
435
  * Drizzle Upsert endpoint.
527
436
  * Creates a record if it doesn't exist, updates it if it does.
528
437
  */
529
438
  declare abstract class DrizzleUpsertEndpoint<E extends Env = Env, M extends MetaInput = MetaInput> extends UpsertEndpoint<E, M> {
530
- /** Drizzle database instance */
531
- abstract db: DrizzleDatabase;
439
+ /** Drizzle database instance. Can be undefined if using context injection. */
440
+ db?: DrizzleDatabase;
441
+ /** Gets the database instance from property or context. */
442
+ protected getDb(): DrizzleDatabase;
532
443
  protected getTable(): Table;
533
444
  protected getColumn(field: string): Column;
534
445
  findExisting(data: Partial<ModelObject<M['model']>>): Promise<ModelObject<M['model']> | null>;
@@ -551,8 +462,10 @@ declare abstract class DrizzleUpsertEndpoint<E extends Env = Env, M extends Meta
551
462
  * Drizzle Batch Upsert endpoint.
552
463
  */
553
464
  declare abstract class DrizzleBatchUpsertEndpoint<E extends Env = Env, M extends MetaInput = MetaInput> extends BatchUpsertEndpoint<E, M> {
554
- /** Drizzle database instance */
555
- abstract db: DrizzleDatabase;
465
+ /** Drizzle database instance. Can be undefined if using context injection. */
466
+ db?: DrizzleDatabase;
467
+ /** Gets the database instance from property or context. */
468
+ protected getDb(): DrizzleDatabase;
556
469
  protected getTable(): Table;
557
470
  protected getColumn(field: string): Column;
558
471
  findExisting(data: Partial<ModelObject<M['model']>>): Promise<ModelObject<M['model']> | null>;
@@ -586,8 +499,10 @@ declare abstract class DrizzleBatchUpsertEndpoint<E extends Env = Env, M extends
586
499
  * Lists all versions for a record.
587
500
  */
588
501
  declare abstract class DrizzleVersionHistoryEndpoint<E extends Env = Env, M extends MetaInput = MetaInput> extends VersionHistoryEndpoint<E, M> {
589
- /** Drizzle database instance */
590
- abstract db: DrizzleDatabase;
502
+ /** Drizzle database instance. Can be undefined if using context injection. */
503
+ db?: DrizzleDatabase;
504
+ /** Gets the database instance from property or context. */
505
+ protected getDb(): DrizzleDatabase;
591
506
  protected getTable(): Table;
592
507
  protected getColumn(field: string): Column;
593
508
  protected recordExists(lookupValue: string): Promise<boolean>;
@@ -609,8 +524,10 @@ declare abstract class DrizzleVersionCompareEndpoint<E extends Env = Env, M exte
609
524
  * Rolls back a record to a previous version.
610
525
  */
611
526
  declare abstract class DrizzleVersionRollbackEndpoint<E extends Env = Env, M extends MetaInput = MetaInput> extends VersionRollbackEndpoint<E, M> {
612
- /** Drizzle database instance */
613
- abstract db: DrizzleDatabase;
527
+ /** Drizzle database instance. Can be undefined if using context injection. */
528
+ db?: DrizzleDatabase;
529
+ /** Gets the database instance from property or context. */
530
+ protected getDb(): DrizzleDatabase;
614
531
  protected getTable(): Table;
615
532
  protected getColumn(field: string): Column;
616
533
  rollback(lookupValue: string, versionData: Record<string, unknown>, newVersion: number): Promise<ModelObject<M['model']>>;
@@ -620,8 +537,10 @@ declare abstract class DrizzleVersionRollbackEndpoint<E extends Env = Env, M ext
620
537
  * Computes aggregations (COUNT, SUM, AVG, MIN, MAX) with GROUP BY support.
621
538
  */
622
539
  declare abstract class DrizzleAggregateEndpoint<E extends Env = Env, M extends MetaInput = MetaInput> extends AggregateEndpoint<E, M> {
623
- /** Drizzle database instance */
624
- abstract db: DrizzleDatabase;
540
+ /** Drizzle database instance. Can be undefined if using context injection. */
541
+ db?: DrizzleDatabase;
542
+ /** Gets the database instance from property or context. */
543
+ protected getDb(): DrizzleDatabase;
625
544
  protected getTable(): Table;
626
545
  protected getColumn(field: string): Column;
627
546
  aggregate(options: AggregateOptions): Promise<AggregateResult>;
@@ -655,8 +574,10 @@ declare abstract class DrizzleAggregateEndpoint<E extends Env = Env, M extends M
655
574
  * ```
656
575
  */
657
576
  declare abstract class DrizzleSearchEndpoint<E extends Env = Env, M extends MetaInput = MetaInput> extends SearchEndpoint<E, M> {
658
- /** Drizzle database instance */
659
- abstract db: DrizzleDatabase;
577
+ /** Drizzle database instance. Can be undefined if using context injection. */
578
+ db?: DrizzleDatabase;
579
+ /** Gets the database instance from property or context. */
580
+ protected getDb(): DrizzleDatabase;
660
581
  /**
661
582
  * Enable PostgreSQL native full-text search.
662
583
  * When true and vectorColumn is set, uses tsvector/tsquery.
@@ -684,8 +605,10 @@ declare abstract class DrizzleSearchEndpoint<E extends Env = Env, M extends Meta
684
605
  * Exports data in CSV or JSON format with support for filtering and field selection.
685
606
  */
686
607
  declare abstract class DrizzleExportEndpoint<E extends Env = Env, M extends MetaInput = MetaInput> extends ExportEndpoint<E, M> {
687
- /** Drizzle database instance */
688
- abstract db: DrizzleDatabase;
608
+ /** Drizzle database instance. Can be undefined if using context injection. */
609
+ db?: DrizzleDatabase;
610
+ /** Gets the database instance from property or context. */
611
+ protected getDb(): DrizzleDatabase;
689
612
  protected getTable(): Table;
690
613
  protected getColumn(field: string): Column;
691
614
  list(filters: ListFilters): Promise<PaginatedResult<ModelObject<M['model']>>>;
@@ -695,8 +618,10 @@ declare abstract class DrizzleExportEndpoint<E extends Env = Env, M extends Meta
695
618
  * Imports data from CSV or JSON with support for create and upsert modes.
696
619
  */
697
620
  declare abstract class DrizzleImportEndpoint<E extends Env = Env, M extends MetaInput = MetaInput> extends ImportEndpoint<E, M> {
698
- /** Drizzle database instance */
699
- abstract db: DrizzleDatabase;
621
+ /** Drizzle database instance. Can be undefined if using context injection. */
622
+ db?: DrizzleDatabase;
623
+ /** Gets the database instance from property or context. */
624
+ protected getDb(): DrizzleDatabase;
700
625
  protected getTable(): Table;
701
626
  protected getColumn(field: string): Column;
702
627
  /**
@@ -713,4 +638,252 @@ declare abstract class DrizzleImportEndpoint<E extends Env = Env, M extends Meta
713
638
  update(existing: ModelObject<M['model']>, data: Partial<ModelObject<M['model']>>): Promise<ModelObject<M['model']>>;
714
639
  }
715
640
 
716
- export { DrizzleAggregateEndpoint, DrizzleBatchCreateEndpoint, DrizzleBatchDeleteEndpoint, DrizzleBatchRestoreEndpoint, DrizzleBatchUpdateEndpoint, DrizzleBatchUpsertEndpoint, DrizzleCreateEndpoint, type DrizzleDB, type DrizzleDatabase, DrizzleDeleteEndpoint, DrizzleExportEndpoint, DrizzleImportEndpoint, DrizzleListEndpoint, DrizzleReadEndpoint, DrizzleRestoreEndpoint, type DrizzleSchemas, DrizzleSearchEndpoint, DrizzleUpdateEndpoint, DrizzleUpsertEndpoint, DrizzleVersionCompareEndpoint, DrizzleVersionHistoryEndpoint, DrizzleVersionReadEndpoint, DrizzleVersionRollbackEndpoint, createDrizzleSchemas, createDrizzleSchemasAsync, createInsertSchema, createSelectSchema, createUpdateSchema, isDrizzleZodAvailable };
641
+ /**
642
+ * Return type of createDrizzleCrud factory function.
643
+ * Provides type-safe base classes for all CRUD operations.
644
+ */
645
+ interface DrizzleCrudClasses<M extends MetaInput> {
646
+ Create: typeof DrizzleCreateEndpoint<Env, M>;
647
+ Read: typeof DrizzleReadEndpoint<Env, M>;
648
+ Update: typeof DrizzleUpdateEndpoint<Env, M>;
649
+ Delete: typeof DrizzleDeleteEndpoint<Env, M>;
650
+ List: typeof DrizzleListEndpoint<Env, M>;
651
+ Restore: typeof DrizzleRestoreEndpoint<Env, M>;
652
+ Upsert: typeof DrizzleUpsertEndpoint<Env, M>;
653
+ BatchCreate: typeof DrizzleBatchCreateEndpoint<Env, M>;
654
+ BatchUpdate: typeof DrizzleBatchUpdateEndpoint<Env, M>;
655
+ BatchDelete: typeof DrizzleBatchDeleteEndpoint<Env, M>;
656
+ BatchRestore: typeof DrizzleBatchRestoreEndpoint<Env, M>;
657
+ BatchUpsert: typeof DrizzleBatchUpsertEndpoint<Env, M>;
658
+ }
659
+ /**
660
+ * Creates a set of Drizzle CRUD endpoint base classes with db and meta pre-configured.
661
+ * This is the cleanest pattern - no need to set `_meta` or `db` in your classes.
662
+ *
663
+ * @param db - Your Drizzle database instance
664
+ * @param meta - The meta object (from defineMeta)
665
+ * @returns Object with Create, Read, Update, Delete, List base classes
666
+ *
667
+ * @example
668
+ * ```ts
669
+ * import { createDrizzleCrud } from 'hono-crud/adapters/drizzle';
670
+ *
671
+ * const projectMeta = defineMeta({ model: ProjectModel, fields: projectSchemas.insert });
672
+ * const Project = createDrizzleCrud(db, projectMeta);
673
+ *
674
+ * // Now define endpoints with minimal boilerplate:
675
+ * class ProjectCreate extends Project.Create {
676
+ * schema = { tags: ["Projects"], summary: "Create a new project" };
677
+ * }
678
+ *
679
+ * class ProjectList extends Project.List {
680
+ * schema = { tags: ["Projects"], summary: "List all projects" };
681
+ * protected searchFields = ["name", "clientName"];
682
+ * protected filterFields = ["status"];
683
+ * }
684
+ * ```
685
+ */
686
+ declare function createDrizzleCrud<M extends MetaInput>(db: DrizzleDatabaseConstraint, meta: M): DrizzleCrudClasses<M>;
687
+ /**
688
+ * Drizzle adapter bundle for use with defineEndpoints.
689
+ *
690
+ * Note: When using DrizzleAdapters with defineEndpoints, you need to provide
691
+ * your own base classes that extend the Drizzle endpoint classes and include
692
+ * the `db` property. The config-based API cannot inject the database instance.
693
+ *
694
+ * @example
695
+ * ```ts
696
+ * import { defineEndpoints } from 'hono-crud';
697
+ * import { DrizzleAdapters } from 'hono-crud/adapters/drizzle';
698
+ *
699
+ * // Create custom adapters with db injected
700
+ * const MyDrizzleAdapters = {
701
+ * CreateEndpoint: class extends DrizzleCreateEndpoint { db = myDb; },
702
+ * ListEndpoint: class extends DrizzleListEndpoint { db = myDb; },
703
+ * ReadEndpoint: class extends DrizzleReadEndpoint { db = myDb; },
704
+ * UpdateEndpoint: class extends DrizzleUpdateEndpoint { db = myDb; },
705
+ * DeleteEndpoint: class extends DrizzleDeleteEndpoint { db = myDb; },
706
+ * };
707
+ *
708
+ * const userEndpoints = defineEndpoints({ meta: userMeta, ... }, MyDrizzleAdapters);
709
+ * ```
710
+ */
711
+ declare const DrizzleAdapters: AdapterBundle;
712
+
713
+ /**
714
+ * Drizzle-Zod schema utilities.
715
+ *
716
+ * This module provides helpers for generating Zod schemas from Drizzle tables
717
+ * using drizzle-zod. This allows automatic schema generation for CRUD operations.
718
+ *
719
+ * Note: drizzle-zod is an optional peer dependency. These utilities will only
720
+ * work if drizzle-zod is installed.
721
+ *
722
+ * @example
723
+ * ```ts
724
+ * import { pgTable, text, timestamp, uuid } from 'drizzle-orm/pg-core';
725
+ * import { createDrizzleSchemas } from 'hono-crud/adapters/drizzle';
726
+ *
727
+ * const users = pgTable('users', {
728
+ * id: uuid('id').primaryKey().defaultRandom(),
729
+ * name: text('name').notNull(),
730
+ * email: text('email').notNull().unique(),
731
+ * createdAt: timestamp('created_at').defaultNow(),
732
+ * });
733
+ *
734
+ * const { select: UserSchema, insert: CreateUserSchema } = createDrizzleSchemas(users);
735
+ * ```
736
+ */
737
+
738
+ /**
739
+ * Duck-typed interface for Drizzle tables.
740
+ * This allows compatibility across different drizzle-orm versions and package installations.
741
+ */
742
+ type DrizzleTable = {
743
+ _: {
744
+ name: string;
745
+ columns: Record<string, any>;
746
+ };
747
+ };
748
+ /**
749
+ * Re-export createSelectSchema from drizzle-zod.
750
+ * Creates a Zod schema for SELECT queries (all columns as required/optional based on table definition).
751
+ *
752
+ * @param table - Drizzle table definition
753
+ * @param refine - Optional refinements for specific columns
754
+ * @returns Zod schema for the table's select type
755
+ *
756
+ * @example
757
+ * ```ts
758
+ * import { users } from './schema';
759
+ * import { createSelectSchema } from 'hono-crud/adapters/drizzle';
760
+ *
761
+ * const UserSchema = createSelectSchema(users);
762
+ * type User = z.infer<typeof UserSchema>;
763
+ * ```
764
+ */
765
+ declare function createSelectSchema<T extends DrizzleTable>(table: T, refine?: Record<string, z.ZodTypeAny>): z.ZodObject<Record<string, z.ZodTypeAny>>;
766
+ /**
767
+ * Re-export createInsertSchema from drizzle-zod.
768
+ * Creates a Zod schema for INSERT queries (columns with defaults become optional).
769
+ *
770
+ * @param table - Drizzle table definition
771
+ * @param refine - Optional refinements for specific columns
772
+ * @returns Zod schema for the table's insert type
773
+ *
774
+ * @example
775
+ * ```ts
776
+ * import { users } from './schema';
777
+ * import { createInsertSchema } from 'hono-crud/adapters/drizzle';
778
+ *
779
+ * const CreateUserSchema = createInsertSchema(users);
780
+ * type CreateUser = z.infer<typeof CreateUserSchema>;
781
+ * ```
782
+ */
783
+ declare function createInsertSchema<T extends DrizzleTable>(table: T, refine?: Record<string, z.ZodTypeAny>): z.ZodObject<Record<string, z.ZodTypeAny>>;
784
+ /**
785
+ * Re-export createUpdateSchema from drizzle-zod (if available).
786
+ * Creates a Zod schema for UPDATE queries (all columns become optional).
787
+ *
788
+ * Note: createUpdateSchema may not be available in older versions of drizzle-zod.
789
+ * Use createInsertSchema(table).partial() as an alternative.
790
+ *
791
+ * @param table - Drizzle table definition
792
+ * @param refine - Optional refinements for specific columns
793
+ * @returns Zod schema for the table's update type
794
+ *
795
+ * @example
796
+ * ```ts
797
+ * import { users } from './schema';
798
+ * import { createUpdateSchema } from 'hono-crud/adapters/drizzle';
799
+ *
800
+ * const UpdateUserSchema = createUpdateSchema(users);
801
+ * type UpdateUser = z.infer<typeof UpdateUserSchema>;
802
+ * ```
803
+ */
804
+ declare function createUpdateSchema<T extends DrizzleTable>(table: T, refine?: Record<string, z.ZodTypeAny>): z.ZodObject<Record<string, z.ZodTypeAny>>;
805
+ /**
806
+ * Result of createDrizzleSchemas helper.
807
+ */
808
+ interface DrizzleSchemas {
809
+ /** Schema for SELECT queries (full record) */
810
+ select: z.ZodObject<Record<string, z.ZodTypeAny>>;
811
+ /** Schema for INSERT queries (required fields only) */
812
+ insert: z.ZodObject<Record<string, z.ZodTypeAny>>;
813
+ /** Schema for UPDATE queries (all fields optional) */
814
+ update: z.ZodObject<Record<string, z.ZodTypeAny>>;
815
+ }
816
+ /**
817
+ * Creates all three common schemas (select, insert, update) for a Drizzle table.
818
+ *
819
+ * This is a convenience helper that generates:
820
+ * - `select`: Full record schema for reading data
821
+ * - `insert`: Schema for creating new records (with date coercion for JSON input)
822
+ * - `update`: Partial schema for updating records (with date coercion for JSON input)
823
+ *
824
+ * Date coercion is automatically applied to timestamp/date columns, allowing
825
+ * both Date objects and ISO 8601 date strings as input values.
826
+ *
827
+ * @param table - Drizzle table definition
828
+ * @param options - Optional configuration
829
+ * @param options.insertRefine - Refinements for insert schema
830
+ * @param options.selectRefine - Refinements for select schema
831
+ * @param options.updateRefine - Refinements for update schema
832
+ * @param options.coerceDates - Whether to coerce date strings to Date objects (default: true)
833
+ * @returns Object containing select, insert, and update schemas
834
+ *
835
+ * @example
836
+ * ```ts
837
+ * import { pgTable, text, uuid } from 'drizzle-orm/pg-core';
838
+ * import { createDrizzleSchemas, defineModel, defineMeta } from 'hono-crud/adapters/drizzle';
839
+ * import { z } from 'zod';
840
+ *
841
+ * const users = pgTable('users', {
842
+ * id: uuid('id').primaryKey().defaultRandom(),
843
+ * name: text('name').notNull(),
844
+ * email: text('email').notNull().unique(),
845
+ * });
846
+ *
847
+ * // Generate schemas from table
848
+ * const schemas = createDrizzleSchemas(users, {
849
+ * insertRefine: {
850
+ * email: z.string().email(), // Add email validation
851
+ * },
852
+ * });
853
+ *
854
+ * // Use with hono-crud model
855
+ * const UserModel = defineModel({
856
+ * tableName: 'users',
857
+ * schema: schemas.select,
858
+ * primaryKeys: ['id'],
859
+ * table: users,
860
+ * });
861
+ * ```
862
+ */
863
+ declare function createDrizzleSchemas<T extends DrizzleTable>(table: T, options?: {
864
+ insertRefine?: Record<string, z.ZodTypeAny>;
865
+ selectRefine?: Record<string, z.ZodTypeAny>;
866
+ updateRefine?: Record<string, z.ZodTypeAny>;
867
+ /** Whether to coerce date strings to Date objects. Default: true */
868
+ coerceDates?: boolean;
869
+ }): DrizzleSchemas;
870
+ /**
871
+ * Async version of createDrizzleSchemas that handles lazy loading.
872
+ * Use this if you're not sure drizzle-zod is already loaded.
873
+ *
874
+ * @param table - Drizzle table definition
875
+ * @param options - Optional configuration
876
+ * @returns Promise resolving to schemas object
877
+ */
878
+ declare function createDrizzleSchemasAsync<T extends DrizzleTable>(table: T, options?: {
879
+ insertRefine?: Record<string, z.ZodTypeAny>;
880
+ selectRefine?: Record<string, z.ZodTypeAny>;
881
+ updateRefine?: Record<string, z.ZodTypeAny>;
882
+ }): Promise<DrizzleSchemas>;
883
+ /**
884
+ * Checks if drizzle-zod is available.
885
+ * @returns true if drizzle-zod can be imported
886
+ */
887
+ declare function isDrizzleZodAvailable(): boolean;
888
+
889
+ export { type Database, DrizzleAdapters, DrizzleAggregateEndpoint, DrizzleBatchCreateEndpoint, DrizzleBatchDeleteEndpoint, DrizzleBatchRestoreEndpoint, DrizzleBatchUpdateEndpoint, DrizzleBatchUpsertEndpoint, DrizzleCreateEndpoint, type DrizzleCrudClasses, type DrizzleDB, type DrizzleDatabase, type DrizzleDatabaseConstraint, DrizzleDeleteEndpoint, type DrizzleEnv, DrizzleExportEndpoint, DrizzleImportEndpoint, DrizzleListEndpoint, DrizzleReadEndpoint, DrizzleRestoreEndpoint, type DrizzleSchemas, DrizzleSearchEndpoint, DrizzleUpdateEndpoint, DrizzleUpsertEndpoint, DrizzleVersionCompareEndpoint, DrizzleVersionHistoryEndpoint, DrizzleVersionReadEndpoint, DrizzleVersionRollbackEndpoint, type QueryBuilder, batchLoadDrizzleRelations, buildWhereCondition, cast, createDrizzleCrud, createDrizzleSchemas, createDrizzleSchemasAsync, createInsertSchema, createSelectSchema, createUpdateSchema, getColumn, getTable, isDrizzleZodAvailable, loadDrizzleRelation, loadDrizzleRelations };