Skip to content

Commit

Permalink
feat: add data columns and sync/async index to TableIndex
Browse files Browse the repository at this point in the history
Add more properties to TableIndex class
from proto file
  • Loading branch information
zeruk committed Nov 21, 2022
1 parent 8def2d7 commit 7304dce
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
7 changes: 7 additions & 0 deletions examples/basic-example-v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Logger,
Session,
TableDescription,
TableIndex,
Types,
withRetries,
} from 'ydb-sdk';
Expand Down Expand Up @@ -73,6 +74,11 @@ async function createTables(session: Session, logger: Logger) {
.withPrimaryKeys('series_id', 'season_id')
);

const episodesIndex = new TableIndex('episodes_index')
.withIndexColumns('title')
.withDataColumns('air_date')
.withGlobalAsync(true)

await session.createTable(
EPISODES_TABLE,
new TableDescription()
Expand All @@ -97,6 +103,7 @@ async function createTables(session: Session, logger: Logger) {
Types.optional(Types.DATE),
))
.withPrimaryKeys('series_id', 'season_id', 'episode_id')
.withIndex(episodesIndex)
);
}

Expand Down
26 changes: 23 additions & 3 deletions src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1095,15 +1095,35 @@ export class TableProfile implements Ydb.Table.ITableProfile {

export class TableIndex implements Ydb.Table.ITableIndex {
public indexColumns: string[] = [];
public dataColumns: string[] | null = null;
public globalIndex: Ydb.Table.IGlobalIndex|null = null;
public globalAsyncIndex: Ydb.Table.IGlobalAsyncIndex|null = null;

constructor(public name: string) {}

withIndexColumns(...indexColumns: string[]) {
for (const index of indexColumns) {
this.indexColumns.push(index);
}
this.indexColumns.push(...indexColumns);
return this;
}

/** Adds [covering index](https://ydb.tech/en/docs/concepts/secondary_indexes#covering) over columns */
withDataColumns(...dataColumns: string[]) {
if(!this.dataColumns) this.dataColumns = []
this.dataColumns?.push(...dataColumns)
return this
}

withGlobalAsync(isAsync: boolean) {
if(isAsync) {
this.globalAsyncIndex = new Ydb.Table.GlobalAsyncIndex()
this.globalIndex = null
}
else {
this.globalAsyncIndex = null
this.globalIndex = new Ydb.Table.GlobalIndex()
}
return this
}
}

export class TtlSettings implements Ydb.Table.ITtlSettings {
Expand Down

0 comments on commit 7304dce

Please sign in to comment.