Budibase is an open-source low-code platform for creating internal apps in minutes. Supports PostgreSQL, MySQL, MSSQL, MongoDB, Rest API, Docker, K8s 🚀
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

45 lines
1.2 KiB

const { DocumentTypes, SEPARATOR } = require("../db/utils")
const { FieldTypes } = require("../constants")
const DOUBLE_SEPARATOR = `${SEPARATOR}${SEPARATOR}`
exports.isExternalTable = tableId => {
return tableId.includes(DocumentTypes.DATASOURCE)
}
exports.buildExternalTableId = (datasourceId, tableName) => {
return `${datasourceId}${DOUBLE_SEPARATOR}${tableName}`
}
exports.breakExternalTableId = tableId => {
const parts = tableId.split(DOUBLE_SEPARATOR)
let tableName = parts.pop()
// if they need joined
let datasourceId = parts.join(DOUBLE_SEPARATOR)
return { datasourceId, tableName }
}
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))
}
exports.convertType = (type, map) => {
for (let [external, internal] of Object.entries(map)) {
if (type.toLowerCase().includes(external)) {
return internal
}
}
return FieldTypes.STRING
}