diff --git a/README.md b/README.md index 033c90a..1f0dc05 100644 --- a/README.md +++ b/README.md @@ -408,6 +408,24 @@ INSERT INTO `user` SET `name` = 'fengmk2', `createdAt` = now() const session = new db.literals.Literal('session()'); ``` +## Class Relation + +```txt ++-----------+ +----------------+ +| RDSClient +-- beginTransaction() --> + RDSTransaction | ++--+----+---+ +----+----+------+ + | | getConnection() .conn | | + | | +---------------+ | | + | +-------->+ RDSConnection +<--------+ | + | +-------+-------+ | + | | extends | + | v | + | extends +-------+-------+ extends | + +------------->+ Operator +<-------------+ + | query() | + +---------------+ +``` + ## License [MIT](LICENSE) diff --git a/src/operator.ts b/src/operator.ts index f5110b0..d86a5f3 100644 --- a/src/operator.ts +++ b/src/operator.ts @@ -79,7 +79,7 @@ export abstract class Operator { } } } - debug('query %o', sql); + debug('[connection#%s] query %o', this.threadId, sql); const queryStart = performance.now(); let rows: any; let lastError: Error | undefined; @@ -90,15 +90,15 @@ export abstract class Operator { try { rows = await this._query(sql); if (Array.isArray(rows)) { - debug('query get %o rows', rows.length); + debug('[connection#%s] query get %o rows', this.threadId, rows.length); } else { - debug('query result: %o', rows); + debug('[connection#%s] query result: %o', this.threadId, rows); } return rows; } catch (err) { lastError = err; err.stack = `${err.stack}\n sql: ${sql}`; - debug('query error: %o', err); + debug('[connection#%s] query error: %o', this.threadId, err); throw err; } finally { const duration = Math.floor((performance.now() - queryStart) * 1000) / 1000; diff --git a/test/PoolConfig.test.ts b/test/PoolConfig.test.ts index 551e0ee..f82e848 100644 --- a/test/PoolConfig.test.ts +++ b/test/PoolConfig.test.ts @@ -81,7 +81,7 @@ describe('test/PoolConfig.test.ts', () => { it('should get connection config from newConnectionConfig()', async () => { assert.equal(db.pool.config.connectionConfig.database, undefined); assert.equal(index, 1); - assert.equal((db.pool.config as any).newConnectionConfig().database, 'test'); + assert.equal((db.pool.config as any).newConnectionConfig().database, config.database); assert.equal(index, 2); }); diff --git a/test/config.ts b/test/config.ts index 71e07eb..79a2b93 100644 --- a/test/config.ts +++ b/test/config.ts @@ -1,13 +1,7 @@ export default { - // host: 'localhost', - host: '127.0.0.1', - port: 3306, - user: 'root', - password: '', - database: 'test', - // host: env.ALI_SDK_RDS_HOST || 'localhost', - // port: env.ALI_SDK_RDS_PORT || 3306, - // user: env.ALI_SDK_RDS_USER || 'root', - // password: env.ALI_SDK_RDS_PASSWORD || '', - // database: env.ALI_SDK_RDS_DATABASE || 'test', + host: process.env.TEST_ALI_RDS_HOST || '127.0.0.1', + port: parseInt(process.env.TEST_ALI_RDS_PORT || '3306'), + user: process.env.TEST_ALI_RDS_USER || 'root', + password: process.env.TEST_ALI_RDS_PASSWORD || '', + database: process.env.TEST_ALI_RDS_DATABASE || 'test', };