Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backwards compatibility for package-query #1460

Merged
merged 6 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion fastn-core/src/library2022/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,10 @@ impl Library2022 {
kind,
doc,
&self.config,
&fastn_core::library2022::processor::sql::get_db_config()?,
&fastn_core::library2022::processor::sql::DatabaseConfig {
db_type: "sqlite".to_string(),
db_url: "".to_string(),
},
)
.await
}
Expand Down
49 changes: 46 additions & 3 deletions fastn-core/src/library2022/processor/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,44 @@ pub async fn process(
) -> ftd::interpreter::Result<ftd::interpreter::Value> {
let (headers, query) = get_p1_data("package-data", &value, doc.name)?;

let use_db = match headers.get_optional_string_by_key("use", doc.name, value.line_number()) {
Ok(Some(k)) => Some(k),
_ => match headers
.get_optional_string_by_key("db", doc.name, value.line_number())
.ok()
{
Some(k) => {
println!("Warning: `db` header is deprecated, use `use` instead.");
k
}
harshdoesdev marked this conversation as resolved.
Show resolved Hide resolved
None => None,
},
};

let sqlite_database_path = match use_db {
Some(k) => {
let mut db_path = camino::Utf8PathBuf::new().join(k.as_str());
harshdoesdev marked this conversation as resolved.
Show resolved Hide resolved
if !db_path.exists() {
if !config.root.join(db_path.as_path()).exists() {
return ftd::interpreter::utils::e2(
"`use` does not exists for sql processor".to_string(),
doc.name,
value.line_number(),
);
}
db_path = config.root.join(db_path.as_path());
}
db_path
}
None => {
assert!(
!db_config.db_url.is_empty(),
"Neither `use` or `db` is present."
);
config.root.join(&db_config.db_url)
}
};

// need the query params
// question is they can be multiple
// so lets say start with passing attributes from ftd file
Expand All @@ -41,9 +79,14 @@ pub async fn process(
// for now they wil be ordered
// select * from users where

let db_path = config.root.join(&db_config.db_url);
let query_response =
execute_query(&db_path, query.as_str(), doc, headers, value.line_number()).await;
let query_response = execute_query(
&sqlite_database_path,
query.as_str(),
doc,
headers,
value.line_number(),
)
.await;

match query_response {
Ok(result) => result_to_value(Ok(result), kind, doc, &value, super::sql::STATUS_OK),
Expand Down
Loading