Skip to content

Commit 55f71e2

Browse files
committed
feat: 添加批量更新和删除操作的支持,增强数据处理能力
1 parent c7bb1ef commit 55f71e2

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

packages/spec/src/data/hook.zod.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export const HookEvent = z.enum([
1515
'beforeInsert', 'afterInsert',
1616
'beforeUpdate', 'afterUpdate',
1717
'beforeDelete', 'afterDelete',
18+
19+
// Bulk Operations (Query-based)
20+
'beforeUpdateMany', 'afterUpdateMany',
21+
'beforeDeleteMany', 'afterDeleteMany',
1822
]);
1923

2024
/**
@@ -115,6 +119,8 @@ export const HookContextSchema = z.object({
115119
* - insert: { doc: Record, options: DriverOptions }
116120
* - update: { id: ID, doc: Record, options: DriverOptions }
117121
* - delete: { id: ID, options: DriverOptions }
122+
* - updateMany: { query: QueryAST, doc: Record, options: DriverOptions }
123+
* - deleteMany: { query: QueryAST, options: DriverOptions }
118124
*/
119125
input: z.record(z.any()).describe('Mutable input parameters'),
120126

packages/spec/src/driver/driver.zod.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,33 @@ export const DriverInterfaceSchema = z.object({
383383
.args(z.string(), z.array(z.string().or(z.number())), DriverOptionsSchema.optional())
384384
.returns(z.promise(z.void())),
385385

386+
/**
387+
* Update multiple records matching a query.
388+
* Direct database push-down. DOES NOT trigger per-record hooks.
389+
*
390+
* @param object - The object name.
391+
* @param query - The filtering criteria.
392+
* @param data - The data to update.
393+
* @returns Count of modified records.
394+
*/
395+
updateMany: z.function()
396+
.args(z.string(), QuerySchema, z.record(z.any()), DriverOptionsSchema.optional())
397+
.returns(z.promise(z.number()))
398+
.optional(),
399+
400+
/**
401+
* Delete multiple records matching a query.
402+
* Direct database push-down. DOES NOT trigger per-record hooks.
403+
*
404+
* @param object - The object name.
405+
* @param query - The filtering criteria.
406+
* @returns Count of deleted records.
407+
*/
408+
deleteMany: z.function()
409+
.args(z.string(), QuerySchema, DriverOptionsSchema.optional())
410+
.returns(z.promise(z.number()))
411+
.optional(),
412+
386413
// ============================================================================
387414
// Transaction Management
388415
// ============================================================================

0 commit comments

Comments
 (0)