1
- use std:: future:: join;
2
-
3
1
use sqlx:: postgres:: PgPool ;
4
2
5
3
use crate :: functions:: Function ;
@@ -22,23 +20,22 @@ impl SchemaCache {
22
20
SchemaCache :: default ( )
23
21
}
24
22
25
- pub async fn load ( pool : & PgPool ) -> SchemaCache {
26
- let ( schemas, tables, functions, types, versions) = join ! (
23
+ pub async fn load ( pool : & PgPool ) -> Result < SchemaCache , sqlx :: Error > {
24
+ let ( schemas, tables, functions, types, versions) = futures_util :: try_join !(
27
25
Schema :: load( pool) ,
28
26
Table :: load( pool) ,
29
27
Function :: load( pool) ,
30
28
PostgresType :: load( pool) ,
31
29
Version :: load( pool) ,
32
- )
33
- . await ;
30
+ ) ?;
34
31
35
- SchemaCache {
32
+ Ok ( SchemaCache {
36
33
schemas,
37
34
tables,
38
35
functions,
39
36
types,
40
37
versions,
41
- }
38
+ } )
42
39
}
43
40
44
41
/// Applies an AST node to the repository
@@ -72,22 +69,21 @@ impl SchemaCache {
72
69
pub trait SchemaCacheItem {
73
70
type Item ;
74
71
75
- async fn load ( pool : & PgPool ) -> Vec < Self :: Item > ;
72
+ async fn load ( pool : & PgPool ) -> Result < Vec < Self :: Item > , sqlx :: Error > ;
76
73
}
77
74
78
75
#[ cfg( test) ]
79
76
mod tests {
80
- use sqlx:: PgPool ;
77
+ use async_std:: task:: block_on;
78
+ use pg_test_utils:: test_database:: get_new_test_db;
81
79
82
80
use crate :: SchemaCache ;
83
81
84
82
#[ test]
85
83
fn test_schema_cache ( ) {
86
- let conn_string = std:: env:: var ( "DATABASE_URL" ) . unwrap ( ) ;
87
-
88
- let pool = async_std:: task:: block_on ( PgPool :: connect ( conn_string. as_str ( ) ) ) . unwrap ( ) ;
84
+ let test_db = block_on ( get_new_test_db ( ) ) ;
89
85
90
- async_std :: task :: block_on ( SchemaCache :: load ( & pool ) ) ;
86
+ block_on ( SchemaCache :: load ( & test_db ) ) . expect ( "Couldn't load Schema Cache" ) ;
91
87
92
88
assert ! ( true ) ;
93
89
}
0 commit comments