Skip to content

Commit

Permalink
Use block_on to run query.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnwpark committed Jan 11, 2025
1 parent 5a30abf commit cee441b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
9 changes: 9 additions & 0 deletions src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ impl Connector {
pub fn get(&self) -> anyhow::Result<&Config, ArcError> {
self.config.as_ref().map_err(Clone::clone)
}

pub async fn run_single_query<R>(self, query: &str) -> Result<Vec<R>, anyhow::Error>
where
R: QueryResult,
{
let mut connection = self.connect().await?;
let results = connection.query(query, &()).await?;
Ok(results)
}
}

impl Connection {
Expand Down
21 changes: 10 additions & 11 deletions src/portable/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,6 @@ fn get_local_instance(options: &Options) -> Result<InstanceInfo, anyhow::Error>
Ok(inst)
}

#[tokio::main(flavor = "current_thread")]
async fn _run_query<R>(connector: Connector, query: &str) -> Result<Vec<R>, anyhow::Error>
where
R: QueryResult,
{
let mut connection = connector.connect().await?;
let results = connection.query(query, &()).await?;
Ok(results)
}

type ExtensionInfo = (String, String);

fn _get_extensions(options: &Options) -> Result<Vec<ExtensionInfo>, anyhow::Error> {
Expand Down Expand Up @@ -105,7 +95,16 @@ fn _get_extensions(options: &Options) -> Result<Vec<ExtensionInfo>, anyhow::Erro
);";

let connector = options.block_on_create_connector()?;
_run_query(connector, query)

let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()?;
let extension_query = runtime.spawn(
connector.run_single_query::<ExtensionInfo>(query)
);

let extensions = runtime.block_on(extension_query)??;
Ok(extensions)
}

fn list(_: &ExtensionList, options: &Options) -> Result<(), anyhow::Error> {
Expand Down

0 comments on commit cee441b

Please sign in to comment.