Replace mysql2 with prisma
also I updated packages, and properly typed api input a lot of time was spent, I don't remeber what really I did x3 but everything was related to replacing mysql2 with prisma
This commit is contained in:
parent
be1e3909b6
commit
eebf25198d
39 changed files with 1081 additions and 1292 deletions
|
@ -1,13 +1,14 @@
|
|||
import { defineEventHandler } from "h3";
|
||||
import { type data, database } from "../utils/database";
|
||||
import { 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;
|
||||
try {
|
||||
const numberOfUsers = await database.user.count();
|
||||
return numberOfUsers === 0;
|
||||
} catch {
|
||||
// We could fall here if the database is not initialized
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export default defineEventHandler((e) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue