Browse Source

clean, change default file extension for json

Ondřej Hruška 4 months ago
parent
commit
66213fceb2
Signed by: Ondřej Hruška <ondra@ondrovo.com> GPG key ID: 2C5FD5035250423D

+ 2 - 0
.gitignore View File

@@ -1,3 +1,5 @@
1 1
 /target
2 2
 .idea/
3 3
 yopa/target
4
+yopa-store.dat
5
+yopa-store.json

BIN
yopa-store.dat View File


+ 6 - 4
yopa-web/src/main.rs View File

@@ -19,7 +19,7 @@ use once_cell::sync::Lazy;
19 19
 use rand::Rng;
20 20
 use tera::Tera;
21 21
 
22
-use yopa::{Storage};
22
+use yopa::Storage;
23 23
 
24 24
 use crate::tera_ext::TeraExt;
25 25
 
@@ -102,7 +102,7 @@ pub(crate) static TERA: Lazy<Tera> = Lazy::new(|| {
102 102
 
103 103
 type YopaStoreWrapper = web::Data<tokio::sync::RwLock<yopa::Storage>>;
104 104
 
105
-const DEF_ADDRESS : &str = "127.0.0.1:8080";
105
+const DEF_ADDRESS: &str = "127.0.0.1:8080";
106 106
 
107 107
 #[actix_web::main]
108 108
 async fn main() -> std::io::Result<()> {
@@ -145,7 +145,9 @@ async fn main() -> std::io::Result<()> {
145 145
     // Ensure the lazy ref is initialized early (to catch template bugs ASAP)
146 146
     let _ = TERA.deref();
147 147
 
148
-    let file = matches.value_of("file").unwrap_or("yopa-store.dat");
148
+    let json = matches.is_present("json");
149
+
150
+    let file = matches.value_of("file").unwrap_or(if json { "yopa-store.json" } else { "yopa-store.dat" });
149 151
 
150 152
     let file_path = if file.starts_with('/') {
151 153
         std::env::current_dir()?.join(file)
@@ -155,7 +157,7 @@ async fn main() -> std::io::Result<()> {
155 157
 
156 158
     debug!("Using database file: {}", file_path.display());
157 159
 
158
-    let mut store = if matches.is_present("json") {
160
+    let mut store = if json {
159 161
         Storage::new_json(file_path)
160 162
     } else {
161 163
         Storage::new_bincode(file_path)

+ 1 - 1
yopa-web/src/routes/models/property.rs View File

@@ -8,7 +8,7 @@ use yopa::{DataType, TypedValue, ID};
8 8
 use crate::routes::models::relation::ObjectOrRelationModelDisplay;
9 9
 use crate::session_ext::SessionExt;
10 10
 use crate::tera_ext::TeraExt;
11
-use crate::utils::{redirect, ParseOrBadReq, StorageErrorIntoResponseError};
11
+use crate::utils::{redirect, StorageErrorIntoResponseError};
12 12
 use crate::TERA;
13 13
 
14 14
 #[get("/model/property/create/{object_id}")]

+ 1 - 1
yopa-web/src/routes/models/relation.rs View File

@@ -7,7 +7,7 @@ use yopa::ID;
7 7
 
8 8
 use crate::session_ext::SessionExt;
9 9
 use crate::tera_ext::TeraExt;
10
-use crate::utils::{redirect, ParseOrBadReq, StorageErrorIntoResponseError};
10
+use crate::utils::{redirect, StorageErrorIntoResponseError};
11 11
 use crate::TERA;
12 12
 
13 13
 #[derive(Serialize, Debug)]