Skip to content

Commit 43ae6c1

Browse files
committed
Merge branch 'develop'
2 parents fa12025 + 2c435d6 commit 43ae6c1

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/orm/field/fields/int-field.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ export default new ORMFieldConfig("IntField", {
1414
return true;
1515
},
1616
dbSave(value, _fieldDef) {
17+
if (value !== null && value !== undefined) {
18+
value = parseInt(value, 10);
19+
if (isNaN(value)) {
20+
value = null;
21+
}
22+
}
23+
1724
return value;
1825
},
1926
});

src/orm/migrate/migration-planner.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type { SettingsType } from "~/orm/settings/settings-type.ts";
77
import type { PgColumnDefinition } from "~/orm/db/db-types.ts";
88
import { MigrationPlan } from "~/orm/migrate/migration-plan.ts";
99
import type { InSpatialORM } from "../inspatial-orm.ts";
10-
import { raiseORMException } from "../orm-exception.ts";
1110

1211
export class MigrationPlanner {
1312
entryTypes: Map<string, EntryTypeMigrator<EntryType>>;

src/orm/shared/base-class.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,24 @@ export class BaseClass<N extends string = string> {
215215
break;
216216
}
217217
case PGErrorCode.UniqueViolation: {
218-
const fieldKey = convertString(e.fullMessage.columnName, "camel");
218+
const { tableName, detail } = e.fullMessage;
219+
if (detail) {
220+
const match = detail.match(
221+
/\((?<column>.+)\)=\((?<value>.+)\)/,
222+
);
223+
if (match?.groups) {
224+
const fieldKey = convertString(match.groups.column, "camel");
225+
const fieldValue = match.groups.value;
226+
raiseORMException(
227+
`Field "${fieldKey}" with value "${fieldValue}" must be unique for "${this._name}"`,
228+
"UniqueField",
229+
400,
230+
);
231+
}
232+
break;
233+
}
219234
raiseORMException(
220-
`Field ${fieldKey} must be unique for ${this._name}`,
235+
`Unique constraint violation on ${tableName} for ${this._name}`,
221236
"UniqueField",
222237
400,
223238
);
@@ -226,5 +241,6 @@ export class BaseClass<N extends string = string> {
226241
default:
227242
throw e;
228243
}
244+
throw e;
229245
}
230246
}

0 commit comments

Comments
 (0)