Skip to content

Commit

Permalink
Convert to Gleam build tool
Browse files Browse the repository at this point in the history
  • Loading branch information
lpil committed Jan 19, 2022
1 parent e68f077 commit caafa4a
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 78 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ log
logs
rebar3.crashdump
doc
build
18 changes: 17 additions & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
name = "gleam_pgo"
version = "0.1.1"
version = "0.2.0"
licences = ["Apache-2.0"]
description = "Gleam bindings to the PGO PostgreSQL client"

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

[dependencies]
gleam_stdlib = "0.19.0"
gleam_erlang = "~> 0.8"
pgo = "~> 0.11"

[dev-dependencies]
gleeunit = "~> 0.6"
18 changes: 18 additions & 0 deletions manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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 = "gleam_erlang", version = "0.8.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "AF437B787D8FFE3608BA71AB879FBAAC52B2B3312F09403C27B1847476588313" },
{ name = "gleam_stdlib", version = "0.19.3", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "14AC79B463A08A428B5802051D3E660AFB0B0A075A630DFBC3E0F45B28D79139" },
{ name = "gleeunit", version = "0.6.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "77701A5E5A565727E1EEAC9196FB878D544049B6331CD0305B5A69699135EA1C" },
{ name = "pg_types", version = "0.4.0", build_tools = ["rebar3"], requirements = [], otp_app = "pg_types", source = "hex", outer_checksum = "B02EFA785CAECECF9702C681C80A9CA12A39F9161A846CE17B01FB20AEEED7EB" },
{ name = "pgo", version = "0.11.1", build_tools = ["rebar3"], requirements = ["telemetry", "backoff", "pg_types"], otp_app = "pgo", source = "hex", outer_checksum = "30F38CA823A98C41EF23967D133E91B45AD14AEE0766F4773E88BCCF46BA17A5" },
{ name = "telemetry", version = "0.4.3", build_tools = ["rebar3"], requirements = [], otp_app = "telemetry", source = "hex", outer_checksum = "EB72B8365FFDA5BED68A620D1DA88525E326CB82A75EE61354FC24B844768041" },
]

[requirements]
gleam_erlang = "~> 0.8"
gleam_stdlib = "0.19.0"
gleeunit = "~> 0.6"
pgo = "~> 0.11"
23 changes: 0 additions & 23 deletions rebar.config

This file was deleted.

31 changes: 0 additions & 31 deletions rebar.lock

This file was deleted.

7 changes: 3 additions & 4 deletions src/gleam/pgo.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import gleam/string
import gleam/io
import gleam/option.{None, Option, Some}
import gleam/uri.{Uri}
import gleam/otp/process.{Pid}

// TODO: use a record
/// Avaliable configuration options when starting a pool.
Expand All @@ -32,14 +31,14 @@ fn parse_database_url(
database_url: String,
) -> Result(#(String, String, String, Int), Nil) {
case uri.parse(database_url) {
Uri(
Ok(Uri(
scheme: Some("postgres"),
userinfo: Some(userinfo),
host: Some(host),
port: Some(db_port),
path: path,
..,
) -> Ok(#(userinfo, host, path, db_port))
)) -> Ok(#(userinfo, host, path, db_port))
_ -> Error(Nil)
}
}
Expand All @@ -62,7 +61,7 @@ pub fn url_config(database_url: String) -> Result(List(PoolConfig), Nil) {
}

// Ideally unnamed
pub external fn start_link(Atom, List(PoolConfig)) -> Result(Pid, Dynamic) =
pub external fn start_link(Atom, List(PoolConfig)) -> Result(Dynamic, Dynamic) =
"pgo_pool" "start_link"

/// Type that can be passed as arguments to a query.
Expand Down
16 changes: 0 additions & 16 deletions src/gleam_pgo.app.src

This file was deleted.

5 changes: 2 additions & 3 deletions test/gleam/pgo_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import gleam/int
import gleam/io
import gleam/pgo
import gleam/string
import gleam/should
import gleeunit/should

pub fn url_config_test() {
pgo.url_config("postgres://u:[email protected]:1234/my_db")
Expand Down Expand Up @@ -84,8 +84,7 @@ pub fn selecting_rows_test() {
RETURNING
id"
assert Ok(#(_, _, [row])) = pgo.query(conn, sql, [])
assert Ok(id) = dynamic.element(row, 0)
assert Ok(id) = dynamic.int(id)
assert Ok(id) = dynamic.element(0, dynamic.int)(row)
let sql = string.append("SELECT * FROM cats WHERE id = ", int.to_string(id))
assert Ok(response) = pgo.query(conn, sql, [])
response.0
Expand Down
5 changes: 5 additions & 0 deletions test/gleam_pgo_test.gleam
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import gleeunit

pub fn main() {
gleeunit.main()
}

0 comments on commit caafa4a

Please sign in to comment.