@@ -9,10 +9,11 @@ use std::{error::Error, fs::read_to_string, path::Path, process::exit, rc::Rc};
99use futures:: stream:: StreamExt ;
1010use typedb_driver:: {
1111 answer:: { QueryAnswer , QueryType } ,
12- TransactionType ,
12+ TransactionOptions , TransactionType ,
1313} ;
1414
1515use crate :: {
16+ constants:: DEFAULT_TRANSACTION_TIMEOUT ,
1617 printer:: { print_document, print_row} ,
1718 repl:: command:: { parse_one_query, CommandResult , ReplError } ,
1819 transaction_repl, ConsoleContext ,
@@ -155,7 +156,9 @@ pub(crate) fn transaction_read(context: &mut ConsoleContext, input: &[String]) -
155156 let db_name_owned = db_name. clone ( ) ;
156157 let transaction = context
157158 . background_runtime
158- . run ( async move { driver. transaction ( db_name_owned, TransactionType :: Read ) . await } )
159+ . run ( async move {
160+ driver. transaction_with_options ( db_name_owned, TransactionType :: Read , default_transaction_options ( ) ) . await
161+ } )
159162 . map_err ( |err| Box :: new ( err) as Box < dyn Error + Send > ) ?;
160163 context. transaction = Some ( ( transaction, false ) ) ;
161164 let repl = transaction_repl ( db_name, TransactionType :: Read ) ;
@@ -169,7 +172,9 @@ pub(crate) fn transaction_write(context: &mut ConsoleContext, input: &[String])
169172 let db_name_owned = db_name. clone ( ) ;
170173 let transaction = context
171174 . background_runtime
172- . run ( async move { driver. transaction ( db_name_owned, TransactionType :: Write ) . await } )
175+ . run ( async move {
176+ driver. transaction_with_options ( db_name_owned, TransactionType :: Write , default_transaction_options ( ) ) . await
177+ } )
173178 . map_err ( |err| Box :: new ( err) as Box < dyn Error + Send > ) ?;
174179 context. transaction = Some ( ( transaction, false ) ) ;
175180 let repl = transaction_repl ( db_name, TransactionType :: Write ) ;
@@ -183,7 +188,9 @@ pub(crate) fn transaction_schema(context: &mut ConsoleContext, input: &[String])
183188 let db_name_owned = db_name. clone ( ) ;
184189 let transaction = context
185190 . background_runtime
186- . run ( async move { driver. transaction ( db_name_owned, TransactionType :: Schema ) . await } )
191+ . run ( async move {
192+ driver. transaction_with_options ( db_name_owned, TransactionType :: Schema , default_transaction_options ( ) ) . await
193+ } )
187194 . map_err ( |err| Box :: new ( err) as Box < dyn Error + Send > ) ?;
188195 context. transaction = Some ( ( transaction, false ) ) ;
189196 let repl = transaction_repl ( db_name, TransactionType :: Schema ) ;
@@ -307,6 +314,10 @@ pub(crate) fn transaction_query(context: &mut ConsoleContext, input: &[impl AsRe
307314 }
308315}
309316
317+ fn default_transaction_options ( ) -> TransactionOptions {
318+ TransactionOptions :: new ( ) . transaction_timeout ( DEFAULT_TRANSACTION_TIMEOUT )
319+ }
320+
310321const QUERY_TYPE_TEMPLATE : & ' static str = "<QUERY TYPE>" ;
311322const QUERY_COMPILATION_SUCCESS : & ' static str = "Finished <QUERY TYPE> query validation and compilation..." ;
312323const QUERY_WRITE_FINISHED_STREAMING_ROWS : & ' static str = "Finished writes. Streaming rows..." ;
0 commit comments