From bf056ff6cf4727903a9dc1fc691b45c038bd70a8 Mon Sep 17 00:00:00 2001 From: inoas Date: Mon, 27 May 2024 22:00:53 +0200 Subject: [PATCH] deps --- birdie_snapshots/base_select_query.accepted | 4 +-- birdie_snapshots/cats_query.accepted | 4 +-- birdie_snapshots/cats_query_2.accepted | 4 +-- birdie_snapshots/cats_sub_query.accepted | 4 +-- birdie_snapshots/combined_query.accepted | 8 +++--- birdie_snapshots/composed.accepted | 26 +++++++++---------- birdie_snapshots/dogs_sub_query.accepted | 4 +-- .../query_where_between_builder_test.accepted | 4 +-- birdie_snapshots/select_query_a.accepted | 4 +-- birdie_snapshots/select_query_b.accepted | 4 +-- gleam.toml | 1 + src/cake/internal/query.gleam | 17 ++++++------ 12 files changed, 43 insertions(+), 41 deletions(-) diff --git a/birdie_snapshots/base_select_query.accepted b/birdie_snapshots/base_select_query.accepted index c00bff3..dd48260 100644 --- a/birdie_snapshots/base_select_query.accepted +++ b/birdie_snapshots/base_select_query.accepted @@ -5,14 +5,14 @@ file: ./test/old_query_test.gleam test_name: query_combined_snap_test --- SelectQuery( - FromTable("cats"), [ SelectColumn("name"), SelectColumn("age"), ], + FromTable("cats"), [], NoWherePart, - NoLimitNoOffset, [], + NoLimitNoOffset, NoEpilogPart, ) \ No newline at end of file diff --git a/birdie_snapshots/cats_query.accepted b/birdie_snapshots/cats_query.accepted index ffafbf4..eb49eec 100644 --- a/birdie_snapshots/cats_query.accepted +++ b/birdie_snapshots/cats_query.accepted @@ -5,11 +5,11 @@ file: ./test/old_query_test.gleam test_name: query_fragment_snap_test --- SelectQuery( - FromTable("cats"), [], + FromTable("cats"), [], NoWherePart, - NoLimitNoOffset, [], + NoLimitNoOffset, NoEpilogPart, ) \ No newline at end of file diff --git a/birdie_snapshots/cats_query_2.accepted b/birdie_snapshots/cats_query_2.accepted index 6ca737d..79f38c4 100644 --- a/birdie_snapshots/cats_query_2.accepted +++ b/birdie_snapshots/cats_query_2.accepted @@ -5,8 +5,8 @@ file: ./test/old_query_test.gleam test_name: query_fragment_snap_test --- SelectQuery( - FromTable("cats"), [], + FromTable("cats"), [], WhereEqual( WhereColumn("name"), @@ -18,7 +18,7 @@ SelectQuery( ], )), ), - NoLimitNoOffset, [], + NoLimitNoOffset, NoEpilogPart, ) \ No newline at end of file diff --git a/birdie_snapshots/cats_sub_query.accepted b/birdie_snapshots/cats_sub_query.accepted index 6109a2b..25da622 100644 --- a/birdie_snapshots/cats_sub_query.accepted +++ b/birdie_snapshots/cats_sub_query.accepted @@ -5,11 +5,11 @@ file: ./test/old_query_test.gleam test_name: query_select_snap_test --- SelectQuery( - FromTable("cats"), [], + FromTable("cats"), [], NoWherePart, - NoLimitNoOffset, [], + NoLimitNoOffset, NoEpilogPart, ) \ No newline at end of file diff --git a/birdie_snapshots/combined_query.accepted b/birdie_snapshots/combined_query.accepted index de6abcc..5f47d45 100644 --- a/birdie_snapshots/combined_query.accepted +++ b/birdie_snapshots/combined_query.accepted @@ -8,11 +8,11 @@ Combined(CombinedQuery( UnionAll, [ SelectQuery( - FromTable("cats"), [ SelectColumn("name"), SelectColumn("age"), ], + FromTable("cats"), [], OrWhere([ WhereLowerOrEqual( @@ -24,23 +24,23 @@ Combined(CombinedQuery( "%ara%", ), ]), - NoLimitNoOffset, [], + NoLimitNoOffset, NoEpilogPart, ), SelectQuery( - FromTable("cats"), [ SelectColumn("name"), SelectColumn("age"), ], + FromTable("cats"), [], NotWhere(WhereIsNotBool( WhereColumn("is_wild"), False, )), - NoLimitNoOffset, [], + NoLimitNoOffset, NoEpilogPart, ), ], diff --git a/birdie_snapshots/composed.accepted b/birdie_snapshots/composed.accepted index 165d356..0e5d313 100644 --- a/birdie_snapshots/composed.accepted +++ b/birdie_snapshots/composed.accepted @@ -5,26 +5,26 @@ file: ./test/old_query_test.gleam test_name: query_select_snap_test --- SelectQuery( + [ + SelectColumn("cats.name"), + SelectColumn("cats.age"), + SelectAlias( + SelectColumn("owners.name"), + "owner_name", + ), + ], FromSubQuery( Select(SelectQuery( - FromTable("cats"), [], + FromTable("cats"), [], NoWherePart, - NoLimitNoOffset, [], + NoLimitNoOffset, NoEpilogPart, )), "cats", ), - [ - SelectColumn("cats.name"), - SelectColumn("cats.age"), - SelectAlias( - SelectColumn("owners.name"), - "owner_name", - ), - ], [ InnerJoin( JoinTable("owners"), @@ -43,12 +43,12 @@ SelectQuery( ), CrossJoin( JoinSubQuery(Select(SelectQuery( - FromTable("dogs"), [], + FromTable("dogs"), [], NoWherePart, - NoLimitNoOffset, [], + NoLimitNoOffset, NoEpilogPart, ))), "dogs", @@ -75,7 +75,7 @@ SelectQuery( ], ), ]), - LimitOffset(1, 0), [OrderByColumnPart("cats.age", Asc)], + LimitOffset(1, 0), NoEpilogPart, ) \ No newline at end of file diff --git a/birdie_snapshots/dogs_sub_query.accepted b/birdie_snapshots/dogs_sub_query.accepted index a439ff6..1b53c11 100644 --- a/birdie_snapshots/dogs_sub_query.accepted +++ b/birdie_snapshots/dogs_sub_query.accepted @@ -5,11 +5,11 @@ file: ./test/old_query_test.gleam test_name: query_select_snap_test --- SelectQuery( - FromTable("dogs"), [], + FromTable("dogs"), [], NoWherePart, - NoLimitNoOffset, [], + NoLimitNoOffset, NoEpilogPart, ) \ No newline at end of file diff --git a/birdie_snapshots/query_where_between_builder_test.accepted b/birdie_snapshots/query_where_between_builder_test.accepted index 9300126..e30110b 100644 --- a/birdie_snapshots/query_where_between_builder_test.accepted +++ b/birdie_snapshots/query_where_between_builder_test.accepted @@ -5,15 +5,15 @@ file: ./test/query_test.gleam test_name: query_where_between_builder_test --- SelectQuery( - FromTable("cats"), [], + FromTable("cats"), [], WhereBetween( WhereColumn("age"), WhereParam(IntParam(10)), WhereParam(IntParam(20)), ), - NoLimitNoOffset, [], + NoLimitNoOffset, NoEpilogPart, ) \ No newline at end of file diff --git a/birdie_snapshots/select_query_a.accepted b/birdie_snapshots/select_query_a.accepted index 641c6b0..96ac6d4 100644 --- a/birdie_snapshots/select_query_a.accepted +++ b/birdie_snapshots/select_query_a.accepted @@ -5,11 +5,11 @@ file: ./test/old_query_test.gleam test_name: query_combined_snap_test --- SelectQuery( - FromTable("cats"), [ SelectColumn("name"), SelectColumn("age"), ], + FromTable("cats"), [], OrWhere([ WhereLowerOrEqual( @@ -21,7 +21,7 @@ SelectQuery( "%ara%", ), ]), - NoLimitNoOffset, [], + NoLimitNoOffset, NoEpilogPart, ) \ No newline at end of file diff --git a/birdie_snapshots/select_query_b.accepted b/birdie_snapshots/select_query_b.accepted index 58a27d8..90e98de 100644 --- a/birdie_snapshots/select_query_b.accepted +++ b/birdie_snapshots/select_query_b.accepted @@ -5,22 +5,22 @@ file: ./test/old_query_test.gleam test_name: query_combined_snap_test --- SelectQuery( - FromTable("cats"), [ SelectColumn("name"), SelectColumn("age"), ], + FromTable("cats"), [], NotWhere(WhereIsNotBool( WhereColumn("is_wild"), False, )), - NoLimitNoOffset, [ OrderByColumnPart( "will_be_removed", Asc, ), ], + NoLimitNoOffset, NoEpilogPart, ) \ No newline at end of file diff --git a/gleam.toml b/gleam.toml index 562a389..df1830d 100644 --- a/gleam.toml +++ b/gleam.toml @@ -8,6 +8,7 @@ description = "An SQL query builder for Gleam targeting Postgres and SQLite - a licences = ["AGPL-3.0-or-later"] repository = { type = "github", user = "inoas", repo = "gleam-cake" } # links = [{ title = "Website", href = "https://gleam.run" }] +gleam = ">= 1.2.0 and < 2.0.0" [dependencies] # act diff --git a/src/cake/internal/query.gleam b/src/cake/internal/query.gleam index abaa237..99a5e45 100644 --- a/src/cake/internal/query.gleam +++ b/src/cake/internal/query.gleam @@ -220,6 +220,8 @@ pub fn order_by_part_to_sql(order_by_part ordbpt: OrderByPart) -> String { // │ Limit & Offset Part │ // └───────────────────────────────────────────────────────────────────────────┘ +// TODO: split limit and offset into separate types and separate functions +// then add one combination function to set both limit and offset. pub type LimitOffsetPart { LimitOffset(limit: Int, offset: Int) LimitNoOffset(limit: Int) @@ -347,23 +349,22 @@ pub fn combined_order_by( // List of SQL parts that will be used to build a select query. pub type SelectQuery { SelectQuery( - from: FromPart, - // comment: String, - // modifier: String, // with: String, + // with_recursive: String, ? select: List(SelectValue), + // modifier: String, // distinct: String, + // window: String, + from: FromPart, join: List(JoinPart), where: WherePart, // group_by: String, // having: String, - // window: String, - // values: String, ? - // with_recursive: String, ? - limit_offset: LimitOffsetPart, order_by: List(OrderByPart), - // kind: SelectQueryKind, + limit_offset: LimitOffsetPart, epilog: EpilogPart, + // comment: String, + // values: String, ? ) }