Merge branch 'plus-datasources' of github.com:Budibase/budibase into feature/opinionated-sql
This commit is contained in:
commit
fd2b7c415a
|
@ -6,7 +6,6 @@ const {
|
|||
} = require("../../db/utils")
|
||||
const { integrations } = require("../../integrations")
|
||||
const plusIntegrations = require("../../integrations/plus")
|
||||
const PostgresConnector = require("../../integrations/plus/postgres")
|
||||
|
||||
exports.fetch = async function (ctx) {
|
||||
const database = new CouchDB(ctx.appId)
|
||||
|
@ -78,11 +77,11 @@ exports.plus = async function (ctx) {
|
|||
await connector.init()
|
||||
|
||||
const datasource = {
|
||||
_id: generateDatasourceID(),
|
||||
type: "datasource:plus",
|
||||
_id: generateDatasourceID({ plus: true }),
|
||||
type: "datasource_plus",
|
||||
relationships: [],
|
||||
...ctx.request.body,
|
||||
entities: connector.tables,
|
||||
relationships: {},
|
||||
}
|
||||
|
||||
const response = await db.post(datasource)
|
||||
|
|
|
@ -1,14 +1,36 @@
|
|||
const Router = require("@koa/router")
|
||||
const datasourceController = require("../controllers/datasource")
|
||||
const authorized = require("../../middleware/authorized")
|
||||
const joiValidator = require("../../middleware/joi-validator")
|
||||
const {
|
||||
BUILDER,
|
||||
PermissionLevels,
|
||||
PermissionTypes,
|
||||
} = require("@budibase/auth/permissions")
|
||||
const Joi = require("joi")
|
||||
const { FieldTypes } = require("../../constants")
|
||||
|
||||
const router = Router()
|
||||
|
||||
function generatePlusDatasourceSchema() {
|
||||
// prettier-ignore
|
||||
return joiValidator.body(Joi.object({
|
||||
_id: Joi.string(),
|
||||
_rev: Joi.string(),
|
||||
source: Joi.string().valid("postgres"),
|
||||
type: Joi.string().valid("datasource_plus"),
|
||||
relationships: Joi.array().required().items(Joi.object({
|
||||
from: Joi.string().required(),
|
||||
to: Joi.string().required(),
|
||||
cardinality: Joi.valid("1:N", "1:1", "N:N").required()
|
||||
})),
|
||||
entities: Joi.array().required().items(Joi.object({
|
||||
type: Joi.string().valid(...Object.values(FieldTypes)).required(),
|
||||
name: Joi.string().required(),
|
||||
})),
|
||||
}).unknown(true))
|
||||
}
|
||||
|
||||
router
|
||||
.get("/api/datasources", authorized(BUILDER), datasourceController.fetch)
|
||||
.get(
|
||||
|
@ -16,7 +38,11 @@ router
|
|||
authorized(PermissionTypes.TABLE, PermissionLevels.READ),
|
||||
datasourceController.find
|
||||
)
|
||||
.post("/api/datasources/plus", datasourceController.plus)
|
||||
.post(
|
||||
"/api/datasources/plus",
|
||||
generatePlusDatasourceSchema(),
|
||||
datasourceController.plus
|
||||
)
|
||||
.post("/api/datasources", authorized(BUILDER), datasourceController.save)
|
||||
.delete(
|
||||
"/api/datasources/:datasourceId/:revId",
|
||||
|
|
|
@ -38,6 +38,7 @@ const DocumentTypes = {
|
|||
LAYOUT: "layout",
|
||||
SCREEN: "screen",
|
||||
DATASOURCE: "datasource",
|
||||
DATASOURCE_PLUS: "datasource_plus",
|
||||
QUERY: "query",
|
||||
}
|
||||
|
||||
|
@ -280,8 +281,10 @@ exports.getWebhookParams = (webhookId = null, otherProps = {}) => {
|
|||
* Generates a new datasource ID.
|
||||
* @returns {string} The new datasource ID which the webhook doc can be stored under.
|
||||
*/
|
||||
exports.generateDatasourceID = () => {
|
||||
return `${DocumentTypes.DATASOURCE}${SEPARATOR}${newid()}`
|
||||
exports.generateDatasourceID = ({ plus = false }) => {
|
||||
return `${
|
||||
plus ? DocumentTypes.DATASOURCE_PLUS : DocumentTypes.DATASOURCE
|
||||
}${SEPARATOR}${newid()}`
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue