Quick improvement to table types, before now the field schema was quite difficult to parse/work out what components of the schema were used for what, this at least separates them into particularly grouped bits of metadata, so it is obvious which parts are used for which. In future we should really flip this a bit, so that FieldSchema is the base implementation, and then each of the types has its own schema extending that base - but that would be a more serious refactor (need to cast to the correct type when using based on the 'type' property.
This commit is contained in:
parent
a5f7dc2215
commit
a56f0c91dd
|
@ -1,97 +0,0 @@
|
|||
import { Document } from "../document"
|
||||
import { View } from "./view"
|
||||
import { RenameColumn } from "../../sdk"
|
||||
import { FieldType } from "./row"
|
||||
|
||||
export enum RelationshipTypes {
|
||||
ONE_TO_MANY = "one-to-many",
|
||||
MANY_TO_ONE = "many-to-one",
|
||||
MANY_TO_MANY = "many-to-many",
|
||||
}
|
||||
|
||||
export enum AutoReason {
|
||||
FOREIGN_KEY = "foreign_key",
|
||||
}
|
||||
|
||||
export interface FieldSchema {
|
||||
type: FieldType
|
||||
externalType?: string
|
||||
fieldName?: string
|
||||
name: string
|
||||
sortable?: boolean
|
||||
tableId?: string
|
||||
relationshipType?: RelationshipTypes
|
||||
through?: string
|
||||
foreignKey?: string
|
||||
icon?: string
|
||||
autocolumn?: boolean
|
||||
autoReason?: AutoReason
|
||||
subtype?: string
|
||||
throughFrom?: string
|
||||
throughTo?: string
|
||||
formula?: string
|
||||
formulaType?: string
|
||||
main?: boolean
|
||||
ignoreTimezones?: boolean
|
||||
timeOnly?: boolean
|
||||
lastID?: number
|
||||
useRichText?: boolean | null
|
||||
order?: number
|
||||
width?: number
|
||||
meta?: {
|
||||
toTable: string
|
||||
toKey: string
|
||||
}
|
||||
constraints?: {
|
||||
type?: string
|
||||
email?: boolean
|
||||
inclusion?: string[]
|
||||
length?: {
|
||||
minimum?: string | number | null
|
||||
maximum?: string | number | null
|
||||
}
|
||||
numericality?: {
|
||||
greaterThanOrEqualTo: string | null
|
||||
lessThanOrEqualTo: string | null
|
||||
}
|
||||
presence?:
|
||||
| boolean
|
||||
| {
|
||||
allowEmpty?: boolean
|
||||
}
|
||||
datetime?: {
|
||||
latest: string
|
||||
earliest: string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface TableSchema {
|
||||
[key: string]: FieldSchema
|
||||
}
|
||||
|
||||
export interface Table extends Document {
|
||||
type?: string
|
||||
views?: { [key: string]: View }
|
||||
name: string
|
||||
primary?: string[]
|
||||
schema: TableSchema
|
||||
primaryDisplay?: string
|
||||
sourceId?: string
|
||||
relatedFormula?: string[]
|
||||
constrained?: string[]
|
||||
sql?: boolean
|
||||
indexes?: { [key: string]: any }
|
||||
rows?: { [key: string]: any }
|
||||
created?: boolean
|
||||
rowHeight?: number
|
||||
}
|
||||
|
||||
export interface ExternalTable extends Table {
|
||||
sourceId: string
|
||||
}
|
||||
|
||||
export interface TableRequest extends Table {
|
||||
_rename?: RenameColumn
|
||||
created?: boolean
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
export enum RelationshipTypes {
|
||||
ONE_TO_MANY = "one-to-many",
|
||||
MANY_TO_ONE = "many-to-one",
|
||||
MANY_TO_MANY = "many-to-many",
|
||||
}
|
||||
|
||||
export enum AutoReason {
|
||||
FOREIGN_KEY = "foreign_key",
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export * from "./table"
|
||||
export * from "./schema"
|
||||
export * from "./constants"
|
|
@ -0,0 +1,98 @@
|
|||
// all added by grid/table when defining the
|
||||
// column size, position and whether it can be viewed
|
||||
import { FieldType } from "../row"
|
||||
import { AutoReason, RelationshipTypes } from "./constants"
|
||||
|
||||
export interface UIFieldMetadata {
|
||||
order?: number
|
||||
width?: number
|
||||
visible?: boolean
|
||||
icon?: string
|
||||
}
|
||||
|
||||
export interface RelationshipFieldMetadata {
|
||||
main?: boolean
|
||||
fieldName?: string
|
||||
tableId?: string
|
||||
// below is used for SQL relationships, needed to define the foreign keys
|
||||
// or the tables used for many-to-many relationships (through)
|
||||
relationshipType?: RelationshipTypes
|
||||
through?: string
|
||||
foreignKey?: string
|
||||
throughFrom?: string
|
||||
throughTo?: string
|
||||
}
|
||||
|
||||
export interface AutoColumnFieldMetadata {
|
||||
autocolumn?: boolean
|
||||
subtype?: string
|
||||
lastID?: number
|
||||
// if the column was turned to an auto-column for SQL, explains why (primary, foreign etc)
|
||||
autoReason?: AutoReason
|
||||
}
|
||||
|
||||
export interface NumberFieldMetadata {
|
||||
// used specifically when Budibase generates external tables, this denotes if a number field
|
||||
// is a foreign key used for a many-to-many relationship
|
||||
meta?: {
|
||||
toTable: string
|
||||
toKey: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface DateFieldMetadata {
|
||||
ignoreTimezones?: boolean
|
||||
timeOnly?: boolean
|
||||
}
|
||||
|
||||
export interface StringFieldMetadata {
|
||||
useRichText?: boolean | null
|
||||
}
|
||||
|
||||
export interface FormulaFieldMetadata {
|
||||
formula?: string
|
||||
formulaType?: string
|
||||
}
|
||||
|
||||
export interface FieldConstraints {
|
||||
type?: string
|
||||
email?: boolean
|
||||
inclusion?: string[]
|
||||
length?: {
|
||||
minimum?: string | number | null
|
||||
maximum?: string | number | null
|
||||
}
|
||||
numericality?: {
|
||||
greaterThanOrEqualTo: string | null
|
||||
lessThanOrEqualTo: string | null
|
||||
}
|
||||
presence?:
|
||||
| boolean
|
||||
| {
|
||||
allowEmpty?: boolean
|
||||
}
|
||||
datetime?: {
|
||||
latest: string
|
||||
earliest: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface FieldSchema
|
||||
extends UIFieldMetadata,
|
||||
DateFieldMetadata,
|
||||
RelationshipFieldMetadata,
|
||||
AutoColumnFieldMetadata,
|
||||
StringFieldMetadata,
|
||||
FormulaFieldMetadata,
|
||||
NumberFieldMetadata {
|
||||
type: FieldType
|
||||
name: string
|
||||
sortable?: boolean
|
||||
// only used by external databases, to denote the real type
|
||||
externalType?: string
|
||||
constraints?: FieldConstraints
|
||||
}
|
||||
|
||||
export interface TableSchema {
|
||||
[key: string]: FieldSchema
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
import { Document } from "../../document"
|
||||
import { View } from "../view"
|
||||
import { RenameColumn } from "../../../sdk"
|
||||
import { TableSchema } from "./schema"
|
||||
|
||||
export interface Table extends Document {
|
||||
type?: string
|
||||
views?: { [key: string]: View }
|
||||
name: string
|
||||
primary?: string[]
|
||||
schema: TableSchema
|
||||
primaryDisplay?: string
|
||||
sourceId?: string
|
||||
relatedFormula?: string[]
|
||||
constrained?: string[]
|
||||
sql?: boolean
|
||||
indexes?: { [key: string]: any }
|
||||
rows?: { [key: string]: any }
|
||||
created?: boolean
|
||||
rowHeight?: number
|
||||
}
|
||||
|
||||
export interface ExternalTable extends Table {
|
||||
sourceId: string
|
||||
}
|
||||
|
||||
export interface TableRequest extends Table {
|
||||
_rename?: RenameColumn
|
||||
created?: boolean
|
||||
}
|
Loading…
Reference in New Issue