Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
inoas committed Apr 24, 2024
1 parent 9222971 commit 11e9bf2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
20 changes: 17 additions & 3 deletions src/cake.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import gleam/erlang/process

pub fn main() {
let _ = run_dummy_select()
let _ = run_dummy_union()
let _ = run_dummy_union_all()

Nil
}
Expand Down Expand Up @@ -61,7 +61,7 @@ pub fn run_dummy_select() {
process.sleep(100)
}

pub fn run_dummy_union() {
pub fn run_dummy_union_all() {
iox.print_dashes()

let select_query =
Expand All @@ -71,12 +71,26 @@ pub fn run_dummy_union() {
query.select_fragment_from_string("name"),
query.select_fragment_from_string("age"),
])

let select_query_a =
select_query
|> query.select_query_set_where(query.WhereColLowerOrEqualParam(
"age",
param.IntParam(4),
))
let select_query_b =
select_query
|> query.select_query_set_where(query.WhereColGreaterOrEqualParam(
"age",
param.IntParam(7),
))

// UNION must take ORDER BY at the outside
// it can also take an own LIMIT and OFFSET
// |> query.select_query_order_asc("name")

let union_query =
query.union_distinct_query_new([select_query, select_query])
query.union_all_query_new([select_query_a, select_query_b])
|> query.query_union_wrap
|> iox.dbg

Expand Down
6 changes: 3 additions & 3 deletions src/cake/adapter/postgres_adapter.gleam
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import cake/internal/query.{type Query}
import cake/param.{BoolParam, FloatParam, IntParam, NullParam, StringParam}
import cake/prepared_statement.{type PreparedStatement}
import cake/prepared_statement_builder/builder

// import cake/stdlib/iox
import cake/param.{BoolParam, FloatParam, IntParam, NullParam, StringParam}
import cake/stdlib/iox
import gleam/dynamic
import gleam/list
import gleam/pgo.{type Connection}
Expand Down Expand Up @@ -53,6 +52,7 @@ pub fn run_query(db_conn, query qry: Query, decoder decoder) {

let result =
sql
|> iox.dbg_label("sql")
|> pgo.execute(on: db_conn, with: db_params, expecting: decoder)

case result {
Expand Down
6 changes: 3 additions & 3 deletions src/cake/adapter/sqlite_adapter.gleam
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import cake/internal/query.{type Query}
import cake/param.{BoolParam, FloatParam, IntParam, NullParam, StringParam}
import cake/prepared_statement.{type PreparedStatement}
import cake/prepared_statement_builder/builder

// import cake/stdlib/iox
import cake/param.{BoolParam, FloatParam, IntParam, NullParam, StringParam}
import cake/stdlib/iox
import gleam/list
import sqlight

Expand Down Expand Up @@ -40,6 +39,7 @@ pub fn run_query(db_connection db_conn, query qry: Query, decoder decoder) {
// |> iox.dbg_label("db_params")

sql
|> iox.dbg_label("sql")
|> sqlight.query(on: db_conn, with: db_params, expecting: decoder)
}

Expand Down

0 comments on commit 11e9bf2

Please sign in to comment.