Order items by .time or .created
This commit is contained in:
parent
c4d53eb993
commit
647584e55b
@ -185,6 +185,7 @@ func GetItem(db *DB, source string, id string) (Item, error) {
|
||||
from items
|
||||
where source = ?
|
||||
and id = ?
|
||||
order by case when time = 0 then created else time end, id
|
||||
`, source, id)
|
||||
if err != nil {
|
||||
return Item{}, err
|
||||
@ -201,6 +202,7 @@ func GetAllActiveItems(db *DB) ([]Item, error) {
|
||||
source, id, created, active, title, author, body, link, time, json(action)
|
||||
from items
|
||||
where active <> 0
|
||||
order by case when time = 0 then created else time end, id
|
||||
`)
|
||||
}
|
||||
|
||||
@ -209,6 +211,7 @@ func GetAllItems(db *DB) ([]Item, error) {
|
||||
select
|
||||
source, id, created, active, title, author, body, link, time, json(action)
|
||||
from items
|
||||
order by case when time = 0 then created else time end, id
|
||||
`)
|
||||
}
|
||||
|
||||
@ -220,6 +223,7 @@ func GetActiveItemsForSource(db *DB, source string) ([]Item, error) {
|
||||
where
|
||||
source = ?
|
||||
and active <> 0
|
||||
order by case when time = 0 then created else time end, id
|
||||
`, source)
|
||||
}
|
||||
|
||||
@ -230,6 +234,7 @@ func GetAllItemsForSource(db *DB, source string) ([]Item, error) {
|
||||
from items
|
||||
where
|
||||
source = ?
|
||||
order by case when time = 0 then created else time end, id
|
||||
`, source)
|
||||
}
|
||||
|
||||
|
@ -73,8 +73,9 @@ func TestAddItem(t *testing.T) {
|
||||
if len(items) != 2 {
|
||||
t.Fatal("should get two items")
|
||||
}
|
||||
AssertItemIs(t, items[0], "test/one/true/////0")
|
||||
AssertItemIs(t, items[1], "test/two/true/title/author/body/link/123456")
|
||||
// order is by (time ?? created) so this ordering is correct as long as you don't run it in early 1970
|
||||
AssertItemIs(t, items[0], "test/two/true/title/author/body/link/123456")
|
||||
AssertItemIs(t, items[1], "test/one/true/////0")
|
||||
|
||||
if _, err = DeactivateItem(db, "test", "one"); err != nil {
|
||||
t.Fatal(err)
|
||||
|
Loading…
Reference in New Issue
Block a user