Field
const
Field:object
Defined in: fields.ts:37
Type declaration
Section titled “Type declaration”array()
Section titled “array()”array<
TElementDef
>(element
,options
):FieldDefinition
<InferFieldType
<TElementDef
>[]>
Defines an array field for a model property.
Supports the SurrealDB max
option for array length.
Type Parameters
Section titled “Type Parameters”TElementDef
Section titled “TElementDef”TElementDef
extends FieldDefinition
<unknown
>
Parameters
Section titled “Parameters”element
Section titled “element”TElementDef
The field definition for the array’s elements.
options
Section titled “options”ArrayFieldOptions
<InferFieldType
<TElementDef
>> = {}
ArrayFieldOptions (supports max
and all FieldOptions)
Returns
Section titled “Returns”FieldDefinition
<InferFieldType
<TElementDef
>[]>
FieldDefinition<Array
Example
Section titled “Example”tags: Field.array(Field.string(), { max: 10 }) posts: Field.array(Field.record((): any => Post), { max: 100 })
bool()
Section titled “bool()”bool(
options
):FieldDefinition
<boolean
>
Defines a boolean field for a model property.
Parameters
Section titled “Parameters”options
Section titled “options”FieldOptions
= {}
Optional field options (default, permissions, etc.)
Returns
Section titled “Returns”FieldDefinition
<boolean
>
FieldDefinition
Example
Section titled “Example”isActive: Field.bool({ default: 'true' })
custom()
Section titled “custom()”custom<
T
>(typeString
,options
):FieldDefinition
<T
>
Defines a field with a custom SurrealQL type string. Useful for advanced or not-yet-implemented types.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”typeString
Section titled “typeString”string
The raw SurrealQL type (e.g., ‘duration’, ‘geometry
options
Section titled “options”CustomFieldOptions
= {}
Optional custom field options. Use { flexible: true } for FLEXIBLE custom fields.
Returns
Section titled “Returns”FieldDefinition
Example
Section titled “Example”duration: Field.custom<number>('duration') meta: Field.custom<object>('object', { flexible: true })
datetime()
Section titled “datetime()”datetime(
options
):FieldDefinition
<Date
>
Defines a datetime field for a model property.
Parameters
Section titled “Parameters”options
Section titled “options”FieldOptions
= {}
Optional field options (default, permissions, etc.)
Returns
Section titled “Returns”FieldDefinition
<Date
>
FieldDefinition
Example
Section titled “Example”createdAt: Field.datetime({ default: 'time::now()' })
number()
Section titled “number()”number(
options
):FieldDefinition
<number
>
Defines a number field for a model property.
Parameters
Section titled “Parameters”options
Section titled “options”FieldOptions
= {}
Optional field options (assert, default, permissions, etc.)
Returns
Section titled “Returns”FieldDefinition
<number
>
FieldDefinition
Example
Section titled “Example”age: Field.number({ assert: '$value >= 0', default: '0' })
object()
Section titled “object()”object<
TSchema
>(schema
,options
):FieldDefinition
<InferShapeFromFields
<TSchema
>>
Defines a nested object field for a model property. The schema generator will handle defining sub-fields with dot notation.
Type Parameters
Section titled “Type Parameters”TSchema
Section titled “TSchema”TSchema
extends Record
<string
, FieldDefinition
<unknown
>>
Parameters
Section titled “Parameters”schema
Section titled “schema”TSchema
The field definitions for the nested object.
options
Section titled “options”ObjectFieldOptions
= {}
Object field options. Use { flexible: true } to emit SurrealQL FLEXIBLE.
Returns
Section titled “Returns”FieldDefinition
<InferShapeFromFields
<TSchema
>>
FieldDefinition