feat: migrate backend storage to postgres
This commit is contained in:
@@ -1,24 +1,29 @@
|
||||
import db from '~/utils/sqlite';
|
||||
import { query } from '~/utils/db';
|
||||
import { useResponseSuccess } from '~/utils/response';
|
||||
|
||||
export default defineEventHandler(() => {
|
||||
const configs = db
|
||||
.prepare<{ id: number; name: string; bot_token: string; chat_id: string; notification_types: string; is_enabled: number; created_at: string; updated_at: string }>(
|
||||
`
|
||||
SELECT id, name, bot_token, chat_id, notification_types, is_enabled, created_at, updated_at
|
||||
FROM telegram_notification_configs
|
||||
ORDER BY created_at DESC
|
||||
`,
|
||||
)
|
||||
.all();
|
||||
export default defineEventHandler(async () => {
|
||||
const { rows } = await query<{
|
||||
id: number;
|
||||
name: string;
|
||||
bot_token: string;
|
||||
chat_id: string;
|
||||
notification_types: string;
|
||||
is_enabled: boolean;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}>(
|
||||
`SELECT id, name, bot_token, chat_id, notification_types, is_enabled, created_at, updated_at
|
||||
FROM telegram_notification_configs
|
||||
ORDER BY created_at DESC`,
|
||||
);
|
||||
|
||||
const result = configs.map((row) => ({
|
||||
const result = rows.map((row) => ({
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
botToken: row.bot_token,
|
||||
chatId: row.chat_id,
|
||||
notificationTypes: JSON.parse(row.notification_types) as string[],
|
||||
isEnabled: row.is_enabled === 1,
|
||||
isEnabled: row.is_enabled,
|
||||
createdAt: row.created_at,
|
||||
updatedAt: row.updated_at,
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user