Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POGGERS #42

Merged
merged 6 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## v1.0.0 - 2024-11-11

- Renamed to `pog`.
- Configuration and query API redesigned.
- Introduced the `Date`, `Time`, and `Timestamp` types.
- The default connection pool size is now 10.

## v0.15.0 - Unreleased

- Ensure `ssl` and `pgo` are running before using `gleam_pgo`.
Expand Down
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# Gleam PGO
# Pog

A PostgreSQL database client for Gleam, based on [PGO][erlang-pgo].

[erlang-pgo]: https://github.com/erleans/pgo

```gleam
import gleam/pgo
import pog
import gleam/dynamic
import gleeunit/should

pub fn main() {
// Start a database connection pool.
// Typically you will want to create one pool for use in your program
let db = pgo.connect(pgo.Config(
..pgo.default_config(),
host: "localhost",
database: "my_database",
pool_size: 15,
))
let db =
pog.default_config()
|> pog.host("localhost")
|> pog.database("my_database")
|> pog.pool_size(15)
|> pog.connect

// An SQL statement to run. It takes one int as a parameter
let sql = "
let sql_query = "
select
name, age, colour, friends
from
Expand All @@ -29,7 +29,7 @@ pub fn main() {
id = $1"

// This is the decoder for the value returned by the query
let return_type = dynamic.tuple4(
let row_decoder = dynamic.tuple4(
dynamic.string,
dynamic.int,
dynamic.string,
Expand All @@ -38,8 +38,11 @@ pub fn main() {

// Run the query against the PostgreSQL database
// The int `1` is given as a parameter
let assert Ok(response) =
pgo.execute(sql, db, [pgo.int(1)], return_type)
let assert Ok(response) =
pog.query(sql_query)
|> pog.parameter(pog.int(1))
|> pog.returning(row_decoder)
|> pog.execute(db)

// And then do something with the returned results
response.count
Expand Down
10 changes: 5 additions & 5 deletions gleam.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name = "gleam_pgo"
version = "0.14.0"
gleam = ">= 0.32.0"
name = "pog"
version = "1.0.0"
gleam = ">= 1.4.0"
licences = ["Apache-2.0"]
description = "Gleam bindings to the PGO PostgreSQL client"
description = "A PostgreSQL database client for Gleam, based on PGO"

repository = { type = "github", user = "gleam-experiments", repo = "pgo" }
repository = { type = "github", user = "lpil", repo = "pog" }
links = [
{ title = "Website", href = "https://gleam.run" },
{ title = "Sponsor", href = "https://github.com/sponsors/lpil" },
Expand Down
Loading
Loading