@proteinjs/db 1.54.1 → 1.54.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/CHANGELOG.md +22 -0
- package/dist/src/Columns.d.ts +12 -6
- package/dist/src/Columns.d.ts.map +1 -1
- package/dist/src/Columns.js +40 -65
- package/dist/src/Columns.js.map +1 -1
- package/dist/src/Db.d.ts.map +1 -1
- package/dist/src/Db.js +2 -5
- package/dist/src/Db.js.map +1 -1
- package/dist/src/Record.d.ts +35 -0
- package/dist/src/Record.d.ts.map +1 -1
- package/dist/src/Record.js +177 -45
- package/dist/src/Record.js.map +1 -1
- package/dist/src/Table.d.ts +18 -1
- package/dist/src/Table.d.ts.map +1 -1
- package/dist/src/encryption/EncryptionRecordHooks.d.ts +9 -4
- package/dist/src/encryption/EncryptionRecordHooks.d.ts.map +1 -1
- package/dist/src/encryption/EncryptionRecordHooks.js +65 -42
- package/dist/src/encryption/EncryptionRecordHooks.js.map +1 -1
- package/dist/test/DateTimeFieldReadOnFirstRead.test.d.ts +2 -0
- package/dist/test/DateTimeFieldReadOnFirstRead.test.d.ts.map +1 -0
- package/dist/test/DateTimeFieldReadOnFirstRead.test.js +238 -0
- package/dist/test/DateTimeFieldReadOnFirstRead.test.js.map +1 -0
- package/dist/test/HydrationBenchmark.test.d.ts +2 -0
- package/dist/test/HydrationBenchmark.test.d.ts.map +1 -0
- package/dist/test/HydrationBenchmark.test.js +299 -0
- package/dist/test/HydrationBenchmark.test.js.map +1 -0
- package/dist/test/LegacyCellHydration.test.d.ts +2 -0
- package/dist/test/LegacyCellHydration.test.d.ts.map +1 -0
- package/dist/test/LegacyCellHydration.test.js +321 -0
- package/dist/test/LegacyCellHydration.test.js.map +1 -0
- package/dist/test/SyncRowHydration.test.d.ts +2 -0
- package/dist/test/SyncRowHydration.test.d.ts.map +1 -0
- package/dist/test/SyncRowHydration.test.js +344 -0
- package/dist/test/SyncRowHydration.test.js.map +1 -0
- package/dist/test/reusable/ColumnTypesTests.d.ts.map +1 -1
- package/dist/test/reusable/ColumnTypesTests.js +55 -0
- package/dist/test/reusable/ColumnTypesTests.js.map +1 -1
- package/package.json +2 -2
- package/src/Columns.ts +14 -7
- package/src/Db.ts +3 -4
- package/src/Record.ts +202 -16
- package/src/Table.ts +21 -1
- package/src/encryption/EncryptionRecordHooks.ts +48 -17
- package/test/DateTimeFieldReadOnFirstRead.test.ts +162 -0
- package/test/HydrationBenchmark.test.ts +209 -0
- package/test/LegacyCellHydration.test.ts +234 -0
- package/test/SyncRowHydration.test.ts +249 -0
- package/test/reusable/ColumnTypesTests.ts +47 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { Db, DbDriver, Record, Table, DefaultTransactionContextFactory } from '@proteinjs/db';
|
|
1
|
+
import { Db, DbDriver, Record, Table, DefaultTransactionContextFactory, QueryBuilderFactory } from '@proteinjs/db';
|
|
2
|
+
import { StatementFactory } from '@proteinjs/db-query';
|
|
3
|
+
import { StatementConfigFactory } from '../../src/StatementConfigFactory';
|
|
2
4
|
import { DbTestEnvironment } from '../util/DbTestEnvironment';
|
|
3
5
|
import { columnTypesTestTables, TestRecord } from '../util/tables/columnTypesTestTables';
|
|
4
6
|
|
|
@@ -78,5 +80,49 @@ export const columnTypeTests = (
|
|
|
78
80
|
|
|
79
81
|
await expect(db.insert(testTable, testRecord)).rejects.toThrow();
|
|
80
82
|
});
|
|
83
|
+
|
|
84
|
+
test('A legacy cell the column cannot deserialize never takes the row with it', async () => {
|
|
85
|
+
// A value written past the serializer — a bare word in a column that stores JSON — the way
|
|
86
|
+
// a hand-run statement or an older writer leaves it: the update statement the db layer
|
|
87
|
+
// itself emits, handed the cells as stored text. The row still serves: that field is
|
|
88
|
+
// omitted, every other field lands, and a query over the table resolves.
|
|
89
|
+
const testTable: Table<TestRecord> = columnTypesTestTables.Test;
|
|
90
|
+
const legacy = await db.insert(testTable, {
|
|
91
|
+
stringColumn: 'legacy',
|
|
92
|
+
objectColumn: { theme: 'dark' },
|
|
93
|
+
arrayColumn: ['a', 'b'],
|
|
94
|
+
});
|
|
95
|
+
const intact = await db.insert(testTable, {
|
|
96
|
+
stringColumn: 'intact',
|
|
97
|
+
objectColumn: { theme: 'light' },
|
|
98
|
+
arrayColumn: ['c'],
|
|
99
|
+
});
|
|
100
|
+
const statementConfigFactory = new StatementConfigFactory(driver.getDbName());
|
|
101
|
+
const legacyRow = new QueryBuilderFactory()
|
|
102
|
+
.getQueryBuilder(testTable)
|
|
103
|
+
.condition({ field: 'id', operator: '=', value: legacy.id });
|
|
104
|
+
await driver.runDml((config) =>
|
|
105
|
+
new StatementFactory<TestRecord>().update(
|
|
106
|
+
testTable.name,
|
|
107
|
+
{ object_column: 'legacyword', array_column: 'legacyword' } as Partial<TestRecord>,
|
|
108
|
+
legacyRow,
|
|
109
|
+
statementConfigFactory.getStatementConfig(config)
|
|
110
|
+
)
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const fetched = await db.get(testTable, { id: legacy.id });
|
|
114
|
+
expect(fetched).toMatchObject({ id: legacy.id, stringColumn: 'legacy' });
|
|
115
|
+
expect(fetched).not.toHaveProperty('objectColumn');
|
|
116
|
+
expect(fetched).not.toHaveProperty('arrayColumn');
|
|
117
|
+
|
|
118
|
+
const all = await db.query(testTable, {});
|
|
119
|
+
expect(all.map((record) => record.id).sort()).toEqual([legacy.id, intact.id].sort());
|
|
120
|
+
const other = all.find((record) => record.id === intact.id);
|
|
121
|
+
expect(other).toMatchObject({ stringColumn: 'intact', objectColumn: { theme: 'light' }, arrayColumn: ['c'] });
|
|
122
|
+
|
|
123
|
+
// Clean up
|
|
124
|
+
await db.delete(testTable, { id: legacy.id });
|
|
125
|
+
await db.delete(testTable, { id: intact.id });
|
|
126
|
+
});
|
|
81
127
|
};
|
|
82
128
|
};
|