Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12242209
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/fantoir-datasource/src/commands/query.rs b/fantoir-datasource/src/commands/query.rs
index fbf79d4..05e141e 100644
--- a/fantoir-datasource/src/commands/query.rs
+++ b/fantoir-datasource/src/commands/query.rs
@@ -1,68 +1,76 @@
use std::process::exit;
use sqlx::PgPool;
use crate::db::connect_to_db;
use crate::QueryArgs;
use crate::services::query::*;
static EXIT_CODE_NO_RESULT_FOUND: i32 = 4;
pub async fn search(args: QueryArgs, database_url: &str) {
let pool = connect_to_db(database_url).await;
if args.code_insee.is_some() && args.code_voie.is_some() {
let code_fantoir = search_fantoir_code(
&pool,
&args.code_insee.unwrap(),
&args.code_voie.unwrap(),
).await;
if let Some(code) = code_fantoir {
search_one_row(&pool, &code).await;
return;
}
exit(EXIT_CODE_NO_RESULT_FOUND);
}
if args.libelle.len() > 0 {
search_libelle(&pool, args).await;
return;
}
unimplemented!()
}
async fn search_one_row(pool: &PgPool, code_fantoir: &str) {
match query_fantoir_code(pool, code_fantoir).await {
None => {
exit(EXIT_CODE_NO_RESULT_FOUND);
}
Some(result) => {
println!("{}", result);
}
}
}
async fn search_libelle(pool: &PgPool, args: QueryArgs) {
let expression = args.libelle.join(" ");
- query_libelle(pool, &expression)
- .await
- .iter()
- .filter(|&entry| entry_matches_conditions(entry, &args))
- .for_each(|entry| {
- println!("{}", entry);
- });
+ let mut found = false;
+
+ query_libelle(pool, &expression)
+ .await
+ .iter()
+ .filter(|&entry| entry_matches_conditions(entry, &args))
+ .for_each(|entry| {
+ found = true;
+
+ println!("{}", entry);
+ });
+
+ if !found {
+ exit(EXIT_CODE_NO_RESULT_FOUND);
+ }
}
fn entry_matches_conditions(entry: &FantoirVoieResult, conditions: &QueryArgs) -> bool {
if let Some(code_insee) = &conditions.code_insee {
if &entry.code_insee != code_insee {
return false;
}
}
return true;
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Oct 12, 07:54 (13 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3061601
Default Alt Text
(2 KB)
Attached To
Mode
rDS Nasqueron Datasources
Attached
Detach File
Event Timeline
Log In to Comment