@zenstackhq/orm 3.5.2 → 3.5.3
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.
- package/dist/index.cjs +77 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +77 -2
- package/dist/index.js.map +1 -1
- package/package.json +19 -9
package/dist/index.cjs
CHANGED
|
@@ -1643,6 +1643,12 @@ var BaseCrudDialect = class {
|
|
|
1643
1643
|
buildExistsExpression(innerQuery) {
|
|
1644
1644
|
return this.eb.exists(innerQuery);
|
|
1645
1645
|
}
|
|
1646
|
+
/**
|
|
1647
|
+
* Builds a binary comparison expression between two operands.
|
|
1648
|
+
*/
|
|
1649
|
+
buildComparison(left, _leftFieldDef, op, right, _rightFieldDef) {
|
|
1650
|
+
return this.eb(left, op, right);
|
|
1651
|
+
}
|
|
1646
1652
|
};
|
|
1647
1653
|
|
|
1648
1654
|
// src/client/crud/dialects/lateral-join-dialect-base.ts
|
|
@@ -2077,6 +2083,33 @@ var PostgresCrudDialect = class _PostgresCrudDialect extends LateralJoinDialectB
|
|
|
2077
2083
|
Bytes: "bytea",
|
|
2078
2084
|
Json: "jsonb"
|
|
2079
2085
|
};
|
|
2086
|
+
// Maps @db.* attribute names to PostgreSQL SQL types for use in VALUES table casts
|
|
2087
|
+
static dbAttributeToSqlTypeMap = {
|
|
2088
|
+
"@db.Uuid": "uuid",
|
|
2089
|
+
"@db.Citext": "citext",
|
|
2090
|
+
"@db.Inet": "inet",
|
|
2091
|
+
"@db.Bit": "bit",
|
|
2092
|
+
"@db.VarBit": "varbit",
|
|
2093
|
+
"@db.Xml": "xml",
|
|
2094
|
+
"@db.Json": "json",
|
|
2095
|
+
"@db.JsonB": "jsonb",
|
|
2096
|
+
"@db.ByteA": "bytea",
|
|
2097
|
+
"@db.Text": "text",
|
|
2098
|
+
"@db.Char": "bpchar",
|
|
2099
|
+
"@db.VarChar": "varchar",
|
|
2100
|
+
"@db.Date": "date",
|
|
2101
|
+
"@db.Time": "time",
|
|
2102
|
+
"@db.Timetz": "timetz",
|
|
2103
|
+
"@db.Timestamp": "timestamp",
|
|
2104
|
+
"@db.Timestamptz": "timestamptz",
|
|
2105
|
+
"@db.SmallInt": "smallint",
|
|
2106
|
+
"@db.Integer": "integer",
|
|
2107
|
+
"@db.BigInt": "bigint",
|
|
2108
|
+
"@db.Real": "real",
|
|
2109
|
+
"@db.DoublePrecision": "double precision",
|
|
2110
|
+
"@db.Decimal": "decimal",
|
|
2111
|
+
"@db.Boolean": "boolean"
|
|
2112
|
+
};
|
|
2080
2113
|
constructor(schema, options) {
|
|
2081
2114
|
super(schema, options);
|
|
2082
2115
|
this.overrideTypeParsers();
|
|
@@ -2341,13 +2374,55 @@ var PostgresCrudDialect = class _PostgresCrudDialect extends LateralJoinDialectB
|
|
|
2341
2374
|
receiver
|
|
2342
2375
|
]).as("$items")).select(this.eb.lit(1).as("_")).where(buildFilter(this.eb.ref("$items.value"))));
|
|
2343
2376
|
}
|
|
2344
|
-
getSqlType(zmodelType) {
|
|
2377
|
+
getSqlType(zmodelType, attributes) {
|
|
2378
|
+
if (attributes) {
|
|
2379
|
+
for (const attr of attributes) {
|
|
2380
|
+
const mapped = _PostgresCrudDialect.dbAttributeToSqlTypeMap[attr.name];
|
|
2381
|
+
if (mapped) {
|
|
2382
|
+
return mapped;
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2345
2386
|
if (isEnum(this.schema, zmodelType)) {
|
|
2346
2387
|
return "text";
|
|
2347
2388
|
} else {
|
|
2348
2389
|
return this.zmodelToSqlTypeMap[zmodelType] ?? "text";
|
|
2349
2390
|
}
|
|
2350
2391
|
}
|
|
2392
|
+
// Resolves the effective SQL type for a field: the native type from any @db.* attribute,
|
|
2393
|
+
// or the base ZModel SQL type if no attribute is present, or undefined if the field is unknown.
|
|
2394
|
+
resolveFieldSqlType(fieldDef) {
|
|
2395
|
+
if (!fieldDef) {
|
|
2396
|
+
return {
|
|
2397
|
+
sqlType: void 0,
|
|
2398
|
+
hasDbOverride: false
|
|
2399
|
+
};
|
|
2400
|
+
}
|
|
2401
|
+
const dbAttr = fieldDef.attributes?.find((a) => a.name.startsWith("@db."));
|
|
2402
|
+
if (dbAttr) {
|
|
2403
|
+
return {
|
|
2404
|
+
sqlType: _PostgresCrudDialect.dbAttributeToSqlTypeMap[dbAttr.name],
|
|
2405
|
+
hasDbOverride: true
|
|
2406
|
+
};
|
|
2407
|
+
}
|
|
2408
|
+
return {
|
|
2409
|
+
sqlType: this.getSqlType(fieldDef.type),
|
|
2410
|
+
hasDbOverride: false
|
|
2411
|
+
};
|
|
2412
|
+
}
|
|
2413
|
+
buildComparison(left, leftFieldDef, op, right, rightFieldDef) {
|
|
2414
|
+
const leftResolved = this.resolveFieldSqlType(leftFieldDef);
|
|
2415
|
+
const rightResolved = this.resolveFieldSqlType(rightFieldDef);
|
|
2416
|
+
if (leftResolved.sqlType !== rightResolved.sqlType && (leftResolved.hasDbOverride || rightResolved.hasDbOverride)) {
|
|
2417
|
+
if (leftResolved.hasDbOverride) {
|
|
2418
|
+
left = this.eb.cast(left, import_kysely4.sql.raw(this.getSqlType(leftFieldDef.type)));
|
|
2419
|
+
}
|
|
2420
|
+
if (rightResolved.hasDbOverride) {
|
|
2421
|
+
right = this.eb.cast(right, import_kysely4.sql.raw(this.getSqlType(rightFieldDef.type)));
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
return super.buildComparison(left, leftFieldDef, op, right, rightFieldDef);
|
|
2425
|
+
}
|
|
2351
2426
|
getStringCasingBehavior() {
|
|
2352
2427
|
return {
|
|
2353
2428
|
supportsILike: true,
|
|
@@ -2369,7 +2444,7 @@ var PostgresCrudDialect = class _PostgresCrudDialect extends LateralJoinDialectB
|
|
|
2369
2444
|
}
|
|
2370
2445
|
const eb = (0, import_kysely4.expressionBuilder)();
|
|
2371
2446
|
return eb.selectFrom(import_kysely4.sql`(VALUES ${import_kysely4.sql.join(rows.map((row) => import_kysely4.sql`(${import_kysely4.sql.join(row.map((v) => import_kysely4.sql.val(v)))})`), import_kysely4.sql.raw(", "))})`.as("$values")).select(fields.map((f, i) => {
|
|
2372
|
-
const mappedType = this.getSqlType(f.type);
|
|
2447
|
+
const mappedType = this.getSqlType(f.type, f.attributes);
|
|
2373
2448
|
const castType = f.array ? import_kysely4.sql`${import_kysely4.sql.raw(mappedType)}[]` : import_kysely4.sql.raw(mappedType);
|
|
2374
2449
|
return this.eb.cast(import_kysely4.sql.ref(`$values.column${i + 1}`), castType).as(f.name);
|
|
2375
2450
|
}));
|