Comments (2)
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.
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)
- Is the repository no longer maintained? HOT 5
- why I must establish relationship before use "leftJoinAndSelect"
- How to correctly create the connection to a local SQL Server database using TypeORM for Langchain? HOT 2
- Typeorm 0.3.20 only supports MongoDB driver 5.x even though the devDependencies use MongoDB driver 6.x for testing HOT 1
- getManyAndCount throws an error when DISTINCT is missing an alias
- Does anyone want to refactor the repository? HOT 1
- Parameter placeholder conflict in TypeORM Query Builder with CTE and WHERE conditions HOT 5
- Output migration SQL
- error or oversight in documentation
- Migrations should use { SET | DROP } NOT NULL instead of recreating column HOT 1
- Left join not working
- OrmUtils.deepCompare cannot compare Map objects HOT 2
- PostgresQueryRunner.loadTables fails when table names contain '"'-sign.
- order by date columns not working
- MySQL ENUM type field is adding values at the end while using field level charset and collation.
- OnDeleteType should include "SET DEFAULT" instead of "DEFAULT"
- Expose more properties from EntityNotFoundError
- Migration: `migration:generate` Can't Generate a Drop SQL Command
- Random connection behavior when using AppDataSource.createQueryRunner().query()
- [email protected] not compatible with [email protected] HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typeorm.