Skip to content
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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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