8000 fix: always return result of last stmt w/ rows · rogervaas/postgres-meta@92c850a · GitHub
[go: up one dir, main page]

Skip to content

Commit 92c850a

Browse files
committed
fix: always return result of last stmt w/ rows
1 parent 8532f86 commit 92c850a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/lib/db.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,19 @@ export const init: (config: PoolConfig) => {
3535
try {
3636
if (!pool) {
3737
const pool = new Pool(config)
38-
const { rows } = await pool.query(sql)
38+
let res = await pool.query(sql)
39+
if (Array.isArray(res)) {
40+
res = res.reverse().find((x) => x.rows.length !== 0) ?? { rows: [] }
41+
}
3942
await pool.end()
40-
return { data: rows, error: null }
43+
return { data: res.rows, error: null }
4144
}
4245

43-
const { rows } = await pool.query(sql)
44-
return { data: rows, error: null }
46+
let res = await pool.query(sql)
47+
if (Array.isArray(res)) {
48+
res = res.reverse().find((x) => x.rows.length !== 0) ?? { rows: [] }
49+
}
50+
return { data: res.rows, error: null }
4551
} catch (e: any) {
4652
return { data: null, error: { message: e.message } }
4753
}

0 commit comments

Comments
 (0)
0