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.
910use anyhow::bail;
1112use crate::action::{ControlFlow, State};
13use crate::parser::BuiltinCommand;
14use crate::util::postgres::postgres_client;
1516pub async fn run_connect(
17mut cmd: BuiltinCommand,
18 state: &mut State,
19) -> Result<ControlFlow, anyhow::Error> {
20let name = cmd.args.string("name")?;
21if name.starts_with("postgres://") {
22bail!("connection name can not be url");
23 }
2425let url = cmd.args.string("url")?;
26 cmd.args.done()?;
2728let (client, _) = postgres_client(&url, state.default_timeout).await?;
29 state.postgres_clients.insert(name.clone(), client);
30Ok(ControlFlow::Continue)
31}