-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backwards compatibility for package-query (#1460)
* backwards compatibility for package-query * refactored code and added deprecation message * removed comments * minor changes * applied recommended changes
- Loading branch information
1 parent
cde85e8
commit 3eb6f6a
Showing
5 changed files
with
81 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
pub async fn process( | ||
value: ftd::ast::VariableValue, | ||
kind: ftd::interpreter::Kind, | ||
doc: &ftd::interpreter::TDoc<'_>, | ||
req_config: &fastn_core::RequestConfig, | ||
) -> ftd::interpreter::Result<ftd::interpreter::Value> { | ||
let (headers, query) = | ||
fastn_core::library2022::processor::sqlite::get_p1_data("package-data", &value, doc.name)?; | ||
|
||
fastn_core::library2022::utils::log_deprecation_warning( | ||
"`package-query` has been deprecated, use `sql` processor instead.", | ||
); | ||
|
||
let sqlite_database = | ||
match headers.get_optional_string_by_key("db", doc.name, value.line_number())? { | ||
Some(k) => k, | ||
None => { | ||
return ftd::interpreter::utils::e2( | ||
"`db` is not specified".to_string(), | ||
doc.name, | ||
value.line_number(), | ||
) | ||
} | ||
}; | ||
|
||
let sqlite_database_path = req_config.config.root.join(sqlite_database.as_str()); | ||
|
||
if !sqlite_database_path.exists() { | ||
return ftd::interpreter::utils::e2( | ||
"`db` does not exists for package-query processor".to_string(), | ||
doc.name, | ||
value.line_number(), | ||
); | ||
} | ||
|
||
let query_response = fastn_core::library2022::processor::sqlite::execute_query( | ||
&sqlite_database_path, | ||
query.as_str(), | ||
doc, | ||
headers, | ||
value.line_number(), | ||
) | ||
.await; | ||
|
||
match query_response { | ||
Ok(result) => fastn_core::library2022::processor::sqlite::result_to_value( | ||
Ok(result), | ||
kind, | ||
doc, | ||
&value, | ||
super::sql::STATUS_OK, | ||
), | ||
Err(e) => fastn_core::library2022::processor::sqlite::result_to_value( | ||
Err(e.to_string()), | ||
kind, | ||
doc, | ||
&value, | ||
super::sql::STATUS_ERROR, | ||
), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters