mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-13 03:40:48 +00:00
parent
c236b90b6f
commit
80dc1f5aed
@ -753,12 +753,14 @@ abstract class PostgresAdapterBase implements DbAdapter {
|
||||
if (!isDataField(key)) return `"${key}"`
|
||||
const arr = key.split('.').filter((p) => p)
|
||||
let tKey = ''
|
||||
let isNestedField = false
|
||||
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const element = arr[i]
|
||||
if (element === '$lookup') {
|
||||
tKey += arr[++i] + '_lookup'
|
||||
} else if (this.hierarchy.isMixin(element as Ref<Class<Doc>>)) {
|
||||
isNestedField = true
|
||||
tKey += `${element}`
|
||||
if (i !== arr.length - 1) {
|
||||
tKey += "'->'"
|
||||
@ -773,7 +775,7 @@ abstract class PostgresAdapterBase implements DbAdapter {
|
||||
tKey = this.checkMixinKey<T>(tKey, _class, isDataArray)
|
||||
}
|
||||
|
||||
return isDataArray ? `data->'${tKey}'` : `data#>>'{${tKey}}'`
|
||||
return isDataArray || isNestedField ? `data->'${tKey}'` : `data#>>'{${tKey}}'`
|
||||
}
|
||||
|
||||
private checkMixinKey<T extends Doc>(key: string, _class: Ref<Class<T>>, isDataArray: boolean): string {
|
||||
@ -1046,7 +1048,9 @@ abstract class PostgresAdapterBase implements DbAdapter {
|
||||
const vals = part
|
||||
.map((doc) => {
|
||||
const d = convertDoc(doc, this.workspaceId.name)
|
||||
return `('${d._id}', '${d.workspaceId}', '${d._class}', '${d.createdBy ?? d.modifiedBy}', '${d.modifiedBy}', ${d.modifiedOn}, ${d.createdOn ?? d.modifiedOn}, '${d.space}', '${d.attachedTo ?? '[NULL]'}', '${escapeBackticks(JSON.stringify(d.data))}')`
|
||||
return `('${d._id}', '${d.workspaceId}', '${d._class}', '${d.createdBy ?? d.modifiedBy}', '${d.modifiedBy}', ${d.modifiedOn}, ${d.createdOn ?? d.modifiedOn}, '${d.space}', ${
|
||||
d.attachedTo != null ? `'${d.attachedTo}'` : 'NULL'
|
||||
}, '${escapeBackticks(JSON.stringify(d.data))}')`
|
||||
})
|
||||
.join(', ')
|
||||
await client.query(
|
||||
@ -1133,7 +1137,9 @@ abstract class PostgresAdapterBase implements DbAdapter {
|
||||
const vals = part
|
||||
.map((doc) => {
|
||||
const d = convertDoc(doc, this.workspaceId.name)
|
||||
return `('${d._id}', '${d.workspaceId}', '${d._class}', '${d.createdBy ?? d.modifiedBy}', '${d.modifiedBy}', ${d.modifiedOn}, ${d.createdOn ?? d.modifiedOn}, '${d.space}', '${d.attachedTo ?? '[NULL]'}', '${escapeBackticks(JSON.stringify(d.data))}')`
|
||||
return `('${d._id}', '${d.workspaceId}', '${d._class}', '${d.createdBy ?? d.modifiedBy}', '${d.modifiedBy}', ${d.modifiedOn}, ${d.createdOn ?? d.modifiedOn}, '${d.space}', ${
|
||||
d.attachedTo != null ? `'${d.attachedTo}'` : 'NULL'
|
||||
}, '${escapeBackticks(JSON.stringify(d.data))}')`
|
||||
})
|
||||
.join(', ')
|
||||
await client.query(
|
||||
|
@ -290,7 +290,7 @@ export function translateDomain (domain: string): string {
|
||||
export function parseDocWithProjection<T extends Doc> (doc: DBDoc, projection: Projection<T> | undefined): T {
|
||||
const { workspaceId, data, ...rest } = doc
|
||||
for (const key in rest) {
|
||||
if ((rest as any)[key] === 'NULL') {
|
||||
if ((rest as any)[key] === 'NULL' || (rest as any)[key] === null) {
|
||||
if (key === 'attachedTo') {
|
||||
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
||||
delete rest[key]
|
||||
@ -321,7 +321,7 @@ export function parseDocWithProjection<T extends Doc> (doc: DBDoc, projection: P
|
||||
export function parseDoc<T extends Doc> (doc: DBDoc): T {
|
||||
const { workspaceId, data, ...rest } = doc
|
||||
for (const key in rest) {
|
||||
if ((rest as any)[key] === 'NULL') {
|
||||
if ((rest as any)[key] === 'NULL' || (rest as any)[key] === null) {
|
||||
if (key === 'attachedTo') {
|
||||
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
||||
delete rest[key]
|
||||
|
Loading…
Reference in New Issue
Block a user