tachybase_todo/docs/en-US/development/server/collections/options.md

138 lines
2.4 KiB
Markdown
Raw Normal View History

2022-11-07 09:21:40 +08:00
# Collection protocol
2022-11-07 09:21:40 +08:00
Collection is the backbone of NocoBase, a protocol for describing data structures (collections and fields), very close to the concept of a relational database, but not limited to relational databases, but can also be a data source for NoSQL databases, HTTP APIs, etc.
<img src="./schema.svg" style="max-width: 800px;" >
2022-11-07 09:21:40 +08:00
At this stage, the Collection protocol is based on the relational database interface (db.collections), and data sources such as NoSQL databases and HTTP APIs will be implemented gradually in the future.
2022-11-07 09:21:40 +08:00
Collection protocol mainly includes two parts: CollectionOptions and FieldOptions. Because Field is extensible, the parameters of FieldOptions are very flexible.
## CollectionOptions
```ts
interface CollectionOptions {
name: string;
title?: string;
2022-11-07 09:21:40 +08:00
// Tree structure table, TreeRepository
tree?: 'adjacency-list' | 'closure-table' | 'materialized-path' | 'nested-set';
2022-11-07 09:21:40 +08:00
// parent-child inheritance
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
2022-11-07 09:21:40 +08:00
Generic field parameters
```ts
interface FieldOptions {
name: string;
type: string;
hidden?: boolean;
index?: boolean;
interface?: string;
uiSchema?: ISchema;
```
2022-11-07 09:21:40 +08:00
[Introduction to UI Schema here](/development/client/ui-schema-designer/what-is-ui-schema)
### Field Type
2022-11-07 09:21:40 +08:00
Field Type includes Attribute Type and 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
- email
- integer
- number
- percent
- password
- icon
**Choices**
- checkbox
- select
- multipleSelect
- radioGroup
- checkboxGroup
- chinaRegion
**Media**
- attachment
- markdown
- richText
**Date & Time**
- datetime
- time
**Relation**
2022-11-07 09:21:40 +08:00
- linkTo - `type: 'believesToMany'`
- oho - `type: 'hasOne'`
2022-11-07 09:21:40 +08:00
- obo - `type: 'believesTo'`
- o2m - `type: 'hasMany'`
2022-11-07 09:21:40 +08:00
- m2o - `type: 'believesTo'`
- m2m - `type: 'believesToMany'`
**Advanced**
- formula
- sequence
**System info**
- id
- createdAt
- createdBy
- updatedAt
- updatedBy