Skip to content

Commit 7304dce

Browse files
committed
feat: add data columns and sync/async index to TableIndex
Add more properties to TableIndex class from proto file
1 parent 8def2d7 commit 7304dce

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

examples/basic-example-v1/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Logger,
88
Session,
99
TableDescription,
10+
TableIndex,
1011
Types,
1112
withRetries,
1213
} from 'ydb-sdk';
@@ -73,6 +74,11 @@ async function createTables(session: Session, logger: Logger) {
7374
.withPrimaryKeys('series_id', 'season_id')
7475
);
7576

77+
const episodesIndex = new TableIndex('episodes_index')
78+
.withIndexColumns('title')
79+
.withDataColumns('air_date')
80+
.withGlobalAsync(true)
81+
7682
await session.createTable(
7783
EPISODES_TABLE,
7884
new TableDescription()
@@ -97,6 +103,7 @@ async function createTables(session: Session, logger: Logger) {
97103
Types.optional(Types.DATE),
98104
))
99105
.withPrimaryKeys('series_id', 'season_id', 'episode_id')
106+
.withIndex(episodesIndex)
100107
);
101108
}
102109

src/table.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,15 +1095,35 @@ export class TableProfile implements Ydb.Table.ITableProfile {
10951095

10961096
export class TableIndex implements Ydb.Table.ITableIndex {
10971097
public indexColumns: string[] = [];
1098+
public dataColumns: string[] | null = null;
1099+
public globalIndex: Ydb.Table.IGlobalIndex|null = null;
1100+
public globalAsyncIndex: Ydb.Table.IGlobalAsyncIndex|null = null;
10981101

10991102
constructor(public name: string) {}
11001103

11011104
withIndexColumns(...indexColumns: string[]) {
1102-
for (const index of indexColumns) {
1103-
this.indexColumns.push(index);
1104-
}
1105+
this.indexColumns.push(...indexColumns);
11051106
return this;
11061107
}
1108+
1109+
/** Adds [covering index](https://ydb.tech/en/docs/concepts/secondary_indexes#covering) over columns */
1110+
withDataColumns(...dataColumns: string[]) {
1111+
if(!this.dataColumns) this.dataColumns = []
1112+
this.dataColumns?.push(...dataColumns)
1113+
return this
1114+
}
1115+
1116+
withGlobalAsync(isAsync: boolean) {
1117+
if(isAsync) {
1118+
this.globalAsyncIndex = new Ydb.Table.GlobalAsyncIndex()
1119+
this.globalIndex = null
1120+
}
1121+
else {
1122+
this.globalAsyncIndex = null
1123+
this.globalIndex = new Ydb.Table.GlobalIndex()
1124+
}
1125+
return this
1126+
}
11071127
}
11081128

11091129
export class TtlSettings implements Ydb.Table.ITtlSettings {

0 commit comments

Comments
 (0)