From bc3f010a5ada8190544a18f839103d387e5ffdd3 Mon Sep 17 00:00:00 2001 From: Bassem Girgis Date: Tue, 17 Aug 2021 16:37:14 -0500 Subject: [PATCH] init --- .gitignore | 1 + .rustfmt.toml | 75 ++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 8 +++++ Makefile | 22 +++++++++++++ README.md | 1 + db/postgres/init.sql | 28 +++++++++++++++++ docker-compose.yml | 25 +++++++++++++++ src/main.rs | 3 ++ 8 files changed, 163 insertions(+) create mode 100644 .gitignore create mode 100644 .rustfmt.toml create mode 100644 Cargo.toml create mode 100644 Makefile create mode 100644 README.md create mode 100644 db/postgres/init.sql create mode 100644 docker-compose.yml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..06a6776 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,75 @@ +max_width = 70 +hard_tabs = false +tab_spaces = 4 +newline_style = "Auto" +indent_style = "Block" +use_small_heuristics = "Default" +fn_call_width = 40 +attr_fn_like_width = 40 +struct_lit_width = 18 +struct_variant_width = 35 +array_width = 40 +chain_width = 40 +single_line_if_else_max_width = 50 +wrap_comments = true +format_code_in_doc_comments = true +comment_width = 70 +normalize_comments = false +normalize_doc_attributes = false +license_template_path = "" +format_strings = true +format_macro_matchers = false +format_macro_bodies = true +empty_item_single_line = true +struct_lit_single_line = true +fn_single_line = false +where_single_line = false +imports_indent = "Block" +imports_layout = "Vertical" +imports_granularity = "Crate" +group_imports = "Preserve" +reorder_imports = true +reorder_modules = true +reorder_impl_items = false +type_punctuation_density = "Wide" +space_before_colon = false +space_after_colon = true +spaces_around_ranges = false +binop_separator = "Back" +remove_nested_parens = true +combine_control_expr = false +overflow_delimited_expr = false +struct_field_align_threshold = 0 +enum_discrim_align_threshold = 0 +match_arm_blocks = true +match_arm_leading_pipes = "Never" +force_multiline_blocks = true +fn_args_layout = "Vertical" +brace_style = "PreferSameLine" +control_brace_style = "ClosingNextLine" +trailing_semicolon = true +trailing_comma = "Vertical" +match_block_trailing_comma = true +blank_lines_upper_bound = 1 +blank_lines_lower_bound = 0 +edition = "2018" +version = "One" +inline_attribute_width = 0 +merge_derives = false +use_try_shorthand = false +use_field_init_shorthand = false +force_explicit_abi = true +condense_wildcard_suffixes = false +color = "Auto" +required_version = "1.4.37" +unstable_features = false +disable_all_formatting = false +skip_children = false +hide_parse_errors = false +error_on_line_overflow = false +error_on_unformatted = false +report_todo = "Never" +report_fixme = "Never" +ignore = [] +emit_mode = "Files" +make_backup = false diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..4599132 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "test-sqlx" +version = "0.1.0" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..48f6eea --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ + +all: + make clean + make build + +clean: + rm -rf target + +build: + cargo build + +test: + cargo test + +up: + docker-compose up -d + +down: + docker-compose down + +run: + cargo run diff --git a/README.md b/README.md new file mode 100644 index 0000000..e043bbf --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# sqlx Test diff --git a/db/postgres/init.sql b/db/postgres/init.sql new file mode 100644 index 0000000..9f1c6c0 --- /dev/null +++ b/db/postgres/init.sql @@ -0,0 +1,28 @@ +-- a single table is used for all events in the cqrs system +CREATE TABLE events +( + aggregate_type text NOT NULL, + aggregate_id text NOT NULL, + sequence bigint CHECK (sequence >= 0) NOT NULL, + payload jsonb NOT NULL, + metadata jsonb NOT NULL, + timestamp timestamp with time zone DEFAULT (CURRENT_TIMESTAMP), + PRIMARY KEY (aggregate_type, aggregate_id, sequence) +); + +CREATE + USER + demo_user +WITH + NOCREATEDB +ENCRYPTED PASSWORD + 'demo_pass'; + +GRANT + ALL PRIVILEGES +ON TABLE + events, + snapshots, + queries +TO + demo_user; diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..45a7d9e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: "3.4" + +services: + db: + image: postgres + volumes: + - "./db:/docker-entrypoint-initdb.d" + networks: + - default + ports: + - "5433:5432" + environment: + - "POSTGRES_DB=demo" + - "POSTGRES_USER=admin" + - "POSTGRES_PASSWORD=admin_pass" + + ui: + image: adminer + restart: always + networks: + - default + ports: + - "8081:8080" + depends_on: + - db diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}