mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
orm: do not order by default, ordering is slow; also fix a bug for tables without defined primary keys
This commit is contained in:
parent
d7deda5078
commit
fa2de89db9
@ -272,13 +272,12 @@ pub fn orm_select_gen(orm SelectConfig, para string, num bool, qm string, start_
|
||||
}
|
||||
}
|
||||
|
||||
str += ' ORDER BY '
|
||||
// NB: do not order, if the user did not want it explicitly,
|
||||
// ordering is *slow*, especially if there are no indexes!
|
||||
if orm.has_order {
|
||||
str += ' ORDER BY '
|
||||
str += '$para$orm.order$para '
|
||||
str += orm.order_type.to_str()
|
||||
} else {
|
||||
str += '$para$orm.primary$para '
|
||||
str += orm.order_type.to_str()
|
||||
}
|
||||
|
||||
if orm.has_limit {
|
||||
|
@ -51,7 +51,7 @@ fn test_orm_select_gen() {
|
||||
fields: get_select_fields()
|
||||
}, "'", true, '?', 0, orm.QueryData{})
|
||||
|
||||
assert query == "SELECT 'id', 'test', 'abc' FROM 'test_table' ORDER BY 'id' ASC;"
|
||||
assert query == "SELECT 'id', 'test', 'abc' FROM 'test_table';"
|
||||
}
|
||||
|
||||
fn test_orm_select_gen_with_limit() {
|
||||
@ -61,7 +61,7 @@ fn test_orm_select_gen_with_limit() {
|
||||
has_limit: true
|
||||
}, "'", true, '?', 0, orm.QueryData{})
|
||||
|
||||
assert query == "SELECT 'id', 'test', 'abc' FROM 'test_table' ORDER BY 'id' ASC LIMIT ?0;"
|
||||
assert query == "SELECT 'id', 'test', 'abc' FROM 'test_table' LIMIT ?0;"
|
||||
}
|
||||
|
||||
fn test_orm_select_gen_with_where() {
|
||||
@ -75,7 +75,7 @@ fn test_orm_select_gen_with_where() {
|
||||
is_and: [true]
|
||||
})
|
||||
|
||||
assert query == "SELECT 'id', 'test', 'abc' FROM 'test_table' WHERE 'abc' = ?0 AND 'test' > ?1 ORDER BY 'id' ASC;"
|
||||
assert query == "SELECT 'id', 'test', 'abc' FROM 'test_table' WHERE 'abc' = ?0 AND 'test' > ?1;"
|
||||
}
|
||||
|
||||
fn test_orm_select_gen_with_order() {
|
||||
@ -96,7 +96,7 @@ fn test_orm_select_gen_with_offset() {
|
||||
has_offset: true
|
||||
}, "'", true, '?', 0, orm.QueryData{})
|
||||
|
||||
assert query == "SELECT 'id', 'test', 'abc' FROM 'test_table' ORDER BY 'id' ASC OFFSET ?0;"
|
||||
assert query == "SELECT 'id', 'test', 'abc' FROM 'test_table' OFFSET ?0;"
|
||||
}
|
||||
|
||||
fn test_orm_select_gen_with_all() {
|
||||
|
Loading…
Reference in New Issue
Block a user