From 33884979c7c4cfaf049e354ae528a9bf919bd11b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jind=C5=99ich=20Moravec?= Date: Sun, 28 Jan 2024 16:45:28 +0100 Subject: [PATCH 1/4] feat: add command complete for create table and index --- server/src/main.rs | 10 ++++++++-- server/src/proto_wrapper.rs | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/server/src/main.rs b/server/src/main.rs index 8ce6785..ea69c48 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -210,8 +210,14 @@ async fn handle_query(writer: &mut W, state: &SharedDbState, query: String, t } false }, - Response::TableCreated => true, - Response::IndexCreated => true, + Response::TableCreated => { + writer.write_command_complete(CompleteStatus::CreateTable).await?; + true + }, + Response::IndexCreated => { + writer.write_command_complete(CompleteStatus::CreateIndex).await?; + true + }, } }; diff --git a/server/src/proto_wrapper.rs b/server/src/proto_wrapper.rs index 3415255..b7680d1 100644 --- a/server/src/proto_wrapper.rs +++ b/server/src/proto_wrapper.rs @@ -13,6 +13,8 @@ pub enum CompleteStatus { }, Delete(usize), Select(usize), + CreateTable, + CreateIndex, } impl CompleteStatus { @@ -21,6 +23,8 @@ impl CompleteStatus { CompleteStatus::Insert { oid, rows } => format!("INSERT {} {}", oid, rows), CompleteStatus::Delete(rows) => format!("DELETE {}", rows), CompleteStatus::Select(rows) => format!("SELECT {}", rows), + CompleteStatus::CreateTable => "CREATE TABLE".to_string(), + CompleteStatus::CreateIndex => "CREATE INDEX".to_string(), } } } From 9cef9caad233f706bec25890a226bc21aac63d71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jind=C5=99ich=20Moravec?= Date: Sun, 28 Jan 2024 18:30:06 +0100 Subject: [PATCH 2/4] ci: add pipeline for build and test --- .gitlab-ci.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..27f39e7 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,16 @@ +stages: + - primary + +build-and-test: + stage: primary + image: rust:1.74.0 + tags: + - shared-fi + rules: + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + script: + # build and test in single job for faster execution + # because shared runner doesn't allow caching + - cargo build --verbose + - cargo test --verbose From 02defb3d5437660440c8749af9095c650741cb1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jind=C5=99ich=20Moravec?= Date: Sun, 28 Jan 2024 18:33:51 +0100 Subject: [PATCH 3/4] chore: min rust version for minisql crate --- minisql/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/minisql/Cargo.toml b/minisql/Cargo.toml index d200f70..3bfcbfa 100644 --- a/minisql/Cargo.toml +++ b/minisql/Cargo.toml @@ -2,6 +2,7 @@ name = "minisql" version = "0.1.0" edition = "2021" +rust-version = "1.74" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From e80beaf1608973f23b9e092be122e21be9a1e35f Mon Sep 17 00:00:00 2001 From: Maxim Svistunov Date: Sun, 28 Jan 2024 19:17:19 +0100 Subject: [PATCH 4/4] Add the port and host CLI arguments Improve args and add them to --help Remove unnecessary unwraps --- Cargo.lock | 1 + client/Cargo.toml | 1 + client/src/main.rs | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 4fee400..44c853f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -203,6 +203,7 @@ name = "client" version = "0.1.0" dependencies = [ "anyhow", + "clap", "minisql", "parser", "proto", diff --git a/client/Cargo.toml b/client/Cargo.toml index a8012c6..4e060c2 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -11,3 +11,4 @@ anyhow = "1.0.76" proto = { path = "../proto" } minisql = { path = "../minisql" } parser = { path = "../parser" } +clap = { version = "4.4.18", features = ["derive"] } \ No newline at end of file diff --git a/client/src/main.rs b/client/src/main.rs index fc845e9..31d5d82 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -1,3 +1,4 @@ +use clap::Parser; use proto::handshake::client::do_client_handshake; use proto::handshake::request::HandshakeRequest; use proto::reader::protoreader::ProtoReader; @@ -9,9 +10,21 @@ use proto::message::frontend::{FrontendMessage, QueryData}; use proto::reader::oneway::OneWayProtoReader; use proto::writer::oneway::OneWayProtoWriter; +#[derive(Parser)] +struct Cli { + /// Port number of the server. + #[arg(short, long, default_value_t = 5432, help = "Port number of the server")] + port: u16, + + /// Host name or IP address of the server. + #[arg(short, long, default_value = "127.0.0.1", help = "Host name or IP address of the server")] + host: String, +} + #[tokio::main] async fn main() -> anyhow::Result<()> { - let addr = "127.0.0.1:5432"; + let cli = Cli::parse(); + let addr = format!("{}:{}", cli.host, cli.port); let mut stream = TcpStream::connect(addr).await?; let (reader, writer) = stream.split();