@powersync/service-module-mysql 0.1.5 → 0.1.7

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.
@@ -200,6 +200,7 @@ INSERT INTO test_data (
200
200
 
201
201
  test('Date types mappings', async () => {
202
202
  await setupTable();
203
+ // Timezone offset is set on the pool to +00:00
203
204
  await connectionManager.query(`
204
205
  INSERT INTO test_data(date_col, datetime_col, timestamp_col, time_col, year_col)
205
206
  VALUES('2023-03-06', '2023-03-06 15:47', '2023-03-06 15:47', '15:47:00', '2023');
@@ -222,23 +223,40 @@ INSERT INTO test_data (
222
223
  test('Date types edge cases mappings', async () => {
223
224
  await setupTable();
224
225
 
225
- await connectionManager.query(`INSERT INTO test_data(timestamp_col) VALUES('1970-01-01 00:00:01')`);
226
- await connectionManager.query(`INSERT INTO test_data(timestamp_col) VALUES('2038-01-19 03:14:07.499')`);
227
- await connectionManager.query(`INSERT INTO test_data(datetime_col) VALUES('1000-01-01 00:00:00')`);
228
- await connectionManager.query(`INSERT INTO test_data(datetime_col) VALUES('9999-12-31 23:59:59.499')`);
229
-
230
- const databaseRows = await getDatabaseRows(connectionManager, 'test_data');
231
- const replicatedRows = await getReplicatedRows(4);
232
- const expectedResults = [
233
- { timestamp_col: '1970-01-01T00:00:01.000Z' },
234
- { timestamp_col: '2038-01-19T03:14:07.499Z' },
235
- { datetime_col: '1000-01-01T00:00:00.000Z' },
236
- { datetime_col: '9999-12-31T23:59:59.499Z' }
237
- ];
238
-
239
- for (let i = 0; i < expectedResults.length; i++) {
240
- expect(databaseRows[i]).toMatchObject(expectedResults[i]);
241
- expect(replicatedRows[i]).toMatchObject(expectedResults[i]);
226
+ const connection = await connectionManager.getConnection();
227
+ try {
228
+ // Disable strict mode, to allow dates such as '2024-00-00'.
229
+ await connection.query(`SET SESSION sql_mode=''`);
230
+ await connection.query(`SET SESSION time_zone='+00:00'`);
231
+
232
+ await connection.query(`INSERT INTO test_data(timestamp_col) VALUES('1970-01-01 00:00:01')`);
233
+ await connection.query(`INSERT INTO test_data(timestamp_col) VALUES('2038-01-19 03:14:07.499')`);
234
+ await connection.query(`INSERT INTO test_data(datetime_col) VALUES('1000-01-01 00:00:00')`);
235
+ await connection.query(`INSERT INTO test_data(datetime_col) VALUES('9999-12-31 23:59:59.499')`);
236
+ await connection.query(`INSERT INTO test_data(datetime_col) VALUES('0000-00-00 00:00:00')`);
237
+ await connection.query(`INSERT INTO test_data(datetime_col) VALUES('2024-00-00 00:00:00')`);
238
+ // TODO: This has a mismatch between querying directly and with Zongji.
239
+ // await connection.query(`INSERT INTO test_data(date_col) VALUES('2024-00-00')`);
240
+
241
+ const expectedResults = [
242
+ { timestamp_col: '1970-01-01T00:00:01.000Z' },
243
+ { timestamp_col: '2038-01-19T03:14:07.499Z' },
244
+ { datetime_col: '1000-01-01T00:00:00.000Z' },
245
+ { datetime_col: '9999-12-31T23:59:59.499Z' },
246
+ { datetime_col: null },
247
+ { datetime_col: null }
248
+ // { date_col: '2023-11-30' } or { date_col: null }?
249
+ ];
250
+
251
+ const databaseRows = await getDatabaseRows(connectionManager, 'test_data');
252
+ const replicatedRows = await getReplicatedRows(expectedResults.length);
253
+
254
+ for (let i = 0; i < expectedResults.length; i++) {
255
+ expect(databaseRows[i]).toMatchObject(expectedResults[i]);
256
+ expect(replicatedRows[i]).toMatchObject(expectedResults[i]);
257
+ }
258
+ } finally {
259
+ connection.release;
242
260
  }
243
261
  });
244
262
 
@@ -282,8 +300,7 @@ async function getReplicatedRows(expectedTransactionsCount?: number): Promise<Sq
282
300
  const zongji = new ZongJi({
283
301
  host: TEST_CONNECTION_OPTIONS.hostname,
284
302
  user: TEST_CONNECTION_OPTIONS.username,
285
- password: TEST_CONNECTION_OPTIONS.password,
286
- timeZone: 'Z' // Ensure no auto timezone manipulation of the dates occur
303
+ password: TEST_CONNECTION_OPTIONS.password
287
304
  });
288
305
 
289
306
  const completionPromise = new Promise<SqliteRow[]>((resolve, reject) => {