-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
56 changed files
with
284 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
23 changes: 6 additions & 17 deletions
23
...03_demo_insert/src/cake_demo_insert.gleam → ...emos/03_insert/src/cake_demo_insert.gleam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Cake demo app: UPDATE | ||
|
||
This demo of Cake shows how to `UPDATE`. | ||
|
||
To start postgres via docker compose, see | ||
[docs/demo-apps/README.md](../../README.md#Installing-prerequisites), then: | ||
|
||
```shell | ||
gleam clean | ||
gleam run | ||
``` | ||
|
||
## Demo source code | ||
|
||
See the [src directory](https://github.com/inoas/gleam-cake/blob/main/docs/demo-apps/demos/05_update/src/). | ||
|
||
--- | ||
|
||
For further demos see [docs/demo-apps/README.md](../../README.md#available-demos). |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...demo_insert_on_conflict_update/gleam.toml → ...s/06_insert_on_conflict_update/gleam.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
1 change: 0 additions & 1 deletion
1
...onflict_update/src/cake_demo_update.gleam → ...cake_demo_insert_on_conflict_update.gleam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import cake/delete as d | ||
import cake/insert as i | ||
import cake/update as u | ||
import cake/where as w | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.beam | ||
*.ez | ||
/build | ||
erl_crash.dump |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# erlang 26.2.5.1 | ||
erlang 27.0 | ||
gleam 1.3.2 | ||
# erlang 26.2.5.1 | ||
# gleam nightly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Cake demo app: SELECT and decode | ||
|
||
This demo of Cake shows how to `SELECT` and decode returning rows into | ||
Gleam records. | ||
|
||
To start postgres via docker compose, see | ||
[docs/demo-apps/README.md](../../README.md#Installing-prerequisites), then: | ||
|
||
```shell | ||
gleam clean | ||
gleam run | ||
``` | ||
|
||
## Demo source code | ||
|
||
See the [src directory](https://github.com/inoas/gleam-cake/blob/main/docs/demo-apps/demos/07_select_join/src/). | ||
|
||
--- | ||
|
||
For further demos see [docs/demo-apps/README.md](../../README.md#available-demos). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name = "cake_demo_select_join" | ||
description = "An demo of using Gleam with Cake and Postgres to run SELECT and JOIN queries and decode returning data into Gleam records" | ||
|
||
[dependencies] | ||
cake = { path = "../../../../" } | ||
helper = { path = "../../helper" } | ||
gleam_pgo = ">= 0.13.0 and < 2.0.0" | ||
gleam_stdlib = ">= 0.39.0 and < 2.0.0" | ||
pprint = ">= 1.0.3 and < 2.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# This file was generated by Gleam | ||
# You typically do not need to edit this file | ||
|
||
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 = "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 = "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" }, | ||
{ 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 = "pprint", version = "1.0.3", build_tools = ["gleam"], requirements = ["glam", "gleam_stdlib"], otp_app = "pprint", source = "hex", outer_checksum = "76BBB92E23D12D954BD452686543F29EDE8EBEBB7FC0ACCBCA66EEF276EC3A06" }, | ||
] | ||
|
||
[requirements] | ||
cake = { path = "../../../../" } | ||
helper = { path = "../../helper" } | ||
gleam_pgo = { 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" } |
34 changes: 34 additions & 0 deletions
34
docs/demo-apps/demos/07_select_join/src/cake_demo_select_join.gleam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import cake/join as j | ||
import cake/select as s | ||
import cake/where as w | ||
import gleam/dynamic | ||
import gleam/io | ||
import helper/demo_data | ||
import helper/postgres | ||
import pprint | ||
|
||
fn select_join_query() { | ||
s.new() | ||
|> s.selects([s.col("owners.name"), s.col("dogs.name")]) | ||
|> s.from_table("owners") | ||
|> s.join(j.left( | ||
with: j.table("dogs"), | ||
on: w.col("owners.id") |> w.eq(w.col("dogs.owner_id")), | ||
alias: "dogs", | ||
)) | ||
|> s.to_query | ||
} | ||
|
||
pub fn main() { | ||
use conn <- postgres.with_connection | ||
demo_data.create_tables_and_insert_rows(conn) | ||
|
||
// NOTICE: This will crash, if the SQL query fails. | ||
let result = | ||
select_join_query() |> postgres.run_read_query(dynamic.dynamic, conn) | ||
|
||
io.println("Result: ") | ||
|
||
result | ||
|> pprint.debug | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.beam | ||
*.ez | ||
/build | ||
erl_crash.dump |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# erlang 26.2.5.1 | ||
erlang 27.0 | ||
gleam 1.3.2 | ||
# gleam nightly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name = "cake_demo_prepared_fragment" | ||
description = "An demo of using Gleam with Cake and Postgres to run queries with fragments including prepared statements" | ||
|
||
[dependencies] | ||
cake = { path = "../../../../" } | ||
helper = { path = "../../helper" } | ||
gleam_pgo = ">= 0.13.0 and < 2.0.0" | ||
gleam_stdlib = ">= 0.39.0 and < 2.0.0" | ||
pprint = ">= 1.0.3 and < 2.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# This file was generated by Gleam | ||
# You typically do not need to edit this file | ||
|
||
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 = "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 = "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" }, | ||
{ 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 = "pprint", version = "1.0.3", build_tools = ["gleam"], requirements = ["glam", "gleam_stdlib"], otp_app = "pprint", source = "hex", outer_checksum = "76BBB92E23D12D954BD452686543F29EDE8EBEBB7FC0ACCBCA66EEF276EC3A06" }, | ||
] | ||
|
||
[requirements] | ||
cake = { path = "../../../../" } | ||
helper = { path = "../../helper" } | ||
gleam_pgo = { 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" } |
37 changes: 37 additions & 0 deletions
37
docs/demo-apps/demos/08_prepared_fragment/src/cake_demo_prepared_fragment.gleam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import cake/fragment as f | ||
import cake/select as s | ||
import cake/where as w | ||
import gleam/dynamic | ||
import gleam/io | ||
import helper/demo_data | ||
import helper/postgres | ||
import pprint | ||
|
||
fn fragment_query() { | ||
s.new() | ||
|> s.from_table("cats") | ||
|> s.where( | ||
w.fragment_value(f.literal("LOWER(cats.name)")) | ||
|> w.eq( | ||
w.fragment_value( | ||
f.prepared("LOWER(" <> f.placeholder <> ")", [f.string("cLaRa")]), | ||
), | ||
), | ||
) | ||
|> s.to_query | ||
} | ||
|
||
pub fn main() { | ||
use conn <- postgres.with_connection | ||
demo_data.create_tables_and_insert_rows(conn) | ||
|
||
// NOTICE: This will crash, if the SQL query fails. | ||
let result = | ||
fragment_query() | ||
|> postgres.run_read_query(dynamic.dynamic, conn) | ||
|
||
io.println("Result: ") | ||
|
||
result | ||
|> pprint.debug | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.