mirror of
https://github.com/lloeki/rebel.git
synced 2025-12-06 10:04:39 +01:00
select: order_by limit
This commit is contained in:
parent
179cba86b6
commit
4ce508862d
2 changed files with 49 additions and 4 deletions
|
|
@ -46,4 +46,21 @@ class TestExec < Minitest::Test
|
|||
insert_into :foo, id: 1, col: 'whatevs'
|
||||
assert_equal(select('*', from: :foo), [[1, 'whatevs']])
|
||||
end
|
||||
|
||||
def test_limit
|
||||
create_table :foo, id: 'INT', col: 'VARCHAR(255)'
|
||||
insert_into :foo, id: 1, col: 'whatevs'
|
||||
insert_into :foo, id: 2, col: 'something else'
|
||||
assert_equal(select('*', from: :foo, limit: 1), [[1, 'whatevs']])
|
||||
end
|
||||
|
||||
def test_order_by
|
||||
create_table :foo, id: 'INT', col: 'VARCHAR(255)', value: 'VARCHAR(255)'
|
||||
insert_into :foo, id: 1, value: '2', col: 'whatevs'
|
||||
insert_into :foo, id: 2, value: '2', col: 'something'
|
||||
insert_into :foo, id: 3, value: '1', col: 'else'
|
||||
assert_equal(select(:id, from: :foo, order_by: :col), [[3], [2], [1]])
|
||||
assert_equal(select(:id, from: :foo, order_by: {id: :desc}), [[3], [2], [1]])
|
||||
assert_equal(select(:id, from: :foo, order_by: [value: :asc, id: :asc]), [[3], [1], [2]])
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue