16 lines
561 B
TypeScript
16 lines
561 B
TypeScript
|
/* global defineEventHandler */
|
||
|
import { data, database } from "../utils/database";
|
||
|
|
||
|
export async function isFirstRun() {
|
||
|
const [tables] = await database.query({ sql: "SHOW TABLES", rowsAsArray: true }, []) as data<[string]>;
|
||
|
if (tables.length === 0) return true;
|
||
|
if (!tables.find(a => a[0] === "users")) return true;
|
||
|
const [[users]] = await database.query("SELECT COUNT(*) as `count` FROM `users`") as data<{count: number}>;
|
||
|
if (users.count === 0) return true;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
export default defineEventHandler((e) => {
|
||
|
return isFirstRun();
|
||
|
});
|