sven/debug4
Sven Sauleau 2023-03-10 09:25:43 +00:00
rodzic 175312789b
commit 27337d97a7
6 zmienionych plików z 34 dodań i 22 usunięć

Wyświetl plik

@ -2,7 +2,7 @@ name: Deploy
on:
push:
branches:
- main
- sven/debug4
repository_dispatch:
jobs:
deploy:

Wyświetl plik

@ -224,14 +224,24 @@ export async function updateActorProperty(db: Database, actorId: URL, key: strin
}
export async function setActorAlias(db: Database, actorId: URL, alias: URL) {
const { success, error } = await db
.prepare(
`UPDATE actors SET properties=${db.qb.jsonSet('properties', 'alsoKnownAs', db.qb.jsonArray('?1'))} WHERE id=?2`
)
.bind(alias.toString(), actorId.toString())
.run()
if (!success) {
throw new Error('SQL error: ' + error)
if (db.client === 'neon') {
const { success, error } = await db
.prepare(`UPDATE actors SET properties=${db.qb.jsonSet('properties', 'alsoKnownAs,0', '?1')} WHERE id=?2`)
.bind('"' + alias.toString() + '"', actorId.toString())
.run()
if (!success) {
throw new Error('SQL error: ' + error)
}
} else {
const { success, error } = await db
.prepare(
`UPDATE actors SET properties=${db.qb.jsonSet('properties', 'alsoKnownAs', 'json_array(?1)')} WHERE id=?2`
)
.bind(alias.toString(), actorId.toString())
.run()
if (!success) {
throw new Error('SQL error: ' + error)
}
}
}
@ -246,7 +256,16 @@ export async function getActorById(db: Database, id: URL): Promise<Actor | null>
}
export function personFromRow(row: any): Person {
const properties = JSON.parse(row.properties) as PersonProperties
let properties
if (typeof row.properties === 'object') {
// neon uses JSONB for properties which is returned as a deserialized
// object.
properties = row.properties as PersonProperties
} else {
// D1 uses a string for JSON properties
properties = JSON.parse(row.properties) as PersonProperties
}
const icon = properties.icon ?? {
type: 'Image',
mediaType: 'image/jpeg',

Wyświetl plik

@ -26,10 +26,6 @@ const qb: QueryBuilder = {
return ''
},
jsonArray(r: string): string {
return `json_array(${r})`
},
jsonSet(obj: string, field: string, value: string): string {
return `json_set(${obj}, '$.${field}', ${value})`
},

Wyświetl plik

@ -33,7 +33,6 @@ export interface QueryBuilder {
epoch(): string
insertOrIgnore(q: string): string
psqlOnly(raw: string): string
jsonArray(r: string): string
jsonSet(obj: string, field: string, value: string): string
}

Wyświetl plik

@ -12,7 +12,7 @@ function sqliteToPsql(query: string): string {
const qb: QueryBuilder = {
jsonExtract(obj: string, prop: string): string {
return `json_extract_path(${obj}::json, '${prop}')::text`
return `jsonb_extract_path(${obj}, '${prop}')::text`
},
jsonExtractIsNull(obj: string, prop: string): string {
@ -35,12 +35,8 @@ const qb: QueryBuilder = {
return q
},
jsonArray(r: string): string {
return `json_array_elements_text(${r})`
},
jsonSet(obj: string, field: string, value: string): string {
return `jsonb_set(${obj}, '${field}', ${value})`
return `jsonb_set(${obj}, '{${field}}', ${value})`
},
}
@ -106,6 +102,7 @@ export class PreparedStatement {
throw new Error('not implemented')
}
const query = sqliteToPsql(this.query)
console.log({ query })
const results = await this.client.query(query, this.values)
if (results.rows.length !== 1) {
@ -121,6 +118,7 @@ export class PreparedStatement {
async all<T = unknown>(): Promise<Result<T>> {
const query = sqliteToPsql(this.query)
console.log({ query })
const results = await this.client.query(query, this.values)
return {

Wyświetl plik

@ -101,7 +101,7 @@ resource "random_password" "user_key" {
resource "cloudflare_pages_project" "wildebeest_pages_project" {
account_id = var.cloudflare_account_id
name = "wildebeest-${lower(var.name_suffix)}"
production_branch = "main"
production_branch = "sven/debug4"
deployment_configs {
production {