diff --git a/.tool-versions b/.tool-versions index b46163e..1303137 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,4 +1,4 @@ -erlang 26.2.5.5 -gleam 1.4.1 -# erlang 27.1.2 -# gleam nightly +# erlang 26.2.5.5 +# gleam 1.5.1 +erlang 27.1.2 +gleam nightly diff --git a/CHANGELOG.md b/CHANGELOG.md index 42db6f6..253f0f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - +## [Unreleased] + +- Added convenience functions to `select` module to select columns by col names: + - `select_cols` + - `replace_select_cols` + - `select_col` + - `replace_select_col` +- Replaced dev/test and adapter target `gleam_pgo` with `pgo` dependency. ## [2.0.2] - 2024-11-03 @@ -176,7 +183,7 @@ about a few slight breaking changes around mostly inserts, updates and deletes. - Removed the hard dependency on any RDMBS specific library. These are now only required when developing and testing this library, but when running you can chose any of the following adapters: - - `gleam_pgo` + - `pog` - `sqlight` - `gmysql` diff --git a/README.md b/README.md index 97c9877..cee131c 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Further documentation can be found on [hexdocs.pm/cake](https://hexdocs.pm/cake) ### Adapters -- 🐘PostgreSQL on Erlang: [hex.pm/packages/cake_gleam_pgo](https://hex.pm/packages/cake_gleam_pgo) +- 🐘PostgreSQL on Erlang: [hex.pm/packages/cake_pog](https://hex.pm/packages/cake_pog) - 🪶SQLite on Erlang: [hex.pm/packages/cake_sqlight](https://hex.pm/packages/cake_sqlight) - 🦭MariaDB and 🐬MySQL on Erlang: [hex.pm/packages/cake_gmysql](https://hex.pm/packages/cake_gmysql) @@ -109,7 +109,7 @@ flexible and powerful tool to compose and craft SQL read and write queries. - Not being tied to any specific dialect or dialect adapter library. - Documentation should be comprehensive. - It should be easy to use with existing gleam dialect adapters such as: - - [gleam_pgo](https://hex.pm/packages/gleam_pgo) + - [pog](https://hex.pm/packages/pog) - [sqlight](https://hex.pm/packages/sqlight) - [gmysql](https://hex.pm/packages/gmysql) - Allow to define custom SQL fragments while still being safe diff --git a/docs/demo-apps/demos/01_select_and_decode/gleam.toml b/docs/demo-apps/demos/01_select_and_decode/gleam.toml index 330ca8e..9efeb95 100644 --- a/docs/demo-apps/demos/01_select_and_decode/gleam.toml +++ b/docs/demo-apps/demos/01_select_and_decode/gleam.toml @@ -4,6 +4,6 @@ description = "An demo of using Gleam with Cake and 🐘PostgreSQL to run SELECT [dependencies] cake = { path = "../../../../" } helper = { path = "../../helper" } -gleam_pgo = ">= 0.13.0 and < 2.0.0" +pog = ">= 1.0.0 and < 2.0.0" gleam_stdlib = ">= 0.39.0 and < 2.0.0" pprint = ">= 1.0.3 and < 2.0.0" diff --git a/docs/demo-apps/demos/01_select_and_decode/manifest.toml b/docs/demo-apps/demos/01_select_and_decode/manifest.toml index 748ea85..ed9e0c2 100644 --- a/docs/demo-apps/demos/01_select_and_decode/manifest.toml +++ b/docs/demo-apps/demos/01_select_and_decode/manifest.toml @@ -4,9 +4,9 @@ packages = [ { name = "backoff", version = "1.1.6", build_tools = ["rebar3"], requirements = [], otp_app = "backoff", source = "hex", outer_checksum = "CF0CFFF8995FB20562F822E5CC47D8CCF664C5ECDC26A684CBE85C225F9D7C39" }, { name = "cake", version = "0.15.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], source = "local", path = "../../../.." }, - { name = "helper", version = "1.0.0", build_tools = ["gleam"], requirements = ["cake", "gleam_pgo", "gleam_stdlib", "pprint"], source = "local", path = "../../helper" }, + { name = "helper", version = "1.0.0", build_tools = ["gleam"], requirements = ["cake", "pog", "gleam_stdlib", "pprint"], source = "local", path = "../../helper" }, { name = "glam", version = "2.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glam", source = "hex", outer_checksum = "66EC3BCD632E51EED029678F8DF419659C1E57B1A93D874C5131FE220DFAD2B2" }, - { name = "gleam_pgo", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "gleam_pgo", source = "hex", outer_checksum = "6A1E7F3E717C077788254871E4EF4A8DFF58FEC07D7FA7C7702C2CCF66095AC8" }, + { name = "pog", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "pog", source = "hex", outer_checksum = "6A1E7F3E717C077788254871E4EF4A8DFF58FEC07D7FA7C7702C2CCF66095AC8" }, { name = "gleam_stdlib", version = "0.39.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "2D7DE885A6EA7F1D5015D1698920C9BAF7241102836CE0C3837A4F160128A9C4" }, { name = "opentelemetry_api", version = "1.3.0", build_tools = ["rebar3", "mix"], requirements = ["opentelemetry_semantic_conventions"], otp_app = "opentelemetry_api", source = "hex", outer_checksum = "B9E5FF775FD064FA098DBA3C398490B77649A352B40B0B730A6B7DC0BDD68858" }, { name = "opentelemetry_semantic_conventions", version = "0.2.0", build_tools = ["rebar3", "mix"], requirements = [], otp_app = "opentelemetry_semantic_conventions", source = "hex", outer_checksum = "D61FA1F5639EE8668D74B527E6806E0503EFC55A42DB7B5F39939D84C07D6895" }, @@ -18,6 +18,6 @@ packages = [ [requirements] cake = { path = "../../../../" } helper = { path = "../../helper" } -gleam_pgo = { version = ">= 0.13.0 and < 2.0.0" } +pog = { version = ">= 0.13.0 and < 2.0.0" } gleam_stdlib = { version = ">= 0.39.0 and < 2.0.0" } pprint = { version = ">= 1.0.3 and < 2.0.0" } diff --git a/docs/demo-apps/demos/02_union_and_decode/gleam.toml b/docs/demo-apps/demos/02_union_and_decode/gleam.toml index 44fbd81..77c84b1 100644 --- a/docs/demo-apps/demos/02_union_and_decode/gleam.toml +++ b/docs/demo-apps/demos/02_union_and_decode/gleam.toml @@ -4,6 +4,6 @@ description = "An demo of using Gleam with Cake and 🐘PostgreSQL to run UNION [dependencies] cake = { path = "../../../../" } helper = { path = "../../helper" } -gleam_pgo = ">= 0.13.0 and < 2.0.0" +pog = ">= 1.0.0 and < 2.0.0" gleam_stdlib = ">= 0.39.0 and < 2.0.0" pprint = ">= 1.0.3 and < 2.0.0" diff --git a/docs/demo-apps/demos/02_union_and_decode/manifest.toml b/docs/demo-apps/demos/02_union_and_decode/manifest.toml index 748ea85..ed9e0c2 100644 --- a/docs/demo-apps/demos/02_union_and_decode/manifest.toml +++ b/docs/demo-apps/demos/02_union_and_decode/manifest.toml @@ -4,9 +4,9 @@ packages = [ { name = "backoff", version = "1.1.6", build_tools = ["rebar3"], requirements = [], otp_app = "backoff", source = "hex", outer_checksum = "CF0CFFF8995FB20562F822E5CC47D8CCF664C5ECDC26A684CBE85C225F9D7C39" }, { name = "cake", version = "0.15.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], source = "local", path = "../../../.." }, - { name = "helper", version = "1.0.0", build_tools = ["gleam"], requirements = ["cake", "gleam_pgo", "gleam_stdlib", "pprint"], source = "local", path = "../../helper" }, + { name = "helper", version = "1.0.0", build_tools = ["gleam"], requirements = ["cake", "pog", "gleam_stdlib", "pprint"], source = "local", path = "../../helper" }, { name = "glam", version = "2.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glam", source = "hex", outer_checksum = "66EC3BCD632E51EED029678F8DF419659C1E57B1A93D874C5131FE220DFAD2B2" }, - { name = "gleam_pgo", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "gleam_pgo", source = "hex", outer_checksum = "6A1E7F3E717C077788254871E4EF4A8DFF58FEC07D7FA7C7702C2CCF66095AC8" }, + { name = "pog", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "pog", source = "hex", outer_checksum = "6A1E7F3E717C077788254871E4EF4A8DFF58FEC07D7FA7C7702C2CCF66095AC8" }, { name = "gleam_stdlib", version = "0.39.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "2D7DE885A6EA7F1D5015D1698920C9BAF7241102836CE0C3837A4F160128A9C4" }, { name = "opentelemetry_api", version = "1.3.0", build_tools = ["rebar3", "mix"], requirements = ["opentelemetry_semantic_conventions"], otp_app = "opentelemetry_api", source = "hex", outer_checksum = "B9E5FF775FD064FA098DBA3C398490B77649A352B40B0B730A6B7DC0BDD68858" }, { name = "opentelemetry_semantic_conventions", version = "0.2.0", build_tools = ["rebar3", "mix"], requirements = [], otp_app = "opentelemetry_semantic_conventions", source = "hex", outer_checksum = "D61FA1F5639EE8668D74B527E6806E0503EFC55A42DB7B5F39939D84C07D6895" }, @@ -18,6 +18,6 @@ packages = [ [requirements] cake = { path = "../../../../" } helper = { path = "../../helper" } -gleam_pgo = { version = ">= 0.13.0 and < 2.0.0" } +pog = { version = ">= 0.13.0 and < 2.0.0" } gleam_stdlib = { version = ">= 0.39.0 and < 2.0.0" } pprint = { version = ">= 1.0.3 and < 2.0.0" } diff --git a/docs/demo-apps/demos/03_insert/gleam.toml b/docs/demo-apps/demos/03_insert/gleam.toml index 5235500..8a780da 100644 --- a/docs/demo-apps/demos/03_insert/gleam.toml +++ b/docs/demo-apps/demos/03_insert/gleam.toml @@ -4,6 +4,6 @@ description = "An demo of using Gleam with Cake and 🐘PostgreSQL to run INSERT [dependencies] cake = { path = "../../../../" } helper = { path = "../../helper" } -gleam_pgo = ">= 0.13.0 and < 2.0.0" +pog = ">= 1.0.0 and < 2.0.0" gleam_stdlib = ">= 0.39.0 and < 2.0.0" pprint = ">= 1.0.3 and < 2.0.0" diff --git a/docs/demo-apps/demos/03_insert/manifest.toml b/docs/demo-apps/demos/03_insert/manifest.toml index 748ea85..ed9e0c2 100644 --- a/docs/demo-apps/demos/03_insert/manifest.toml +++ b/docs/demo-apps/demos/03_insert/manifest.toml @@ -4,9 +4,9 @@ packages = [ { name = "backoff", version = "1.1.6", build_tools = ["rebar3"], requirements = [], otp_app = "backoff", source = "hex", outer_checksum = "CF0CFFF8995FB20562F822E5CC47D8CCF664C5ECDC26A684CBE85C225F9D7C39" }, { name = "cake", version = "0.15.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], source = "local", path = "../../../.." }, - { name = "helper", version = "1.0.0", build_tools = ["gleam"], requirements = ["cake", "gleam_pgo", "gleam_stdlib", "pprint"], source = "local", path = "../../helper" }, + { name = "helper", version = "1.0.0", build_tools = ["gleam"], requirements = ["cake", "pog", "gleam_stdlib", "pprint"], source = "local", path = "../../helper" }, { name = "glam", version = "2.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glam", source = "hex", outer_checksum = "66EC3BCD632E51EED029678F8DF419659C1E57B1A93D874C5131FE220DFAD2B2" }, - { name = "gleam_pgo", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "gleam_pgo", source = "hex", outer_checksum = "6A1E7F3E717C077788254871E4EF4A8DFF58FEC07D7FA7C7702C2CCF66095AC8" }, + { name = "pog", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "pog", source = "hex", outer_checksum = "6A1E7F3E717C077788254871E4EF4A8DFF58FEC07D7FA7C7702C2CCF66095AC8" }, { name = "gleam_stdlib", version = "0.39.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "2D7DE885A6EA7F1D5015D1698920C9BAF7241102836CE0C3837A4F160128A9C4" }, { name = "opentelemetry_api", version = "1.3.0", build_tools = ["rebar3", "mix"], requirements = ["opentelemetry_semantic_conventions"], otp_app = "opentelemetry_api", source = "hex", outer_checksum = "B9E5FF775FD064FA098DBA3C398490B77649A352B40B0B730A6B7DC0BDD68858" }, { name = "opentelemetry_semantic_conventions", version = "0.2.0", build_tools = ["rebar3", "mix"], requirements = [], otp_app = "opentelemetry_semantic_conventions", source = "hex", outer_checksum = "D61FA1F5639EE8668D74B527E6806E0503EFC55A42DB7B5F39939D84C07D6895" }, @@ -18,6 +18,6 @@ packages = [ [requirements] cake = { path = "../../../../" } helper = { path = "../../helper" } -gleam_pgo = { version = ">= 0.13.0 and < 2.0.0" } +pog = { version = ">= 0.13.0 and < 2.0.0" } gleam_stdlib = { version = ">= 0.39.0 and < 2.0.0" } pprint = { version = ">= 1.0.3 and < 2.0.0" } diff --git a/docs/demo-apps/demos/04_delete/gleam.toml b/docs/demo-apps/demos/04_delete/gleam.toml index 3c38863..924c324 100644 --- a/docs/demo-apps/demos/04_delete/gleam.toml +++ b/docs/demo-apps/demos/04_delete/gleam.toml @@ -4,6 +4,6 @@ description = "An demo of using Gleam with Cake and 🐘PostgreSQL to run DELETE [dependencies] cake = { path = "../../../../" } helper = { path = "../../helper" } -gleam_pgo = ">= 0.13.0 and < 2.0.0" +pog = ">= 1.0.0 and < 2.0.0" gleam_stdlib = ">= 0.39.0 and < 2.0.0" pprint = ">= 1.0.3 and < 2.0.0" diff --git a/docs/demo-apps/demos/04_delete/manifest.toml b/docs/demo-apps/demos/04_delete/manifest.toml index 748ea85..ed9e0c2 100644 --- a/docs/demo-apps/demos/04_delete/manifest.toml +++ b/docs/demo-apps/demos/04_delete/manifest.toml @@ -4,9 +4,9 @@ packages = [ { name = "backoff", version = "1.1.6", build_tools = ["rebar3"], requirements = [], otp_app = "backoff", source = "hex", outer_checksum = "CF0CFFF8995FB20562F822E5CC47D8CCF664C5ECDC26A684CBE85C225F9D7C39" }, { name = "cake", version = "0.15.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], source = "local", path = "../../../.." }, - { name = "helper", version = "1.0.0", build_tools = ["gleam"], requirements = ["cake", "gleam_pgo", "gleam_stdlib", "pprint"], source = "local", path = "../../helper" }, + { name = "helper", version = "1.0.0", build_tools = ["gleam"], requirements = ["cake", "pog", "gleam_stdlib", "pprint"], source = "local", path = "../../helper" }, { name = "glam", version = "2.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glam", source = "hex", outer_checksum = "66EC3BCD632E51EED029678F8DF419659C1E57B1A93D874C5131FE220DFAD2B2" }, - { name = "gleam_pgo", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "gleam_pgo", source = "hex", outer_checksum = "6A1E7F3E717C077788254871E4EF4A8DFF58FEC07D7FA7C7702C2CCF66095AC8" }, + { name = "pog", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "pog", source = "hex", outer_checksum = "6A1E7F3E717C077788254871E4EF4A8DFF58FEC07D7FA7C7702C2CCF66095AC8" }, { name = "gleam_stdlib", version = "0.39.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "2D7DE885A6EA7F1D5015D1698920C9BAF7241102836CE0C3837A4F160128A9C4" }, { name = "opentelemetry_api", version = "1.3.0", build_tools = ["rebar3", "mix"], requirements = ["opentelemetry_semantic_conventions"], otp_app = "opentelemetry_api", source = "hex", outer_checksum = "B9E5FF775FD064FA098DBA3C398490B77649A352B40B0B730A6B7DC0BDD68858" }, { name = "opentelemetry_semantic_conventions", version = "0.2.0", build_tools = ["rebar3", "mix"], requirements = [], otp_app = "opentelemetry_semantic_conventions", source = "hex", outer_checksum = "D61FA1F5639EE8668D74B527E6806E0503EFC55A42DB7B5F39939D84C07D6895" }, @@ -18,6 +18,6 @@ packages = [ [requirements] cake = { path = "../../../../" } helper = { path = "../../helper" } -gleam_pgo = { version = ">= 0.13.0 and < 2.0.0" } +pog = { version = ">= 0.13.0 and < 2.0.0" } gleam_stdlib = { version = ">= 0.39.0 and < 2.0.0" } pprint = { version = ">= 1.0.3 and < 2.0.0" } diff --git a/docs/demo-apps/demos/05_update/gleam.toml b/docs/demo-apps/demos/05_update/gleam.toml index 3228b62..85b9308 100644 --- a/docs/demo-apps/demos/05_update/gleam.toml +++ b/docs/demo-apps/demos/05_update/gleam.toml @@ -4,6 +4,6 @@ description = "An demo of using Gleam with Cake and 🐘PostgreSQL to run UPDATE [dependencies] cake = { path = "../../../../" } helper = { path = "../../helper" } -gleam_pgo = ">= 0.13.0 and < 2.0.0" +pog = ">= 1.0.0 and < 2.0.0" gleam_stdlib = ">= 0.39.0 and < 2.0.0" pprint = ">= 1.0.3 and < 2.0.0" diff --git a/docs/demo-apps/demos/05_update/manifest.toml b/docs/demo-apps/demos/05_update/manifest.toml index 748ea85..ed9e0c2 100644 --- a/docs/demo-apps/demos/05_update/manifest.toml +++ b/docs/demo-apps/demos/05_update/manifest.toml @@ -4,9 +4,9 @@ packages = [ { name = "backoff", version = "1.1.6", build_tools = ["rebar3"], requirements = [], otp_app = "backoff", source = "hex", outer_checksum = "CF0CFFF8995FB20562F822E5CC47D8CCF664C5ECDC26A684CBE85C225F9D7C39" }, { name = "cake", version = "0.15.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], source = "local", path = "../../../.." }, - { name = "helper", version = "1.0.0", build_tools = ["gleam"], requirements = ["cake", "gleam_pgo", "gleam_stdlib", "pprint"], source = "local", path = "../../helper" }, + { name = "helper", version = "1.0.0", build_tools = ["gleam"], requirements = ["cake", "pog", "gleam_stdlib", "pprint"], source = "local", path = "../../helper" }, { name = "glam", version = "2.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glam", source = "hex", outer_checksum = "66EC3BCD632E51EED029678F8DF419659C1E57B1A93D874C5131FE220DFAD2B2" }, - { name = "gleam_pgo", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "gleam_pgo", source = "hex", outer_checksum = "6A1E7F3E717C077788254871E4EF4A8DFF58FEC07D7FA7C7702C2CCF66095AC8" }, + { name = "pog", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "pog", source = "hex", outer_checksum = "6A1E7F3E717C077788254871E4EF4A8DFF58FEC07D7FA7C7702C2CCF66095AC8" }, { name = "gleam_stdlib", version = "0.39.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "2D7DE885A6EA7F1D5015D1698920C9BAF7241102836CE0C3837A4F160128A9C4" }, { name = "opentelemetry_api", version = "1.3.0", build_tools = ["rebar3", "mix"], requirements = ["opentelemetry_semantic_conventions"], otp_app = "opentelemetry_api", source = "hex", outer_checksum = "B9E5FF775FD064FA098DBA3C398490B77649A352B40B0B730A6B7DC0BDD68858" }, { name = "opentelemetry_semantic_conventions", version = "0.2.0", build_tools = ["rebar3", "mix"], requirements = [], otp_app = "opentelemetry_semantic_conventions", source = "hex", outer_checksum = "D61FA1F5639EE8668D74B527E6806E0503EFC55A42DB7B5F39939D84C07D6895" }, @@ -18,6 +18,6 @@ packages = [ [requirements] cake = { path = "../../../../" } helper = { path = "../../helper" } -gleam_pgo = { version = ">= 0.13.0 and < 2.0.0" } +pog = { version = ">= 0.13.0 and < 2.0.0" } gleam_stdlib = { version = ">= 0.39.0 and < 2.0.0" } pprint = { version = ">= 1.0.3 and < 2.0.0" } diff --git a/docs/demo-apps/demos/06_insert_on_conflict_update/gleam.toml b/docs/demo-apps/demos/06_insert_on_conflict_update/gleam.toml index 58f2d88..a83023d 100644 --- a/docs/demo-apps/demos/06_insert_on_conflict_update/gleam.toml +++ b/docs/demo-apps/demos/06_insert_on_conflict_update/gleam.toml @@ -4,6 +4,6 @@ description = "An demo of using Gleam with Cake and Postgres to run INSERT ON CO [dependencies] cake = { path = "../../../../" } helper = { path = "../../helper" } -gleam_pgo = ">= 0.13.0 and < 2.0.0" +pog = ">= 1.0.0 and < 2.0.0" gleam_stdlib = ">= 0.39.0 and < 2.0.0" pprint = ">= 1.0.3 and < 2.0.0" diff --git a/docs/demo-apps/demos/06_insert_on_conflict_update/manifest.toml b/docs/demo-apps/demos/06_insert_on_conflict_update/manifest.toml index 748ea85..ed9e0c2 100644 --- a/docs/demo-apps/demos/06_insert_on_conflict_update/manifest.toml +++ b/docs/demo-apps/demos/06_insert_on_conflict_update/manifest.toml @@ -4,9 +4,9 @@ packages = [ { name = "backoff", version = "1.1.6", build_tools = ["rebar3"], requirements = [], otp_app = "backoff", source = "hex", outer_checksum = "CF0CFFF8995FB20562F822E5CC47D8CCF664C5ECDC26A684CBE85C225F9D7C39" }, { name = "cake", version = "0.15.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], source = "local", path = "../../../.." }, - { name = "helper", version = "1.0.0", build_tools = ["gleam"], requirements = ["cake", "gleam_pgo", "gleam_stdlib", "pprint"], source = "local", path = "../../helper" }, + { name = "helper", version = "1.0.0", build_tools = ["gleam"], requirements = ["cake", "pog", "gleam_stdlib", "pprint"], source = "local", path = "../../helper" }, { name = "glam", version = "2.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glam", source = "hex", outer_checksum = "66EC3BCD632E51EED029678F8DF419659C1E57B1A93D874C5131FE220DFAD2B2" }, - { name = "gleam_pgo", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "gleam_pgo", source = "hex", outer_checksum = "6A1E7F3E717C077788254871E4EF4A8DFF58FEC07D7FA7C7702C2CCF66095AC8" }, + { name = "pog", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "pog", source = "hex", outer_checksum = "6A1E7F3E717C077788254871E4EF4A8DFF58FEC07D7FA7C7702C2CCF66095AC8" }, { name = "gleam_stdlib", version = "0.39.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "2D7DE885A6EA7F1D5015D1698920C9BAF7241102836CE0C3837A4F160128A9C4" }, { name = "opentelemetry_api", version = "1.3.0", build_tools = ["rebar3", "mix"], requirements = ["opentelemetry_semantic_conventions"], otp_app = "opentelemetry_api", source = "hex", outer_checksum = "B9E5FF775FD064FA098DBA3C398490B77649A352B40B0B730A6B7DC0BDD68858" }, { name = "opentelemetry_semantic_conventions", version = "0.2.0", build_tools = ["rebar3", "mix"], requirements = [], otp_app = "opentelemetry_semantic_conventions", source = "hex", outer_checksum = "D61FA1F5639EE8668D74B527E6806E0503EFC55A42DB7B5F39939D84C07D6895" }, @@ -18,6 +18,6 @@ packages = [ [requirements] cake = { path = "../../../../" } helper = { path = "../../helper" } -gleam_pgo = { version = ">= 0.13.0 and < 2.0.0" } +pog = { version = ">= 0.13.0 and < 2.0.0" } gleam_stdlib = { version = ">= 0.39.0 and < 2.0.0" } pprint = { version = ">= 1.0.3 and < 2.0.0" } diff --git a/docs/demo-apps/demos/07_select_join/gleam.toml b/docs/demo-apps/demos/07_select_join/gleam.toml index 4a6ee47..6c29c0c 100644 --- a/docs/demo-apps/demos/07_select_join/gleam.toml +++ b/docs/demo-apps/demos/07_select_join/gleam.toml @@ -4,6 +4,6 @@ description = "An demo of using Gleam with Cake and 🐘PostgreSQL to run SELECT [dependencies] cake = { path = "../../../../" } helper = { path = "../../helper" } -gleam_pgo = ">= 0.13.0 and < 2.0.0" +pog = ">= 1.0.0 and < 2.0.0" gleam_stdlib = ">= 0.39.0 and < 2.0.0" pprint = ">= 1.0.3 and < 2.0.0" diff --git a/docs/demo-apps/demos/07_select_join/manifest.toml b/docs/demo-apps/demos/07_select_join/manifest.toml index 748ea85..ed9e0c2 100644 --- a/docs/demo-apps/demos/07_select_join/manifest.toml +++ b/docs/demo-apps/demos/07_select_join/manifest.toml @@ -4,9 +4,9 @@ packages = [ { name = "backoff", version = "1.1.6", build_tools = ["rebar3"], requirements = [], otp_app = "backoff", source = "hex", outer_checksum = "CF0CFFF8995FB20562F822E5CC47D8CCF664C5ECDC26A684CBE85C225F9D7C39" }, { name = "cake", version = "0.15.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], source = "local", path = "../../../.." }, - { name = "helper", version = "1.0.0", build_tools = ["gleam"], requirements = ["cake", "gleam_pgo", "gleam_stdlib", "pprint"], source = "local", path = "../../helper" }, + { name = "helper", version = "1.0.0", build_tools = ["gleam"], requirements = ["cake", "pog", "gleam_stdlib", "pprint"], source = "local", path = "../../helper" }, { name = "glam", version = "2.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glam", source = "hex", outer_checksum = "66EC3BCD632E51EED029678F8DF419659C1E57B1A93D874C5131FE220DFAD2B2" }, - { name = "gleam_pgo", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "gleam_pgo", source = "hex", outer_checksum = "6A1E7F3E717C077788254871E4EF4A8DFF58FEC07D7FA7C7702C2CCF66095AC8" }, + { name = "pog", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "pog", source = "hex", outer_checksum = "6A1E7F3E717C077788254871E4EF4A8DFF58FEC07D7FA7C7702C2CCF66095AC8" }, { name = "gleam_stdlib", version = "0.39.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "2D7DE885A6EA7F1D5015D1698920C9BAF7241102836CE0C3837A4F160128A9C4" }, { name = "opentelemetry_api", version = "1.3.0", build_tools = ["rebar3", "mix"], requirements = ["opentelemetry_semantic_conventions"], otp_app = "opentelemetry_api", source = "hex", outer_checksum = "B9E5FF775FD064FA098DBA3C398490B77649A352B40B0B730A6B7DC0BDD68858" }, { name = "opentelemetry_semantic_conventions", version = "0.2.0", build_tools = ["rebar3", "mix"], requirements = [], otp_app = "opentelemetry_semantic_conventions", source = "hex", outer_checksum = "D61FA1F5639EE8668D74B527E6806E0503EFC55A42DB7B5F39939D84C07D6895" }, @@ -18,6 +18,6 @@ packages = [ [requirements] cake = { path = "../../../../" } helper = { path = "../../helper" } -gleam_pgo = { version = ">= 0.13.0 and < 2.0.0" } +pog = { version = ">= 0.13.0 and < 2.0.0" } gleam_stdlib = { version = ">= 0.39.0 and < 2.0.0" } pprint = { version = ">= 1.0.3 and < 2.0.0" } diff --git a/docs/demo-apps/demos/08_prepared_fragment/gleam.toml b/docs/demo-apps/demos/08_prepared_fragment/gleam.toml index a4283f5..b28436f 100644 --- a/docs/demo-apps/demos/08_prepared_fragment/gleam.toml +++ b/docs/demo-apps/demos/08_prepared_fragment/gleam.toml @@ -4,6 +4,6 @@ description = "An demo of using Gleam with Cake and 🐘PostgreSQL to run querie [dependencies] cake = { path = "../../../../" } helper = { path = "../../helper" } -gleam_pgo = ">= 0.13.0 and < 2.0.0" +pog = ">= 1.0.0 and < 2.0.0" gleam_stdlib = ">= 0.39.0 and < 2.0.0" pprint = ">= 1.0.3 and < 2.0.0" diff --git a/docs/demo-apps/demos/08_prepared_fragment/manifest.toml b/docs/demo-apps/demos/08_prepared_fragment/manifest.toml index 748ea85..ed9e0c2 100644 --- a/docs/demo-apps/demos/08_prepared_fragment/manifest.toml +++ b/docs/demo-apps/demos/08_prepared_fragment/manifest.toml @@ -4,9 +4,9 @@ packages = [ { name = "backoff", version = "1.1.6", build_tools = ["rebar3"], requirements = [], otp_app = "backoff", source = "hex", outer_checksum = "CF0CFFF8995FB20562F822E5CC47D8CCF664C5ECDC26A684CBE85C225F9D7C39" }, { name = "cake", version = "0.15.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], source = "local", path = "../../../.." }, - { name = "helper", version = "1.0.0", build_tools = ["gleam"], requirements = ["cake", "gleam_pgo", "gleam_stdlib", "pprint"], source = "local", path = "../../helper" }, + { name = "helper", version = "1.0.0", build_tools = ["gleam"], requirements = ["cake", "pog", "gleam_stdlib", "pprint"], source = "local", path = "../../helper" }, { name = "glam", version = "2.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glam", source = "hex", outer_checksum = "66EC3BCD632E51EED029678F8DF419659C1E57B1A93D874C5131FE220DFAD2B2" }, - { name = "gleam_pgo", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "gleam_pgo", source = "hex", outer_checksum = "6A1E7F3E717C077788254871E4EF4A8DFF58FEC07D7FA7C7702C2CCF66095AC8" }, + { name = "pog", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "pog", source = "hex", outer_checksum = "6A1E7F3E717C077788254871E4EF4A8DFF58FEC07D7FA7C7702C2CCF66095AC8" }, { name = "gleam_stdlib", version = "0.39.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "2D7DE885A6EA7F1D5015D1698920C9BAF7241102836CE0C3837A4F160128A9C4" }, { name = "opentelemetry_api", version = "1.3.0", build_tools = ["rebar3", "mix"], requirements = ["opentelemetry_semantic_conventions"], otp_app = "opentelemetry_api", source = "hex", outer_checksum = "B9E5FF775FD064FA098DBA3C398490B77649A352B40B0B730A6B7DC0BDD68858" }, { name = "opentelemetry_semantic_conventions", version = "0.2.0", build_tools = ["rebar3", "mix"], requirements = [], otp_app = "opentelemetry_semantic_conventions", source = "hex", outer_checksum = "D61FA1F5639EE8668D74B527E6806E0503EFC55A42DB7B5F39939D84C07D6895" }, @@ -18,6 +18,6 @@ packages = [ [requirements] cake = { path = "../../../../" } helper = { path = "../../helper" } -gleam_pgo = { version = ">= 0.13.0 and < 2.0.0" } +pog = { version = ">= 0.13.0 and < 2.0.0" } gleam_stdlib = { version = ">= 0.39.0 and < 2.0.0" } pprint = { version = ">= 1.0.3 and < 2.0.0" } diff --git a/docs/demo-apps/helper/gleam.toml b/docs/demo-apps/helper/gleam.toml index 7728cfe..99486ad 100644 --- a/docs/demo-apps/helper/gleam.toml +++ b/docs/demo-apps/helper/gleam.toml @@ -4,6 +4,6 @@ version = "1.0.0" [dependencies] cake = { path = "../../../../" } -gleam_pgo = ">= 0.13.0 and < 2.0.0" +pog = ">= 1.0.0 and < 2.0.0" gleam_stdlib = ">= 0.39.0 and < 2.0.0" pprint = ">= 1.0.3 and < 2.0.0" diff --git a/docs/demo-apps/helper/manifest.toml b/docs/demo-apps/helper/manifest.toml index 3d960dc..b9639ab 100644 --- a/docs/demo-apps/helper/manifest.toml +++ b/docs/demo-apps/helper/manifest.toml @@ -5,7 +5,7 @@ packages = [ { name = "backoff", version = "1.1.6", build_tools = ["rebar3"], requirements = [], otp_app = "backoff", source = "hex", outer_checksum = "CF0CFFF8995FB20562F822E5CC47D8CCF664C5ECDC26A684CBE85C225F9D7C39" }, { name = "cake", version = "0.10.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], source = "local", path = "../../.." }, { name = "glam", version = "2.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glam", source = "hex", outer_checksum = "66EC3BCD632E51EED029678F8DF419659C1E57B1A93D874C5131FE220DFAD2B2" }, - { name = "gleam_pgo", version = "0.12.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "gleam_pgo", source = "hex", outer_checksum = "D66DDF151FF1EBF65F30FB54C8CA938EA52A563811BC67DB53866D1861CE1528" }, + { name = "pog", version = "0.12.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "pog", source = "hex", outer_checksum = "D66DDF151FF1EBF65F30FB54C8CA938EA52A563811BC67DB53866D1861CE1528" }, { name = "gleam_stdlib", version = "0.39.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "2D7DE885A6EA7F1D5015D1698920C9BAF7241102836CE0C3837A4F160128A9C4" }, { name = "opentelemetry_api", version = "1.3.0", build_tools = ["rebar3", "mix"], requirements = ["opentelemetry_semantic_conventions"], otp_app = "opentelemetry_api", source = "hex", outer_checksum = "B9E5FF775FD064FA098DBA3C398490B77649A352B40B0B730A6B7DC0BDD68858" }, { name = "opentelemetry_semantic_conventions", version = "0.2.0", build_tools = ["rebar3", "mix"], requirements = [], otp_app = "opentelemetry_semantic_conventions", source = "hex", outer_checksum = "D61FA1F5639EE8668D74B527E6806E0503EFC55A42DB7B5F39939D84C07D6895" }, @@ -16,6 +16,6 @@ packages = [ [requirements] cake = { path = "../../../" } -gleam_pgo = { version = ">= 0.12.0 and < 1.0.0" } +pog = { version = ">= 0.12.0 and < 1.0.0" } gleam_stdlib = { version = ">= 0.39.0 and < 2.0.0" } pprint = { version = ">= 1.0.3 and < 2.0.0" } diff --git a/docs/demo-apps/helper/src/helper/postgres.gleam b/docs/demo-apps/helper/src/helper/postgres.gleam index be317e8..93853f1 100644 --- a/docs/demo-apps/helper/src/helper/postgres.gleam +++ b/docs/demo-apps/helper/src/helper/postgres.gleam @@ -1,5 +1,5 @@ //// 🐘PostgreSQL adapter which which passes `PreparedStatements` -//// to the `gleam_pgo` library for execution. +//// to the `pog` library for execution. //// import cake.{type PreparedStatement, type ReadQuery, type WriteQuery} @@ -11,7 +11,7 @@ import gleam/dynamic import gleam/io import gleam/list import gleam/option.{Some} -import gleam/pgo.{type Connection, type Value} +import pog.{type Connection, type Value} import pprint pub fn read_query_to_prepared_statement( diff --git a/gleam.toml b/gleam.toml index a6cacb2..78dddd8 100644 --- a/gleam.toml +++ b/gleam.toml @@ -1,5 +1,5 @@ name = "cake" -version = "2.0.2" +version = "2.1.0" description = "An SQL query builder for Gleam for SQL dialects 🐘PostgreSQL, 🪶SQLite, 🦭MariaDB, and 🐬MySQL" licences = ["MPL-2.0"] repository = { type = "github", user = "inoas", repo = "gleam-cake" } @@ -17,7 +17,7 @@ gleam_stdlib = ">= 0.39.0 and < 2.0.0" [dev-dependencies] birdie = ">= 1.2.3 and < 2.0.0" -gleam_pgo = ">= 0.14.0 and < 2.0.0" +pog = ">= 1.0.0 and < 2.0.0" gleeunit = ">= 1.2.0 and < 2.0.0" gmysql = ">= 1.4.0 and < 2.0.0" pprint = ">= 1.0.4 and < 2.0.0" diff --git a/manifest.toml b/manifest.toml index 14ab3d7..ae9feb4 100644 --- a/manifest.toml +++ b/manifest.toml @@ -16,7 +16,6 @@ packages = [ { name = "gleam_erlang", version = "0.28.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "BE551521F708DCE5CB954AFBBDF08519C1C44986521FD40753608825F48FFA9E" }, { name = "gleam_json", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "9063D14D25406326C0255BDA0021541E797D8A7A12573D849462CAFED459F6EB" }, { name = "gleam_otp", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "F7EA44C81679B2A6032FF1B3851F0EFB43F4F1F1CAC616CB7F4A18497F39FAB9" }, - { name = "gleam_pgo", version = "0.14.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "gleam_pgo", source = "hex", outer_checksum = "12256A7F351E994A6E43AB67276DD8AACE752991C013F48A288C4A848F3A9758" }, { name = "gleam_stdlib", version = "0.41.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "1B2F80CB1B66B027E3198A2FF71EF3F2F31DF89ED97AD606F25FD387A4C3C1EF" }, { name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" }, { name = "glexer", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glexer", source = "hex", outer_checksum = "BD477AD657C2B637FEF75F2405FAEFFA533F277A74EF1A5E17B55B1178C228FB" }, @@ -26,6 +25,7 @@ packages = [ { name = "opentelemetry_api", version = "1.4.0", build_tools = ["rebar3", "mix"], requirements = [], otp_app = "opentelemetry_api", source = "hex", outer_checksum = "3DFBBFAA2C2ED3121C5C483162836C4F9027DEF469C41578AF5EF32589FCFC58" }, { name = "pg_types", version = "0.4.0", build_tools = ["rebar3"], requirements = [], otp_app = "pg_types", source = "hex", outer_checksum = "B02EFA785CAECECF9702C681C80A9CA12A39F9161A846CE17B01FB20AEEED7EB" }, { name = "pgo", version = "0.14.0", build_tools = ["rebar3"], requirements = ["backoff", "opentelemetry_api", "pg_types"], otp_app = "pgo", source = "hex", outer_checksum = "71016C22599936E042DC0012EE4589D24C71427D266292F775EBF201D97DF9C9" }, + { name = "pog", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "pog", source = "hex", outer_checksum = "00D57120936AFBF486BE357C472E483C1F0CA507FF9C3668075E87C733CA53F8" }, { name = "pprint", version = "1.0.4", build_tools = ["gleam"], requirements = ["glam", "gleam_stdlib"], otp_app = "pprint", source = "hex", outer_checksum = "C310A98BDC0995644847C3C8702DE19656D6BCD638B2A8A358B97824379ECAA1" }, { name = "rank", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "rank", source = "hex", outer_checksum = "5660E361F0E49CBB714CC57CC4C89C63415D8986F05B2DA0C719D5642FAD91C9" }, { name = "simplifile", version = "2.2.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0DFABEF7DC7A9E2FF4BB27B108034E60C81BEBFCB7AB816B9E7E18ED4503ACD8" }, @@ -36,9 +36,9 @@ packages = [ [requirements] birdie = { version = ">= 1.2.3 and < 2.0.0" } -gleam_pgo = { version = ">= 0.14.0 and < 2.0.0" } gleam_stdlib = { version = ">= 0.39.0 and < 2.0.0" } gleeunit = { version = ">= 1.2.0 and < 2.0.0" } gmysql = { version = ">= 1.4.0 and < 2.0.0" } +pog = { version = ">= 1.0.0 and < 2.0.0" } pprint = { version = ">= 1.0.4 and < 2.0.0" } sqlight = { version = ">= 0.9.1 and < 2.0.0" } diff --git a/src/cake/dialect/postgres_dialect.gleam b/src/cake/dialect/postgres_dialect.gleam index 2554b6a..d692fbd 100644 --- a/src/cake/dialect/postgres_dialect.gleam +++ b/src/cake/dialect/postgres_dialect.gleam @@ -1,4 +1,4 @@ -//// 🐘PostgreSQL dialect to be used in conjunction with the `gleam_pgo` +//// 🐘PostgreSQL dialect to be used in conjunction with the `pog` //// library. //// diff --git a/src/cake/select.gleam b/src/cake/select.gleam index 0ada7e5..c46eb50 100644 --- a/src/cake/select.gleam +++ b/src/cake/select.gleam @@ -195,6 +195,14 @@ pub fn get_from(select slct: Select) -> From { // ▒▒▒ SELECT ▒▒▒ +/// Add a column name to the `Select` query as a `SelectValue`. +/// +/// If the query already has any `SelectValue`s, the new one is appended. +/// +pub fn select_col(select slct: Select, name nm: String) -> Select { + nm |> col |> select(select: slct) +} + /// Add a `SelectValue` to the `Select` query. /// /// If the query already has any `SelectValue`s, the new one is appended. @@ -207,6 +215,14 @@ pub fn select(select slct: Select, select_value sv: SelectValue) -> Select { } } +/// Add a column name to the `Select` query as a `SelectValue`. +/// +/// If the query already has any `SelectValue`s, they are replaced. +/// +pub fn replace_select_col(select slct: Select, name nm: String) -> Select { + nm |> col |> replace_select(select: slct) +} + /// Add a `SelectValue`s to the `Select` query. /// /// If the query already has any `SelectValue`s, they are replaced. @@ -222,6 +238,17 @@ pub fn replace_select( } } +/// Adds many column names as `SelectValue`s to the `Select` query. +/// +/// If the query already has any `SelectValue`s, the new ones are appended. +/// +pub fn select_cols( + select slct: Select, + select_cols scls: List(String), +) -> Select { + scls |> list.map(col) |> selects(select: slct) +} + /// Adds many `SelectValue`s to the `Select` query. /// /// If the query already has any `SelectValue`s, the new ones are appended. @@ -238,6 +265,17 @@ pub fn selects( } } +/// Adds many column names as `SelectValue`s to the `Select` query. +/// +/// If the query already has any `SelectValue`s, the new ones are replaced. +/// +pub fn replace_select_cols( + select slct: Select, + select_cols scls: List(String), +) -> Select { + scls |> list.map(col) |> replace_selects(select: slct) +} + /// Adds many `SelectValue`s to the `Select` query. /// /// If the query already has any `SelectValue`s, they are replaced. diff --git a/test/test_support/adapter/postgres.gleam b/test/test_support/adapter/postgres.gleam index 09d7d5b..c67101e 100644 --- a/test/test_support/adapter/postgres.gleam +++ b/test/test_support/adapter/postgres.gleam @@ -1,5 +1,5 @@ //// 🐘PostgreSQL adapter which which passes `PreparedStatements` -//// to the `gleam_pgo` library for execution. +//// to the `pog` library for execution. //// import cake @@ -10,10 +10,9 @@ import cake/internal/write_query.{type WriteQuery} import cake/param.{ type Param, BoolParam, FloatParam, IntParam, NullParam, StringParam, } -import gleam/dynamic import gleam/list import gleam/option.{Some} -import gleam/pgo.{type Connection, type Value} +import pog.{type Connection, type Value} import test_support/iox pub fn read_query_to_prepared_statement( @@ -30,17 +29,17 @@ pub fn write_query_to_prepared_statement( pub fn with_connection(f: fn(Connection) -> a) -> a { let connection = - pgo.Config( - ..pgo.default_config(), + pog.Config( + ..pog.default_config(), host: "localhost", user: "postgres", password: Some("postgres"), database: "gleam_cake_test", ) - |> pgo.connect + |> pog.connect let value = f(connection) - pgo.disconnect(connection) + pog.disconnect(connection) value } @@ -54,20 +53,25 @@ pub fn run_read_query(query qry: ReadQuery, decoder dcdr, db_connection db_conn) params |> list.map(fn(param: Param) -> Value { case param { - BoolParam(param) -> pgo.bool(param) - FloatParam(param) -> pgo.float(param) - IntParam(param) -> pgo.int(param) - StringParam(param) -> pgo.text(param) - NullParam -> pgo.null() + BoolParam(param) -> pog.bool(param) + FloatParam(param) -> pog.float(param) + IntParam(param) -> pog.int(param) + StringParam(param) -> pog.text(param) + NullParam -> pog.null() } }) |> iox.print_tap("Params: ") |> iox.inspect_println_tap - let result = sql |> pgo.execute(on: db_conn, with: db_params, expecting: dcdr) + let result = + sql + |> pog.query + |> pog_parameters(db_params:) + |> pog.returning(dcdr) + |> pog.execute(on: db_conn) case result { - Ok(pgo.Returned(_result_count, v)) -> Ok(v) + Ok(pog.Returned(_result_count, v)) -> Ok(v) Error(e) -> Error(e) } } @@ -85,24 +89,39 @@ pub fn run_write_query( params |> list.map(fn(param: Param) -> Value { case param { - BoolParam(param) -> pgo.bool(param) - FloatParam(param) -> pgo.float(param) - IntParam(param) -> pgo.int(param) - StringParam(param) -> pgo.text(param) - NullParam -> pgo.null() + BoolParam(param) -> pog.bool(param) + FloatParam(param) -> pog.float(param) + IntParam(param) -> pog.int(param) + StringParam(param) -> pog.text(param) + NullParam -> pog.null() } }) |> iox.print_tap("Params: ") |> iox.inspect_println_tap - let result = sql |> pgo.execute(on: db_conn, with: db_params, expecting: dcdr) + let result = + sql + |> pog.query + |> pog_parameters(db_params:) + |> pog.returning(dcdr) + |> pog.execute(on: db_conn) case result { - Ok(pgo.Returned(_result_count, v)) -> Ok(v) + Ok(pog.Returned(_result_count, v)) -> Ok(v) Error(e) -> Error(e) } } pub fn execute_raw_sql(sql sql: String, connection conn: Connection) { - sql |> pgo.execute(conn, with: [], expecting: dynamic.dynamic) + sql |> pog.query |> pog.execute(on: conn) +} + +fn pog_parameters( + pog_query pg_qry: pog.Query(a), + db_params db_params: List(pog.Value), +) -> pog.Query(a) { + db_params + |> list.fold(pg_qry, fn(pg_qry, db_param) { + pg_qry |> pog.parameter(db_param) + }) }