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
44
server/utils/prismaToWeb.ts
Normal file
44
server/utils/prismaToWeb.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import { Decimal } from "@prisma/client/runtime/library";
|
||||
|
||||
type func = (...args: any[]) => any | Function;
|
||||
|
||||
export type replaceJsonUnparsableToString<T> =
|
||||
T extends Array<infer E> ? Array<replaceJsonUnparsableToString<E>>
|
||||
: {
|
||||
[K in keyof T]:
|
||||
T[K] extends null ? null
|
||||
: T[K] extends func ? never
|
||||
: T[K] extends Decimal ? `${number}`
|
||||
: T[K] extends Array<infer E> ? Array<replaceJsonUnparsableToString<E>>
|
||||
: T[K] extends object ? replaceJsonUnparsableToString<T[K]>
|
||||
: T[K] extends bigint ? `${bigint}`
|
||||
: T[K]
|
||||
};
|
||||
|
||||
type exactToInterface = (...args: any[]) => any extends Function ? true : false;
|
||||
|
||||
function arrayPrismaToWeb<T>(array: Array<T>) {
|
||||
return array.reduce(
|
||||
(pV, cV) => {
|
||||
pV.push(prismaToWeb(cV));
|
||||
return pV;
|
||||
},
|
||||
[] as Array<replaceJsonUnparsableToString<T>>,
|
||||
);
|
||||
}
|
||||
|
||||
export function prismaToWeb<T>(ivalue: T): replaceJsonUnparsableToString<T> {
|
||||
const rvalue: any = ivalue instanceof Array ? [] : {};
|
||||
|
||||
for (const i in ivalue) {
|
||||
const current = ivalue[i];
|
||||
if (current === null) rvalue[i] = null;
|
||||
else if (typeof current === 'function') continue;
|
||||
else if (current instanceof Decimal) rvalue[i] = current.toString();
|
||||
else if (current instanceof Array) rvalue[i] = arrayPrismaToWeb(current);
|
||||
else if (typeof current === 'object') rvalue[i] = prismaToWeb(current);
|
||||
else if (typeof current === 'bigint') rvalue[i] = current.toString();
|
||||
else rvalue[i] = current;
|
||||
}
|
||||
return rvalue;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue