TanStack

BaseIndex

Defined in: packages/db/src/indexes/base-index.ts:137

Base abstract class that all index types extend

Extended by

Type Parameters

TKey

TKey extends string | number = string | number

Implements

Constructors

Constructor

ts
new BaseIndex<TKey>(
   id, 
   expression, 
   name?, 
options?): BaseIndex<TKey>;

Defined in: packages/db/src/indexes/base-index.ts:158

Parameters

id

number

expression

BasicExpression

name?

string

options?

any

Returns

BaseIndex<TKey>

Properties

compareFn()

ts
protected readonly compareFn: (a, b) => number;

Defined in: packages/db/src/indexes/base-index.ts:149

Orders indexed values. Every result is checked, because a custom comparator or custom collation may be supplied by the user.

Parameters

a

any

b

any

Returns

number


compareOptions

ts
protected readonly compareOptions: CompareOptions;

Defined in: packages/db/src/indexes/base-index.ts:144


expression

ts
readonly expression: BasicExpression;

Defined in: packages/db/src/indexes/base-index.ts:142


hasCustomComparator

ts
protected readonly hasCustomComparator: boolean;

Defined in: packages/db/src/indexes/base-index.ts:155

A user-supplied comparator's ordering may not match the WHERE evaluator's relational operators.


id

ts
readonly id: number;

Defined in: packages/db/src/indexes/base-index.ts:140


name?

ts
readonly optional name: string;

Defined in: packages/db/src/indexes/base-index.ts:141


supportedOperations

ts
readonly supportedOperations: Set<"eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "ilike">;

Defined in: packages/db/src/indexes/base-index.ts:143

Accessors

keyCount

Get Signature

ts
get abstract keyCount(): number;

Defined in: packages/db/src/indexes/base-index.ts:203

Returns

number

Implementation of

IndexInterface.keyCount


supportsOrderOptimization

Get Signature

ts
get supportsOrderOptimization(): boolean;

Defined in: packages/db/src/indexes/base-index.ts:259

Whether a query can use this index for its declared ordered prefix.

Returns

boolean

Whether a query can use this index for its declared ordered prefix.

Implementation of

IndexInterface.supportsOrderOptimization


supportsRangeOptimization

Get Signature

ts
get supportsRangeOptimization(): boolean;

Defined in: packages/db/src/indexes/base-index.ts:255

Whether range lookups (gt/gte/lt/lte) on this index can be trusted to return every matching key. Range traversal relies on the index ordering, so it is unsafe when the index uses a custom comparator, whose order may not match the WHERE evaluator's relational operators. Callers must fall back to a full scan when this is false.

Returns

boolean

Implementation of

IndexInterface.supportsRangeOptimization

Methods

add()

ts
abstract add(key, item): void;

Defined in: packages/db/src/indexes/base-index.ts:179

Parameters

key

TKey

item

any

Returns

void

Implementation of

IndexInterface.add


addRangeValue()

ts
protected addRangeValue(value): void;

Defined in: packages/db/src/indexes/base-index.ts:277

Parameters

value

unknown

Returns

void


build()

ts
abstract build(entries): void;

Defined in: packages/db/src/indexes/base-index.ts:182

Parameters

entries

Iterable<[TKey, any]>

Returns

void

Implementation of

IndexInterface.build


canOptimizeRangeFor()

ts
canOptimizeRangeFor(value): boolean;

Defined in: packages/db/src/indexes/base-index.ts:299

Whether the live values in this index share the predicate operand's relational domain. Mixed domains can sort differently in the index and WHERE evaluator, which can make a range lookup omit matching rows.

Parameters

value

unknown

Returns

boolean

Implementation of

IndexInterface.canOptimizeRangeFor


clear()

ts
abstract clear(): void;

Defined in: packages/db/src/indexes/base-index.ts:183

Returns

void

Implementation of

IndexInterface.clear


clearRangeValues()

ts
protected clearRangeValues(): void;

Defined in: packages/db/src/indexes/base-index.ts:295

Returns

void


equalityLookup()

ts
abstract equalityLookup(value): Set<TKey>;

Defined in: packages/db/src/indexes/base-index.ts:204

Parameters

value

any

Returns

Set<TKey>

Implementation of

IndexInterface.equalityLookup


evaluateAddedValue()

ts
protected evaluateAddedValue(key, item): any;

Defined in: packages/db/src/indexes/base-index.ts:374

The indexed value of a row being added. A throwing expression fails the write.

Parameters

key

TKey

item

any

Returns

any


evaluateIndexExpression()

ts
protected evaluateIndexExpression(item): any;

Defined in: packages/db/src/indexes/base-index.ts:367

Parameters

item

any

Returns

any


exactBucketKeys()

ts
protected exactBucketKeys(value): Iterable<TKey, any, any> | undefined;

Defined in: packages/db/src/indexes/base-index.ts:205

Parameters

value

any

Returns

Iterable<TKey, any, any> | undefined


inArrayLookup()

ts
inArrayLookup(values): Set<TKey>;

Defined in: packages/db/src/indexes/base-index.ts:228

Combine exact buckets without copying each bucket first.

Parameters

values

any[]

Returns

Set<TKey>

Implementation of

IndexInterface.inArrayLookup


initialize()

ts
protected initialize(_options?): void;

Defined in: packages/db/src/indexes/base-index.ts:365

Parameters

_options?

any

Returns

void


lookup()

ts
abstract lookup(operation, value): Set<TKey>;

Defined in: packages/db/src/indexes/base-index.ts:184

Parameters

operation

"eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "ilike"

value

any

Returns

Set<TKey>

Implementation of

IndexInterface.lookup


lookupSupportedOperation()

ts
protected lookupSupportedOperation(operation, value): Set<TKey> | undefined;

Defined in: packages/db/src/indexes/base-index.ts:211

Parameters

operation

"eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "ilike"

value

any

Returns

Set<TKey> | undefined


matchesCompareOptions()

ts
matchesCompareOptions(compareOptions): boolean;

Defined in: packages/db/src/indexes/base-index.ts:321

Checks if the compare options match the index's compare options. The direction is ignored because the index can be reversed if the direction is different.

Parameters

compareOptions

CompareOptions

Returns

boolean

Implementation of

IndexInterface.matchesCompareOptions


matchesDirection()

ts
matchesDirection(direction): boolean;

Defined in: packages/db/src/indexes/base-index.ts:361

Checks if the index matches the provided direction.

Parameters

direction

OrderByDirection

Returns

boolean

Implementation of

IndexInterface.matchesDirection


matchesField()

ts
matchesField(fieldPath): boolean;

Defined in: packages/db/src/indexes/base-index.ts:309

Parameters

fieldPath

string[]

Returns

boolean

Implementation of

IndexInterface.matchesField


rangeQuery()

ts
abstract rangeQuery(options): Set<TKey>;

Defined in: packages/db/src/indexes/base-index.ts:208

Parameters

options

RangeQueryOptions

Returns

Set<TKey>

Implementation of

IndexInterface.rangeQuery


rangeQueryReversed()

ts
rangeQueryReversed(options): Set<TKey>;

Defined in: packages/db/src/indexes/base-index.ts:237

Parameters

options

RangeQueryOptions = {}

Returns

Set<TKey>

Implementation of

IndexInterface.rangeQueryReversed


remove()

ts
abstract remove(key, item): void;

Defined in: packages/db/src/indexes/base-index.ts:180

Parameters

key

TKey

item

any

Returns

void

Implementation of

IndexInterface.remove


removeRangeValue()

ts
protected removeRangeValue(value): void;

Defined in: packages/db/src/indexes/base-index.ts:286

Parameters

value

unknown

Returns

void


supports()

ts
supports(operation): boolean;

Defined in: packages/db/src/indexes/base-index.ts:251

Parameters

operation

"eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "ilike"

Returns

boolean

Implementation of

IndexInterface.supports


take()

ts
abstract take(
   n, 
   from, 
   filterFn?): TKey[];

Defined in: packages/db/src/indexes/base-index.ts:185

Parameters

n

number

from

unknown

filterFn?

(key) => boolean

Returns

TKey[]

Implementation of

IndexInterface.take


takeFromStart()

ts
abstract takeFromStart(n, filterFn?): TKey[];

Defined in: packages/db/src/indexes/base-index.ts:190

Parameters

n

number

filterFn?

(key) => boolean

Returns

TKey[]

Implementation of

IndexInterface.takeFromStart


takeReversed()

ts
abstract takeReversed(
   n, 
   from, 
   filterFn?): TKey[];

Defined in: packages/db/src/indexes/base-index.ts:194

Parameters

n

number

from

unknown

filterFn?

(key) => boolean

Returns

TKey[]

Implementation of

IndexInterface.takeReversed


takeReversedFromEnd()

ts
abstract takeReversedFromEnd(n, filterFn?): TKey[];

Defined in: packages/db/src/indexes/base-index.ts:199

Parameters

n

number

filterFn?

(key) => boolean

Returns

TKey[]

Implementation of

IndexInterface.takeReversedFromEnd


update()

ts
abstract update(
   key, 
   oldItem, 
   newItem): void;

Defined in: packages/db/src/indexes/base-index.ts:181

Parameters

key

TKey

oldItem

any

newItem

any

Returns

void

Implementation of

IndexInterface.update