-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support export sql query template in logger (#314)
Co-authored-by: JimmyDaddy <[email protected]>
- Loading branch information
1 parent
95f8636
commit ac39adb
Showing
7 changed files
with
49 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,29 +26,33 @@ describe('=> MySQL driver', () => { | |
result.push([ sql, duration, opts, res ]); | ||
}, | ||
}); | ||
await driver2.query('SELECT 1'); | ||
await driver2.query('SELECT ?, ? FROM users WHERE email = ? AND status = ?', ['id', 'nickname', '[email protected]', 1]); | ||
const [ sql, duration, opts, res ] = result[0]; | ||
assert.equal(sql, 'SELECT 1'); | ||
assert.equal(sql, "SELECT 'id', 'nickname' FROM users WHERE email = '[email protected]' AND status = 1"); | ||
assert.ok(duration >= 0); | ||
assert.ok(res); | ||
assert.ok(opts); | ||
assert.equal(opts.query, 'SELECT ?, ? FROM users WHERE email = ? AND status = ?'); | ||
}); | ||
|
||
it('driver.logger.logQueryError', async () => { | ||
const result = []; | ||
const driver2 = new MysqlDriver({ | ||
...options, | ||
logger: { | ||
logQueryError(sql, err) { | ||
result.push([ sql, err ]); | ||
logQueryError(err, sql, duration, opts) { | ||
result.push([ err, sql, duration, opts ]); | ||
}, | ||
}, | ||
}); | ||
await assert.rejects(async () => await driver2.query('SELECT x')); | ||
const [ err, sql ] = result[0]; | ||
assert.equal(sql, 'SELECT x'); | ||
await assert.rejects(async () => await driver2.query('SELECT x, ? FROM users WHERE email = ? AND status = ?', ['nickname', '[email protected]', 1])); | ||
const [ err, sql, duration, opts ] = result[0]; | ||
assert.equal(sql, "SELECT x, 'nickname' FROM users WHERE email = '[email protected]' AND status = 1"); | ||
assert.ok(duration >= 0); | ||
assert.ok(err); | ||
assert.ok(/ER_BAD_FIELD_ERROR/.test(err.message)); | ||
assert.ok(opts); | ||
assert.equal(opts.query, 'SELECT x, ? FROM users WHERE email = ? AND status = ?'); | ||
}); | ||
|
||
it('driver.querySchemaInfo()', async () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,29 +26,33 @@ describe('=> PostgreSQL driver', () => { | |
result.push([ sql, duration, opts, res ]); | ||
}, | ||
}); | ||
await driver2.query('SELECT 1'); | ||
await driver2.query('SELECT ?, ? FROM users WHERE email = ? AND status = ?', ['id', 'nickname', '[email protected]', 1]); | ||
const [ sql, duration, opts, res ] = result[0]; | ||
assert.equal(sql, 'SELECT 1'); | ||
assert.ok(duration > 0); | ||
assert.equal(sql, "SELECT 'id', 'nickname' FROM users WHERE email = '[email protected]' AND status = 1"); | ||
assert.ok(duration >= 0); | ||
assert.ok(res); | ||
assert.ok(opts); | ||
assert.equal(opts.query, 'SELECT ?, ? FROM users WHERE email = ? AND status = ?'); | ||
}); | ||
|
||
it('driver.logger.logQueryError', async () => { | ||
const result = []; | ||
const driver2 = new PostgresDriver({ | ||
...options, | ||
logger: { | ||
logQueryError(sql, err) { | ||
result.push([ sql, err ]); | ||
logQueryError(err, sql, duration, opts) { | ||
result.push([ err, sql, duration, opts ]); | ||
}, | ||
}, | ||
}); | ||
await assert.rejects(async () => await driver2.query('SELECT x')); | ||
const [ err, sql ] = result[0]; | ||
assert.equal(sql, 'SELECT x'); | ||
await assert.rejects(async () => await driver2.query('SELECT x, ? FROM users WHERE email = ? AND status = ?', ['nickname', '[email protected]', 1])); | ||
const [ err, sql, duration, opts ] = result[0]; | ||
assert.equal(sql, "SELECT x, 'nickname' FROM users WHERE email = '[email protected]' AND status = 1"); | ||
assert.ok(duration >= 0); | ||
assert.ok(err); | ||
assert.ok(/column "x" does not exist/.test(err.message)); | ||
assert.ok(opts); | ||
assert.equal(opts.query, 'SELECT x, ? FROM users WHERE email = ? AND status = ?'); | ||
}); | ||
|
||
it('driver.querySchemaInfo()', async () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,29 +28,33 @@ describe('=> SQLite driver', () => { | |
result.push([ sql, duration, opts, res ]); | ||
}, | ||
}); | ||
await driver2.query('SELECT 1'); | ||
await driver2.query('SELECT ?, ? FROM users WHERE email = ? AND status = ?', ['id', 'nickname', '[email protected]', 1]); | ||
const [ sql, duration, opts, res ] = result[0]; | ||
assert.equal(sql, 'SELECT 1'); | ||
assert.equal(sql, "SELECT 'id', 'nickname' FROM users WHERE email = '[email protected]' AND status = 1"); | ||
assert.ok(duration >= 0); | ||
assert.ok(res); | ||
assert.ok(opts); | ||
assert.equal(opts.query, 'SELECT ?, ? FROM users WHERE email = ? AND status = ?'); | ||
}); | ||
|
||
it('driver.logger.logQueryError', async () => { | ||
const result = []; | ||
const driver2 = new SqliteDriver({ | ||
...options, | ||
logger: { | ||
logQueryError(sql, err) { | ||
result.push([ sql, err ]); | ||
logQueryError(err, sql, duration, opts) { | ||
result.push([ err, sql, duration, opts ]); | ||
}, | ||
}, | ||
}); | ||
await assert.rejects(async () => await driver2.query('SELECT x')); | ||
const [ err, sql ] = result[0]; | ||
assert.equal(sql, 'SELECT x'); | ||
await assert.rejects(async () => await driver2.query('SELECT x, ? FROM users WHERE email = ? AND status = ?', ['nickname', '[email protected]', 1])); | ||
const [ err, sql, duration, opts ] = result[0]; | ||
assert.equal(sql, "SELECT x, 'nickname' FROM users WHERE email = '[email protected]' AND status = 1"); | ||
assert.ok(duration >= 0); | ||
assert.ok(err); | ||
assert.ok(/no such column/.test(err.message)); | ||
assert.ok(opts); | ||
assert.equal(opts.query, 'SELECT x, ? FROM users WHERE email = ? AND status = ?'); | ||
}); | ||
|
||
it('driver.querySchemaInfo()', async () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters