Skip to content

Commit c70f8a5

Browse files
authored
Merge pull request #1 from inoas/move-to-pog
move to pog
2 parents 1b487ea + b971469 commit c70f8a5

7 files changed

+70
-46
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
55

66
<!-- ## [Unreleased] -->
77

8+
## [1.0.3] - 2024-11-14
9+
10+
- Renamed library from `cake_gleam_pgo` to `cake_pog`.
11+
- Use `pog` instead of `gleam_pgo` as a gleam postgres client dependency.
12+
- Adapt to breaking changes this move brought.
13+
814
## [1.0.2] - 2024-11-03
915

1016
- Added omitted license file.

README.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
# Adapter between `cake` and `gleam_pgo`
1+
# Adapter between `cake` and `pog`
22

3-
[![Package <a href="https://github.com/inoas/gleam-cake-pgo/releases"><img src="https://img.shields.io/github/release/inoas/gleam-cake-gleam_pgo" alt="GitHub release"></a> Version](https://img.shields.io/hexpm/v/cake_gleam_pgo)](https://hex.pm/packages/cake_gleam_pgo)
3+
[![Package <a href="https://github.com/inoas/gleam-cake-pgo/releases"><img src="https://img.shields.io/github/release/inoas/gleam-cake-pog" alt="GitHub release"></a> Version](https://img.shields.io/hexpm/v/cake_pog)](https://hex.pm/packages/cake_pog)
44
[![Erlang-compatible](https://img.shields.io/badge/target-erlang-b83998)](https://www.erlang.org/)
5-
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/cake_gleam_pgo/)
5+
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/cake_pog/)
66
[![Discord](https://img.shields.io/discord/768594524158427167?label=discord%20chat&amp;color=5865F2)](https://discord.gg/Fm8Pwmy)
77

88
<!--
9-
[![CI Test](https://github.com/inoas/gleam-cake-gleam_pgo/actions/workflows/test.yml/badge.svg?branch=main&amp;event=push)](https://github.com/inoas/gleam-cake-gleam_pgo/actions/workflows/test.yml)
9+
[![CI Test](https://github.com/inoas/gleam-cake-pog/actions/workflows/test.yml/badge.svg?branch=main&amp;event=push)](https://github.com/inoas/gleam-cake-pog/actions/workflows/test.yml)
1010
-->
1111

12-
🎂[Cake](http://hex.pm/packages/cake) 🐘PostgreSQL adapter which passes `PreparedStatement`s to the [gleam_pgo](http://hex.pm/packages/gleam_pgo) library for execution written in [Gleam](https://gleam.run/).
12+
🎂[Cake](http://hex.pm/packages/cake) 🐘PostgreSQL adapter which passes `PreparedStatement`s to the [pog](http://hex.pm/packages/pog) library for execution written in [Gleam](https://gleam.run/).
1313

1414
## Installation
1515

1616
```sh
17-
gleam add cake_gleam_pgo@1
17+
gleam add cake_pog@1
1818
```
1919

2020
## Example
@@ -93,3 +93,7 @@ fn delete_from_table_birds(db_connection) {
9393
|> io.debug
9494
}
9595
```
96+
97+
## History
98+
99+
This used to be <https://github.com/inoas/gleam-cake-gleam_pgo>

gleam.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
name = "cake_gleam_pgo"
2-
version = "1.0.2"
3-
description = "🎂Cake 🐘PostgreSQL adapter which passes PreparedStatements to the gleam_pgo library for execution written in Gleam."
1+
name = "cake_pog"
2+
version = "1.0.3"
3+
description = "🎂Cake 🐘PostgreSQL adapter which passes PreparedStatements to the pog library for execution written in Gleam."
44
licences = ["MPL-2.0"]
5-
repository = { type = "github", user = "inoas", repo = "gleam-cake-gleam_pgo" }
5+
repository = { type = "github", user = "inoas", repo = "gleam-cake-pog" }
66
# links = [{ title = "Website", href = "https://gleam.run" }]
77

88
gleam = ">= 1.4.0 and < 2.0.0"
@@ -14,5 +14,5 @@ pages = [
1414

1515
[dependencies]
1616
cake = ">= 2.0.0 and < 3.0.0"
17-
gleam_pgo = ">= 0.14.0 and < 2.0.0"
17+
pog = ">= 1.0.0 and < 2.0.0"
1818
gleam_stdlib = ">= 0.40.0 and < 2.0.0"

manifest.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
packages = [
55
{ name = "backoff", version = "1.1.6", build_tools = ["rebar3"], requirements = [], otp_app = "backoff", source = "hex", outer_checksum = "CF0CFFF8995FB20562F822E5CC47D8CCF664C5ECDC26A684CBE85C225F9D7C39" },
66
{ name = "cake", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "cake", source = "hex", outer_checksum = "0F9D47447C0BDABE21522CC9792DA42AEBC1EC43E53919F6173FD843DA88A1B8" },
7-
{ name = "gleam_pgo", version = "0.14.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "gleam_pgo", source = "hex", outer_checksum = "12256A7F351E994A6E43AB67276DD8AACE752991C013F48A288C4A848F3A9758" },
87
{ name = "gleam_stdlib", version = "0.40.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "86606B75A600BBD05E539EB59FABC6E307EEEA7B1E5865AFB6D980A93BCB2181" },
98
{ name = "opentelemetry_api", version = "1.4.0", build_tools = ["rebar3", "mix"], requirements = [], otp_app = "opentelemetry_api", source = "hex", outer_checksum = "3DFBBFAA2C2ED3121C5C483162836C4F9027DEF469C41578AF5EF32589FCFC58" },
109
{ name = "pg_types", version = "0.4.0", build_tools = ["rebar3"], requirements = [], otp_app = "pg_types", source = "hex", outer_checksum = "B02EFA785CAECECF9702C681C80A9CA12A39F9161A846CE17B01FB20AEEED7EB" },
1110
{ name = "pgo", version = "0.14.0", build_tools = ["rebar3"], requirements = ["backoff", "opentelemetry_api", "pg_types"], otp_app = "pgo", source = "hex", outer_checksum = "71016C22599936E042DC0012EE4589D24C71427D266292F775EBF201D97DF9C9" },
11+
{ name = "pog", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "pog", source = "hex", outer_checksum = "00D57120936AFBF486BE357C472E483C1F0CA507FF9C3668075E87C733CA53F8" },
1212
]
1313

1414
[requirements]
1515
cake = { version = ">= 2.0.0 and < 3.0.0" }
16-
gleam_pgo = { version = ">= 0.14.0 and < 2.0.0" }
1716
gleam_stdlib = { version = ">= 0.40.0 and < 2.0.0" }
17+
pog = { version = ">= 1.0.0 and < 2.0.0" }

src/cake/adapter/postgres.gleam

+38-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//// 🎂Cake 🐘PostgreSQL adapter which passes `PreparedStatement`s
2-
//// to the `gleam_pgo` library for execution.
2+
//// to the `pog` library for execution.
33
////
44

55
import cake.{
@@ -13,11 +13,11 @@ import cake/param.{
1313
import gleam/dynamic.{type DecodeError, type Dynamic}
1414
import gleam/list
1515
import gleam/option.{type Option}
16-
import gleam/pgo.{type Connection, type QueryError, type Returned, type Value}
16+
import pog.{type Connection, type QueryError, type Returned, type Value}
1717

1818
/// Connection to a PostgreSQL database.
1919
///
20-
/// This is a thin wrapper around the `gleam_pgo` library's `Connection` type.
20+
/// This is a thin wrapper around the `pog` library's `Connection` type.
2121
///
2222
pub fn with_connection(
2323
host host: String,
@@ -28,18 +28,18 @@ pub fn with_connection(
2828
callback callback: fn(Connection) -> a,
2929
) -> a {
3030
let connection =
31-
pgo.Config(
32-
..pgo.default_config(),
31+
pog.Config(
32+
..pog.default_config(),
3333
host: host,
3434
port: port,
3535
user: username,
3636
password: password,
3737
database: database,
3838
)
39-
|> pgo.connect
39+
|> pog.connect
4040

4141
let value = callback(connection)
42-
pgo.disconnect(connection)
42+
pog.disconnect(connection)
4343

4444
value
4545
}
@@ -63,7 +63,7 @@ pub fn write_query_to_prepared_statement(
6363
pub fn run_read_query(
6464
query query: ReadQuery,
6565
decoder decoder: fn(Dynamic) -> Result(a, List(DecodeError)),
66-
db_connection db_connection: Connection,
66+
db_connection on: Connection,
6767
) {
6868
let prepared_statement = query |> read_query_to_prepared_statement
6969
let sql_string = prepared_statement |> cake.get_sql
@@ -74,10 +74,13 @@ pub fn run_read_query(
7474

7575
let result =
7676
sql_string
77-
|> pgo.execute(on: db_connection, with: db_params, expecting: decoder)
77+
|> pog.query
78+
|> pog_parameters(db_params:)
79+
|> pog.returning(decoder)
80+
|> pog.execute(on: on)
7881

7982
case result {
80-
Ok(pgo.Returned(_result_count, v)) -> Ok(v)
83+
Ok(pog.Returned(_result_count, v)) -> Ok(v)
8184
Error(e) -> Error(e)
8285
}
8386
}
@@ -87,7 +90,7 @@ pub fn run_read_query(
8790
pub fn run_write_query(
8891
query query: WriteQuery(a),
8992
decoder decoder: fn(Dynamic) -> Result(a, List(DecodeError)),
90-
db_connection db_connection: Connection,
93+
db_connection on: Connection,
9194
) -> Result(List(a), QueryError) {
9295
let prepared_statement = query |> write_query_to_prepared_statement
9396
let sql_string = prepared_statement |> cake.get_sql
@@ -98,10 +101,13 @@ pub fn run_write_query(
98101

99102
let result =
100103
sql_string
101-
|> pgo.execute(on: db_connection, with: db_params, expecting: decoder)
104+
|> pog.query
105+
|> pog_parameters(db_params:)
106+
|> pog.returning(decoder)
107+
|> pog.execute(on: on)
102108

103109
case result {
104-
Ok(pgo.Returned(_result_count, v)) -> Ok(v)
110+
Ok(pog.Returned(_result_count, v)) -> Ok(v)
105111
Error(e) -> Error(e)
106112
}
107113
}
@@ -125,18 +131,29 @@ pub fn run_query(
125131

126132
pub fn execute_raw_sql(
127133
sql_string sql_string: String,
128-
db_connection db_connection: Connection,
129-
) -> Result(Returned(Dynamic), QueryError) {
134+
db_connection on: Connection,
135+
) -> Result(Returned(Nil), QueryError) {
130136
sql_string
131-
|> pgo.execute(on: db_connection, with: [], expecting: dynamic.dynamic)
137+
|> pog.query
138+
|> pog.execute(on:)
132139
}
133140

134141
fn cake_param_to_client_param(param param: Param) -> Value {
135142
case param {
136-
BoolParam(param) -> pgo.bool(param)
137-
FloatParam(param) -> pgo.float(param)
138-
IntParam(param) -> pgo.int(param)
139-
StringParam(param) -> pgo.text(param)
140-
NullParam -> pgo.null()
143+
BoolParam(param) -> pog.bool(param)
144+
FloatParam(param) -> pog.float(param)
145+
IntParam(param) -> pog.int(param)
146+
StringParam(param) -> pog.text(param)
147+
NullParam -> pog.null()
141148
}
142149
}
150+
151+
fn pog_parameters(
152+
pog_query pg_qry: pog.Query(a),
153+
db_params db_params: List(pog.Value),
154+
) -> pog.Query(a) {
155+
db_params
156+
|> list.fold(pg_qry, fn(pg_qry, db_param) {
157+
pg_qry |> pog.parameter(db_param)
158+
})
159+
}

src/cake_gleam_pgo.gleam

-12
This file was deleted.

src/cake_pog.gleam

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import gleam/io
2+
3+
/// As a library *cake_pog* cannot be invoked directly in a meaningful way.
4+
///
5+
@internal
6+
pub fn main() {
7+
{ "\n" <> "cake_pog is an adapter library and cannot be invoked directly." }
8+
|> io.println
9+
}

0 commit comments

Comments
 (0)