@@ -187,15 +187,29 @@ module.exports = (function () {
187
187
188
188
index = attributes . index ;
189
189
190
- indexParts = adapter . _parseIndex ( index , columnName ) ;
191
- indexName = indexParts [ 0 ] ;
192
- indexType = indexParts [ 1 ] ;
190
+ if ( _ . isArray ( index ) ) {
191
+ index . forEach ( ( oneIndex ) => {
192
+ indexParts = adapter . _parseIndex ( oneIndex , columnName ) ;
193
+ indexName = indexParts [ 0 ] ;
194
+ indexType = indexParts [ 1 ] ;
195
+
196
+ if ( typeof indices [ indexName ] === 'undefined' ) {
197
+ indices [ indexName ] = { } ;
198
+ }
199
+
200
+ indices [ indexName ] [ indexType ] = columnName ;
201
+ } ) ;
202
+ } else {
203
+ indexParts = adapter . _parseIndex ( index , columnName ) ;
204
+ indexName = indexParts [ 0 ] ;
205
+ indexType = indexParts [ 1 ] ;
193
206
194
- if ( typeof indices [ indexName ] === 'undefined' ) {
195
- indices [ indexName ] = { } ;
196
- }
207
+ if ( typeof indices [ indexName ] === 'undefined' ) {
208
+ indices [ indexName ] = { } ;
209
+ }
197
210
198
- indices [ indexName ] [ indexType ] = columnName ;
211
+ indices [ indexName ] [ indexType ] = columnName ;
212
+ }
199
213
200
214
}
201
215
@@ -549,6 +563,8 @@ module.exports = (function () {
549
563
scanning = false ;
550
564
551
565
if ( indexing ) {
566
+ // console.log("USING INDEX")
567
+ // console.log(indexing);
552
568
query = model . query ( options . where [ hash ] )
553
569
delete options . where [ hash ] ;
554
570
@@ -758,6 +774,14 @@ module.exports = (function () {
758
774
var indexInfo ;
759
775
var indexName ;
760
776
var indexType ;
777
+
778
+ if ( ! ( _ . isArray ( fields ) ) ) {
779
+ fields = Object . keys ( fields ) ;
780
+ }
781
+
782
+ // console.log("FIELDS")
783
+ // console.log(fields);
784
+
761
785
for ( var i = 0 ; i < fields . length ; i ++ ) {
762
786
763
787
fieldName = fields [ i ] ;
@@ -778,8 +802,25 @@ module.exports = (function () {
778
802
779
803
// using secondary or GSIs
780
804
if ( column . index ) {
805
+ // console.log("COLUMN.INDEX")
806
+ // console.log(column.index)
781
807
if ( _ . isArray ( column . index ) ) {
782
- throw new Error ( `No support yet for multiple non-primary indexes, ${ fieldName } = ${ column . index } ` ) ;
808
+ column . index . forEach ( ( oneIndex ) => {
809
+ if ( oneIndex === 'secondary' ) {
810
+ secondaryRange = fieldName ;
811
+ } else {
812
+ indexInfo = adapter . _parseIndex ( oneIndex , fieldName ) ;
813
+ indexName = indexInfo [ 0 ] ;
814
+ indexType = indexInfo [ 1 ] ;
815
+
816
+ if ( typeof indices [ indexName ] === 'undefined' ) {
817
+ indices [ indexName ] = { } ;
818
+ }
819
+
820
+ indices [ indexName ] [ indexType ] = fieldName ;
821
+ }
822
+ } ) ;
823
+ // throw new Error(`No support yet for multiple non-primary indexes, ${fieldName} = ${column.index}`);
783
824
} else if ( column . index === 'secondary' ) {
784
825
secondaryRange = fieldName ;
785
826
} else {
@@ -797,6 +838,9 @@ module.exports = (function () {
797
838
798
839
}
799
840
841
+ // console.log("INDICES")
842
+ // console.log(indices)
843
+
800
844
// set global secondary hash info
801
845
var indicesHashed ;
802
846
var indicesRanged ;
0 commit comments