2021-06-16 17:27:33 +02:00
|
|
|
const { DocumentTypes, SEPARATOR } = require("../db/utils")
|
|
|
|
|
2021-06-17 15:42:30 +02:00
|
|
|
const DOUBLE_SEPARATOR = `${SEPARATOR}${SEPARATOR}`
|
|
|
|
|
2021-06-16 17:27:33 +02:00
|
|
|
exports.isExternalTable = tableId => {
|
|
|
|
return tableId.includes(DocumentTypes.DATASOURCE)
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.buildExternalTableId = (datasourceId, tableName) => {
|
2021-06-17 15:42:30 +02:00
|
|
|
return `${datasourceId}${DOUBLE_SEPARATOR}${tableName}`
|
2021-06-16 17:27:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.breakExternalTableId = tableId => {
|
2021-06-17 15:42:30 +02:00
|
|
|
const parts = tableId.split(DOUBLE_SEPARATOR)
|
2021-06-16 17:27:33 +02:00
|
|
|
let tableName = parts.pop()
|
2021-06-17 15:42:30 +02:00
|
|
|
// if they need joined
|
|
|
|
let datasourceId = parts.join(DOUBLE_SEPARATOR)
|
2021-06-16 17:27:33 +02:00
|
|
|
return { datasourceId, tableName }
|
|
|
|
}
|
2021-06-16 19:38:00 +02:00
|
|
|
|
|
|
|
exports.generateRowIdField = (keyProps = []) => {
|
|
|
|
if (!Array.isArray(keyProps)) {
|
|
|
|
keyProps = [keyProps]
|
|
|
|
}
|
|
|
|
// this conserves order and types
|
|
|
|
return encodeURIComponent(JSON.stringify(keyProps))
|
|
|
|
}
|
|
|
|
|
|
|
|
// should always return an array
|
|
|
|
exports.breakRowIdField = _id => {
|
|
|
|
if (!_id) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
return JSON.parse(decodeURIComponent(_id))
|
|
|
|
}
|