@@ -47,18 +47,27 @@ fn query_uses_per_fact_pseudo_attr(query: &DatalogQuery) -> bool {
4747/// println!("{}: {:?}", vars[0], row[0]);
4848/// }
4949/// }
50- /// QueryResult::Transacted( tx_id) => println!("wrote tx {}", tx_id),
51- /// QueryResult::Retracted( tx_id) => println!("retracted tx {}", tx_id),
50+ /// QueryResult::Transacted { tx_id, tx_count } => println!("tx {} (count {}) ", tx_id, tx_count ),
51+ /// QueryResult::Retracted { tx_id, tx_count } => println!("retracted tx {} (count {}) ", tx_id, tx_count ),
5252/// QueryResult::Ok => {}
5353/// }
5454/// ```
5555#[ derive( Debug , Clone , PartialEq ) ]
5656pub enum QueryResult {
57- /// Transaction completed successfully. The inner value is the transaction ID
58- /// (Unix milliseconds), also displayed by the REPL as the `tx` counter.
59- Transacted ( TxId ) ,
60- /// Retraction completed successfully with the transaction ID.
61- Retracted ( TxId ) ,
57+ /// Transaction completed successfully.
58+ Transacted {
59+ /// Unix-millisecond timestamp of the transaction.
60+ tx_id : TxId ,
61+ /// Monotonic counter (1, 2, 3 …). This is the value used by `:as-of N`.
62+ tx_count : u64 ,
63+ } ,
64+ /// Retraction completed successfully.
65+ Retracted {
66+ /// Unix-millisecond timestamp of the retraction.
67+ tx_id : TxId ,
68+ /// Monotonic counter (1, 2, 3 …). This is the value used by `:as-of N`.
69+ tx_count : u64 ,
70+ } ,
6271 /// Query results: list of variable bindings
6372 QueryResults {
6473 /// The variable names in the order they appear in the `:find` clause.
@@ -236,12 +245,12 @@ impl DatalogExecutor {
236245 fact_tuples. push ( ( entity_id, attribute, value, per_fact_opts) ) ;
237246 }
238247
239- let tx_id = self
248+ let ( tx_id, tx_count ) = self
240249 . storage
241250 . transact_batch ( fact_tuples, tx_opts)
242251 . map_err ( |e| anyhow ! ( "Transaction failed: {}" , e) ) ?;
243252
244- Ok ( QueryResult :: Transacted ( tx_id) )
253+ Ok ( QueryResult :: Transacted { tx_id, tx_count } )
245254 }
246255
247256 /// Execute a retract command: retract facts from storage
@@ -266,12 +275,12 @@ impl DatalogExecutor {
266275 fact_tuples. push ( ( entity_id, attribute, value) ) ;
267276 }
268277
269- let tx_id = self
278+ let ( tx_id, tx_count ) = self
270279 . storage
271280 . retract ( fact_tuples)
272281 . map_err ( |e| anyhow ! ( "Retraction failed: {}" , e) ) ?;
273282
274- Ok ( QueryResult :: Retracted ( tx_id) )
283+ Ok ( QueryResult :: Retracted { tx_id, tx_count } )
275284 }
276285
277286 /// Build a filtered fact snapshot for a query's temporal constraints.
@@ -1679,8 +1688,9 @@ mod tests {
16791688
16801689 let result = executor. execute ( cmd) . unwrap ( ) ;
16811690 match result {
1682- QueryResult :: Transacted ( tx_id) => {
1691+ QueryResult :: Transacted { tx_id, tx_count } => {
16831692 assert ! ( tx_id > 0 ) ;
1693+ assert ! ( tx_count > 0 ) ;
16841694 }
16851695 _ => panic ! ( "Expected Transacted result" ) ,
16861696 }
@@ -1817,8 +1827,9 @@ mod tests {
18171827
18181828 let result = executor. execute ( cmd) . unwrap ( ) ;
18191829 match result {
1820- QueryResult :: Retracted ( tx_id) => {
1830+ QueryResult :: Retracted { tx_id, tx_count } => {
18211831 assert ! ( tx_id > 0 ) ;
1832+ assert ! ( tx_count > 0 ) ;
18221833 }
18231834 _ => panic ! ( "Expected Retracted result" ) ,
18241835 }
@@ -1844,7 +1855,7 @@ mod tests {
18441855
18451856 let result = executor. execute ( cmd) . unwrap ( ) ;
18461857 match result {
1847- QueryResult :: Transacted ( _ ) => { }
1858+ QueryResult :: Transacted { .. } => { }
18481859 _ => panic ! ( "Expected Transacted result" ) ,
18491860 }
18501861
0 commit comments