@@ -28,12 +28,12 @@ pub enum CustomerSelector {
2828 ByLastName ( String ) ,
2929}
3030
31- type WarehouseId = u16 ;
31+ type WarehouseId = u32 ;
3232
3333#[ derive( Clone , Debug , SpacetimeType ) ]
3434pub struct OrderStatusLineResult {
3535 pub item_id : u32 ,
36- pub supply_w_id : WarehouseId ,
36+ pub supply_w_id : u32 ,
3737 pub quantity : u32 ,
3838 pub amount_cents : i64 ,
3939 pub delivery_d : Option < Timestamp > ,
@@ -54,7 +54,7 @@ pub struct OrderStatusResult {
5454
5555#[ derive( Clone , Debug , SpacetimeType ) ]
5656pub struct StockLevelResult {
57- pub warehouse_id : WarehouseId ,
57+ pub warehouse_id : u32 ,
5858 pub district_id : u8 ,
5959 pub threshold : i32 ,
6060 pub low_stock_count : u32 ,
@@ -64,7 +64,7 @@ pub struct StockLevelResult {
6464pub struct DeliveryQueueAck {
6565 pub scheduled_id : u64 ,
6666 pub queued_at : Timestamp ,
67- pub warehouse_id : WarehouseId ,
67+ pub warehouse_id : u32 ,
6868 pub carrier_id : u8 ,
6969}
7070
@@ -82,7 +82,7 @@ pub struct DeliveryCompletionView {
8282 pub driver_id : String ,
8383 pub terminal_id : u32 ,
8484 pub request_id : u64 ,
85- pub warehouse_id : WarehouseId ,
85+ pub warehouse_id : u32 ,
8686 pub carrier_id : u8 ,
8787 pub queued_at : Timestamp ,
8888 pub completed_at : Timestamp ,
@@ -94,7 +94,7 @@ pub struct DeliveryCompletionView {
9494#[ derive( Clone , Debug ) ]
9595pub struct Warehouse {
9696 #[ primary_key]
97- pub w_id : WarehouseId ,
97+ pub w_id : u32 ,
9898 pub w_name : String ,
9999 pub w_street_1 : String ,
100100 pub w_street_2 : String ,
@@ -113,7 +113,7 @@ pub struct Warehouse {
113113pub struct District {
114114 #[ primary_key]
115115 pub district_key : u32 ,
116- pub d_w_id : WarehouseId ,
116+ pub d_w_id : u32 ,
117117 pub d_id : u8 ,
118118 pub d_name : String ,
119119 pub d_street_1 : String ,
@@ -135,7 +135,7 @@ pub struct District {
135135pub struct Customer {
136136 #[ primary_key]
137137 pub customer_key : u64 ,
138- pub c_w_id : WarehouseId ,
138+ pub c_w_id : u32 ,
139139 pub c_d_id : u8 ,
140140 pub c_id : u32 ,
141141 pub c_first : String ,
@@ -166,9 +166,9 @@ pub struct History {
166166 pub history_id : u64 ,
167167 pub h_c_id : u32 ,
168168 pub h_c_d_id : u8 ,
169- pub h_c_w_id : WarehouseId ,
169+ pub h_c_w_id : u32 ,
170170 pub h_d_id : u8 ,
171- pub h_w_id : u16 ,
171+ pub h_w_id : u32 ,
172172 pub h_date : Timestamp ,
173173 pub h_amount_cents : i64 ,
174174 pub h_data : String ,
@@ -193,7 +193,7 @@ pub struct Item {
193193pub struct Stock {
194194 #[ primary_key]
195195 pub stock_key : u64 ,
196- pub s_w_id : WarehouseId ,
196+ pub s_w_id : u32 ,
197197 pub s_i_id : u32 ,
198198 pub s_quantity : i32 ,
199199 pub s_dist_01 : String ,
@@ -221,7 +221,7 @@ pub struct Stock {
221221pub struct OOrder {
222222 #[ primary_key]
223223 pub order_key : u64 ,
224- pub o_w_id : WarehouseId ,
224+ pub o_w_id : u32 ,
225225 pub o_d_id : u8 ,
226226 pub o_id : u32 ,
227227 pub o_c_id : u32 ,
@@ -239,7 +239,7 @@ pub struct OOrder {
239239pub struct NewOrder {
240240 #[ primary_key]
241241 pub new_order_key : u64 ,
242- pub no_w_id : WarehouseId ,
242+ pub no_w_id : u32 ,
243243 pub no_d_id : u8 ,
244244 pub no_o_id : u32 ,
245245}
@@ -252,12 +252,12 @@ pub struct NewOrder {
252252pub struct OrderLine {
253253 #[ primary_key]
254254 pub order_line_key : u64 ,
255- pub ol_w_id : WarehouseId ,
255+ pub ol_w_id : u32 ,
256256 pub ol_d_id : u8 ,
257257 pub ol_o_id : u32 ,
258258 pub ol_number : u8 ,
259259 pub ol_i_id : u32 ,
260- pub ol_supply_w_id : u16 ,
260+ pub ol_supply_w_id : u32 ,
261261 pub ol_delivery_d : Option < Timestamp > ,
262262 pub ol_quantity : u32 ,
263263 pub ol_amount_cents : i64 ,
@@ -280,7 +280,7 @@ pub struct DeliveryJob {
280280 pub terminal_id : u32 ,
281281 pub request_id : u64 ,
282282 pub queued_at : Timestamp ,
283- pub w_id : WarehouseId ,
283+ pub w_id : u32 ,
284284 pub carrier_id : u8 ,
285285 pub next_d_id : u8 ,
286286 pub skipped_districts : u8 ,
@@ -300,7 +300,7 @@ pub struct DeliveryCompletion {
300300 pub driver_id : String ,
301301 pub terminal_id : u32 ,
302302 pub request_id : u64 ,
303- pub warehouse_id : WarehouseId ,
303+ pub warehouse_id : u32 ,
304304 pub carrier_id : u8 ,
305305 pub queued_at : Timestamp ,
306306 pub completed_at : Timestamp ,
@@ -441,7 +441,7 @@ pub fn load_order_lines(ctx: &ReducerContext, rows: Vec<OrderLine>) -> Result<()
441441#[ reducer]
442442pub fn order_status (
443443 ctx : & ReducerContext ,
444- w_id : u16 ,
444+ w_id : u32 ,
445445 d_id : u8 ,
446446 customer : CustomerSelector ,
447447) -> Result < OrderStatusResult , String > {
@@ -491,7 +491,12 @@ pub fn order_status(
491491}
492492
493493#[ reducer]
494- pub fn stock_level ( ctx : & ReducerContext , w_id : u16 , d_id : u8 , threshold : i32 ) -> Result < StockLevelResult , String > {
494+ pub fn stock_level (
495+ ctx : & ReducerContext ,
496+ w_id : u32 ,
497+ d_id : u8 ,
498+ threshold : i32 ,
499+ ) -> Result < StockLevelResult , String > {
495500 let _timer = LogStopwatch :: new ( "stock_level" ) ;
496501
497502 let district = find_district ( ctx, w_id, d_id) ?;
@@ -531,7 +536,7 @@ pub fn queue_delivery(
531536 driver_id : String ,
532537 terminal_id : u32 ,
533538 request_id : u64 ,
534- w_id : u16 ,
539+ w_id : u32 ,
535540 carrier_id : u8 ,
536541) -> Result < DeliveryQueueAck , String > {
537542 let _timer = LogStopwatch :: new ( "queue_delivery" ) ;
@@ -640,10 +645,7 @@ pub fn run_delivery_job(ctx: &ReducerContext, job: DeliveryJob) -> Result<(), St
640645}
641646
642647fn validate_warehouse_row ( row : & Warehouse ) -> Result < ( ) , String > {
643- ensure ! (
644- ( 1 ..=i32 :: from( u16 :: MAX ) ) . contains( & ( row. w_id as i32 ) ) ,
645- "warehouse id must be positive"
646- ) ;
648+ ensure ! ( row. w_id > 0 , "warehouse id must be positive" ) ;
647649 Ok ( ( ) )
648650}
649651
@@ -691,7 +693,7 @@ fn validate_stock_row(row: &Stock) -> Result<(), String> {
691693
692694fn process_delivery_district (
693695 ctx : & ReducerContext ,
694- w_id : u16 ,
696+ w_id : WarehouseId ,
695697 d_id : u8 ,
696698 carrier_id : u8 ,
697699 delivered_at : Timestamp ,
@@ -740,7 +742,12 @@ fn process_delivery_district(
740742 Ok ( true )
741743}
742744
743- fn resolve_customer ( tx : & ReducerContext , w_id : u16 , d_id : u8 , selector : & CustomerSelector ) -> Result < Customer , String > {
745+ fn resolve_customer (
746+ tx : & ReducerContext ,
747+ w_id : WarehouseId ,
748+ d_id : u8 ,
749+ selector : & CustomerSelector ,
750+ ) -> Result < Customer , String > {
744751 match selector {
745752 CustomerSelector :: ById ( id) => find_customer_by_id ( tx, w_id, d_id, * id) ,
746753 CustomerSelector :: ByLastName ( last_name) => {
@@ -756,19 +763,19 @@ fn resolve_customer(tx: &ReducerContext, w_id: u16, d_id: u8, selector: &Custome
756763 }
757764}
758765
759- fn find_warehouse ( tx : & ReducerContext , w_id : u16 ) -> Result < Warehouse , String > {
766+ fn find_warehouse ( tx : & ReducerContext , w_id : WarehouseId ) -> Result < Warehouse , String > {
760767 tx. db
761768 . warehouse ( )
762769 . w_id ( )
763770 . find ( w_id)
764771 . ok_or_else ( || format ! ( "warehouse {w_id} not found" ) )
765772}
766773
767- fn ensure_warehouse_exists ( tx : & ReducerContext , w_id : u16 ) -> Result < ( ) , String > {
774+ fn ensure_warehouse_exists ( tx : & ReducerContext , w_id : WarehouseId ) -> Result < ( ) , String > {
768775 find_warehouse ( tx, w_id) . map ( |_| ( ) )
769776}
770777
771- fn find_district ( tx : & ReducerContext , w_id : u16 , d_id : u8 ) -> Result < District , String > {
778+ fn find_district ( tx : & ReducerContext , w_id : WarehouseId , d_id : u8 ) -> Result < District , String > {
772779 tx. db
773780 . district ( )
774781 . by_w_d ( )
@@ -777,7 +784,7 @@ fn find_district(tx: &ReducerContext, w_id: u16, d_id: u8) -> Result<District, S
777784 . ok_or_else ( || format ! ( "district ({w_id}, {d_id}) not found" ) )
778785}
779786
780- fn find_customer_by_id ( tx : & ReducerContext , w_id : u16 , d_id : u8 , c_id : u32 ) -> Result < Customer , String > {
787+ fn find_customer_by_id ( tx : & ReducerContext , w_id : WarehouseId , d_id : u8 , c_id : u32 ) -> Result < Customer , String > {
781788 tx. db
782789 . customer ( )
783790 . by_w_d_c_id ( )
@@ -786,7 +793,7 @@ fn find_customer_by_id(tx: &ReducerContext, w_id: u16, d_id: u8, c_id: u32) -> R
786793 . ok_or_else ( || format ! ( "customer ({w_id}, {d_id}, {c_id}) not found" ) )
787794}
788795
789- fn find_stock ( tx : & ReducerContext , w_id : u16 , item_id : u32 ) -> Result < Stock , String > {
796+ fn find_stock ( tx : & ReducerContext , w_id : WarehouseId , item_id : u32 ) -> Result < Stock , String > {
790797 tx. db
791798 . stock ( )
792799 . by_w_i ( )
@@ -795,19 +802,19 @@ fn find_stock(tx: &ReducerContext, w_id: u16, item_id: u32) -> Result<Stock, Str
795802 . ok_or_else ( || format ! ( "stock ({w_id}, {item_id}) not found" ) )
796803}
797804
798- fn pack_district_key ( w_id : u16 , d_id : u8 ) -> u32 {
799- ( u32 :: from ( w_id) * 100 ) + u32:: from ( d_id)
805+ fn pack_district_key ( w_id : WarehouseId , d_id : u8 ) -> u32 {
806+ ( w_id * 100 ) + u32:: from ( d_id)
800807}
801808
802- fn pack_customer_key ( w_id : u16 , d_id : u8 , c_id : u32 ) -> u64 {
809+ fn pack_customer_key ( w_id : WarehouseId , d_id : u8 , c_id : u32 ) -> u64 {
803810 ( ( u64:: from ( w_id) * 100 ) + u64:: from ( d_id) ) * 10_000 + u64:: from ( c_id)
804811}
805812
806- fn pack_stock_key ( w_id : u16 , item_id : u32 ) -> u64 {
813+ fn pack_stock_key ( w_id : WarehouseId , item_id : u32 ) -> u64 {
807814 u64:: from ( w_id) * 1_000_000 + u64:: from ( item_id)
808815}
809816
810- fn pack_order_key ( w_id : u16 , d_id : u8 , o_id : u32 ) -> u64 {
817+ fn pack_order_key ( w_id : WarehouseId , d_id : u8 , o_id : u32 ) -> u64 {
811818 ( ( u64:: from ( w_id) * 100 ) + u64:: from ( d_id) ) * 10_000_000 + u64:: from ( o_id)
812819}
813820
0 commit comments