Skip to content

Index

const Index: object

Defined in: define/index/index.ts:4

define(tableThunk, options): IndexDefinition

Defines a database index for a table. This definition can be passed to applySchema to create the index in SurrealDB.

() => AnyModelClass

A thunk function that returns the model class. This is used to avoid circular dependency issues.

IndexDefineOptions

Configuration for the index.

IndexDefinition

An index definition object.

// Define a simple unique index
const UserEmailIndex = Index.define(() => User, {
name: 'user_email_unique',
fields: ['email'],
unique: true,
});
// Define a full-text search index with a specific analyzer
const PostContentFTS = Index.define(() => Post, {
name: 'post_content_fts',
fields: ['title', 'content'],
analyzer: 'english',
});
// Apply to the database
await applySchema(db, [User, Post, UserEmailIndex, PostContentFTS]);