Skip to content

Commit d9d07b4

Browse files
Copilothotlong
andcommitted
refactor: replace Error with ObjectQLError in SQL driver
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 899f76e commit d9d07b4

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

packages/drivers/sql/src/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type DriverInterface = z.infer<typeof Data.DriverInterface>;
1010
* LICENSE file in the root directory of this source tree.
1111
*/
1212

13-
import { Driver, IntrospectedSchema, IntrospectedTable, IntrospectedColumn, IntrospectedForeignKey } from '@objectql/types';
13+
import { Driver, IntrospectedSchema, IntrospectedTable, IntrospectedColumn, IntrospectedForeignKey, ObjectQLError } from '@objectql/types';
1414
import knex, { Knex } from 'knex';
1515
import { nanoid } from 'nanoid';
1616

@@ -475,7 +475,7 @@ export class SqlDriver implements Driver {
475475
case 'avg': return 'avg';
476476
case 'min': return 'min';
477477
case 'max': return 'max';
478-
default: throw new Error(`Unsupported aggregate function: ${func}`);
478+
default: throw new ObjectQLError({ code: 'DRIVER_UNSUPPORTED_OPERATION', message: `Unsupported aggregate function: ${func}` });
479479
}
480480
}
481481

@@ -1305,7 +1305,7 @@ export class SqlDriver implements Driver {
13051305
switch (command.type) {
13061306
case 'create':
13071307
if (!command.data) {
1308-
throw new Error('Create command requires data');
1308+
throw new ObjectQLError({ code: 'DRIVER_QUERY_FAILED', message: 'Create command requires data' });
13091309
}
13101310
const created = await this.create(command.object, command.data, cmdOptions);
13111311
return {
@@ -1316,7 +1316,7 @@ export class SqlDriver implements Driver {
13161316

13171317
case 'update':
13181318
if (!command.id || !command.data) {
1319-
throw new Error('Update command requires id and data');
1319+
throw new ObjectQLError({ code: 'DRIVER_QUERY_FAILED', message: 'Update command requires id and data' });
13201320
}
13211321
const updated = await this.update(command.object, command.id, command.data, cmdOptions);
13221322
return {
@@ -1327,7 +1327,7 @@ export class SqlDriver implements Driver {
13271327

13281328
case 'delete':
13291329
if (!command.id) {
1330-
throw new Error('Delete command requires id');
1330+
throw new ObjectQLError({ code: 'DRIVER_QUERY_FAILED', message: 'Delete command requires id' });
13311331
}
13321332
await this.delete(command.object, command.id, cmdOptions);
13331333
return {
@@ -1337,7 +1337,7 @@ export class SqlDriver implements Driver {
13371337

13381338
case 'bulkCreate':
13391339
if (!command.records || !Array.isArray(command.records)) {
1340-
throw new Error('BulkCreate command requires records array');
1340+
throw new ObjectQLError({ code: 'DRIVER_QUERY_FAILED', message: 'BulkCreate command requires records array' });
13411341
}
13421342
// Bulk insert using Knex
13431343
const builder = this.getBuilder(command.object, cmdOptions);
@@ -1351,7 +1351,7 @@ export class SqlDriver implements Driver {
13511351

13521352
case 'bulkUpdate':
13531353
if (!command.updates || !Array.isArray(command.updates)) {
1354-
throw new Error('BulkUpdate command requires updates array');
1354+
throw new ObjectQLError({ code: 'DRIVER_QUERY_FAILED', message: 'BulkUpdate command requires updates array' });
13551355
}
13561356
// Execute updates sequentially (Knex doesn't support batch update well)
13571357
const updateResults = [];
@@ -1367,7 +1367,7 @@ export class SqlDriver implements Driver {
13671367

13681368
case 'bulkDelete':
13691369
if (!command.ids || !Array.isArray(command.ids)) {
1370-
throw new Error('BulkDelete command requires ids array');
1370+
throw new ObjectQLError({ code: 'DRIVER_QUERY_FAILED', message: 'BulkDelete command requires ids array' });
13711371
}
13721372
// Bulk delete using whereIn
13731373
const deleteBuilder = this.getBuilder(command.object, cmdOptions);
@@ -1378,7 +1378,7 @@ export class SqlDriver implements Driver {
13781378
};
13791379

13801380
default:
1381-
throw new Error(`Unknown command type: ${(command as any).type}`);
1381+
throw new ObjectQLError({ code: 'DRIVER_UNSUPPORTED_OPERATION', message: `Unknown command type: ${(command as any).type}` });
13821382
}
13831383
} catch (error: any) {
13841384
return {

0 commit comments

Comments
 (0)