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")
|
} = require("../../db/utils")
|
||||||
const { integrations } = require("../../integrations")
|
const { integrations } = require("../../integrations")
|
||||||
const plusIntegrations = require("../../integrations/plus")
|
const plusIntegrations = require("../../integrations/plus")
|
||||||
const PostgresConnector = require("../../integrations/plus/postgres")
|
|
||||||
|
|
||||||
exports.fetch = async function (ctx) {
|
exports.fetch = async function (ctx) {
|
||||||
const database = new CouchDB(ctx.appId)
|
const database = new CouchDB(ctx.appId)
|
||||||
|
@ -78,11 +77,11 @@ exports.plus = async function (ctx) {
|
||||||
await connector.init()
|
await connector.init()
|
||||||
|
|
||||||
const datasource = {
|
const datasource = {
|
||||||
_id: generateDatasourceID(),
|
_id: generateDatasourceID({ plus: true }),
|
||||||
type: "datasource:plus",
|
type: "datasource_plus",
|
||||||
|
relationships: [],
|
||||||
...ctx.request.body,
|
...ctx.request.body,
|
||||||
entities: connector.tables,
|
entities: connector.tables,
|
||||||
relationships: {},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await db.post(datasource)
|
const response = await db.post(datasource)
|
||||||
|
|
|
@ -1,14 +1,36 @@
|
||||||
const Router = require("@koa/router")
|
const Router = require("@koa/router")
|
||||||
const datasourceController = require("../controllers/datasource")
|
const datasourceController = require("../controllers/datasource")
|
||||||
const authorized = require("../../middleware/authorized")
|
const authorized = require("../../middleware/authorized")
|
||||||
|
const joiValidator = require("../../middleware/joi-validator")
|
||||||
const {
|
const {
|
||||||
BUILDER,
|
BUILDER,
|
||||||
PermissionLevels,
|
PermissionLevels,
|
||||||
PermissionTypes,
|
PermissionTypes,
|
||||||
} = require("@budibase/auth/permissions")
|
} = require("@budibase/auth/permissions")
|
||||||
|
const Joi = require("joi")
|
||||||
|
const { FieldTypes } = require("../../constants")
|
||||||
|
|
||||||
const router = Router()
|
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
|
router
|
||||||
.get("/api/datasources", authorized(BUILDER), datasourceController.fetch)
|
.get("/api/datasources", authorized(BUILDER), datasourceController.fetch)
|
||||||
.get(
|
.get(
|
||||||
|
@ -16,7 +38,11 @@ router
|
||||||
authorized(PermissionTypes.TABLE, PermissionLevels.READ),
|
authorized(PermissionTypes.TABLE, PermissionLevels.READ),
|
||||||
datasourceController.find
|
datasourceController.find
|
||||||
)
|
)
|
||||||
.post("/api/datasources/plus", datasourceController.plus)
|
.post(
|
||||||
|
"/api/datasources/plus",
|
||||||
|
generatePlusDatasourceSchema(),
|
||||||
|
datasourceController.plus
|
||||||
|
)
|
||||||
.post("/api/datasources", authorized(BUILDER), datasourceController.save)
|
.post("/api/datasources", authorized(BUILDER), datasourceController.save)
|
||||||
.delete(
|
.delete(
|
||||||
"/api/datasources/:datasourceId/:revId",
|
"/api/datasources/:datasourceId/:revId",
|
||||||
|
|
|
@ -38,6 +38,7 @@ const DocumentTypes = {
|
||||||
LAYOUT: "layout",
|
LAYOUT: "layout",
|
||||||
SCREEN: "screen",
|
SCREEN: "screen",
|
||||||
DATASOURCE: "datasource",
|
DATASOURCE: "datasource",
|
||||||
|
DATASOURCE_PLUS: "datasource_plus",
|
||||||
QUERY: "query",
|
QUERY: "query",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,8 +281,10 @@ exports.getWebhookParams = (webhookId = null, otherProps = {}) => {
|
||||||
* Generates a new datasource ID.
|
* Generates a new datasource ID.
|
||||||
* @returns {string} The new datasource ID which the webhook doc can be stored under.
|
* @returns {string} The new datasource ID which the webhook doc can be stored under.
|
||||||
*/
|
*/
|
||||||
exports.generateDatasourceID = () => {
|
exports.generateDatasourceID = ({ plus = false }) => {
|
||||||
return `${DocumentTypes.DATASOURCE}${SEPARATOR}${newid()}`
|
return `${
|
||||||
|
plus ? DocumentTypes.DATASOURCE_PLUS : DocumentTypes.DATASOURCE
|
||||||
|
}${SEPARATOR}${newid()}`
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue