Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dirty hack for pass string literal into a self-defined join method #1049

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading