forked from ali-sdk/ali-rds
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: use sql params #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -357,7 +357,7 @@ describe('test/client.test.ts', () => { | |
| [ table, prefix + '[email protected]' ]); | ||
| assert.deepEqual(mockLogs, [ | ||
| 'show tables', | ||
| `select * from \`${table}\` where email = '${prefix + '[email protected]'}' limit 1`, | ||
| 'select * from ?? where email = ? limit 1', | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
@@ -1478,7 +1478,7 @@ describe('test/client.test.ts', () => { | |
| counter2After++; | ||
| }); | ||
| await db.query('select * from ?? limit 10', [ table ]); | ||
| assert.equal(lastSql, 'select * from `myrds-test-user` limit 10'); | ||
| assert.equal(lastSql, 'select * from ?? limit 10'); | ||
| assert.equal(lastArgs[0], lastSql); | ||
| assert.equal(Array.isArray(lastArgs[1]), true); | ||
| assert.equal(count, 1); | ||
|
|
@@ -1491,8 +1491,8 @@ describe('test/client.test.ts', () => { | |
| values(?, ?, now(), now())`, | ||
| [ table, prefix + 'beginTransactionScope1', prefix + '[email protected]' ]); | ||
| }); | ||
| assert.equal(lastSql, 'insert into `myrds-test-user`(name, email, gmt_create, gmt_modified)\n' + | ||
| ` values('${prefix}beginTransactionScope1', '${prefix}[email protected]', now(), now())`); | ||
| assert.equal(lastSql, 'insert into ??(name, email, gmt_create, gmt_modified)\n' + | ||
| ' values(?, ?, now(), now())'); | ||
| assert.equal(lastArgs[0], lastSql); | ||
| assert.equal(lastArgs[1].affectedRows, 1); | ||
| assert.equal(count, 2); | ||
|
|
@@ -1502,8 +1502,8 @@ describe('test/client.test.ts', () => { | |
| values(?, ?, now(), now())`, | ||
| [ table, prefix + 'beginDoomedTransactionScope1', prefix + '[email protected]' ]); | ||
| }); | ||
| assert.equal(lastSql, 'insert into `myrds-test-user`(name, email, gmt_create, gmt_modified)\n' + | ||
| ` values('${prefix}beginDoomedTransactionScope1', '${prefix}[email protected]', now(), now())`); | ||
| assert.equal(lastSql, 'insert into ??(name, email, gmt_create, gmt_modified)\n' + | ||
| ' values(?, ?, now(), now())'); | ||
| assert.equal(lastArgs[0], lastSql); | ||
| assert.equal(lastArgs[1].affectedRows, 1); | ||
| assert.equal(count, 3); | ||
|
|
@@ -1514,8 +1514,8 @@ describe('test/client.test.ts', () => { | |
| values(?, ?, now(), now())`, | ||
| [ table, prefix + 'transaction1', prefix + '[email protected]' ]); | ||
| await conn.commit(); | ||
| assert.equal(lastSql, 'insert into `myrds-test-user`(name, email, gmt_create, gmt_modified)\n' + | ||
| ` values('${prefix}transaction1', '${prefix}[email protected]', now(), now())`); | ||
| assert.equal(lastSql, 'insert into ??(name, email, gmt_create, gmt_modified)\n' + | ||
| ' values(?, ?, now(), now())'); | ||
| assert.equal(lastArgs[0], lastSql); | ||
| assert.equal(lastArgs[1].affectedRows, 1); | ||
| assert.equal(count, 4); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Type mismatch with
PoolConnectionPromisify.queryinterface.The
valuestype here isobject | any[], but intypes.tsthequerymethod acceptsany | any[] | { [param: string]: any }, which includes primitives. This inconsistency could cause type errors when forwarding query parameters to these message interfaces.Consider aligning the types. Apply this diff to match the types.ts interface:
export interface QueryStartMessage { connection: PoolConnectionPromisify; - values?: object | any[]; + values?: any | any[] | { [param: string]: any }; sql: string; } export interface QueryEndMessage { connection: PoolConnectionPromisify; sql: string; - values?: object | any[]; + values?: any | any[] | { [param: string]: any }; duration: number; error?: Error; }Alternatively, verify whether MySQL actually accepts primitive values for query parameters, and if not, update types.ts to use the stricter type:
Also applies to: 34-34
🏁 Script executed:
Length of output: 567
[/run_scripts]
🏁 Script executed:
Length of output: 4458
🏁 Script executed:
Length of output: 146
🏁 Script executed:
Length of output: 440
[/run_scripts]
🏁 Script executed:
Length of output: 1130
🏁 Script executed:
Length of output: 129
Type mismatch confirmed between
PoolConnectionPromisify.queryinterface and usage.The type inconsistency is real and documented:
query(sql: string, values?: any | any[] | { [param: string]: any }): Promise<any>;values?: object | any[];values?: object | any[]The broader type in types.ts (which includes primitives via
any) conflicts with the narrower type in channels.ts and all implementations (object | any[]). This inconsistency could cause type errors if a caller passes a primitive value to the query method.However, note that all implementations consistently use the narrower type, not the broader one declared in types.ts. Before applying the suggested diff, verify which direction to align: either make channels.ts match types.ts (accepting the broader type), or update types.ts to match all implementations and channel messages (using the narrower type).
🤖 Prompt for AI Agents