Skip to content

Commit

Permalink
Merge pull request #14 from inoas/releases/2.0
Browse files Browse the repository at this point in the history
2.0
  • Loading branch information
inoas authored Oct 19, 2024
2 parents 02f63da + 753b37c commit 09fe6b8
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 29 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

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

## [2.0.0] - 2024-10-19

- Breaking changes:
- Renamed `cake.cake_read_query` to `cake.to_read_query`
- Renamed `cake.cake_write_query` to `cake.to_write_query`
- Renamed `cake.cake_query_to_prepared_statement` to `cake.to_prepared_statement`

## [1.1.2] - 2024-08-30

- Consistent dialect function names across all 4 RDMBS, fixed/renamed functions:
Expand Down
38 changes: 26 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
[![Package
<a href="https://github.com/inoas/gleam-cake/releases"><img src="https://img.shields.io/github/release/inoas/gleam-cake" alt="GitHub release"></a>
<a href="https://discord.gg/Fm8Pwmy"><img src="https://img.shields.io/discord/768594524158427167?color=blue" alt="Discord chat"></a>
![CI](https://github.com/inoas/gleam-cake/workflows/test/badge.svg?branch=main)
Version](https://img.shields.io/hexpm/v/cake)](https://hex.pm/packages/cake)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/cake/)
![Erlang-compatible](https://img.shields.io/badge/target-erlang-b83998)
![JavaScript Compatible](https://img.shields.io/badge/target-javascript-f3e155)
![CI](https://github.com/inoas/gleam-cake/workflows/test/badge.svg?branch=main)
Version](https://img.shields.io/hexpm/v/cake)](https://hex.pm/packages/cake)
![test](https://github.com/inoas/gleam-cake/actions/workflows/test.yml/badge.svg?branch=main&event=push)

<br>
Expand All @@ -20,7 +20,10 @@ Version](https://img.shields.io/hexpm/v/cake)](https://hex.pm/packages/cake)
<br>

<p align="center">
<i>Cake is a library written in Gleam to compose SQL queries targeting SQL dialects 🐘PostgreSQL, 🪶SQLite, 🦭MariaDB and 🐬MySQL.</i>
<i>
🎂Cake is a library written in Gleam to compose SQL queries targeting SQL
dialects 🐘PostgreSQL, 🪶SQLite, 🦭MariaDB and 🐬MySQL.
</i>
</p>

<br>
Expand All @@ -29,7 +32,7 @@ Version](https://img.shields.io/hexpm/v/cake)](https://hex.pm/packages/cake)
## Installation

```shell
gleam add cake@v1
gleam add cake
```

Further documentation can be found on [hexdocs.pm/cake](https://hexdocs.pm/cake).
Expand Down Expand Up @@ -57,9 +60,12 @@ See [docs/demo-apps/README.md](https://github.com/inoas/gleam-cake/blob/main/doc

### Unit tests as examples

See Cake's [tests](https://github.com/inoas/gleam-cake/tree/main/test/cake_test), especially the _Setup_ sections in each test module.
See Cake's [tests](https://github.com/inoas/gleam-cake/tree/main/test/cake_test),
especially the _Setup_ sections in each test module.

You may also compare the tests with the [snapshots](https://github.com/inoas/gleam-cake/tree/main/birdie_snapshots) results.
You may also compare the tests with the
[snapshots](https://github.com/inoas/gleam-cake/tree/main/birdie_snapshots)
results.

### Intended aliases

Expand All @@ -80,14 +86,17 @@ import cake/fragment as f // For arbitrary SQL code including functions

### Scope

This is an SQL query building library, thus it is not concerned about executing queries or decoding return values from queries, but merely about being a flexible and powerful tool to compose and craft SQL read and write queries.
This is an SQL query building library, thus it is not concerned about executing
queries or decoding return values from queries, but merely about being a
flexible and powerful tool to compose and craft SQL read and write queries.

#### Goals

- High degree of flexibility to compose queries:
While the focus is on building queries there is also support for replacing
or removing parts of queries.
- General support on these 4 large RDMS: 🐘PostgreSQL, 🪶SQLite, 🦭MariaDB and 🐬MySQL.
- General support on these 4 large RDMS: 🐘PostgreSQL, 🪶SQLite, 🦭MariaDB and
🐬MySQL.
- Not being tied to any specific dialect or dialect adapter library.
- Documentation should be comprehensive.
- It should be easy to use with existing gleam dialect adapters such as:
Expand Down Expand Up @@ -122,8 +131,10 @@ This is an SQL query building library, thus it is not concerned about executing

The tests run on Erlang but are generally target agnostic.

While the primary use case is to run queries on servers, this library runs on any Gleam target and for example in conjunction with following adapters, you may run queries composed with this library in browsers:
- [sqlite3 WASM/JS](https://sqlite.org/wasm)
While the primary use case is to run queries on servers, this library runs on
any Gleam target and for example in conjunction with following adapters, you may
run queries composed with this library in browsers:
- [sqlite3 WASM/JS](https://sqlite.org/wasm)
- [PGLite (Postgres WASM)](https://pglite.dev/)

## Development
Expand Down Expand Up @@ -153,6 +164,9 @@ bin/birdie/reject-all

## Library naming

The best part of working with CakePHP 3+ used to be its Query Builder. This library is inspired by that and thus the name.
The best part of working with CakePHP 3+ used to be its Query Builder. This
library is inspired by that and thus the name.

Thank you [@lorenzo](https://github.com/lorenzo) and [@markstory](https://github.com/markstory) for creating and maintaining CakePHP and its awesome query builder over the years.
Thank you [@lorenzo](https://github.com/lorenzo) and
[@markstory](https://github.com/markstory) for creating and maintaining CakePHP
and its awesome query builder over the years.
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "cake"
version = "1.1.3"
version = "2.0.0"
description = "An SQL query builder for Gleam for SQL dialects 🐘PostgreSQL, 🪶SQLite, 🦭MariaDB, and 🐬MySQL"
licences = ["MPL-2.0"]
repository = { type = "github", user = "inoas", repo = "gleam-cake" }
Expand Down
9 changes: 4 additions & 5 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,22 @@ packages = [
{ name = "glance", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "glexer"], otp_app = "glance", source = "hex", outer_checksum = "8F3314D27773B7C3B9FB58D8C02C634290422CE531988C0394FA0DF8676B964D" },
{ name = "gleam_community_ansi", version = "1.4.1", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "4CD513FC62523053E62ED7BAC2F36136EC17D6A8942728250A9A00A15E340E4B" },
{ name = "gleam_community_colour", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "795964217EBEDB3DA656F5EB8F67D7AD22872EB95182042D3E7AFEF32D3FD2FE" },
{ name = "gleam_erlang", version = "0.26.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "3DF72F95F4716883FA51396FB0C550ED3D55195B541568CAF09745984FD37AD1" },
{ name = "gleam_erlang", version = "0.27.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "DE468F676D71B313C6C8C5334425CFCF827837333F8AB47B64D8A6D7AA40185D" },
{ name = "gleam_json", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "9063D14D25406326C0255BDA0021541E797D8A7A12573D849462CAFED459F6EB" },
{ name = "gleam_otp", version = "0.12.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "CD5FC777E99673BDB390092DF85E34EAA6B8EE1882147496290AB3F45A4960B1" },
{ name = "gleam_otp", version = "0.12.1", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "BFACC1513410DF5A1617169A9CD7EA334973AC71D860A17574BA7B2EADD89A6F" },
{ name = "gleam_pgo", version = "0.14.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "gleam_pgo", source = "hex", outer_checksum = "12256A7F351E994A6E43AB67276DD8AACE752991C013F48A288C4A848F3A9758" },
{ name = "gleam_stdlib", version = "0.40.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "86606B75A600BBD05E539EB59FABC6E307EEEA7B1E5865AFB6D980A93BCB2181" },
{ name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" },
{ name = "glexer", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glexer", source = "hex", outer_checksum = "BD477AD657C2B637FEF75F2405FAEFFA533F277A74EF1A5E17B55B1178C228FB" },
{ name = "gmysql", version = "1.4.0", build_tools = ["gleam"], requirements = ["based", "gleam_erlang", "gleam_otp", "gleam_stdlib", "mysql"], otp_app = "gmysql", source = "hex", outer_checksum = "BEBE389DE4350637A5F69D1A857FB1AAF1DFDEC94E8A66C4CAD2FBC7A8D2D9AD" },
{ name = "justin", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "justin", source = "hex", outer_checksum = "7FA0C6DB78640C6DC5FBFD59BF3456009F3F8B485BF6825E97E1EB44E9A1E2CD" },
{ name = "mysql", version = "1.8.0", build_tools = ["make", "rebar3", "mix"], requirements = [], otp_app = "mysql", source = "hex", outer_checksum = "D473C479C19E5CDE20237458EEAD6673C3C00E0EF84AFD30615AEBBB67FEE7B3" },
{ name = "opentelemetry_api", version = "1.3.1", build_tools = ["rebar3", "mix"], requirements = ["opentelemetry_semantic_conventions"], otp_app = "opentelemetry_api", source = "hex", outer_checksum = "9E8A5CC38671E3AC61BE48ABE5F6B3AFDBBB50A1DC08B7950C56F169611505C1" },
{ name = "opentelemetry_semantic_conventions", version = "0.2.0", build_tools = ["rebar3", "mix"], requirements = [], otp_app = "opentelemetry_semantic_conventions", source = "hex", outer_checksum = "D61FA1F5639EE8668D74B527E6806E0503EFC55A42DB7B5F39939D84C07D6895" },
{ name = "opentelemetry_api", version = "1.4.0", build_tools = ["rebar3", "mix"], requirements = [], otp_app = "opentelemetry_api", source = "hex", outer_checksum = "3DFBBFAA2C2ED3121C5C483162836C4F9027DEF469C41578AF5EF32589FCFC58" },
{ name = "pg_types", version = "0.4.0", build_tools = ["rebar3"], requirements = [], otp_app = "pg_types", source = "hex", outer_checksum = "B02EFA785CAECECF9702C681C80A9CA12A39F9161A846CE17B01FB20AEEED7EB" },
{ name = "pgo", version = "0.14.0", build_tools = ["rebar3"], requirements = ["backoff", "opentelemetry_api", "pg_types"], otp_app = "pgo", source = "hex", outer_checksum = "71016C22599936E042DC0012EE4589D24C71427D266292F775EBF201D97DF9C9" },
{ name = "pprint", version = "1.0.3", build_tools = ["gleam"], requirements = ["glam", "gleam_stdlib"], otp_app = "pprint", source = "hex", outer_checksum = "76BBB92E23D12D954BD452686543F29EDE8EBEBB7FC0ACCBCA66EEF276EC3A06" },
{ name = "rank", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "rank", source = "hex", outer_checksum = "5660E361F0E49CBB714CC57CC4C89C63415D8986F05B2DA0C719D5642FAD91C9" },
{ name = "simplifile", version = "2.1.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "BDD04F5D31D6D34E2EDFAEF0B68A6297AEC939888C3BFCE61133DE13857F6DA2" },
{ name = "simplifile", version = "2.2.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0DFABEF7DC7A9E2FF4BB27B108034E60C81BEBFCB7AB816B9E7E18ED4503ACD8" },
{ name = "sqlight", version = "0.9.1", build_tools = ["gleam"], requirements = ["esqlite", "gleam_stdlib"], otp_app = "sqlight", source = "hex", outer_checksum = "A495F2892627B2268CCBCC5107EDC1E1AD9547D5F4F21A5DB04CEA72B8931B00" },
{ name = "thoas", version = "1.2.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "E38697EDFFD6E91BD12CEA41B155115282630075C2A727E7A6B2947F5408B86A" },
{ name = "trie_again", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "trie_again", source = "hex", outer_checksum = "5B19176F52B1BD98831B57FDC97BD1F88C8A403D6D8C63471407E78598E27184" },
Expand Down
10 changes: 5 additions & 5 deletions src/cake.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,27 @@ pub type CakeQuery(a) {
CakeWriteQuery(WriteQuery(a))
}

/// Create a Cake query from a read query.
/// Create a Cake read query from a read query.
///
/// Also see `cake/dialect/*` for dialect specific implementations of this.
///
pub fn cake_read_query(query qry: ReadQuery) -> CakeQuery(a) {
pub fn to_read_query(query qry: ReadQuery) -> CakeQuery(a) {
qry |> CakeReadQuery
}

/// Create a Cake query from a write query.
/// Create a Cake write query from a write query.
///
/// Also see `cake/dialect/*` for dialect specific implementations of this.
///
pub fn cake_write_query(query qry: WriteQuery(a)) -> CakeQuery(a) {
pub fn to_write_query(query qry: WriteQuery(a)) -> CakeQuery(a) {
qry |> CakeWriteQuery
}

/// Create a prepared statement from a Cake query.
///
/// Also see `cake/dialect/*` for dialect specific implementations of this.
///
pub fn cake_query_to_prepared_statement(
pub fn to_prepared_statement(
query qry: CakeQuery(a),
dialect dlct: Dialect,
) -> PreparedStatement {
Expand Down
2 changes: 1 addition & 1 deletion src/cake/dialect/maria_dialect.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub type WriteQuery(a) =
pub fn cake_query_to_prepared_statement(
query qry: CakeQuery(a),
) -> PreparedStatement {
qry |> cake.cake_query_to_prepared_statement(dialect: Maria)
qry |> cake.to_prepared_statement(dialect: Maria)
}

/// Converts read query to a 🦭MariaDB prepared statement.
Expand Down
2 changes: 1 addition & 1 deletion src/cake/dialect/mysql_dialect.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub type WriteQuery(a) =
pub fn cake_query_to_prepared_statement(
query qry: CakeQuery(a),
) -> PreparedStatement {
qry |> cake.cake_query_to_prepared_statement(dialect: Mysql)
qry |> cake.to_prepared_statement(dialect: Mysql)
}

/// Converts read query to a 🐬MySQL prepared statement.
Expand Down
2 changes: 1 addition & 1 deletion src/cake/dialect/postgres_dialect.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub type WriteQuery(a) =
pub fn cake_query_to_prepared_statement(
query qry: CakeQuery(a),
) -> PreparedStatement {
qry |> cake.cake_query_to_prepared_statement(dialect: Postgres)
qry |> cake.to_prepared_statement(dialect: Postgres)
}

/// Converts read query to a 🐘PostgreSQL prepared statement.
Expand Down
2 changes: 1 addition & 1 deletion src/cake/dialect/sqlite_dialect.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub type WriteQuery(a) =
pub fn cake_query_to_prepared_statement(
query qry: CakeQuery(a),
) -> PreparedStatement {
qry |> cake.cake_query_to_prepared_statement(dialect: Sqlite)
qry |> cake.to_prepared_statement(dialect: Sqlite)
}

/// Converts read query to a 🪶SQLite prepared statement.
Expand Down
4 changes: 2 additions & 2 deletions src/cake/internal/write_query.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import gleam/string
/// in SQL Databases, such as `INSERT`, `UPDATE` and `DELETE`.
///
/// While read queries never use write queries, write queries can use read
/// queries, as they can use subqueries to define the data to be written or for
/// atomic updates or conflict resolution.
/// queries, as they can use subqueries to define the data to be written or they
/// are being utilized for atomic updates or conflict resolution.
///
pub type WriteQuery(a) {
InsertQuery(Insert(a))
Expand Down

0 comments on commit 09fe6b8

Please sign in to comment.