Add state blob to source
This commit is contained in:
parent
68038839ec
commit
5692f60318
@ -238,6 +238,18 @@ func GetAllItemsForSource(db *DB, source string) ([]Item, error) {
|
||||
`, source)
|
||||
}
|
||||
|
||||
func GetState(db *DB, source string) ([]byte, error) {
|
||||
row := db.QueryRow("select state from sources where name = ?", source)
|
||||
var state []byte
|
||||
err := row.Scan(&state)
|
||||
return state, err
|
||||
}
|
||||
|
||||
func SetState(db *DB, source string, state []byte) error {
|
||||
_, err := db.Exec("update sources set state = ? where name = ?", state, source)
|
||||
return err
|
||||
}
|
||||
|
||||
// Given the results of a fetch, add new items, update existing items, and delete expired items.
|
||||
//
|
||||
// Returns the number of new and deleted items on success.
|
||||
|
@ -291,3 +291,30 @@ func TestOnCreateAction(t *testing.T) {
|
||||
t.Fatal("unexpected changes to id, active, or created fields")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSourceState(t *testing.T) {
|
||||
db := EphemeralDb(t)
|
||||
if err := AddSource(db, "s"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
state, err := GetState(db, "s")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(state) != 0 {
|
||||
t.Fatal("expected no state on a fresh source")
|
||||
}
|
||||
|
||||
if err = SetState(db, "s", []byte("hello, world")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
state, err = GetState(db, "s")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(state) != "hello, world" {
|
||||
t.Fatalf("expected hello, world, got %s", state)
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
create table sources(
|
||||
name text not null,
|
||||
state blob,
|
||||
primary key (name)
|
||||
) strict;
|
||||
create table actions(
|
||||
|
Loading…
Reference in New Issue
Block a user