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

Release/v1.1.0 #2

Merged
merged 5 commits into from
Jan 12, 2025
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
10 changes: 10 additions & 0 deletions .github/sh/create-database-gleam_cake_pog_test-postgres.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env sh

set -eu

psql <<SQL
SELECT 'CREATE DATABASE gleam_cake_pog_test'
WHERE NOT EXISTS (
SELECT FROM pg_database WHERE datname = 'gleam_cake_pog_test'
)\\gexec
SQL
78 changes: 78 additions & 0 deletions .github/workflows/abstract_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Test

on:
workflow_call:
inputs:
gleam_version:
type: string
required: true
default: "1.6"
erlang_version:
type: string
default: "26"
test_erlang:
type: boolean
default: true
test_node:
type: boolean
default: true

jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: inoas/gleam_actions/.github/actions/install_gleam@main-on-upstream
with:
gleam_version: ${{inputs.gleam_version}}
erlang_version: ${{inputs.erlang_version}}
- uses: inoas/gleam_actions/.github/actions/format@main-on-upstream

deps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: inoas/gleam_actions/.github/actions/install_gleam@main-on-upstream
with:
gleam_version: ${{ inputs.gleam_version }}
erlang_version: ${{ inputs.erlang_version }}
- uses: inoas/gleam_actions/.github/actions/deps_cache@main-on-upstream
with:
gleam_version: ${{ inputs.gleam_version }}

test_erlang:
if: inputs.test_erlang
runs-on: ubuntu-latest
services:
postgres:
image: postgres:latest
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
needs: deps
strategy:
fail-fast: true
matrix:
erlang:
- ${{inputs.erlang_version}}
steps:
- uses: actions/checkout@v4
- uses: inoas/gleam_actions/.github/actions/install_gleam@main-on-upstream
with:
gleam_version: ${{ inputs.gleam_version }}
erlang_version: ${{ matrix.erlang }}
- run: ./.github/sh/create-database-gleam_cake_pog_test-postgres.sh
env:
PGHOST: localhost
PGPORT: 5432
PGPASSWORD: postgres
PGUSER: postgres
- uses: inoas/gleam_actions/.github/actions/test@main-on-upstream
with:
target: "erlang"
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Test

on:
push:
branches:
- main
pull_request:
workflow_call:

jobs:
test_lowest:
uses: ./.github/workflows/abstract_test.yml
with:
erlang_version: "26"
gleam_version: "1.6.3"
test_erlang: true
test_node: false
test_highest:
uses: ./.github/workflows/abstract_test.yml
with:
erlang_version: "27"
gleam_version: "1.7.0"
test_erlang: true
test_node: false
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
*.ez
/build
erl_crash.dump

/docker/data/*
!/docker/data/.gitkeep
5 changes: 5 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# erlang 26.2.5.6
# gleam 1.6.3
erlang 27.2
gleam 1.7.0
# gleam nightly
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

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

## [1.1.0] - 2025-01-12

- Added unit tests, CI and fixed compatibility with `gleam_stdlib >= 0.50`.

## [1.0.3] - 2024-11-14

- Renamed library from `cake_gleam_pgo` to `cake_pog`.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import cake/delete as d
import cake/insert as i
import cake/select as s
import cake/where as w
import gleam/dynamic
import gleam/dynamic/decode
import gleam/option.{None}

const postgres_database_name = "my_postgres_database_name"
Expand Down Expand Up @@ -71,7 +71,7 @@ fn insert_into_table_birds(db_connection) {
]
)
|> i.to_query
|> postgres.run_write_query(dynamic.dynamic, db_connection)
|> postgres.run_write_query(decode.dynamic, db_connection)
|> io.debug
}

Expand All @@ -80,7 +80,7 @@ fn select_from_table_birds(db_connection) {
|> s.from_table("table")
|> s.selects([s.col("species")])
|> s.to_query
|> postgres.run_read_query(dynamic.dynamic, db_connection)
|> postgres.run_read_query(decode.dynamic, db_connection)
|> io.debug
}

Expand All @@ -89,7 +89,7 @@ fn delete_from_table_birds(db_connection) {
|> d.table("birds")
|> d.where(w.col("species") |> w.eq(w.string("Dodo")))
|> d.to_query
|> postgres.run_write_query(dynamic.dynamic, db_connection)
|> postgres.run_write_query(decode.dynamic, db_connection)
|> io.debug
}
```
Expand Down
4 changes: 4 additions & 0 deletions bin/birdie/accept-all
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

gleam test >/dev/null 2>&1
gleam run --module birdie accept-all
4 changes: 4 additions & 0 deletions bin/birdie/interactive-review
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

gleam test >/dev/null 2>&1
gleam run --module birdie review
4 changes: 4 additions & 0 deletions bin/birdie/reject-all
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

gleam test >/dev/null 2>&1
gleam run --module birdie reject-all
6 changes: 6 additions & 0 deletions bin/cloc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

# Go to the root of the project
cd "$(dirname "$0")" && cd ..

cloc ./bin ./birdie_snapshots ./src ./test
11 changes: 11 additions & 0 deletions bin/docker/attached
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

# Go to the root of the project
cd "$(dirname "$0")" && cd ../..

docker compose down
docker rm gleam-cake-test-postgres --force --volumes 2>/dev/null
docker rm gleam-cake-test-mariadb --force --volumes 2>/dev/null
rm -rf docker/data/*
touch docker/data/.keep
docker compose up --remove-orphans
11 changes: 11 additions & 0 deletions bin/docker/detached
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

# Go to the root of the project
cd "$(dirname "$0")" && cd ../..

docker compose down
docker rm gleam-cake-test-postgres --force --volumes 2>/dev/null
docker rm gleam-cake-test-mariadb --force --volumes 2>/dev/null
rm -rf docker/data/*
touch docker/data/.keep
docker compose up --remove-orphans --detach
8 changes: 8 additions & 0 deletions bin/docker/down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

# Go to the root of the project
cd "$(dirname "$0")" && cd ../..

docker compose down
rm -rf postgres-data
rm -rf docker/data/postgres/pgdata
6 changes: 6 additions & 0 deletions bin/rg-pub-fn-in-src
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

# Go to the root of the project
cd "$(dirname "$0")" && cd ..

rg 'pub fn' --count --sort-files src
6 changes: 6 additions & 0 deletions bin/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

# Go to the root of the project
cd "$(dirname "$0")" && cd ..

gleam test
7 changes: 7 additions & 0 deletions birdie_snapshots/delete_execution_result_test.accepted
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: 1.2.5
title: delete_execution_result_test
file: ./test/cake_test/delete_test.gleam
test_name: delete_execution_result_test
---
Ok([])
13 changes: 13 additions & 0 deletions birdie_snapshots/delete_prepared_statement_test.accepted
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
version: 1.2.5
title: delete_prepared_statement_test
file: ./test/cake_test/delete_test.gleam
test_name: delete_prepared_statement_test
---
PreparedStatement(
"$",
"DELETE FROM owners USING cats INNER JOIN dogs AS dogs ON dogs.name = cats.name WHERE owners.name = $1 AND cats.owner_id = owners.id RETURNING owners.id",
[StringParam("Alice")],
1,
Postgres,
)
37 changes: 37 additions & 0 deletions birdie_snapshots/delete_test.accepted
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
version: 1.2.5
title: delete_test
file: ./test/cake_test/delete_test.gleam
test_name: delete_test
---
DeleteQuery(Delete(
NoDeleteModifier,
DeleteTable("owners"),
DeleteUsing([FromTable("cats")]),
Joins([
InnerJoin(
JoinTable("dogs"),
"dogs",
WhereComparison(
WhereColumnValue("dogs.name"),
Equal,
WhereColumnValue("cats.name"),
),
),
]),
AndWhere([
WhereComparison(
WhereColumnValue("owners.name"),
Equal,
WhereParamValue(StringParam("Alice")),
),
WhereComparison(
WhereColumnValue("cats.owner_id"),
Equal,
WhereColumnValue("owners.id"),
),
]),
Returning(["owners.id"]),
NoEpilog,
NoComment,
))
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: 1.2.5
title: insert_values_execution_result_test
file: ./test/cake_test/insert_values_test.gleam
test_name: insert_values_execution_result_test
---
Ok([#("Whiskers")])
17 changes: 17 additions & 0 deletions birdie_snapshots/insert_values_prepared_statement_test.accepted
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
version: 1.2.5
title: insert_values_prepared_statement_test
file: ./test/cake_test/insert_values_test.gleam
test_name: insert_values_prepared_statement_test
---
PreparedStatement(
"$",
"INSERT INTO cats (name, rating, age) VALUES ($1, $2, $3) RETURNING name",
[
StringParam("Whiskers"),
FloatParam(3.14),
IntParam(42),
],
3,
Postgres,
)
26 changes: 26 additions & 0 deletions birdie_snapshots/insert_values_test.accepted
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
version: 1.2.5
title: insert_values_test
file: ./test/cake_test/insert_values_test.gleam
test_name: insert_values_test
---
InsertQuery(Insert(
InsertIntoTable("cats"),
InsertColumns([
"name",
"rating",
"age",
]),
NoInsertModifier,
InsertSourceRows([
InsertRow([
InsertParam(StringParam("Whiskers")),
InsertParam(FloatParam(3.14)),
InsertParam(IntParam(42)),
]),
]),
InsertConflictError,
Returning(["name"]),
NoEpilog,
NoComment,
))
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: 1.2.5
title: select_distinct_execution_result_test
file: ./test/cake_test/select_test.gleam
test_name: select_distinct_execution_result_test
---
Ok([False, True, Null])
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
version: 1.2.5
title: select_distinct_prepared_statement_test
file: ./test/cake_test/select_test.gleam
test_name: select_distinct_prepared_statement_test
---
PreparedStatement(
"$",
"SELECT DISTINCT is_wild FROM cats ORDER BY is_wild ASC",
[],
0,
Postgres,
)
Loading
Loading