Skip to content

fix: Check for empty row #18

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 1 commit into from
Mar 3, 2024
Merged
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
6 changes: 6 additions & 0 deletions examples/bun-postgres/src/db/query_sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export async function getAuthor(sql: Sql, args: GetAuthorArgs): Promise<GetAutho
return null;
}
const row = rows[0];
if (!row) {
return null;
}
return {
id: row[0],
name: row[1],
Expand Down Expand Up @@ -70,6 +73,9 @@ export async function createAuthor(sql: Sql, args: CreateAuthorArgs): Promise<Cr
return null;
}
const row = rows[0];
if (!row) {
return null;
}
return {
id: row[0],
name: row[1],
Expand Down
6 changes: 6 additions & 0 deletions examples/node-postgres/src/db/query_sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export async function getAuthor(sql: Sql, args: GetAuthorArgs): Promise<GetAutho
return null;
}
const row = rows[0];
if (!row) {
return null;
}
return {
id: row[0],
name: row[1],
Expand Down Expand Up @@ -70,6 +73,9 @@ export async function createAuthor(sql: Sql, args: CreateAuthorArgs): Promise<Cr
return null;
}
const row = rows[0];
if (!row) {
return null;
}
return {
id: row[0],
name: row[1],
Expand Down
49 changes: 37 additions & 12 deletions src/drivers/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,21 +417,25 @@ export function manyDecl(
),
]
),
factory.createIdentifier("values"),
factory.createIdentifier("values")
),
undefined,
undefined,
undefined
)
),
factory.createIdentifier("map"),
factory.createIdentifier("map")
),
undefined,
[
factory.createArrowFunction(
undefined,
undefined,
[
factory.createParameterDeclaration(undefined, undefined, "row"),
factory.createParameterDeclaration(
undefined,
undefined,
"row"
),
],
undefined,
factory.createToken(SyntaxKind.EqualsGreaterThanToken),
Expand Down Expand Up @@ -510,7 +514,9 @@ export function oneDecl(
params.map((param, i) =>
factory.createPropertyAccessExpression(
factory.createIdentifier("args"),
factory.createIdentifier(argName(i, param.column))
factory.createIdentifier(
argName(i, param.column)
)
)
),
false
Expand All @@ -520,7 +526,7 @@ export function oneDecl(
factory.createIdentifier("values")
),
undefined,
undefined,
undefined
)
)
),
Expand Down Expand Up @@ -550,12 +556,31 @@ export function oneDecl(
),
factory.createVariableStatement(
undefined,
factory.createVariableDeclarationList([
factory.createVariableDeclaration("row", undefined, undefined, factory.createElementAccessExpression(
factory.createIdentifier("rows"),
factory.createNumericLiteral("0")
)),
], NodeFlags.Const)
factory.createVariableDeclarationList(
[
factory.createVariableDeclaration(
"row",
undefined,
undefined,
factory.createElementAccessExpression(
factory.createIdentifier("rows"),
factory.createNumericLiteral("0")
)
),
],
NodeFlags.Const
)
),
factory.createIfStatement(
factory.createPrefixUnaryExpression(
SyntaxKind.ExclamationToken,
factory.createIdentifier("row")
),
factory.createBlock(
[factory.createReturnStatement(factory.createNull())],
true
),
undefined
),
factory.createReturnStatement(
factory.createObjectLiteralExpression(
Expand Down