Skip to content

Commit

Permalink
πŸ“ Update README and CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomocavalieri committed Nov 11, 2024
1 parent e0addc8 commit 851eb87
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## Unreleased

- The generated code now uses the [`pog`](https://hexdocs.pm/pog/index.html)
package instead of `gleam_pgo`.
([Giacomo Cavalieri](https://github.com/giacomocavalieri))

## v1.8.1 - 2024-11-08

- Squirrel now errors if a query returns multiple columns with the same name
Expand Down
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ If you need to talk with a database in Gleam you'll have to write something like
this:

```gleam
import gleam/pgo
import pog
import decode/zero
pub type FindSquirrelRow {
Expand All @@ -20,7 +20,7 @@ pub type FindSquirrelRow {
/// Find a squirrel and its owned acorns given its name.
///
pub fn find_squirrel(db: pgo.Connection, name: String) {
pub fn find_squirrel(db: pog.Connection, name: String) {
let squirrel_row_decoder = {
use name <- zero.field(0, zero.string)
use owned_acorns <- zero.field(1, zero.int)
Expand All @@ -36,7 +36,10 @@ pub fn find_squirrel(db: pgo.Connection, name: String) {
where
name = $1
"
|> pgo.execute(db, [pgo.text(name)], zero.run(_, squirrel_row_decoder))
|> pog.query
|> pog.parameter(pog.text(name))
|> pog.returning(zero.run(_, squirrel_row_decoder))
|> pog.execute(db)
}
```

Expand Down Expand Up @@ -76,13 +79,13 @@ And run `gleam run -m squirrel`. Just like magic you'll now have a type-safe
function `find_squirrel` you can use just as you'd expect:

```gleam
import gleam/pgo
import pog
import squirrels/sql
pub fn main() {
let db = todo as "the pgo connection"
let db = todo as "the pog connection"
// And it just works as you'd expect:
let assert Ok(pgo.Returned(_rows_count, rows)) = sql.find_squirrel("sandy")
let assert Ok(pog.Returned(_rows_count, rows)) = sql.find_squirrel("sandy")
let assert [FindSquirrelRow(name: "sandy", owned_acorns: 11_111)] = rows
}
```
Expand All @@ -107,11 +110,6 @@ First you'll need to add Squirrel to your project as a dev dependency:

```sh
gleam add squirrel --dev

# Remember to add these packages if you haven't yet, they are needed by the
# generated code to run and decode the read rows!
gleam add gleam_pgo
gleam add decode
```

Then you can ask it to generate code running the `squirrel` module:
Expand All @@ -136,11 +134,11 @@ work:
>
> ```txt
> β”œβ”€β”€ src
> β”‚Β Β  β”œβ”€β”€ squirrels
> β”‚ β”œβ”€β”€ squirrels
> β”‚ β”‚ └── sql
> β”‚ β”‚ β”œβ”€β”€ find_squirrel.sql
> β”‚ β”‚ └── list_squirrels.sql
> β”‚Β Β  └── squirrels.gleam
> β”‚ └── squirrels.gleam
> └── test
> └── squirrels_test.gleam
> ```
Expand Down
2 changes: 1 addition & 1 deletion src/squirrel.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const squirrel_version = "v1.8.1"
/// > - `PGPASSWORD`: `""`
///
/// > ⚠️ The generated code relies on the
/// > [`gleam_pgo`](https://hexdocs.pm/gleam_pgo/) and
/// > [`pog`](https://hexdocs.pm/pog/) and
/// > [`decode`](https://hexdocs.pm/decode/) packages to work, so make sure to
/// > add those as dependencies to your project.
///
Expand Down

0 comments on commit 851eb87

Please sign in to comment.