Skip to content

Defined in: schema/FieldBuilder.ts:20

Fluent builder for defining a single field's properties.

Consumers should use the field factory object rather than instantiating this class directly.

Example ​

ts
field.string().primaryKey().unique().default('hello').build()
// → { type: 'string', primaryKey: true, unique: true, optional: false, defaultValue: 'hello' }

Constructors ​

Constructor ​

new FieldBuilder(type): FieldBuilder

Defined in: schema/FieldBuilder.ts:28

Parameters ​

type ​

SupportedFieldType

Returns ​

FieldBuilder

Methods ​

build() ​

build(): FieldMetadata

Defined in: schema/FieldBuilder.ts:64

Compiles the builder into a plain metadata object.

Returns ​

FieldMetadata

The field metadata.


default() ​

default(value): this

Defined in: schema/FieldBuilder.ts:53

Sets a default value for the field.

Parameters ​

value ​

unknown

The default value. Its type must match the field type (validated by validateSchema at compile time).

Returns ​

this


optional() ​

optional(): this

Defined in: schema/FieldBuilder.ts:42

Returns ​

this


primaryKey() ​

primaryKey(): this

Defined in: schema/FieldBuilder.ts:32

Returns ​

this


unique() ​

unique(): this

Defined in: schema/FieldBuilder.ts:37

Returns ​

this

Released under the MIT License.