@mastra/pg 0.17.5 → 0.17.6-alpha.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.
package/dist/index.js
CHANGED
|
@@ -2663,7 +2663,7 @@ var StoreOperationsPG = class extends StoreOperations {
|
|
|
2663
2663
|
return Object.entries(record).map(([key, value]) => {
|
|
2664
2664
|
const schema = TABLE_SCHEMAS[tableName];
|
|
2665
2665
|
const columnSchema = schema?.[key];
|
|
2666
|
-
if (columnSchema?.type === "jsonb" && value !== null &&
|
|
2666
|
+
if (columnSchema?.type === "jsonb" && value !== null && value !== void 0) {
|
|
2667
2667
|
return JSON.stringify(value);
|
|
2668
2668
|
}
|
|
2669
2669
|
return value;
|
|
@@ -2685,15 +2685,24 @@ var StoreOperationsPG = class extends StoreOperations {
|
|
|
2685
2685
|
}
|
|
2686
2686
|
/**
|
|
2687
2687
|
* Prepares a value for database operations, handling Date objects and JSON serialization
|
|
2688
|
+
* This is schema-aware and only stringifies objects for JSONB columns
|
|
2688
2689
|
*/
|
|
2689
|
-
prepareValue(value) {
|
|
2690
|
+
prepareValue(value, columnName, tableName) {
|
|
2691
|
+
if (value === null || value === void 0) {
|
|
2692
|
+
return value;
|
|
2693
|
+
}
|
|
2690
2694
|
if (value instanceof Date) {
|
|
2691
2695
|
return value.toISOString();
|
|
2692
|
-
}
|
|
2696
|
+
}
|
|
2697
|
+
const schema = TABLE_SCHEMAS[tableName];
|
|
2698
|
+
const columnSchema = schema?.[columnName];
|
|
2699
|
+
if (columnSchema?.type === "jsonb") {
|
|
2700
|
+
return JSON.stringify(value);
|
|
2701
|
+
}
|
|
2702
|
+
if (typeof value === "object") {
|
|
2693
2703
|
return JSON.stringify(value);
|
|
2694
|
-
} else {
|
|
2695
|
-
return value;
|
|
2696
2704
|
}
|
|
2705
|
+
return value;
|
|
2697
2706
|
}
|
|
2698
2707
|
async setupSchema() {
|
|
2699
2708
|
if (!this.schemaName || this.schemaSetupComplete) {
|
|
@@ -3362,14 +3371,14 @@ var StoreOperationsPG = class extends StoreOperations {
|
|
|
3362
3371
|
Object.entries(data).forEach(([key, value]) => {
|
|
3363
3372
|
const parsedKey = parseSqlIdentifier(key, "column name");
|
|
3364
3373
|
setColumns.push(`"${parsedKey}" = $${paramIndex++}`);
|
|
3365
|
-
setValues.push(this.prepareValue(value));
|
|
3374
|
+
setValues.push(this.prepareValue(value, key, tableName));
|
|
3366
3375
|
});
|
|
3367
3376
|
const whereConditions = [];
|
|
3368
3377
|
const whereValues = [];
|
|
3369
3378
|
Object.entries(keys).forEach(([key, value]) => {
|
|
3370
3379
|
const parsedKey = parseSqlIdentifier(key, "column name");
|
|
3371
3380
|
whereConditions.push(`"${parsedKey}" = $${paramIndex++}`);
|
|
3372
|
-
whereValues.push(this.prepareValue(value));
|
|
3381
|
+
whereValues.push(this.prepareValue(value, key, tableName));
|
|
3373
3382
|
});
|
|
3374
3383
|
const tableName_ = getTableName({
|
|
3375
3384
|
indexName: tableName,
|