Git Product home page Git Product logo

Comments (2)

taoliujun avatar taoliujun commented on September 22, 2024

I found that two interface requests, querying the table twice in parallel, would cause the time_zone to change.

// the code here, don't use await before query.
 const timezone2 = await DB_DEFAULT.query('select @@session.time_zone;');
console.log('==timezone2', timezone2);

DB_DEFAULT.query(
            'SELECT `AdminUserModel`.`id` AS `AdminUserModel_id`, `AdminUserModel`.`createTime` AS `AdminUserModel_createTime`, `AdminUserModel`.`updateTime` AS `AdminUserModel_updateTime`, `AdminUserModel`.`status` AS `AdminUserModel_status`, `AdminUserModel`.`nickname` AS `AdminUserModel_nickname`, `AdminUserModel`.`contact` AS `AdminUserModel_contact`, `AdminUserModel`.`roleIds` AS `AdminUserModel_roleIds` FROM `adminUser` `AdminUserModel` WHERE ((`AdminUserModel`.`id` = ?)) LIMIT 1 ',
            ['28'],
        );
DB_DEFAULT.query(
            'SELECT `AdminUserModel`.`id` AS `AdminUserModel_id`, `AdminUserModel`.`createTime` AS `AdminUserModel_createTime`, `AdminUserModel`.`updateTime` AS `AdminUserModel_updateTime`, `AdminUserModel`.`status` AS `AdminUserModel_status`, `AdminUserModel`.`nickname` AS `AdminUserModel_nickname`, `AdminUserModel`.`contact` AS `AdminUserModel_contact`, `AdminUserModel`.`roleIds` AS `AdminUserModel_roleIds` FROM `adminUser` `AdminUserModel` WHERE ((`AdminUserModel`.`id` = ?)) LIMIT 1 ',
            ['29'],
        );

const timezone3 = await DB_DEFAULT.query('select @@session.time_zone;');
console.log('==timezone3', timezone3);
// the log here
==timezone2 [ { '@@session.time_zone': 'SYSTEM' } ]
query: SELECT `AdminUserModel`.`id` AS `AdminUserModel_id`, `AdminUserModel`.`createTime` AS `AdminUserModel_createTime`, `AdminUserModel`.`updateTime` AS `AdminUserModel_updateTime`, `AdminUserModel`.`status` AS `AdminUserModel_status`, `AdminUserModel`.`nickname` AS `AdminUserModel_nickname`, `AdminUserModel`.`contact` AS `AdminUserModel_contact`, `AdminUserModel`.`roleIds` AS `AdminUserModel_roleIds` FROM `adminUser` `AdminUserModel` WHERE ((`AdminUserModel`.`id` = ?)) LIMIT 1  -- PARAMETERS: ["28"]
query: SELECT `AdminUserModel`.`id` AS `AdminUserModel_id`, `AdminUserModel`.`createTime` AS `AdminUserModel_createTime`, `AdminUserModel`.`updateTime` AS `AdminUserModel_updateTime`, `AdminUserModel`.`status` AS `AdminUserModel_status`, `AdminUserModel`.`nickname` AS `AdminUserModel_nickname`, `AdminUserModel`.`contact` AS `AdminUserModel_contact`, `AdminUserModel`.`roleIds` AS `AdminUserModel_roleIds` FROM `adminUser` `AdminUserModel` WHERE ((`AdminUserModel`.`id` = ?)) LIMIT 1  -- PARAMETERS: ["29"]
query: select @@session.time_zone;
==timezone3 [ { '@@session.time_zone': '+08:00' } ]

from typeorm.

alumni avatar alumni commented on September 22, 2024

Not sure how it is for MySQL, but for other drivers (e.g. SAP HANA), a DataSource maintains multiple database connections in a pool. Every query will get a random database connection from this pool.

So you might want to use a QueryRunner for setting session variables and execute every query using that QueryRunner. Don't forget to clean up when you're done (unset the session variable), since the database connection is returned to the pool and reused later by someone else.

I would close this issue since it's working correctly.

from typeorm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.