Index
const
Index:object
Defined in: define/index/index.ts:4
Type declaration
Section titled “Type declaration”define()
Section titled “define()”define(
tableThunk
,options
):IndexDefinition
Defines a database index for a table.
This definition can be passed to applySchema
to create the index in SurrealDB.
Parameters
Section titled “Parameters”tableThunk
Section titled “tableThunk”() => AnyModelClass
A thunk function that returns the model class. This is used to avoid circular dependency issues.
options
Section titled “options”IndexDefineOptions
Configuration for the index.
Returns
Section titled “Returns”IndexDefinition
An index definition object.
Example
Section titled “Example”// Define a simple unique indexconst UserEmailIndex = Index.define(() => User, { name: 'user_email_unique', fields: ['email'], unique: true,});
// Define a full-text search index with a specific analyzerconst PostContentFTS = Index.define(() => Post, { name: 'post_content_fts', fields: ['title', 'content'], analyzer: 'english',});
// Apply to the databaseawait applySchema(db, [User, Post, UserEmailIndex, PostContentFTS]);