work in progress: storage/tracking

This commit is contained in:
Helmut Merz 2024-03-22 11:20:16 +01:00
parent 16c9b87d3c
commit 3923d49666
3 changed files with 30 additions and 6 deletions

View file

@ -1,6 +1,6 @@
package tracking
const sql_table = `
const Sql_table = `
create table {{ .tablename }} (
trackid {{ .idType }} primary key,
{{- range .headFields -}}{{ . }} text,

View file

@ -6,10 +6,27 @@ import (
"time"
lib "git.sr.ht/~cco/go-scopes"
sql "git.sr.ht/~cco/go-scopes/storage"
)
type Track struct {
head map[string]string
timestamp *time.Time
data lib.Payload
TrackId uint
Head map[string]string
TimeStamp *time.Time
Data lib.Payload
Container *Container
}
type Container struct {
headFields []string
indexes [][]string
storage *sql.Storage
}
func MakeContainer(st *sql.Storage) Container {
return Container{
headFields: []string{"taskId", "userName"},
indexes: [][]string{[]string{"taskId", "userName"}, []string{"userName"}},
storage: st,
}
}

View file

@ -9,6 +9,7 @@ import (
_ "git.sr.ht/~cco/go-scopes/storage/db/pgsql"
_ "git.sr.ht/~cco/go-scopes/storage/db/sqlite"
msgstore "git.sr.ht/~cco/go-scopes/storage/message"
"git.sr.ht/~cco/go-scopes/storage/tracking"
"git.sr.ht/~cco/go-scopes/tests/etc"
)
@ -30,7 +31,8 @@ func TestPgsql(tb *tbase.T) {
func DoTests(t *testing.T, cfg *sql.Cfg, db *sql.Storage) {
t.Run("base", func(t *testing.T) { BaseTest(t, cfg, db) })
t.Run("message", func(t *testing.T) { MsgstoreTest(t, cfg, db) })
t.Run("message", func(t *testing.T) { MessageTest(t, cfg, db) })
t.Run("tracking", func(t *testing.T) { TrackingTest(t, cfg, db) })
}
type greet struct {
@ -60,11 +62,16 @@ func BaseTest(t *testing.T, cfg *sql.Cfg, db *sql.Storage) {
t.AssertEqual(data[1].label, "Good Afternoon")
}
func MsgstoreTest(t *testing.T, cfg *sql.Cfg, db *sql.Storage) {
func MessageTest(t *testing.T, cfg *sql.Cfg, db *sql.Storage) {
msg := message.SimpleMessage("data")
msgstore.StoreDB(db, msg)
}
func TrackingTest(t *testing.T, cfg *sql.Cfg, db *sql.Storage) {
_ = tracking.Sql_table
_ = tracking.MakeContainer(db)
}
func resetSqlite(db *sql.Storage) {
db.DropTable("test")
db.Exec(sqlite_create_table)