@d34d/w-orm - v0.6.0
    Preparing search index...

    Type Alias Index

    Indexes are a feature of IndexedDB that allow for faster queries if used properly.

    // 1st use case, multi-field ordering:
    // An index can be created with multiple fields, when using that index the results will be ordered by the fields in the index.

    @Table({
    indexes: {
    nameAge: {
    fields: ['name', 'age'],
    },
    },
    })
    class Test extends Model {
    id!: number
    name!: string
    age!: number
    }

    // The results will be ordered by name and then by age
    await Test.withIndex('nameAge').all()

    // 2nd use case, unique fields:
    // An index can be created with the `unique` option, this will enforce that the field, or combination of fields is unique.
    @Table({
    indexes: {
    uniqueName: { fields: ['firstName', 'lastName'], unique: true },
    }
    })
    class Test2 extends Model {
    id!: number
    firstName!: string
    lastName!: string
    }

    await Test2.create({ firstName: 'John', lastName: 'Doe', id: 1 })
    // This will fail
    await Test2.create({ firstName: 'John', lastName: 'Doe', id: 2 })

    // 3rd use case, multi-field filtering:
    // An index with multiple fields can also be used to speed up filtering.
    @Table({
    indexes: {
    nameAge: {
    fields: ['name', 'age'],
    },
    },
    })
    class Test3 extends Model {
    id!: number
    name!: string
    age!: number
    }
    // Looking for people named John that are 30 years old
    await Test3.withIndex('nameAge', Between(['John', 30], ['John', 30])).all()
    // The alternative will only use the name index and check the age for each result
    await Test3.filter({ name: 'John', age: 30 }).all()
    // "Between" can also be used for ranges, eg. looking for people named John that are between 30 and 40 years old
    await Test3.withIndex('nameAge', Between(['John', 30], ['John', 40])).all()

    // 4th use case, filter + ordering:
    // You can combine all this information and use the first field(s) for filtering and leaving the rest for ordering.

    // Looking for people named John, ordered by age
    await Test3.withIndex('nameAge', Between(['John', BetweenFilter.minKey], ['John', BetweenFilter.maxKey])).all()
    type Index = {
        fields: string[];
        multiEntry: boolean;
        unique: boolean;
    }
    Index
    fields: string[]
    multiEntry: boolean
    unique: boolean