some renaming of packages; work in progress / just started: storage/tracking
This commit is contained in:
parent
9f09a35f3b
commit
16c9b87d3c
11 changed files with 39 additions and 9 deletions
|
@ -7,8 +7,8 @@ import (
|
||||||
"git.sr.ht/~cco/go-scopes/core/action"
|
"git.sr.ht/~cco/go-scopes/core/action"
|
||||||
"git.sr.ht/~cco/go-scopes/logging"
|
"git.sr.ht/~cco/go-scopes/logging"
|
||||||
"git.sr.ht/~cco/go-scopes/server"
|
"git.sr.ht/~cco/go-scopes/server"
|
||||||
|
sql "git.sr.ht/~cco/go-scopes/storage"
|
||||||
msgstore "git.sr.ht/~cco/go-scopes/storage/message"
|
msgstore "git.sr.ht/~cco/go-scopes/storage/message"
|
||||||
"git.sr.ht/~cco/go-scopes/storage/sql"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Config() lib.Config {
|
func Config() lib.Config {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"demo/etc"
|
"demo/etc"
|
||||||
|
|
||||||
"git.sr.ht/~cco/go-scopes/app"
|
"git.sr.ht/~cco/go-scopes/app"
|
||||||
_ "git.sr.ht/~cco/go-scopes/storage/sql/pgsql"
|
_ "git.sr.ht/~cco/go-scopes/storage/db/pgsql"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -2,7 +2,7 @@ package message
|
||||||
|
|
||||||
import (
|
import (
|
||||||
lib "git.sr.ht/~cco/go-scopes"
|
lib "git.sr.ht/~cco/go-scopes"
|
||||||
"git.sr.ht/~cco/go-scopes/storage/sql"
|
sql "git.sr.ht/~cco/go-scopes/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Store(act lib.Action) bool {
|
func Store(act lib.Action) bool {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package sql
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
@ -167,5 +167,5 @@ func (db *Storage) logErr(err error, info, inp string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
sql_drop = `drop table %s`
|
sql_drop = `drop table if exists %s`
|
||||||
)
|
)
|
15
storage/tracking/sql_code.go
Normal file
15
storage/tracking/sql_code.go
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package tracking
|
||||||
|
|
||||||
|
const sql_table = `
|
||||||
|
create table {{ .tablename }} (
|
||||||
|
trackid {{ .idType }} primary key,
|
||||||
|
{{- range .headFields -}}{{ . }} text,
|
||||||
|
{{ end -}}
|
||||||
|
timestamp timestamptz default current_timestamp,
|
||||||
|
data {{ .jsonType -}}
|
||||||
|
);
|
||||||
|
|
||||||
|
{{ range $i, $cols := .indexes }}
|
||||||
|
create index idx_{{ .i }} on {{ .tablename }} ({{ .cols }});
|
||||||
|
{{- end }}
|
||||||
|
create index idx_timestamp on {{ .tablename }} (timestamp);`
|
15
storage/tracking/tracking.go
Normal file
15
storage/tracking/tracking.go
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
// Package `tracking` defines a generic track (sort of record) type
|
||||||
|
// and a container type that allows storing of tracks in a SQL database.
|
||||||
|
package tracking
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
lib "git.sr.ht/~cco/go-scopes"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Track struct {
|
||||||
|
head map[string]string
|
||||||
|
timestamp *time.Time
|
||||||
|
data lib.Payload
|
||||||
|
}
|
|
@ -2,7 +2,7 @@ package etc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.sr.ht/~cco/go-scopes/config"
|
"git.sr.ht/~cco/go-scopes/config"
|
||||||
"git.sr.ht/~cco/go-scopes/storage/sql"
|
sql "git.sr.ht/~cco/go-scopes/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ConfigSqlite() *sql.Cfg {
|
func ConfigSqlite() *sql.Cfg {
|
||||||
|
|
|
@ -5,10 +5,10 @@ import (
|
||||||
|
|
||||||
"git.sr.ht/~cco/go-scopes/common/testing"
|
"git.sr.ht/~cco/go-scopes/common/testing"
|
||||||
"git.sr.ht/~cco/go-scopes/core/message"
|
"git.sr.ht/~cco/go-scopes/core/message"
|
||||||
|
sql "git.sr.ht/~cco/go-scopes/storage"
|
||||||
|
_ "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"
|
msgstore "git.sr.ht/~cco/go-scopes/storage/message"
|
||||||
"git.sr.ht/~cco/go-scopes/storage/sql"
|
|
||||||
_ "git.sr.ht/~cco/go-scopes/storage/sql/pgsql"
|
|
||||||
_ "git.sr.ht/~cco/go-scopes/storage/sql/sqlite"
|
|
||||||
"git.sr.ht/~cco/go-scopes/tests/etc"
|
"git.sr.ht/~cco/go-scopes/tests/etc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue