forked from cadence/out-of-your-element
PK: Fix mentions/replies using UUID
This commit is contained in:
parent
3d87bd9da5
commit
f48c1f3f31
9 changed files with 81 additions and 7 deletions
5
db/migrations/0010-add-sim-proxy.sql
Normal file
5
db/migrations/0010-add-sim-proxy.sql
Normal file
|
@ -0,0 +1,5 @@
|
|||
CREATE TABLE IF NOT EXISTS sim_proxy (
|
||||
user_id TEXT NOT NULL,
|
||||
proxy_owner_id TEXT NOT NULL,
|
||||
PRIMARY KEY(user_id)
|
||||
) WITHOUT ROWID;
|
6
db/orm-defs.d.ts
vendored
6
db/orm-defs.d.ts
vendored
|
@ -63,6 +63,11 @@ export type Models = {
|
|||
hashed_profile_content: number
|
||||
}
|
||||
|
||||
sim_proxy: {
|
||||
user_id: string
|
||||
proxy_owner_id: string
|
||||
}
|
||||
|
||||
webhook: {
|
||||
channel_id: string
|
||||
webhook_id: string
|
||||
|
@ -100,3 +105,4 @@ export type Prepared<Row> = {
|
|||
export type AllKeys<U> = U extends any ? keyof U : never
|
||||
export type PickTypeOf<T, K extends AllKeys<T>> = T extends { [k in K]?: any } ? T[K] : never
|
||||
export type Merge<U> = {[x in AllKeys<U>]: PickTypeOf<U, x>}
|
||||
export type Nullable<T> = {[k in keyof T]: T[k] | null}
|
||||
|
|
|
@ -38,6 +38,8 @@ class From {
|
|||
/** @private @type {Table[]} */
|
||||
this.tables = [table]
|
||||
/** @private */
|
||||
this.directions = []
|
||||
/** @private */
|
||||
this.sql = ""
|
||||
/** @private */
|
||||
this.cols = []
|
||||
|
@ -53,12 +55,14 @@ class From {
|
|||
* @template {keyof U.Models} Table2
|
||||
* @param {Table2} table
|
||||
* @param {Col & (keyof U.Models[Table2])} col
|
||||
* @param {"inner" | "left"} [direction]
|
||||
*/
|
||||
join(table, col) {
|
||||
join(table, col, direction = "inner") {
|
||||
/** @type {From<Table | Table2, keyof U.Merge<U.Models[Table | Table2]>>} */
|
||||
// @ts-ignore
|
||||
const r = this
|
||||
r.tables.push(table)
|
||||
r.directions.push(direction.toUpperCase())
|
||||
r.using.push(col)
|
||||
return r
|
||||
}
|
||||
|
@ -112,7 +116,8 @@ class From {
|
|||
for (let i = 1; i < this.tables.length; i++) {
|
||||
const table = this.tables[i]
|
||||
const col = this.using[i-1]
|
||||
sql += `INNER JOIN ${table} USING (${col}) `
|
||||
const direction = this.directions[i-1]
|
||||
sql += `${direction} JOIN ${table} USING (${col}) `
|
||||
}
|
||||
sql += this.sql
|
||||
/** @type {U.Prepared<Pick<U.Merge<U.Models[Table]>, Col>>} */
|
||||
|
|
|
@ -44,3 +44,12 @@ test("orm: from: where and pluck works", t => {
|
|||
const subtypes = from("event_message").where({message_id: "1141501302736695316"}).pluck("event_subtype").all()
|
||||
t.deepEqual(subtypes.sort(), ["m.image", "m.text"])
|
||||
})
|
||||
|
||||
test("orm: from: join direction works", t => {
|
||||
const hasOwner = from("sim").join("sim_proxy", "user_id", "left").select("user_id", "proxy_owner_id").where({sim_name: "_pk_zoego"}).get()
|
||||
t.deepEqual(hasOwner, {user_id: "43d378d5-1183-47dc-ab3c-d14e21c3fe58", proxy_owner_id: "196188877885538304"})
|
||||
const hasNoOwner = from("sim").join("sim_proxy", "user_id", "left").select("user_id", "proxy_owner_id").where({sim_name: "crunch_god"}).get()
|
||||
t.deepEqual(hasNoOwner, {user_id: "820865262526005258", proxy_owner_id: null})
|
||||
const hasNoOwnerInner = from("sim").join("sim_proxy", "user_id", "inner").select("user_id", "proxy_owner_id").where({sim_name: "crunch_god"}).get()
|
||||
t.deepEqual(hasNoOwnerInner, null)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue