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.
 
 
 
 
 
 

38 lines
1.4 KiB

import { newModel } from "../src/schema/models.mjs"
import { newView } from "../src/schema/views.mjs"
import { getNewField } from "../src/schema/fields.mjs"
import { fullSchema } from "../src/schema/fullSchema.mjs"
import { commonRecordValidationRules } from "../src/records/recordValidationRules.mjs"
export function testSchema() {
const addFieldToModel = (model, { type, name }) => {
const field = getNewField(type || "string")
field.name = name
model.fields.push(field)
}
const contactModel = newModel()
contactModel.name = "Contact"
contactModel.primaryField = "Name"
addFieldToModel(contactModel, { name: "Name" })
addFieldToModel(contactModel, { name: "Is Active", type: "bool" })
addFieldToModel(contactModel, { name: "Created", type: "datetime" })
addFieldToModel(contactModel, { name: "Status", type: "string" })
contactModel.validationRules.push(
commonRecordValidationRules.fieldNotEmpty("Name")
)
const activeContactsView = newView(contactModel.id)
activeContactsView.name = "Active Contacts"
activeContactsView.map = "if (doc['Is Active']) emit(doc.Name, doc)"
const dealModel = newModel()
dealModel.name = "Deal"
addFieldToModel(dealModel, { name: "Name" })
addFieldToModel(dealModel, { name: "Estimated Value", type: "number" })
addFieldToModel(dealModel, { name: "Contact", type: "link" })
return fullSchema([contactModel, dealModel], [activeContactsView])
}