mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-21 06:29:29 -05:00
* From scrims * wip * wip * wip * wip * WIP * wip * wip * wip * wip * wip * import ordering
38 lines
890 B
TypeScript
38 lines
890 B
TypeScript
import { type ColumnType, sql } from "kysely";
|
|
import type { Tables } from "~/db/tables";
|
|
|
|
export const COMMON_USER_FIELDS = [
|
|
"User.id",
|
|
"User.username",
|
|
"User.discordId",
|
|
"User.discordAvatar",
|
|
"User.customUrl",
|
|
] as const;
|
|
|
|
export type CommonUser = Pick<
|
|
Tables["User"],
|
|
"id" | "username" | "discordId" | "discordAvatar" | "customUrl"
|
|
>;
|
|
|
|
export const userChatNameColor = sql<
|
|
string | null
|
|
>`IIF(COALESCE("User"."patronTier", 0) >= 2, "User"."css" ->> 'chat', null)`.as(
|
|
"chatNameColor",
|
|
);
|
|
|
|
/** Prevents ParseJSONResultsPlugin from trying to parse this as JSON */
|
|
export function unJsonify<T>(value: T) {
|
|
if (typeof value !== "string") {
|
|
return value;
|
|
}
|
|
|
|
if (value.match(/^[\[\{]/) === null) {
|
|
return value;
|
|
}
|
|
|
|
return `\\${value}`;
|
|
}
|
|
|
|
export type JSONColumnTypeNullable<SelectType extends object | null> =
|
|
ColumnType<SelectType | null, string | null, string | null>;
|