diff --git a/ismism.ts/src/eid/db.ts b/ismism.ts/src/eid/db.ts new file mode 100644 index 0000000..80a9930 --- /dev/null +++ b/ismism.ts/src/eid/db.ts @@ -0,0 +1,101 @@ +import { Collection, IndexOptions, MongoClient, UpdateFilter, Document } from "./mod.ts" +import { Act, Agd, Aut, Dst, Lit, Ord, Soc, Usr, Video, Work, Wsl } from "./typ.ts" + +const conn = new MongoClient() +await conn.connect("mongodb://127.0.0.1:27017") + +export let coll = await db("tst", true) + +export type Coll = Collection +export type Update = UpdateFilter +export type DocC<_Id> = Promise | null> +export type DocR = Promise | null> +export type DocU = Promise<0 | 1 | null> +export type DocD = Promise<0 | 1 | null> + +const nam: IndexOptions[] = [{ + key: { nam: 1 }, name: "nam", unique: true, +}] +const adm: IndexOptions[] = [{ + key: { adm1: 1 }, name: "adm1", +}, { + key: { adm2: 1 }, name: "adm2", +},] +const re: IndexOptions[] = [{ + key: { rej: 1 }, name: "rej", + partialFilterExpression: { rej: { $exists: true } }, +}, { + key: { ref: 1 }, name: "ref", + partialFilterExpression: { ref: { $exists: true } }, +}] +const rel: IndexOptions[] = [{ + key: { sec: 1 }, name: "sec", +}, { + key: { uid: 1 }, name: "uid", +}, { + key: { res: 1 }, name: "res", + partialFilterExpression: { res: { $exists: true } }, +}] +const nbr: IndexOptions[] = [{ + key: { nbr: 1 }, name: "nbr", unique: true, + partialFilterExpression: { nbr: { $exists: true } }, +}] +const rec: IndexOptions[] = [{ + key: { "_id.uid": 1, "_id.utc": -1 }, name: "uid-utc" +}, { + key: { "_id.aid": 1, "_id.utc": -1 }, name: "aid-utc" +}, { + key: { "_id.utc": -1 }, name: "utc" +}] +const live: IndexOptions[] = [{ + key: { "utc.end": -1, "utc.start": -1 }, name: "live", + partialFilterExpression: { utc: { $exists: true } }, +}] +const dst: IndexOptions[] = [{ + key: { "_id.rd": 1, "_id.aid": 1, "_id.uid": 1 }, name: "rd-aid-uid", +}] +const md: IndexOptions[] = [{ + key: { pin: 1, "utc.put": -1 }, name: "pin", + partialFilterExpression: { pin: { $exists: true } } +}] + +export async function db( + dbnam: "ismism-dev" | "tst", + reset = false, +) { + const db = conn.database(dbnam) + const c = { + usr: db.collection("usr"), + agd: db.collection("agd"), + soc: db.collection("soc"), + + work: db.collection("work"), + video: db.collection