Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
lpil committed Dec 22, 2024
1 parent 6c30d42 commit c5195a8
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A PostgreSQL database client for Gleam, based on [PGO][erlang-pgo].

```gleam
import pog
import gleam/dynamic
import gleam/dynamic/decode
import gleeunit/should
pub fn main() {
Expand All @@ -29,12 +29,13 @@ pub fn main() {
id = $1"
// This is the decoder for the value returned by the query
let row_decoder = dynamic.tuple4(
dynamic.string,
dynamic.int,
dynamic.string,
dynamic.list(dynamic.string),
)
let row_decoder = {
use name <- decode.field(0, decode.string)
use age <- decode.field(1, decode.int)
use colour <- decode.field(2, decode.string)
use friends <- decode.field(3, decode.list(decode.string))
decode.success(#(name, age, colour, friends))
}
// Run the query against the PostgreSQL database
// The int `1` is given as a parameter
Expand Down Expand Up @@ -92,7 +93,7 @@ pub fn read_connection_uri() -> Result(pog.Connection, Nil) {
In Postgres, you can define a type `json` or `jsonb`. Such a type can be query
in SQL, but Postgres returns it a simple string, and accepts it as a simple string!
When writing or reading a JSON, you can simply use
`pog.text(json.to_string(my_json))` and `dynamic.string` to respectively write
`pog.text(json.to_string(my_json))` and `decode.string` to respectively write
and read them!

## Timeout
Expand Down

0 comments on commit c5195a8

Please sign in to comment.