stratadb / SchemaField
Type Alias: SchemaField<T, K>
type SchemaField<T, K> = object;Defined in: src/schema-types.ts:111
Schema field definition for document properties.
Remarks
Defines how a document field is stored and indexed in SQLite. The path is optional - if omitted, it defaults to $.{fieldName} for top-level fields. Only specify path explicitly when:
- Accessing nested properties (e.g.,
$.profile.bio) - Using a shorter field name for a nested property (e.g., field name
themewith path$.profile.settings.theme)
Example
// Top-level field - path is optional (defaults to $.name)
.field('name', {
type: 'TEXT',
indexed: true
})
// Nested property with explicit path
.field('bio', {
path: '$.profile.bio',
type: 'TEXT',
indexed: true
})
// Unique constraint with default value
.field('email', {
type: 'TEXT',
indexed: true,
unique: true,
nullable: false
})
// ❌ Compiler error - type mismatch
.field('name', {
type: 'INTEGER', // Error: string field cannot use INTEGER
})Type Parameters
T
T
The document type
K
K extends keyof T
The field key within the document type
Properties
default?
readonly optional default: T[K];Defined in: src/schema-types.ts:139
Default value when field is not provided on insert
indexed?
readonly optional indexed: boolean;Defined in: src/schema-types.ts:133
Whether to create an index on this field for faster queries
name
readonly name: K;Defined in: src/schema-types.ts:113
The field name as it appears in the TypeScript type
nullable?
readonly optional nullable: boolean;Defined in: src/schema-types.ts:130
Whether the field can be null (default: true for optional fields)
path?
readonly optional path: JsonPath;Defined in: src/schema-types.ts:120
JSON path for extracting the value from the document. Defaults to $.{name} if omitted (top-level field). Only specify for nested properties or custom mappings.
type
readonly type: TypeScriptToSQLite<T[K]>;Defined in: src/schema-types.ts:127
SQLite column type for the generated column. Must be compatible with the TypeScript type of the field. Compile-time type checking ensures type safety.
unique?
readonly optional unique: boolean;Defined in: src/schema-types.ts:136
Whether to enforce uniqueness constraint on this field