Skip to content

Commit 402b9f3

Browse files
committed
return number | string from mysql execlastid
1 parent 1a42ab0 commit 402b9f3

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

‎examples/node-mysql2/src/db/query_sql.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export interface CreateAuthorReturnIdArgs{
9191
bio: string|null;
9292
}
9393

94-
exportasyncfunctioncreateAuthorReturnId(client: Client,args: CreateAuthorReturnIdArgs): Promise<number>{
94+
exportasyncfunctioncreateAuthorReturnId(client: Client,args: CreateAuthorReturnIdArgs): Promise<number|string>{
9595
const[result]=awaitclient.query<ResultSetHeader>({
9696
sql: createAuthorReturnIdQuery,
9797
values: [args.name,args.bio]

‎src/drivers/mysql2.ts‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ function funcParamsDecl(iface: string | undefined, params: Parameter[]){
4545
}
4646

4747
exportclassDriver{
48-
privatereadonlyoptions: Mysql2Options
48+
privatereadonlyoptions: Mysql2Options;
4949

5050
constructor(options?: Mysql2Options){
51-
this.options=options??{}
51+
this.options=options??{};
5252
}
5353

5454
columnType(column?: Column): TypeNode{
@@ -63,12 +63,12 @@ export class Driver{
6363

6464
if(this.options.support_big_numbers){
6565
if(this.options.big_number_strings){
66-
typ=factory.createKeywordTypeNode(SyntaxKind.StringKeyword)
66+
typ=factory.createKeywordTypeNode(SyntaxKind.StringKeyword);
6767
}else{
6868
typ=factory.createUnionTypeNode([
6969
factory.createKeywordTypeNode(SyntaxKind.NumberKeyword),
70-
factory.createKeywordTypeNode(SyntaxKind.StringKeyword)
71-
])
70+
factory.createKeywordTypeNode(SyntaxKind.StringKeyword),
71+
]);
7272
}
7373
}
7474

@@ -655,6 +655,14 @@ export class Driver{
655655
){
656656
constfuncParams=funcParamsDecl(argIface,params);
657657

658+
letreturnType: TypeNode=factory.createTypeReferenceNode("number",undefined);
659+
if(this.options.support_big_numbers){
660+
returnType=factory.createUnionTypeNode([
661+
factory.createTypeReferenceNode("number",undefined),
662+
factory.createTypeReferenceNode("string",undefined),
663+
]);
664+
}
665+
658666
returnfactory.createFunctionDeclaration(
659667
[
660668
factory.createToken(SyntaxKind.ExportKeyword),
@@ -665,7 +673,7 @@ export class Driver{
665673
undefined,
666674
funcParams,
667675
factory.createTypeReferenceNode(factory.createIdentifier("Promise"),[
668-
factory.createTypeReferenceNode("number",undefined),
676+
returnType,
669677
]),
670678
factory.createBlock(
671679
[

0 commit comments

Comments
(0)