diff --git a/package.json b/package.json index 6b4484df..857e2d2d 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,6 @@ "addbot": "node addbot.js", "test": "cross-env FORCE_COLOR=true supertape --no-check-assertions-count --format tap test/test.js | tap-dot", "test-slow": "cross-env FORCE_COLOR=true supertape --no-check-assertions-count --format tap --no-worker test/test.js -- --slow | tap-dot", - "cover": "c8 -o test/coverage --skip-full -x db/migrations -x matrix/file.js -x matrix/api.js -x matrix/mreq.js -x d2m/converters/rlottie-wasm.js -r html -r text supertape --no-check-assertions-count --format fail --no-worker test/test.js -- --slow" + "cover": "c8 -o test/coverage --skip-full -x db/migrations -x src/matrix/file.js -x src/matrix/api.js -x src/matrix/mreq.js -x src/d2m/converters/rlottie-wasm.js -r html -r text supertape --no-check-assertions-count --format fail --no-worker test/test.js -- --slow" } } diff --git a/src/db/migrations/0002-optimise-profile-content.up.js b/src/db/migrations/0002-optimise-profile-content.up.js index a8619cf0..5b540cb3 100644 --- a/src/db/migrations/0002-optimise-profile-content.up.js +++ b/src/db/migrations/0002-optimise-profile-content.up.js @@ -3,6 +3,7 @@ module.exports = async function(db) { const contents = db.prepare("SELECT distinct hashed_profile_content FROM sim_member WHERE hashed_profile_content IS NOT NULL").pluck().all() const stmt = db.prepare("UPDATE sim_member SET hashed_profile_content = ? WHERE hashed_profile_content = ?") db.transaction(() => { + /* c8 ignore next 6 */ for (let s of contents) { let b = Buffer.isBuffer(s) ? Uint8Array.from(s) : Uint8Array.from(Buffer.from(s)) const unsignedHash = hasher.h64Raw(b) diff --git a/src/db/orm-defs.d.ts b/src/db/orm-defs.d.ts index b1e6b795..c235e99c 100644 --- a/src/db/orm-defs.d.ts +++ b/src/db/orm-defs.d.ts @@ -124,3 +124,4 @@ export type PickTypeOf> = T extends { [k in K]?: any } ? export type Merge = {[x in AllKeys]: PickTypeOf} export type Nullable = {[k in keyof T]: T[k] | null} export type Numberish = {[k in keyof T]: T[k] extends number ? (number | bigint) : T[k]} +export type ValueOrArray = {[k in keyof T]: T[k][] | T[k]} diff --git a/src/db/orm.js b/src/db/orm.js index 646012bc..4d9b6f1a 100644 --- a/src/db/orm.js +++ b/src/db/orm.js @@ -8,7 +8,7 @@ const U = require("./orm-defs") * @template {keyof U.Models[Table]} Col * @param {Table} table * @param {Col[] | Col} cols - * @param {Partial>} where + * @param {Partial>>} where * @param {string} [e] */ function select(table, cols, where = {}, e = "") { diff --git a/src/db/orm.test.js b/src/db/orm.test.js index a53cc660..278723a2 100644 --- a/src/db/orm.test.js +++ b/src/db/orm.test.js @@ -30,6 +30,11 @@ test("orm: select: all, where and pluck works on multiple columns", t => { t.deepEqual(names, ["cadence [they]"]) }) +test("orm: select: in array works", t => { + const ids = select("emoji", "emoji_id", {name: ["online", "upstinky"]}).pluck().all() + t.deepEqual(ids, ["288858540888686602", "606664341298872324"]) +}) + test("orm: from: get pluck works", t => { const guildID = from("guild_space").pluck("guild_id").and("WHERE space_id = ?").get("!jjWAGMeQdNrVZSSfvz:cadence.moe") t.equal(guildID, data.guild.general.id)