@@ -3,13 +3,11 @@ use sqlx_test::new;
3
3
4
4
#[ cfg_attr( feature = "runtime-async-std" , async_std:: test) ]
5
5
#[ cfg_attr( feature = "runtime-tokio" , tokio:: test) ]
6
- async fn macro_select_from_cte ( ) -> anyhow:: Result < ( ) > {
6
+ async fn macro_select ( ) -> anyhow:: Result < ( ) > {
7
7
let mut conn = new :: < Sqlite > ( ) . await ?;
8
- let account = sqlx:: query!(
9
- "with accounts(id, name) as (values (1, 'Herp Derpinson')) select * from accounts"
10
- )
11
- . fetch_one ( & mut conn)
12
- . await ?;
8
+ let account = sqlx:: query!( "select * from accounts" )
9
+ . fetch_one ( & mut conn)
10
+ . await ?;
13
11
14
12
println ! ( "{:?}" , account) ;
15
13
println ! ( "{}: {}" , account. id, account. name) ;
@@ -19,14 +17,11 @@ async fn macro_select_from_cte() -> anyhow::Result<()> {
19
17
20
18
#[ cfg_attr( feature = "runtime-async-std" , async_std:: test) ]
21
19
#[ cfg_attr( feature = "runtime-tokio" , tokio:: test) ]
22
- async fn macro_select_from_cte_bind ( ) -> anyhow:: Result < ( ) > {
20
+ async fn macro_select_bind ( ) -> anyhow:: Result < ( ) > {
23
21
let mut conn = new :: < Sqlite > ( ) . await ?;
24
- let account = sqlx:: query!(
25
- "with accounts(id, name) as (select 1, 'Herp Derpinson') select * from accounts where id = ?" ,
26
- 1i32
27
- )
28
- . fetch_one ( & mut conn)
29
- . await ?;
22
+ let account = sqlx:: query!( "select * from accounts where id = ?" , 1i32 )
23
+ . fetch_one ( & mut conn)
24
+ . await ?;
30
25
31
26
println ! ( "{:?}" , account) ;
32
27
println ! ( "{}: {}" , account. id, account. name) ;
@@ -36,24 +31,21 @@ async fn macro_select_from_cte_bind() -> anyhow::Result<()> {
36
31
37
32
#[ derive( Debug ) ]
38
33
struct RawAccount {
39
- r#type : i32 ,
40
- name : Option < String > ,
34
+ id : i32 ,
35
+ name : String ,
41
36
}
42
37
43
38
#[ cfg_attr( feature = "runtime-async-std" , async_std:: test) ]
44
39
#[ cfg_attr( feature = "runtime-tokio" , tokio:: test) ]
45
40
async fn test_query_as_raw ( ) -> anyhow:: Result < ( ) > {
46
41
let mut conn = new :: < Sqlite > ( ) . await ?;
47
42
48
- let account = sqlx:: query_as!(
49
- RawAccount ,
50
- "SELECT * from (select 1 as type, cast(null as char) as name) accounts"
51
- )
52
- . fetch_one ( & mut conn)
53
- . await ?;
43
+ let account = sqlx:: query_as!( RawAccount , "SELECT * from accounts" )
44
+ . fetch_one ( & mut conn)
45
+ . await ?;
54
46
55
- assert_eq ! ( None , account. name ) ;
56
- assert_eq ! ( 1 , account. r#type ) ;
47
+ assert_eq ! ( 1 , account. id ) ;
48
+ assert_eq ! ( "Herp Derpinson" , account. name ) ;
57
49
58
50
println ! ( "{:?}" , account) ;
59
51
0 commit comments