Merge pull request #399 from cloudflare/sven/fix-properties-parsing-neon2

more fix properties parsing with Neon
pull/400/head
Sven Sauleau 2023-03-20 11:24:00 +01:00 zatwierdzone przez GitHub
commit cd423b8bfd
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 27 dodań i 3 usunięć

Wyświetl plik

@ -128,7 +128,15 @@ export async function cacheObject(
}
{
const properties = JSON.parse(row.properties)
let properties
if (typeof row.properties === 'object') {
// neon uses JSONB for properties which is returned as a deserialized
// object.
properties = row.properties
} else {
// D1 uses a string for JSON properties
properties = JSON.parse(row.properties)
}
const object = {
published: new Date(row.cdate).toISOString(),
...properties,
@ -206,7 +214,15 @@ export async function getObjectBy(db: Database, key: ObjectByKey, value: string)
}
const result: any = results[0]
const properties = JSON.parse(result.properties)
let properties
if (typeof result.properties === 'object') {
// neon uses JSONB for properties which is returned as a deserialized
// object.
properties = result.properties
} else {
// D1 uses a string for JSON properties
properties = JSON.parse(result.properties)
}
return {
published: new Date(result.cdate).toISOString(),

Wyświetl plik

@ -36,7 +36,15 @@ export async function hasKey(db: Database, key: string): Promise<APObject | null
}
const result = results[0]
const properties = JSON.parse(result.properties)
let properties
if (typeof result.properties === 'object') {
// neon uses JSONB for properties which is returned as a deserialized
// object.
properties = result.properties
} else {
// D1 uses a string for JSON properties
properties = JSON.parse(result.properties)
}
return {
published: new Date(result.cdate).toISOString(),