File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,23 @@ impl<'stmt> Rows<'stmt> {
50
50
self . stmt . columns ( )
51
51
}
52
52
53
+ /// Returns the number of rows present.
54
+ pub fn len ( & self ) -> usize {
55
+ self . data . len ( )
56
+ }
57
+
58
+ /// Returns a specific `Row`.
59
+ ///
60
+ /// # Panics
61
+ ///
62
+ /// Panics if `idx` is out of bounds.
63
+ pub fn get < ' a > ( & ' a self , idx : usize ) -> Row < ' a > {
64
+ Row {
65
+ stmt : self . stmt ,
66
+ data : Cow :: Borrowed ( & self . data [ idx] ) ,
67
+ }
68
+ }
69
+
53
70
/// Returns an iterator over the `Row`s.
54
71
pub fn iter < ' a > ( & ' a self ) -> Iter < ' a > {
55
72
Iter {
Original file line number Diff line number Diff line change @@ -892,3 +892,16 @@ fn test_transaction_isolation_level() {
892
892
or_panic ! ( conn. set_transaction_isolation( IsolationLevel :: ReadCommitted ) ) ;
893
893
assert_eq ! ( IsolationLevel :: ReadCommitted , or_panic!( conn. transaction_isolation( ) ) ) ;
894
894
}
895
+
896
+ #[ test]
897
+ fn test_rows_index ( ) {
898
+ let conn = Connection :: connect ( "postgres://postgres@localhost" , & SslMode :: None ) . unwrap ( ) ;
899
+ conn. batch_execute ( "
900
+ CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY);
901
+ INSERT INTO foo (id) VALUES (1), (2), (3);
902
+ " ) . unwrap ( ) ;
903
+ let stmt = conn. prepare ( "SELECT id FROM foo ORDER BY id" ) . unwrap ( ) ;
904
+ let rows = stmt. query ( & [ ] ) . unwrap ( ) ;
905
+ assert_eq ! ( 3 , rows. len( ) ) ;
906
+ assert_eq ! ( 2i32 , rows. get( 1 ) . get( 0 ) ) ;
907
+ }
You can’t perform that action at this time.
0 commit comments