File tree Expand file tree Collapse file tree 1 file changed +18
-8
lines changed Expand file tree Collapse file tree 1 file changed +18
-8
lines changed Original file line number Diff line number Diff line change 1
- use std:: io:: { Error , ErrorKind } ;
2
- use rusqlite:: { Connection , Row } ;
3
- use crate :: database:: { Database , DBRawToStruct } ;
1
+ use crate :: database:: { DBRawToStruct , Database } ;
4
2
use crate :: results:: TelemetryData ;
3
+ use rusqlite:: { Connection , Row } ;
4
+ use std:: io:: { Error , ErrorKind } ;
5
+ use std:: path:: PathBuf ;
5
6
6
7
pub struct SQLite {
7
8
pub connection : Connection ,
8
9
}
9
10
10
- pub fn init ( database_file : & Option < String > ) -> std:: io:: Result < Connection > {
11
+ pub fn init ( database_file : & Option < String > ) -> std:: io:: Result < Connection > {
11
12
match database_file {
12
- None => {
13
- Err ( Error :: new ( ErrorKind :: Other , "Error setup sqlite invalid database file." ) )
14
- }
13
+ None => Err ( Error :: new (
14
+ ErrorKind :: Other ,
15
+ "Error setup sqlite invalid database file." ,
16
+ ) ) ,
15
17
Some ( database_file) => {
16
- let connection = Connection :: open ( database_file) ;
18
+ let mut database_path = PathBuf :: from ( database_file) ;
19
+ if !database_path. is_absolute ( ) {
20
+ database_path = PathBuf :: from ( std:: env:: current_dir ( ) . unwrap ( ) . join ( database_file) ) ;
21
+ }
22
+
23
+ // attempt to create the parent directory and ignore errors if it already exists
24
+ let _ = std:: fs:: create_dir_all ( database_path. parent ( ) . unwrap ( ) ) ;
25
+
26
+ let connection = Connection :: open ( database_path) ;
17
27
match connection {
18
28
Ok ( connection) => {
19
29
let create_table = connection. execute (
You can’t perform that action at this time.
0 commit comments