mirror of
https://github.com/haexhub/haex-hub.git
synced 2025-12-16 22:20:51 +01:00
Improve database query handling with automatic fallback for RETURNING clauses
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "haex-hub",
|
"name": "haex-hub",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.1.11",
|
"version": "0.1.12",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "nuxt build",
|
"build": "nuxt build",
|
||||||
|
|||||||
@ -365,17 +365,37 @@ async function handleDatabaseMethodAsync(
|
|||||||
|
|
||||||
switch (request.method) {
|
switch (request.method) {
|
||||||
case 'haextension.db.query': {
|
case 'haextension.db.query': {
|
||||||
const rows = await invoke<unknown[]>('extension_sql_select', {
|
try {
|
||||||
sql: params.query || '',
|
const rows = await invoke<unknown[]>('extension_sql_select', {
|
||||||
params: params.params || [],
|
sql: params.query || '',
|
||||||
publicKey: extension.publicKey,
|
params: params.params || [],
|
||||||
name: extension.name,
|
publicKey: extension.publicKey,
|
||||||
})
|
name: extension.name,
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
rows,
|
rows,
|
||||||
rowsAffected: 0,
|
rowsAffected: 0,
|
||||||
lastInsertId: undefined,
|
lastInsertId: undefined,
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
// If error is about non-SELECT statements (INSERT/UPDATE/DELETE with RETURNING),
|
||||||
|
// automatically retry with execute
|
||||||
|
if (error?.message?.includes('Only SELECT statements are allowed')) {
|
||||||
|
const rows = await invoke<unknown[]>('extension_sql_execute', {
|
||||||
|
sql: params.query || '',
|
||||||
|
params: params.params || [],
|
||||||
|
publicKey: extension.publicKey,
|
||||||
|
name: extension.name,
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
rows,
|
||||||
|
rowsAffected: rows.length,
|
||||||
|
lastInsertId: undefined,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user