class Bones::SQL::SQL
- Bones::SQL::SQL
- Reference
- Object
Included Modules
Defined in:
bones/api/sql.crInstance Method Summary
-
#from(table : TableDef) : SQL
From SQL clause, with a TableDef argument.
- #from_table : TableDef
- #from_table=(from_table : TableDef)
- #group_by : GroupBy
-
#group_by(*columns) : SQL
Group By SQL clause, you can add a series of columns.
- #group_by=(group_by : GroupBy)
-
#having(aggregate_function = AggregateFunction.new) : SQL
Having SQL clause, allow only one aggregate function argument, the rest can be concatenated.
- #having=(having : Having | Nil)
-
#limit(value : Int32) : SQL
Limit SQL clause, accept only Int32 values.
- #limit : Limit | Nil
- #limit=(limit : Limit | Nil)
-
#offset(value : Int32) : SQL
Offset SQL clause, accept only Int32 values.
- #offset : Offset | Nil
- #offset=(offset : Offset | Nil)
- #order_by : OrderBy
-
#order_by(*columns) : SQL
Order By SQL clause, you can add a series of columns.
- #order_by=(order_by : OrderBy)
-
#select(*columns) : SQL
Starts the query builder, it's the select clause with a series of columns arguments.
- #select_fields : Select
- #select_fields=(select_fields : Select)
-
#to_sql_string : String
Returns the SQL query in a String.
-
#where(column = Column.new) : SQL
Where SQL clause, allow only one column argument, the rest can be concatenated.
- #where=(where : Where | Nil)
Instance methods inherited from module Bones::SQL::QueryJoins
inner_join(from_table = @from_table, to_table = TableDef.new, on = Column.new) : SQL
inner_join,
join_tables : Array(Joins::Join)
join_tables,
join_tables=(join_tables : Array(Joins::Join))
join_tables=,
left_join(from_table = @from_table, to_table = TableDef.new, on = Column.new) : SQL
left_join,
outer_join(from_table = @from_table, to_table = TableDef.new, on = Column.new) : SQL
outer_join,
right_join(from_table = @from_table, to_table = TableDef.new, on = Column.new) : SQL
right_join
Instance methods inherited from module Bones::SQL::AggregateFunctions
avg(column = Column.new) : AggregateFunction
avg,
count(column = Column.new) : AggregateFunction
count,
count_all(table : TableDef | Nil = nil) : AggregateFunction
count_all,
sum(column = Column.new) : AggregateFunction
sum
Instance Method Detail
From SQL clause, with a TableDef argument.
sql.select(my_column, sql.sum(my_another_column)).from(my_table)
Group By SQL clause, you can add a series of columns. It checks all columns in select clause are added here or in an aggregate function.
sql.select(my_column).from(my_table).group_by(my_column)
Having SQL clause, allow only one aggregate function argument, the rest can be concatenated.
sql.select(my_column).from(my_table).having(sql.count(my_column).gt(1).and(sql.avg(my_another_column).gt(10)))
Limit SQL clause, accept only Int32 values.
sql.select(my_column).from(my_table).limit(100)
Offset SQL clause, accept only Int32 values.
sql.select(my_column).from(my_table).limit(100).offset(1)
Order By SQL clause, you can add a series of columns.
sql.select(my_column).from(my_table).order_by(my_column.asc)
Starts the query builder, it's the select clause with a series of columns arguments.
class MyColumn < Bones::Column
column name : String
end
class MyAnotherColumn < Bones::Column
column name : Int32
end
class MyTable < Bones::TableDef
end
my_table = MyTable.new
my_column = MyColumn.new(my_table)
sql = Bones::SQL::SQL.new
sql.select(my_column, sql.sum(my_another_column))
Returns the SQL query in a String.
sql.select(my_column).from(my_table).where(my_column.eq("Peter").and(my_another_column.gt(10))).to_sql_string
# => SELECT my_table.my_column FROM my_table WHERE my_table.my_column = 'Peter' AND my_table.my_another_column > 10
Where SQL clause, allow only one column argument, the rest can be concatenated.
sql.select(my_column).from(my_table).where(my_column.eq("Peter").and(my_another_column.gt(10)))