mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 20:16:58 +00:00
98259e88a1
* feat: update docs * feat: update docs * feat: update docs
2.4 KiB
2.4 KiB
Collection 协议
Collection 是 NocoBase 的中枢,是一种用于描述数据结构(数据表和字段)的协议,和关系型数据库的概念非常接近,但不仅限于关系型数据库,也可以是 NoSQL 数据库、HTTP API 等数据源。
现阶段基于 Collection 协议实现了关系型数据库的对接(db.collections),NoSQL 数据库、HTTP API 等数据源在未来也会逐步实现。
Collection 协议主要包括 CollectionOptions 和 FieldOptions 两部分,因为 Field 是可扩展的,所以 FieldOptions 的参数非常灵活。
CollectionOptions
interface CollectionOptions {
name: string;
title?: string;
// 树结构表,TreeRepository
tree?: 'adjacency-list' | 'closure-table' | 'materialized-path' | 'nested-set';
// 父子继承
inherits?: string | string[];
fields?: FieldOptions[];
timestamps?: boolean;
paranoid?: boolean;
sortable?: CollectionSortable;
model?: string;
repository?: string;
[key: string]: any;
}
type CollectionSortable = string | boolean | { name?: string; scopeKey?: string };
FieldOptions
通用的字段参数
interface FieldOptions {
name: string;
type: string;
hidden?: boolean;
index?: boolean;
interface?: string;
uiSchema?: ISchema;
Field Type
Field Type 包括 Attribute Type 和 Association Type 两类:
Attribute Type
- 'boolean'
- 'integer'
- 'bigInt'
- 'double'
- 'real'
- 'decimal'
- 'string'
- 'text'
- 'password'
- 'date'
- 'time'
- 'array'
- 'json'
- 'jsonb'
- 'uuid'
- 'uid'
- 'formula'
- 'radio'
- 'sort'
- 'virtual'
Association Type
- 'belongsTo'
- 'hasOne'
- 'hasMany'
- 'belongsToMany'
Field Interface
Basic
- input
- textarea
- phone
- integer
- number
- percent
- password
- icon
Choices
- checkbox
- select
- multipleSelect
- radioGroup
- checkboxGroup
- chinaRegion
Media
- attachment
- markdown
- richText
Date & Time
- datetime
- time
Relation
- linkTo -
type: 'belongsToMany'
- oho -
type: 'hasOne'
- obo -
type: 'belongsTo'
- o2m -
type: 'hasMany'
- m2o -
type: 'belongsTo'
- m2m -
type: 'belongsToMany'
Advanced
- formula
- sequence
System info
- id
- createdAt
- createdBy
- updatedAt
- updatedBy