sqlite --> postgres

This commit is contained in:
2025-12-28 14:35:41 +09:00
parent 6196c03e46
commit 9de6af2789
3 changed files with 79 additions and 158 deletions

View File

@@ -1,10 +1,10 @@
import { getDb } from '../../../utils/db'
import { execute } from '../../../utils/db'
import { refreshServerTimer } from '../../../utils/server-scheduler'
export default defineEventHandler(async (event) => {
const targetId = getRouterParam(event, 'id')
const body = await readBody(event)
const { server_name, server_ip, glances_url, is_active, collect_interval } = body
const { name, host, port, username, auth_type, is_active } = body
if (!targetId) {
throw createError({
@@ -13,24 +13,23 @@ export default defineEventHandler(async (event) => {
})
}
const db = getDb()
const result = db.prepare(`
const changes = await execute(`
UPDATE server_targets
SET server_name = ?,
server_ip = ?,
glances_url = ?,
is_active = ?,
collect_interval = ?,
updated_at = datetime('now', 'localtime')
WHERE target_id = ?
`).run(server_name, server_ip, glances_url, is_active ? 1 : 0, collect_interval || 60, targetId)
SET name = $1,
host = $2,
port = $3,
username = $4,
auth_type = $5,
is_active = $6,
updated_at = NOW()
WHERE target_id = $7
`, [name, host, port || 22, username, auth_type || 'password', is_active ? 1 : 0, targetId])
// 스케줄러에 반영
refreshServerTimer(Number(targetId))
return {
success: true,
changes: result.changes
changes
}
})