mz_testdrive/action/sql_server/
connect.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10use anyhow::Context;
11use mz_sql_server_util::{Client, Config};
12
13use crate::action::{ControlFlow, State};
14use crate::parser::BuiltinCommand;
15
16pub async fn run_connect(
17    mut cmd: BuiltinCommand,
18    state: &mut State,
19) -> Result<ControlFlow, anyhow::Error> {
20    let name = cmd.args.string("name")?;
21    cmd.args.done()?;
22
23    let ado_string = cmd.input.join("\n");
24
25    let config = Config::from_ado_string(&ado_string).context("parsing ADO string: {}")?;
26    let client = Client::connect(config)
27        .await
28        .context("connecting to SQL server")?;
29    state.sql_server_clients.insert(name.clone(), client);
30
31    Ok(ControlFlow::Continue)
32}