Skip to content

Commit

Permalink
dirty hack for pass string literal into a self-defined join method
Browse files Browse the repository at this point in the history
  • Loading branch information
zw963 committed Jun 21, 2024
1 parent 3a27ebb commit ed3777e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/avram/query_builder.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "*"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/avram/queryable.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ed3777e

Please sign in to comment.