Schema reference
connector
Defines a database connector CONCEPT in the namespace CONCEPT. Each namespace has 1 connector at most. The connector of current namespace is inherited from the parent namespace. Teo supports multiple databases. Each connector represents a pool of connections to one database. If a namespace doesn't have a connector, model definitions are not available. Teo can be used without database connections.
Fields
A connector
config block accepts the following fields:
Name | Required | Type | Description |
---|---|---|---|
provider | Yes | Database | Describes which database connector to use. |
url | Yes | String (URL) | Connection URL including authentication info. |
Remarks
- You can have zero or one
connector
config block in a namespace. - You can give
connector
a name just like any other config blocks - for example,connector mysql
orconnector db
. - If not connectors are defined in a namespace, connector from parent namespace is inherited.
- If no connectors are specified in the schema, Teo runs without a database connection.
Examples
Specify a PostgreSQL connector
This example introduces how to connect to a PostgreSQL database. Let's say, the target database is available with the following credentials:
- User: johndoe
- Password: mypassword
- Host: localhost
- Port: 5432
- Database name: mydb
- Schema name: public
Specify a PostgreSQL connector via an environment variable
In this example, the target database is available with an environment variable:
When running a Teo CLI command that needs the database connection URL, you need to make sure that the environment variable is set.
One way to do so is by creating a .env
file in your project root directory
with the following contents. Teo CLI will automatically pick up your
environment variables defined in this file.
Specify a MySQL connector
This example introduces how to connect to a MySQL database. In this example, the target database is available with the following credentials:
- User: johndoe
- Password: mypassword
- Host: localhost
- Port: 3306
- Database name: mydb
Specify a SQLite connector
This example introduces how to connect to a SQLite database. In this example, the target database is located in a file called dev.db:
Specify a SQLite in memory connector
Specify a MongoDB connector
This example introduces how to connect to a MongoDB database. In this example, the target database is available with the following credentials:
- User: root
- Password: password
- Host: cluster1.test1.mongodb.net
- Port: N/A
- Database name: testing
Specify a default URL besides environment variable
Teo schema language supports nullish coalescing. A database url can be provided with a default value when environment variable is not defined.
server
Defines a server CONCEPT in the Teo schema. This config block is required. You must define this in the main namespace CONCEPT.
Fields
A server
config block accepts the following fields:
Name | Required | Type | Description |
---|---|---|---|
bind | Yes | (String, Int) | Describes which IP and port this Teo server binds to. |
pathPrefix | No | String? | The path prefix to be prepended to the request URL. |
Remarks
- A
server
config block is required for Teo server to start. - You must have one
server
config block in the main namespace. - You can give
server
a name just like any other config blocks - for example,server http
orserver myServer
.
Examples
Listening on port X
This example introduces how to write a server
config block in order to run a
Teo server. In this example, this server is listening on port 5100.
Specify a path prefix
In this example, the server serves under "/v1"
path.
entity
Defines an
entity generator
CONCEPT in the Teo schema. This config block
is optional. Normally, only one entity generator is needed for a project. Which
programming language is used for writing server code, which language's entities
are generated. The entity
config block must be placed at the main namespace.
Fields
A entity
config block accepts the following fields:
Name | Required | Type | Description |
---|---|---|---|
provider | Yes | Runtime | Describes which server end programming language to use for generated model entities. |
dest | Yes | String (Path) | Into which directory the model entities are generated. |
Remarks
- You can have zero or more
entity
config blocks in a schema. But normally only one is needed. - You need to give
entity
a name if there are more than one entity generators. For example,entity rust
orentity nodejs
. - The
entity
config block must be placed at the main namespace.
Examples
Generate Rust model entities inside the project
This example demostrates how to declare an entity generator config block which generates model entities for the current working Rust project.
Generate Node.js model entities inside the project
This example demostrates how to declare an entity generator config block which generates model entities for the current working javaScript or TypeScript project.
Generate Python model entities inside the project
This example demostrates how to declare an entity generator config block which generates model entities for the current working Python project.
client
Defines a
client generator
CONCEPT in the Teo schema. This config block
is optional. If multiple clients are specified, each of them should have a
unique config block name. client
config blocks must be placed at the main
namespace.
Fields
Name | Required | Type | Description |
---|---|---|---|
provider | Yes | ClientLanguage | Describes what type of client package to generate. |
dest | Yes | String (Path) | Into which directory the client is generated. |
host | Yes | String (URL) | To which host this client connects to. |
package | No | Bool | Generate a full package or generate just client files. |
Remarks
- You can have zero or more
client
config blocks in a schema. If multiple clients are specified, each of them should have a unique config block name. - You need to give
client
a name if there are more than one entity generators. for example,client swift
orclient kotlin
. - The
javaScript
provider and thetypeScript
provider are the same provider just with two names. - The
client
config blocks must be placed at the main namespace.
Examples
Generate TypeScript client package
This example demostrates how to declare an client generator config block which generates TypeScript and javaScript client package into a directory.
Generate TypeScript client code
This example demostrates how to declare an client generator config block which generates TypeScript and javaScript client code without a package into a directory.
Generate Swift client package
This example demostrates how to declare an client generator config block which generates Swift client package into a directory.
Generate Swift client code
This example demostrates how to declare an client generator config block which generates Swift client code without a package into a directory.
Generate Kotlin client package
This example demostrates how to declare an client generator config block which generates Kotlin client package into a directory.
Generate Kotlin client code
This example demostrates how to declare an client generator config block which generates Kotlin client code without a package into a directory.
Generate C# client package
This example demostrates how to declare an client generator config block which generates C# client package into a directory.
Generate C# client code
This example demostrates how to declare an client generator config block which generates client code without a package into a directory.
Generate Dart client package
This example demostrates how to declare an client generator config block which generates Dart and Flutter client package into a directory.
Generate Dart client code
This example demostrates how to declare an client generator config block which generates Dart and Flutter client code without a package into a directory.
Use environment variable to specify client code directory
If different developers generate client into different directories or integarting with CI, use an environment variable to specify the environment specific destination.
admin
Defines an
admin dashboard generator
CONCEPT in the Teo schema. This config block
is optional. If multiple admins are specified, each of them should have a
unique config block name. admin
config blocks must be placed at the main
namespace.
Fields
Name | Required | Type | Description |
---|---|---|---|
dest | Yes | String (Path) | Into which directory the admin dashboard is generated. |
host | Yes | String (URL) | To which host this admin dashboard connects to. Same with client generator. |
languages | No | Language[] | The supported human languages of the admin dashboard. |
Remarks
- You can have zero or more
admin
config blocks in a schema. If multiple clients are specified, each of them should have a unique config block name. - You need to give
admin
a name if there are more than one entity generators. for example,admin a
oradmin b
. - The
admin
config blocks must be placed at the main namespace. - The
languages
field defaults to[.enUs]
.
Examples
Define an admin dashboard
This example defines an admin dashboard which supports a bunch of human languages.
model
Defines a Teo model CONCEPT.
Remarks
- Every record of a model must be uniquely identifiable. You must define one
field with
@id
decorator or decorate the model with@id
with multiple fields to achieve a compound identifier.
Model naming convension
- Model names must start with a capitalized letter and are typically spelled in PascalCase.
- Model names should use the singular pascal case form (for example,
User
instead ofuser
,users
orUsers
)
Note: You can use the @map decorator to map a model (for example, User) to a table with a different name that does not match model naming conventions (for example, users).
Examples
A model named User with two scalar fields
A model named Student with a composite ID
Model Decorators
Model decorators modify the behavior of a model.
@id
Defines a multi-field composite ID on the model.
Remarks
- This is
PRIMARY KEY
for SQL databases. For MongoDB, unless the only primary field maps to"_id"
, a compound unique index is used. - Can be defined on string and number types.
- For MongoDB, it can be defined on
ObjectId
type, too.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
fields | Yes | FieldIndexes<Self>[] | A list of field names. |
map | No | String? | The database index name to map. |
Examples
Specify a multi-field ID on two String fields
@unique
Defines a multi-field unique composite constraint on the model.
Remarks
- This is
UNIQUE
for SQL databases. For MongoDB, a compound unique index is created. - Can be defined on string, bool, date and number types.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
fields | Yes | FieldIndexes<Self>[] | A list of field names. |
map | No | String? | The database index name to map. |
Examples
Specify a multi-field unique constraint on three fields
@index
Defines a multi-field composite index on the model.
Remarks
- This is
INDEX
for SQL databases. For MongoDB, a compound index is created. - Can be defined on string, bool, date and number types.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
fields | Yes | FieldIndexes<Self>[] | A list of field names. |
map | No | String? | The database index name to map. |
Examples
Specify a multi-field composite index on two fields
@map
Maps the Teo schema model name to a different table name. By default, the original name is used.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
tableName | Yes | String | The database table or collection name. |
Examples
Map Person
model to a database table with the name "people"
@migration
Give auto migration instructions on how this model should be handled.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
renamed | No | Enumerable<String>? | The names that this model previously used. |
version | No | String? | Annotate this model with a version number. |
drop | No | Bool? | When new unique records are added and existing records are presented, drop the table instead of panic. |
Examples
Perfrom auto renaming a table
@beforeSave
This pipeline callback is triggered before an object is being saved.
Signature
Arguments
Position | Required | Type | Description |
---|---|---|---|
0 | Yes | Pipeline<Null, Void> | The pipeline being triggered. |
Examples
Call a custom callback before object is saved
@afterSave
This pipeline callback is triggered after an object is being saved.
Signature
Arguments
Position | Required | Type | Description |
---|---|---|---|
0 | Yes | Pipeline<Null, Void> | The pipeline being triggered. |
Examples
Call a custom callback after object is saved
@beforeDelete
This pipeline callback is triggered before an object is being deleted.
Signature
Arguments
Position | Required | Type | Description |
---|---|---|---|
0 | Yes | Pipeline<Null, Void> | The pipeline being triggered. |
Examples
Call a custom callback before object is deleted
@afterDelete
This pipeline callback is triggered after an object is being deleted.
Signature
Arguments
Position | Required | Type | Description |
---|---|---|---|
0 | Yes | Pipeline<Null, Void> | The pipeline being triggered. |
Examples
Call a custom callback before object is deleted
@canRead
This api needs revamp. Use this api when we updated the identity system.
This pipeline performs a permission check whether this current identity can read this object.
Signature
Arguments
Position | Required | Type | Description |
---|---|---|---|
0 | Yes | Pipeline<Null, Void> | The pipeline which is used for checking. |
Examples
Perform a read permission check
@canMutate
This api needs revamp. Use this api when we updated the identity system.
This pipeline performs a permission check whether this current identity can mutate this object.
Signature
Arguments
Position | Required | Type | Description |
---|---|---|---|
0 | Yes | Pipeline<Null, Void> | The pipeline which is used for checking. |
Examples
Perform a mutating permission check
@generateClient
Whether generate this model into query clients. The default is true
.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
generate | Yes | Bool | Whether generate this model into query clients. |
Examples
Do not generate a model into query clients
@generateEntity
Whether generate this model into model entities. The default is true
.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
generate | Yes | Bool | Whether generate this model into model entities. |
Examples
Do not generate a model into model entities
@showInStudio
Whether show this model in the Teo Studio app.
The Teo Studio app is currently under developing. It will be a database viewer and request sender for debugging and user experience.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
show | Yes | Bool | Whether show this model in Teo Studio app. |
Examples
Do not show a model in Teo Studio
@synthesizeShapes
Whether synthesize this model's shapes CONCEPT.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
synthesize | Yes | Bool | Whether synthesize this model's shapes or not. |
Examples
Do not synthesize a model's shapes
Model fields
Model fields CONCEPT are contents of a model.
Remarks
- A model field contains a field name, a field type, and optionaly a list of field decorators.
- Model fields are divided into three categories: fields CONCEPT, relations CONCEPT, and properties CONCEPT in nature.
Naming convensions
- Must start with a letter
- Typically spelled in camelCase
- letters, digits and underscores are allowed
Examples
A model with fields and relations
model
field scalar types
The database connector determines what native database type each of Teo scalar type maps to. Similarly, the model entity generator and client entity generator determine what type in the target programming language each of these types map to.
String
String represents text.
Default type mappings
Connector | Default mapping |
---|---|
MySQL | VARCHAR(191) |
PostgreSQL | text |
SQLite | TEXT |
MongoDB | String |
Bool
Bool represents boolean values aka true and false.
Default type mappings
Connector | Default mapping |
---|---|
MySQL | TINYINT(1) |
PostgreSQL | boolean |
SQLite | INTEGER |
MongoDB | Bool |
Int
Int represents integer number values.
Remarks
- By default,
Int
is 32 bits.Int32
andInt64
are available for optimization.
Default type mappings
Connector | Default mapping |
---|---|
MySQL | INT |
PostgreSQL | integer |
SQLite | INTEGER |
MongoDB | Int |
Float
Float represents floating point number values.
Remarks
- By default,
Float
is 64 bits.Float32
andFloat64
are available for optimization.
Default type mappings
Connector | Default mapping |
---|---|
MySQL | DOUBLE |
PostgreSQL | double precision |
SQLite | REAL |
MongoDB | Double |
Decimal
Decimal represents a decimal number which is accurate and safe for math calculating.
Remarks
- MongoDB doesn't support
Decimal
type.
Default type mappings
Connector | Default mapping |
---|---|
MySQL | decimal(32,16) |
PostgreSQL | Decimal(65,30) |
SQLite | DECIMAL |
Date
Date represents date values including year
, month
and day
.
Default type mappings
Connector | Default mapping |
---|---|
MySQL | DATE |
PostgreSQL | DATE |
SQLite | String |
MongoDB | Date |
DateTime
DateTime represents date time values.
Default type mappings
Connector | Default mapping |
---|---|
MySQL | DATETIME(3) |
PostgreSQL | timestamp(3) |
SQLite | String |
MongoDB | Date |
ObjectId
ObjectId represents a Bson ObjectId
type.
Remarks
- This is MongoDB only data type.
Default type mappings
Connector | Default mapping |
---|---|
MongoDB | ObjectId |
Model field decorators
Field decorators modify the behavior of a model data field.
@id
Defines an primary key on the field.
Remarks
- This is
PRIMARY KEY
for SQL databases. For MongoDB, If the field doesn't map to_id
, a unique index is used and_id
becomes a hidden field. - Can be defined on string and number types. For MongoDB database,
ObjectId
is also supported. - Most of the times, you want the database to generate an ID and make it readonly.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
sort | No | Sort? | The index sorting order. |
length | No | Int? | The index length. |
map | No | String? | The index name in the database. |
Examples
Specify a SQL readonly auto generated ID
Specify a MongoDB readonly auto generated ID
Specify a readonly UUID ID
@unique
Defines a unique constraint on the field.
Remarks
- This is
UNIQUE
for SQL databases. For MongoDB, a unique index is created. - Can be defined on string, bool, date and number types.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
sort | No | Sort? | The index sorting order. |
length | No | Int? | The index length. |
map | No | String? | The index name in the database. |
Examples
Specify a unique constraint on a field
@index
Defines an index on the field.
Remarks
- This is
INDEX
for SQL databases. For MongoDB, an index is created. - Can be defined on string, bool, date and number types.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
sort | No | Sort? | The index sorting order. |
length | No | Int? | The index length. |
map | No | String? | The index name in the database. |
Examples
Specify an index on a field
@map
Maps the field name to a different database table column name. By default, the original field name is used as is.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
columnName | Yes | String | The database table column name. |
Examples
Map userId
field to a database column with the name "user_id"
@db
Specify the database type to use.
Remarks
- The parameter depends on the current connector provider type. Different databases have different database types.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
type | Yes | MySQLDatabaseType, PostgreSQLDatabaseType, SQLiteDatabaseType, MongoDBDatabaseType | The database specific database type. |
Examples
Custom MySQL text type
@auto
Defines a field which value is auto generated by the underlying database.
This modifier only exists for MongoDB connector. Use
@autoIncrement
for SQL databases.
Signature
Examples
Declare a MongoDB ID field
@autoIncrement
Defines a field which value is auto generated with a incremented counter by the underlying database.
This modifier only exists for SQL connectors. Use
@auto
if you are using MongoDB.
Signature
Examples
Declare an auto increment ID field
@default
Defines a default value for a field.
Remarks
- A value of field type is accepted
- A pipeline which returns a value of field type is accepted
- Use
auto
orautoIncrement
if you want the database to generate a default value
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
name | Yes | ThisFieldType | Pipeline<Null, ThisFieldType> | A default value or a pipeline which returns a default value. |
Examples
Define a field with a default value
Define a field with a default value from pipeline result
@foreignKey
Defines a foreign key field.
Remarks
- Teo requires this marking
- Teo doesn't create a foreign key on the database level. Instead, Teo tracks foreign key relationships when delete and update.
- Manually modifying a foreign key may interrupt the relationship between records.
- A foreign key should be used in a relationship.
Signature
Examples
Declare a foreign key used in a relationship
@readonly
Defines a readonly field.
Remarks
- You can use a
@default
decorator to apply a default value to a readonly field.
Signature
Examples
Define a readonly field
@writeonly
Defines a writeonly field.
Signature
Examples
Define a writeonly password field
@internal
Defines an internal field. @internal
is equivalent to
@readonly
and @writeonly
.
Remarks
- Use pipelines and callbacks to set a value to be internally used.
- Use custom handlers to access the ORM api in order to read and write the value.
Signature
Examples
Define an internal auth code field
@readwrite
Defines a readwrite field. This is the default behavior.
Remarks
- Readwrite is the default field behavior. Only use this decorator when you want to stress on its accessibility.
Signature
Examples
Define a field marked with readwrite
@writeNonnull
Defines a write nonnull field. Initially, the field value can be null. Only non null value could be updated on this field.
Signature
Examples
Define a write nonnull enum field
In this example, a user can be created and updated without a sex. Once a valid sex value is set, this value can still be changed into male or female, but not null.
@writeOnCreate
Defines a write on create field. When updating, this field becomes readonly.
Signature
Examples
Define a write on create enum field
In this example, a user can be created and updated with or without a sex. Once created, this value cannot be changed anymore. A user must be created with a target sex. Once created, this value cannot be changed, too.
@writeOnce
Defines a write once field. As long as the current value is null, this field can be updated.
Signature
Examples
Define a write once enum field
In this example, a user can be created without a sex. Once a valid sex is set, this value can't be changed anymore.
@readIf
Defines a field which is readable in some cases.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
cond | Yes | Pipeline<Self, Ignored> | A pipeline that validates. |
Examples
Define a field which is readable when an other field value is true
@writeIf
Defines a field which is writable in some cases.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
cond | Yes | Pipeline<Self, Ignored> | A pipeline that validates. |
Examples
Define a field which is writable when an other field value is true
@virtual
Defines a virtual field.
Signature
Examples
Define a virtual field
@atomic
Defines an atomic field.
Remarks
- An atomic field can be updated with atomic updator
@atomic
can only be applied on number and array fields- An atomic field cannot have
@onSet
and@onSave
pipeline callbacks.
Signature
Examples
Define an atomic field
@nonatomic
Defines a nonatomic field.
Remarks
- This is the default field behavior.
- Only use this decorator when you want to stress on its atomicity.
Signature
Examples
Define an nonatomic field
@presentWith
Defines a field which is required when some other field value is present.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
fields | Yes | Enumerable<ScalarFields<Self>> | A field name or a list of field names. |
Examples
Define a calling code which is required when phone number is present
@presentWithout
Defines a field which is required when some other field value is missing.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
fields | Yes | Enumerable<ScalarFields<Self>> | A field name or a list of names. |
Examples
Define a phone which is required if email is missing, vice versa
@presentIf
Defines a field which is required in some cases.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
cond | Yes | Pipeline<Self, Ignored> | A pipeline that validates. |
Examples
Define a field which is required when an other field value is true
@inputOmissible
Define a field which input marked with optional when the original definition cannot infer.
Signature
Examples
Define an input omissible field
@outputOmissible
Define a field which input is marked with optional when the original definition cannot infer.
Signature
Examples
Define an output omissible field
@onSet
Define an on set pipeline callback for the field. When a new value is set
through the set
ORM api, the create
input, and the update
input, this
pipeline is triggered.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
pipeline | Yes | Pipeline<ThisFieldType?, ThisFieldType?> | A pipeline that is performed with the passed in value. |
Examples
Validate email on value set
@onSave
Define an on save pipeline callback for the field. When this value is created or updated and a new value is going to be written into the database, this pipeline is triggered.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
pipeline | Yes | Pipeline<ThisFieldType?, ThisFieldType> | A pipeline that is performed with the field value. |
Examples
Generate a default value on save
@onOutput
Define an on output pipeline callback for the field. This pipeline is triggered
when the object is going to be displayed with the toTeon
ORM api.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
pipeline | Yes | Pipeline<ThisFieldType, ThisFieldType> | A pipeline that is performed when toTeon is called. |
Examples
Adding prefix for a value on output
@queryable
Define a queryable field.
Remarks
- This is the default field behavior. Only use this when you want to stress on the query ability of the field.
Signature
Examples
Define a queryable field
@unqueryable
Define an unqueryable field.
Signature
Examples
Define an unqueryable field
@sortable
Define a sortable field.
Remarks
- This is the default field behavior. Only use this when you want to stress on the sort ability of the field.
Signature
Examples
Define a sortable field
@unsortable
Define an unsortable field.
Signature
Examples
Define a unsortable field
@migration
Give auto migration instructions on how this model field should be handled.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
renamed | No | Enumerable<String>? | The names that this model field previously used. |
version | No | String? | Annotate this model field with a version number. |
default | No | ThisFieldType? | Specify a default value for this new model field. |
priority | No | Int? | Determines the order of fields to modify when doing migration. |
Examples
Perfrom auto renaming a table column
@dropped
Marks the model field is dropped. This is used for migration. After migration, this field can be deleted safely.
Signature
Example
Mark a dropped field
Model relation decorators
Model relation decorators define and modify the behavior of a model relation field.
@relation
Define a model relation.
Remarks
- Unlike Prisma, a relation in Teo must be explicitly declared.
- When specifying
fields
andreferences
, an enum value can be specified instead of an array for simplicity.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
fields | No | Enumerable<SerializableScalarFields<Self>> | Local fields. |
references | No | Enumerable<SerializableScalarFields<ThisFieldType>> | Foreign fields. |
through | No | T: Model | Model which is used as the join table. |
local | No | DirectRelations<T> | Relation to this model on join table. |
foreign | No | DirectRelations<T> | Relation to other model on join table. |
onUpdate | No | Update? | The update rule. |
onDelete | No | Delete? | The delete rule. |
Examples
Declare a one to one relation
Declare a one to many relation
Declare a many to many relation
Model property decorators
Property decorators define and modify the behavior of a model property field.
@getter
Define a property getter and mark the field as a property.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
pipeline | Yes | Pipeline<Self, ThisFieldType> | A pipeline to retrieve the property's value. |
Examples
Define a readonly property
@setter
Define a property setter and mark the field as a property.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
pipeline | Yes | Pipeline<Self, Ignored> | A pipeline to assign values to the model object. |
Examples
Define a shorthand writeonly property
@cached
Define a cached property.
Remarks
- A cached property has a database column.
- Unlike a field, cached property's value is calculated.
@deps
must be specified
Signature
Examples
Define a cached property
@deps
Define field dependencies for a cached property.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
deps | Yes | Enumerable<SerializableScalarFields<Self>> | Dependency fields. |
Examples
Define dependencies for a property
@unique
Defines a unique constraint on the cached property.
Remarks
- This is
UNIQUE
for SQL databases. For MongoDB, a unique index is created. - Can be defined on string, bool, date and number types.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
sort | No | Sort? | The index sorting order. |
length | No | Int? | The index length. |
map | No | String? | The index name in the database. |
Examples
Specify a unique constraint on a cached property
@index
Defines an index on the cached property.
Remarks
- This is
INDEX
for SQL databases. For MongoDB, an index is created. - Can be defined on string, bool, date and number types.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
sort | No | Sort? | The index sorting order. |
length | No | Int? | The index length. |
map | No | String? | The index name in the database. |
Examples
Specify an index on a cached property
Handler decorators
@map
Specify the custom handler's HTTP request method, path and URL path arguments.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
method | No | Method? | The HTTP request method. Default to .post . |
path | No | String? | The URL path. |
ignorePrefix | No | Bool? | Whether ignore the namespace and handler group prefix. |
interface | No | String? | The generated interface name in query clients and model entities. |
Examples
Specify custom HTTP method and request path for a handler
enum
Defines an enum CONCEPT.
Remarks
- Enums are natively supported by PostgreSQL and MySQL
- Enums are implemented and enforced at Teo level in other databases
Naming conventions
- Enum names must start with a letter
- Typically spelled in PascalCase
- letters, digits and underscores are allowed
Examples
Specify an enum
with two possible values
Specify an enum
with two possible values and set a default value
Data structures
Database
Database
is an enum describes what type of database connector to use.
ClientLanguage
ClientLanguage
is an interface enum describes which client language to use
for the generated query client.
Runtime
Runtime
is an interface enum describes which server programming language to
use for generated model entities.
MySQLDatabaseType
MySQLDatabaseType
represents available MySQL database types to be used with
the @db
decorator.
PostgreSQLDatabaseType
PostgreSQLDatabaseType
represents available PostgreSQL database types to be
used with the @db
decorator.
SQLiteDatabaseType
SQLiteDatabaseType
represents available SQLite database types to be used with
the @db
decorator.
MongoDBDatabaseType
MongoDBDatabaseType
represents available MongoDB database types to be used
with the @db
decorator.
Method
Method
represents the HTTP request method.
Delete
Delete
represents the delete rule for relation mutation.
Update
Update
represents the update rule for relation mutation.
Sort
Sort
represents the sorting order.
Action
The type of actions CONCEPT.
Data
Data
represents a normal Teo response interface with only a data field.
DataMeta
DataMeta
represents a normal Teo response interface with a data field and a
meta field.
PagingInfo
PagingInfo
represents a paging info response entry in a findMany
handler.
ResponseError
ResponseError
represents the typical shape of an error response in Teo.
Constants
ENV
The ENV
object represents environment variables.