Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to custom sorting in storage index search #142

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
## [Unreleased]
### Added
- Add runtime support for registering a shutdown hook function.
- Add support to custom sorting in storage index search.

## [1.31.0] - 2024-03-17
### Added
Expand Down
6 changes: 4 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2341,11 +2341,12 @@ declare namespace nkruntime {
* @param collection - Collection of storage engine to index objects from.
* @param key - Key of storage objects to index. Set to null, undefined or emtpy string to index all objects of collection.
* @param fields - Array of fields of object to index. The values of these fields will be searchable in the index.
* @param sortableFields - Opt. Array of fields of object. The values of these fields will be sortable in an index search. The fields must exist within the previously specified fields to be indexed.
* @param maxEntries - Maximum number of entries to keep in the index.
* @param indexOnly - Opt. The returned values are fetched from the index only instead of the db, which might return a partial value. Defaults to false.
* @throws {TypeError, GoError}
*/
registerStorageIndex(name: string, collection: string, key: string | void, fields: string[], maxEntries: number, indexOnly: boolean): void;
registerStorageIndex(name: string, collection: string, key: string | void, fields: string[], sortableFields: string[], maxEntries: number, indexOnly: boolean): void;

/**
* Register purchase notification Google handler.
Expand Down Expand Up @@ -4865,11 +4866,12 @@ declare namespace nkruntime {
* @param indexName - Index to query.
* @param query - The query to specify the index lookup criteria.
* @param limit - The maximum number of results to retrieve from the index.
* @param order - Opt. The storage object fields to sort the query results by. The prefix '-' before a field name indicates descending order. All specified fields must be indexed and sortable.
* @param callerId - Opt. User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permissions are bypassed.
* @returns A list of storage objects matching the query criteria.
* @throws {TypeError, GoError}
*/
storageIndexList(indexName: string, query: string, limit: number, callerId?: string | void): StorageObject[];
storageIndexList(indexName: string, query: string, limit: number, order?: string[], callerId?: string | void): StorageObject[];

/**
* Get Satori object.
Expand Down
4 changes: 2 additions & 2 deletions runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ type Initializer interface {
RegisterEventSessionEnd(fn func(ctx context.Context, logger Logger, evt *api.Event)) error

// Register a new storage index.
RegisterStorageIndex(name, collection, key string, fields []string, maxEntries int, indexOnly bool) error
RegisterStorageIndex(name, collection, key string, fields []string, sortableFields []string, maxEntries int, indexOnly bool) error

// RegisterStorageIndexFilter can be used to define a filtering function for a given storage index.
RegisterStorageIndexFilter(indexName string, fn func(ctx context.Context, logger Logger, db *sql.DB, nk NakamaModule, write *StorageWrite) bool) error
Expand Down Expand Up @@ -1087,7 +1087,7 @@ type NakamaModule interface {
StorageRead(ctx context.Context, reads []*StorageRead) ([]*api.StorageObject, error)
StorageWrite(ctx context.Context, writes []*StorageWrite) ([]*api.StorageObjectAck, error)
StorageDelete(ctx context.Context, deletes []*StorageDelete) error
StorageIndexList(ctx context.Context, callerID, indexName, query string, limit int) (*api.StorageObjects, error)
StorageIndexList(ctx context.Context, callerID, indexName, query string, limit int, order []string) (*api.StorageObjects, error)

MultiUpdate(ctx context.Context, accountUpdates []*AccountUpdate, storageWrites []*StorageWrite, storageDeletes []*StorageDelete, walletUpdates []*WalletUpdate, updateLedger bool) ([]*api.StorageObjectAck, []*WalletUpdateResult, error)

Expand Down