Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/node-mysql2/src/db/query_sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export interface CreateAuthorReturnIdArgs {
bio: string | null;
}

export async function createAuthorReturnId(client: Client, args: CreateAuthorReturnIdArgs): Promise<number> {
export async function createAuthorReturnId(client: Client, args: CreateAuthorReturnIdArgs): Promise<number | string> {
const [result] = await client.query<ResultSetHeader>({
sql: createAuthorReturnIdQuery,
values: [args.name, args.bio]
Expand Down
20 changes: 14 additions & 6 deletions src/drivers/mysql2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ function funcParamsDecl(iface: string | undefined, params: Parameter[]) {
}

export class Driver {
private readonly options: Mysql2Options
private readonly options: Mysql2Options;

constructor(options?: Mysql2Options) {
this.options = options ?? {}
this.options = options ?? {};
}

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

if (this.options.support_big_numbers) {
if (this.options.big_number_strings) {
typ = factory.createKeywordTypeNode(SyntaxKind.StringKeyword)
typ = factory.createKeywordTypeNode(SyntaxKind.StringKeyword);
} else {
typ = factory.createUnionTypeNode([
factory.createKeywordTypeNode(SyntaxKind.NumberKeyword),
factory.createKeywordTypeNode(SyntaxKind.StringKeyword)
])
factory.createKeywordTypeNode(SyntaxKind.StringKeyword),
]);
}
}

Expand Down Expand Up @@ -655,6 +655,14 @@ export class Driver {
) {
const funcParams = funcParamsDecl(argIface, params);

let returnType: TypeNode = factory.createTypeReferenceNode("number", undefined);
if (this.options.support_big_numbers) {
returnType = factory.createUnionTypeNode([
factory.createTypeReferenceNode("number", undefined),
factory.createTypeReferenceNode("string", undefined),
]);
}

return factory.createFunctionDeclaration(
[
factory.createToken(SyntaxKind.ExportKeyword),
Expand All @@ -665,7 +673,7 @@ export class Driver {
undefined,
funcParams,
factory.createTypeReferenceNode(factory.createIdentifier("Promise"), [
factory.createTypeReferenceNode("number", undefined),
returnType,
]),
factory.createBlock(
[
Expand Down