idz: Add idz_my_chara table
This commit is contained in:
@@ -278,3 +278,12 @@ create table "idz_weekly_missions" (
|
|||||||
"progress_right" integer not null,
|
"progress_right" integer not null,
|
||||||
"params_right" integer not null
|
"params_right" integer not null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
create table "idz_my_chara" (
|
||||||
|
"id" integer primary key not null,
|
||||||
|
"profile_id" integer not null
|
||||||
|
references "idz_profile"("id")
|
||||||
|
on delete cascade,
|
||||||
|
"my_chara_no" integer not null,
|
||||||
|
constraint "idz_my_chara_uq" unique ("profile_id", "my_chara_no")
|
||||||
|
);
|
||||||
|
|||||||
@@ -1,3 +1,12 @@
|
|||||||
|
create table "idz_my_chara" (
|
||||||
|
"id" integer primary key not null,
|
||||||
|
"profile_id" integer not null
|
||||||
|
references "idz_profile"("id")
|
||||||
|
on delete cascade,
|
||||||
|
"my_chara_no" integer not null,
|
||||||
|
constraint "idz_my_chara_uq" unique ("profile_id", "my_chara_no")
|
||||||
|
);
|
||||||
|
|
||||||
create table "new_idz_settings" (
|
create table "new_idz_settings" (
|
||||||
"id" integer primary key not null
|
"id" integer primary key not null
|
||||||
references "idz_profile"("id")
|
references "idz_profile"("id")
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
export type BackgroundCode = number & { __brand: "backgroundCode" };
|
export type BackgroundCode = number & { __brand: "backgroundCode" };
|
||||||
export type CourseNo = number & { __brand: "courseNo" };
|
export type CourseNo = number & { __brand: "courseNo" };
|
||||||
export type ExtId<T> = number & { __extId: T };
|
export type ExtId<T> = number & { __extId: T };
|
||||||
|
export type MyCharaCode = number & { __brand: "myCharaCode" };
|
||||||
export type RouteNo = number & { __brand: "routeNo" };
|
export type RouteNo = number & { __brand: "routeNo" };
|
||||||
export type StampCode = number & { __brand: "stampCode" };
|
export type StampCode = number & { __brand: "stampCode" };
|
||||||
export type TitleCode = number & { __brand: "titleCode" };
|
export type TitleCode = number & { __brand: "titleCode" };
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ export {
|
|||||||
BackgroundCode,
|
BackgroundCode,
|
||||||
CourseNo,
|
CourseNo,
|
||||||
ExtId,
|
ExtId,
|
||||||
|
MyCharaCode,
|
||||||
RouteNo,
|
RouteNo,
|
||||||
StampCode,
|
StampCode,
|
||||||
TitleCode,
|
TitleCode,
|
||||||
|
|||||||
@@ -177,6 +177,8 @@ export interface Repositories {
|
|||||||
// not really a facet tbh
|
// not really a facet tbh
|
||||||
missions(): FacetRepository<Model.MissionState>;
|
missions(): FacetRepository<Model.MissionState>;
|
||||||
|
|
||||||
|
myChara(): FlagRepository<Model.MyCharaCode>;
|
||||||
|
|
||||||
profile(): ProfileRepository;
|
profile(): ProfileRepository;
|
||||||
|
|
||||||
settings(): FacetRepository<Model.Settings>;
|
settings(): FacetRepository<Model.Settings>;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { SqlCarRepository } from "./car";
|
|||||||
import { SqlCharaRepository } from "./chara";
|
import { SqlCharaRepository } from "./chara";
|
||||||
import { SqlCoursePlaysRepository } from "./coursePlays";
|
import { SqlCoursePlaysRepository } from "./coursePlays";
|
||||||
import { SqlMissionsRepository } from "./missions";
|
import { SqlMissionsRepository } from "./missions";
|
||||||
|
import { SqlMyCharaRepository } from "./myChara";
|
||||||
import { SqlProfileRepository } from "./profile";
|
import { SqlProfileRepository } from "./profile";
|
||||||
import { SqlSettingsRepository } from "./settings";
|
import { SqlSettingsRepository } from "./settings";
|
||||||
import { SqlStampsRepository } from "./stamps";
|
import { SqlStampsRepository } from "./stamps";
|
||||||
@@ -43,6 +44,10 @@ export class SqlRepositories implements Repo.Repositories {
|
|||||||
return new SqlMissionsRepository(this._txn);
|
return new SqlMissionsRepository(this._txn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
myChara(): Repo.FlagRepository<Model.MyCharaCode> {
|
||||||
|
return new SqlMyCharaRepository(this._txn);
|
||||||
|
}
|
||||||
|
|
||||||
profile(): Repo.ProfileRepository {
|
profile(): Repo.ProfileRepository {
|
||||||
return new SqlProfileRepository(this._txn);
|
return new SqlProfileRepository(this._txn);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import sql from "sql-bricks-postgres";
|
||||||
|
|
||||||
|
import { MyCharaCode } from "../model/base";
|
||||||
|
import { Profile } from "../model/profile";
|
||||||
|
import { FlagRepository } from "../repo";
|
||||||
|
import { Id } from "../../../model";
|
||||||
|
import { Transaction } from "../../../sql";
|
||||||
|
|
||||||
|
export class SqlMyCharaRepository implements FlagRepository<MyCharaCode> {
|
||||||
|
constructor(private readonly _txn: Transaction) {}
|
||||||
|
|
||||||
|
async loadAll(id: Id<Profile>): Promise<Set<MyCharaCode>> {
|
||||||
|
const loadSql = sql
|
||||||
|
.select("mc.my_chara_no")
|
||||||
|
.from("idz_mychara_unlock mc")
|
||||||
|
.join("idz_profile p", { "mc.profile_id": "p.id" })
|
||||||
|
.where("p.id", id);
|
||||||
|
|
||||||
|
const rows = await this._txn.fetchRows(loadSql);
|
||||||
|
const result = new Set<MyCharaCode>();
|
||||||
|
|
||||||
|
for (const row of rows) {
|
||||||
|
result.add(parseInt(row.my_chara_no!) as MyCharaCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
async saveAll(
|
||||||
|
profileId: Id<Profile>,
|
||||||
|
flags: Set<MyCharaCode>
|
||||||
|
): Promise<void> {
|
||||||
|
const existing = await this.loadAll(profileId);
|
||||||
|
|
||||||
|
for (const flag of flags) {
|
||||||
|
if (existing.has(flag)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const saveSql = sql
|
||||||
|
.insert("idz_mychara_unlock", {
|
||||||
|
id: this._txn.generateId(),
|
||||||
|
profile_id: profileId,
|
||||||
|
my_chara_no: flag,
|
||||||
|
})
|
||||||
|
.onConflict("profile_id", "my_chara_no")
|
||||||
|
.doNothing();
|
||||||
|
|
||||||
|
await this._txn.modify(saveSql);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user