@@ -2,7 +2,7 @@ use super::{
22 btree_index:: { BTreeIndex , BTreeIndexIter , BTreeIndexRangeIter } ,
33 RowId ,
44} ;
5- use crate :: db:: datastore:: traits:: TableSchema ;
5+ use crate :: db:: datastore:: traits:: { ColId , TableSchema } ;
66use nonempty:: NonEmpty ;
77use spacetimedb_sats:: { AlgebraicValue , ProductType , ProductValue } ;
88use std:: {
@@ -13,14 +13,14 @@ use std::{
1313pub ( crate ) struct Table {
1414 pub ( crate ) row_type : ProductType ,
1515 pub ( crate ) schema : TableSchema ,
16- pub ( crate ) indexes : HashMap < NonEmpty < u32 > , BTreeIndex > ,
16+ pub ( crate ) indexes : HashMap < NonEmpty < ColId > , BTreeIndex > ,
1717 pub ( crate ) rows : BTreeMap < RowId , ProductValue > ,
1818}
1919
2020impl Table {
2121 pub ( crate ) fn insert_index ( & mut self , mut index : BTreeIndex ) {
2222 index. build_from_rows ( self . scan_rows ( ) ) . unwrap ( ) ;
23- self . indexes . insert ( index. cols . clone ( ) , index) ;
23+ self . indexes . insert ( index. cols . clone ( ) . map ( ColId ) , index) ;
2424 }
2525
2626 pub ( crate ) fn insert ( & mut self , row_id : RowId , row : ProductValue ) {
@@ -33,7 +33,7 @@ impl Table {
3333 pub ( crate ) fn delete ( & mut self , row_id : & RowId ) -> Option < ProductValue > {
3434 let row = self . rows . remove ( row_id) ?;
3535 for ( cols, index) in self . indexes . iter_mut ( ) {
36- let col_value = row. project_not_empty ( cols) . unwrap ( ) ;
36+ let col_value = row. project_not_empty ( & cols. clone ( ) . map ( |x| x . 0 ) ) . unwrap ( ) ;
3737 index. delete ( & col_value, row_id)
3838 }
3939 Some ( row)
@@ -64,19 +64,19 @@ impl Table {
6464 /// For a unique index this will always yield at most one `RowId`.
6565 pub ( crate ) fn index_seek < ' a > (
6666 & ' a self ,
67- cols : NonEmpty < u32 > ,
67+ cols : NonEmpty < ColId > ,
6868 value : & ' a AlgebraicValue ,
6969 ) -> Option < BTreeIndexRangeIter < ' a > > {
7070 self . indexes . get ( & cols) . map ( |index| index. seek ( value) )
7171 }
7272
73- pub ( crate ) fn _index_scan ( & self , cols : NonEmpty < u32 > ) -> BTreeIndexIter < ' _ > {
73+ pub ( crate ) fn _index_scan ( & self , cols : NonEmpty < ColId > ) -> BTreeIndexIter < ' _ > {
7474 self . indexes . get ( & cols) . unwrap ( ) . scan ( )
7575 }
7676
7777 pub ( crate ) fn _index_range_scan (
7878 & self ,
79- cols : NonEmpty < u32 > ,
79+ cols : NonEmpty < ColId > ,
8080 range : impl RangeBounds < AlgebraicValue > ,
8181 ) -> BTreeIndexRangeIter < ' _ > {
8282 self . indexes . get ( & cols) . unwrap ( ) . scan_range ( range)
0 commit comments