Skip to content

Commit

Permalink
allow templating
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Fontanier authored and Henry Fontanier committed Nov 22, 2023
1 parent 177c636 commit c6b63c8
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions core/src/blocks/database.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::blocks::block::{parse_pair, Block, BlockResult, BlockType, Env};
use crate::data_sources::data_source;
use crate::Rule;
use anyhow::{anyhow, Result};
use async_trait::async_trait;
Expand All @@ -7,6 +8,7 @@ use pest::iterators::Pair;
use serde_json::{json, Value};
use tokio::sync::mpsc::UnboundedSender;

use super::block::replace_variables_in_string;
use super::helpers::get_data_source_project;

#[derive(Clone)]
Expand Down Expand Up @@ -82,19 +84,23 @@ impl Block for Database {
env: &Env,
_event_sender: Option<UnboundedSender<Value>>,
) -> Result<BlockResult> {
let project =
get_data_source_project(&self.workspace_id, &self.data_source_id, env).await?;
let workspace_id = replace_variables_in_string(&self.workspace_id, "workspace_id", env)?;
let data_source_id =
replace_variables_in_string(&self.data_source_id, "data_source_id", env)?;
let database_id = replace_variables_in_string(&self.database_id, "database_id", env)?;

let project = get_data_source_project(&workspace_id, &data_source_id, env).await?;

let database = match env
.store
.load_database(&project, &self.data_source_id, &self.database_id)
.load_database(&project, &data_source_id, &database_id)
.await?
{
Some(d) => d,
None => Err(anyhow!(
"Database `{}` not found in data source `{}`",
self.database_id,
self.data_source_id
database_id,
data_source_id
))?,
};

Expand All @@ -105,8 +111,8 @@ impl Block for Database {
Ok(r) => r,
Err(e) => Err(anyhow!(
"Error querying database `{}` in data source `{}`: {}",
self.database_id,
self.data_source_id,
database_id,
data_source_id,
e
))?,
};
Expand Down

0 comments on commit c6b63c8

Please sign in to comment.