Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ export class MySQLConnectionManager {
* @param params
*/
async query(query: string, params?: any[]): Promise<[RowDataPacket[], FieldPacket[]]> {
return this.promisePool.query<RowDataPacket[]>(query, params);
let connection: mysqlPromise.PoolConnection | undefined;
try {
connection = await this.promisePool.getConnection();
connection.query(`SET time_zone = "+00:00"`);
return connection.query<RowDataPacket[]>(query, params);
} finally {
connection?.release();
}
}

/**
Expand Down
5 changes: 3 additions & 2 deletions modules/module-mysql/test/src/mysql-to-sqlite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ INSERT INTO test_data (

test('Date types mappings', async () => {
await setupTable();
// Timezone offset is set on the pool to +00:00
await connectionManager.query(`
INSERT INTO test_data(date_col, datetime_col, timestamp_col, time_col, year_col)
VALUES('2023-03-06', '2023-03-06 15:47', '2023-03-06 15:47', '15:47:00', '2023');
Expand All @@ -222,6 +223,7 @@ INSERT INTO test_data (
test('Date types edge cases mappings', async () => {
await setupTable();

// Timezone offset is set on the pool to +00:00
await connectionManager.query(`INSERT INTO test_data(timestamp_col) VALUES('1970-01-01 00:00:01')`);
await connectionManager.query(`INSERT INTO test_data(timestamp_col) VALUES('2038-01-19 03:14:07.499')`);
await connectionManager.query(`INSERT INTO test_data(datetime_col) VALUES('1000-01-01 00:00:00')`);
Expand Down Expand Up @@ -282,8 +284,7 @@ async function getReplicatedRows(expectedTransactionsCount?: number): Promise<Sq
const zongji = new ZongJi({
host: TEST_CONNECTION_OPTIONS.hostname,
user: TEST_CONNECTION_OPTIONS.username,
password: TEST_CONNECTION_OPTIONS.password,
timeZone: 'Z' // Ensure no auto timezone manipulation of the dates occur
password: TEST_CONNECTION_OPTIONS.password
});

const completionPromise = new Promise<SqliteRow[]>((resolve, reject) => {
Expand Down
Loading