File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed
examples/basic-example-v1 Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change 7
7
Logger ,
8
8
Session ,
9
9
TableDescription ,
10
+ TableIndex ,
10
11
Types ,
11
12
withRetries ,
12
13
} from 'ydb-sdk' ;
@@ -73,6 +74,11 @@ async function createTables(session: Session, logger: Logger) {
73
74
. withPrimaryKeys ( 'series_id' , 'season_id' )
74
75
) ;
75
76
77
+ const episodesIndex = new TableIndex ( 'episodes_index' )
78
+ . withIndexColumns ( 'title' )
79
+ . withDataColumns ( 'air_date' )
80
+ . withGlobalAsync ( true )
81
+
76
82
await session . createTable (
77
83
EPISODES_TABLE ,
78
84
new TableDescription ( )
@@ -97,6 +103,7 @@ async function createTables(session: Session, logger: Logger) {
97
103
Types . optional ( Types . DATE ) ,
98
104
) )
99
105
. withPrimaryKeys ( 'series_id' , 'season_id' , 'episode_id' )
106
+ . withIndex ( episodesIndex )
100
107
) ;
101
108
}
102
109
Original file line number Diff line number Diff line change @@ -1095,15 +1095,35 @@ export class TableProfile implements Ydb.Table.ITableProfile {
1095
1095
1096
1096
export class TableIndex implements Ydb . Table . ITableIndex {
1097
1097
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 ;
1098
1101
1099
1102
constructor ( public name : string ) { }
1100
1103
1101
1104
withIndexColumns ( ...indexColumns : string [ ] ) {
1102
- for ( const index of indexColumns ) {
1103
- this . indexColumns . push ( index ) ;
1104
- }
1105
+ this . indexColumns . push ( ...indexColumns ) ;
1105
1106
return this ;
1106
1107
}
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
+ }
1107
1127
}
1108
1128
1109
1129
export class TtlSettings implements Ydb . Table . ITtlSettings {
You can’t perform that action at this time.
0 commit comments