@powersync/service-module-mssql 0.0.0-dev-20251208145829 → 0.0.0-dev-20260114113449
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 +32 -5
- package/dist/common/mssqls-to-sqlite.js +33 -7
- package/dist/common/mssqls-to-sqlite.js.map +1 -1
- package/dist/replication/CDCStream.js.map +1 -1
- package/dist/utils/mssql.js +6 -8
- package/dist/utils/mssql.js.map +1 -1
- package/package.json +7 -7
- package/src/common/mssqls-to-sqlite.ts +48 -7
- package/src/replication/CDCStream.ts +8 -2
- package/src/utils/mssql.ts +23 -18
- package/test/src/mssql-to-sqlite.test.ts +60 -21
- package/test/tsconfig.json +5 -2
- package/tsconfig.json +6 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/vitest.config.ts +2 -14
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
applyRowContext,
|
|
3
|
+
CompatibilityContext,
|
|
4
|
+
SQLITE_TRUE,
|
|
5
|
+
SqliteInputRow,
|
|
6
|
+
TimeValuePrecision
|
|
7
|
+
} from '@powersync/service-sync-rules';
|
|
2
8
|
import { afterAll, beforeEach, describe, expect, test } from 'vitest';
|
|
3
9
|
import { clearTestDb, createUpperCaseUUID, TEST_CONNECTION_OPTIONS, waitForPendingCDCChanges } from './util.js';
|
|
4
10
|
import { CDCToSqliteRow, toSqliteInputRow } from '@module/common/mssqls-to-sqlite.js';
|
|
@@ -43,10 +49,10 @@ describe('MSSQL Data Types Tests', () => {
|
|
|
43
49
|
|
|
44
50
|
date_col DATE,
|
|
45
51
|
datetime_col DATETIME,
|
|
46
|
-
datetime2_col DATETIME2(
|
|
52
|
+
datetime2_col DATETIME2(7),
|
|
47
53
|
smalldatetime_col SMALLDATETIME,
|
|
48
54
|
datetimeoffset_col DATETIMEOFFSET(3),
|
|
49
|
-
time_col TIME(
|
|
55
|
+
time_col TIME(7),
|
|
50
56
|
|
|
51
57
|
char_col CHAR(10),
|
|
52
58
|
varchar_col VARCHAR(255),
|
|
@@ -214,7 +220,14 @@ describe('MSSQL Data Types Tests', () => {
|
|
|
214
220
|
|
|
215
221
|
test('Date types mappings', async () => {
|
|
216
222
|
const beforeLSN = await getLatestLSN(connectionManager);
|
|
217
|
-
const testDate = new Date('2023-03-06T15:47:00.
|
|
223
|
+
const testDate = new Date('2023-03-06T15:47:00.123Z');
|
|
224
|
+
// This adds 0.4567 milliseconds to the JS date, see https://github.com/tediousjs/tedious/blob/0c256f186600d7230aec05553ebad209bed81acc/src/data-types/datetime2.ts#L74.
|
|
225
|
+
// Note that there's a typo in tedious there. When reading dates, the property is actually called nanosecondsDelta.
|
|
226
|
+
// This is only relevant when binding datetime values, so only in this test.
|
|
227
|
+
Object.defineProperty(testDate, 'nanosecondDelta', {
|
|
228
|
+
enumerable: false,
|
|
229
|
+
value: 0.0004567
|
|
230
|
+
});
|
|
218
231
|
await connectionManager.query(
|
|
219
232
|
`
|
|
220
233
|
INSERT INTO ${escapeIdentifier(connectionManager.schema)}.test_data(
|
|
@@ -235,9 +248,9 @@ describe('MSSQL Data Types Tests', () => {
|
|
|
235
248
|
[
|
|
236
249
|
{ name: 'date_col', type: sql.Date, value: testDate },
|
|
237
250
|
{ name: 'datetime_col', type: sql.DateTime, value: testDate },
|
|
238
|
-
{ name: 'datetime2_col', type: sql.DateTime2(
|
|
251
|
+
{ name: 'datetime2_col', type: sql.DateTime2(7), value: testDate },
|
|
239
252
|
{ name: 'smalldatetime_col', type: sql.SmallDateTime, value: testDate },
|
|
240
|
-
{ name: 'time_col', type: sql.Time(
|
|
253
|
+
{ name: 'time_col', type: sql.Time(7), value: testDate }
|
|
241
254
|
]
|
|
242
255
|
);
|
|
243
256
|
await waitForPendingCDCChanges(beforeLSN, connectionManager);
|
|
@@ -246,14 +259,32 @@ describe('MSSQL Data Types Tests', () => {
|
|
|
246
259
|
const replicatedRows = await getReplicatedRows(connectionManager, 'test_data');
|
|
247
260
|
const expectedResult = {
|
|
248
261
|
date_col: '2023-03-06',
|
|
249
|
-
datetime_col: '2023-03-06T15:47:00.
|
|
250
|
-
datetime2_col: '2023-03-06T15:47:00.
|
|
251
|
-
smalldatetime_col: '2023-03-06T15:47:00.
|
|
252
|
-
time_col: '15:47:00.
|
|
262
|
+
datetime_col: '2023-03-06T15:47:00.123000000Z',
|
|
263
|
+
datetime2_col: '2023-03-06T15:47:00.123456700Z',
|
|
264
|
+
smalldatetime_col: '2023-03-06T15:47:00.000000000Z',
|
|
265
|
+
time_col: '15:47:00.123456700'
|
|
253
266
|
};
|
|
254
267
|
|
|
255
|
-
expect(databaseRows[0]).toMatchObject(
|
|
256
|
-
|
|
268
|
+
expect(applyRowContext(databaseRows[0], CompatibilityContext.FULL_BACKWARDS_COMPATIBILITY)).toMatchObject(
|
|
269
|
+
expectedResult
|
|
270
|
+
);
|
|
271
|
+
expect(applyRowContext(replicatedRows[0], CompatibilityContext.FULL_BACKWARDS_COMPATIBILITY)).toMatchObject(
|
|
272
|
+
expectedResult
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
const restrictedPrecisionResult = {
|
|
276
|
+
date_col: '2023-03-06',
|
|
277
|
+
datetime_col: '2023-03-06T15:47:00.123000Z',
|
|
278
|
+
datetime2_col: '2023-03-06T15:47:00.123456Z',
|
|
279
|
+
smalldatetime_col: '2023-03-06T15:47:00.000000Z',
|
|
280
|
+
time_col: '15:47:00.123456'
|
|
281
|
+
};
|
|
282
|
+
const restrictedPrecision = new CompatibilityContext({
|
|
283
|
+
edition: 2,
|
|
284
|
+
maxTimeValuePrecision: TimeValuePrecision.microseconds
|
|
285
|
+
});
|
|
286
|
+
expect(applyRowContext(databaseRows[0], restrictedPrecision)).toMatchObject(restrictedPrecisionResult);
|
|
287
|
+
expect(applyRowContext(replicatedRows[0], restrictedPrecision)).toMatchObject(restrictedPrecisionResult);
|
|
257
288
|
});
|
|
258
289
|
|
|
259
290
|
test('Date types edge cases mappings', async () => {
|
|
@@ -277,18 +308,22 @@ describe('MSSQL Data Types Tests', () => {
|
|
|
277
308
|
await waitForPendingCDCChanges(beforeLSN, connectionManager);
|
|
278
309
|
|
|
279
310
|
const expectedResults = [
|
|
280
|
-
{ datetime2_col: '0001-01-01T00:00:00.
|
|
281
|
-
{ datetime2_col: '9999-12-31T23:59:59.
|
|
282
|
-
{ datetime_col: '1753-01-01T00:00:00.
|
|
283
|
-
{ datetime_col: '9999-12-31T23:59:59.
|
|
311
|
+
{ datetime2_col: '0001-01-01T00:00:00.000000000Z' },
|
|
312
|
+
{ datetime2_col: '9999-12-31T23:59:59.999000000Z' },
|
|
313
|
+
{ datetime_col: '1753-01-01T00:00:00.000000000Z' },
|
|
314
|
+
{ datetime_col: '9999-12-31T23:59:59.997000000Z' }
|
|
284
315
|
];
|
|
285
316
|
|
|
286
317
|
const databaseRows = await getDatabaseRows(connectionManager, 'test_data');
|
|
287
318
|
const replicatedRows = await getReplicatedRows(connectionManager, 'test_data');
|
|
288
319
|
|
|
289
320
|
for (let i = 0; i < expectedResults.length; i++) {
|
|
290
|
-
expect(databaseRows[i]).toMatchObject(
|
|
291
|
-
|
|
321
|
+
expect(applyRowContext(databaseRows[i], CompatibilityContext.FULL_BACKWARDS_COMPATIBILITY)).toMatchObject(
|
|
322
|
+
expectedResults[i]
|
|
323
|
+
);
|
|
324
|
+
expect(applyRowContext(replicatedRows[i], CompatibilityContext.FULL_BACKWARDS_COMPATIBILITY)).toMatchObject(
|
|
325
|
+
expectedResults[i]
|
|
326
|
+
);
|
|
292
327
|
}
|
|
293
328
|
});
|
|
294
329
|
|
|
@@ -302,15 +337,19 @@ describe('MSSQL Data Types Tests', () => {
|
|
|
302
337
|
await waitForPendingCDCChanges(beforeLSN, connectionManager);
|
|
303
338
|
|
|
304
339
|
const expectedResult = {
|
|
305
|
-
datetimeoffset_col: '2023-03-06T10:47:00.
|
|
340
|
+
datetimeoffset_col: '2023-03-06T10:47:00.000000000Z' // Converted to UTC
|
|
306
341
|
};
|
|
307
342
|
|
|
308
343
|
const databaseRows = await getDatabaseRows(connectionManager, 'test_data');
|
|
309
344
|
const replicatedRows = await getReplicatedRows(connectionManager, 'test_data');
|
|
310
345
|
|
|
311
346
|
// Note: The driver converts DateTimeOffset to Date, which incorporates the timezone offset which is then represented in UTC.
|
|
312
|
-
expect(databaseRows[0]).toMatchObject(
|
|
313
|
-
|
|
347
|
+
expect(applyRowContext(databaseRows[0], CompatibilityContext.FULL_BACKWARDS_COMPATIBILITY)).toMatchObject(
|
|
348
|
+
expectedResult
|
|
349
|
+
);
|
|
350
|
+
expect(applyRowContext(replicatedRows[0], CompatibilityContext.FULL_BACKWARDS_COMPATIBILITY)).toMatchObject(
|
|
351
|
+
expectedResult
|
|
352
|
+
);
|
|
314
353
|
});
|
|
315
354
|
|
|
316
355
|
test('UniqueIdentifier type mapping', async () => {
|
package/test/tsconfig.json
CHANGED
|
@@ -19,10 +19,13 @@
|
|
|
19
19
|
"path": "../"
|
|
20
20
|
},
|
|
21
21
|
{
|
|
22
|
-
"path": "../../../packages/service-core
|
|
22
|
+
"path": "../../../packages/service-core-tests"
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
|
-
"path": "
|
|
25
|
+
"path": "../../module-mongodb-storage"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"path": "../../module-postgres-storage"
|
|
26
29
|
}
|
|
27
30
|
]
|
|
28
31
|
}
|