File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 3
3
4
4
use diesel;
5
5
use diesel:: prelude:: * ;
6
+ use diesel:: pg:: PgConnection ;
6
7
use toml;
7
8
8
9
use db;
@@ -99,11 +100,14 @@ struct NewCategory {
99
100
}
100
101
101
102
pub fn sync ( toml_str : & str ) -> CargoResult < ( ) > {
103
+ let conn = db:: connect_now ( ) . unwrap ( ) ;
104
+ sync_with_connection ( toml_str, & conn)
105
+ }
106
+
107
+ pub fn sync_with_connection ( toml_str : & str , conn : & PgConnection ) -> CargoResult < ( ) > {
102
108
use diesel:: pg:: upsert:: * ;
103
109
use diesel:: expression:: dsl:: all;
104
110
105
- let conn = db:: connect_now ( ) . unwrap ( ) ;
106
-
107
111
let toml: toml:: value:: Table =
108
112
toml:: from_str ( toml_str) . expect ( "Could not parse categories toml" ) ;
109
113
@@ -133,10 +137,10 @@ pub fn sync(toml_str: &str) -> CargoResult<()> {
133
137
let slugs = diesel:: insert ( & to_insert)
134
138
. into ( categories:: table)
135
139
. returning ( categories:: slug)
136
- . get_results :: < String > ( & conn) ?;
140
+ . get_results :: < String > ( & * conn) ?;
137
141
138
142
let to_delete = categories:: table. filter ( categories:: slug. ne ( all ( slugs) ) ) ;
139
- diesel:: delete ( to_delete) . execute ( & conn) ?;
143
+ diesel:: delete ( to_delete) . execute ( & * conn) ?;
140
144
Ok ( ( ) )
141
145
} )
142
146
}
You can’t perform that action at this time.
0 commit comments