From ed3777ec3ac16e5e05ae170bdec334f1bd41d5f9 Mon Sep 17 00:00:00 2001 From: "Billy.Zheng" Date: Fri, 21 Jun 2024 13:51:56 +0800 Subject: [PATCH] dirty hack for pass string literal into a self-defined join method --- src/avram/query_builder.cr | 9 ++++++++- src/avram/queryable.cr | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/avram/query_builder.cr b/src/avram/query_builder.cr index 1d67e8703..b9f22b2ee 100644 --- a/src/avram/query_builder.cr +++ b/src/avram/query_builder.cr @@ -8,6 +8,7 @@ class Avram::QueryBuilder @offset : Int32? @wheres = [] of Avram::Where::Condition @joins = [] of Avram::Join::SqlClause + @raw_joins = [] of String @orders = [] of Avram::OrderByClause @groups = [] of ColumnName @selections : String = "*" @@ -314,12 +315,18 @@ class Avram::QueryBuilder self end + def join(join_string : String) : self + @raw_joins << join_string + self + end + def joins : Array(Avram::Join::SqlClause) @joins.uniq(&.to_sql) end private def joins_sql : String - joins.join(" ", &.to_sql) + # joins.join(" ", &.to_sql) + @raw_joins.join(" ") end def where(where_clause : Avram::Where::Condition) : self diff --git a/src/avram/queryable.cr b/src/avram/queryable.cr index ccbb9bdb0..760cd7d7f 100644 --- a/src/avram/queryable.cr +++ b/src/avram/queryable.cr @@ -124,6 +124,10 @@ module Avram::Queryable(T) clone.tap &.query.join(join_clause) end + def join(join_string : String) : self + clone.tap &.query.join(join_string) + end + def where(column : Symbol, value) : self clone.tap &.query.where(Avram::Where::Equal.new(column, value.to_s)) end