Skip to content

Commit

Permalink
test: suppprt custom env to run test (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Jun 12, 2023
1 parent 53cb794 commit 37d8d8c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/PoolConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
16 changes: 5 additions & 11 deletions test/config.ts
Original file line number Diff line number Diff line change
@@ -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',
};

0 comments on commit 37d8d8c

Please sign in to comment.