mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-03 08:38:42 -05:00
Move app to apps/web-react in pnpm workspace layout
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { db } from "~/db/sql";
|
||||
import type { TablesInsertable } from "~/db/tables";
|
||||
|
||||
type FindAllResult = Awaited<ReturnType<typeof queryAll>>;
|
||||
let cachedRotations: FindAllResult | null = null;
|
||||
|
||||
export async function replaceAll(
|
||||
rotations: Omit<TablesInsertable["SplatoonRotation"], "id">[],
|
||||
) {
|
||||
await db.transaction().execute(async (trx) => {
|
||||
await trx.deleteFrom("SplatoonRotation").execute();
|
||||
|
||||
await trx.insertInto("SplatoonRotation").values(rotations).execute();
|
||||
});
|
||||
|
||||
cachedRotations = await queryAll();
|
||||
}
|
||||
|
||||
export async function findAll() {
|
||||
if (cachedRotations) return cachedRotations;
|
||||
|
||||
const result = await queryAll();
|
||||
cachedRotations = result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function queryAll() {
|
||||
return db
|
||||
.selectFrom("SplatoonRotation")
|
||||
.select([
|
||||
"SplatoonRotation.id",
|
||||
"SplatoonRotation.type",
|
||||
"SplatoonRotation.mode",
|
||||
"SplatoonRotation.stageId1",
|
||||
"SplatoonRotation.stageId2",
|
||||
"SplatoonRotation.startsAt",
|
||||
"SplatoonRotation.endsAt",
|
||||
])
|
||||
.orderBy("SplatoonRotation.startsAt", "asc")
|
||||
.execute();
|
||||
}
|
||||
Reference in New Issue
Block a user