1- use std:: future:: join;
2-
31use sqlx:: postgres:: PgPool ;
42
53use crate :: functions:: Function ;
@@ -22,23 +20,22 @@ impl SchemaCache {
2220 SchemaCache :: default ( )
2321 }
2422
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 !(
2725 Schema :: load( pool) ,
2826 Table :: load( pool) ,
2927 Function :: load( pool) ,
3028 PostgresType :: load( pool) ,
3129 Version :: load( pool) ,
32- )
33- . await ;
30+ ) ?;
3431
35- SchemaCache {
32+ Ok ( SchemaCache {
3633 schemas,
3734 tables,
3835 functions,
3936 types,
4037 versions,
41- }
38+ } )
4239 }
4340
4441 /// Applies an AST node to the repository
@@ -72,22 +69,21 @@ impl SchemaCache {
7269pub trait SchemaCacheItem {
7370 type Item ;
7471
75- async fn load ( pool : & PgPool ) -> Vec < Self :: Item > ;
72+ async fn load ( pool : & PgPool ) -> Result < Vec < Self :: Item > , sqlx :: Error > ;
7673}
7774
7875#[ cfg( test) ]
7976mod tests {
80- use sqlx:: PgPool ;
77+ use async_std:: task:: block_on;
78+ use pg_test_utils:: test_database:: get_new_test_db;
8179
8280 use crate :: SchemaCache ;
8381
8482 #[ test]
8583 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 ( ) ) ;
8985
90- async_std :: task :: block_on ( SchemaCache :: load ( & pool ) ) ;
86+ block_on ( SchemaCache :: load ( & test_db ) ) . expect ( "Couldn't load Schema Cache" ) ;
9187
9288 assert ! ( true ) ;
9389 }
0 commit comments