Compare commits
No commits in common. "3646aa096126ac2bcf1cda1aeba413c67a96a5de" and "95a847d97cd8569a26748d471310dea9a9564e0a" have entirely different histories.
3646aa0961
...
95a847d97c
3
Makefile
3
Makefile
|
@ -4,8 +4,5 @@ plan-deploy:
|
||||||
sync-run:
|
sync-run:
|
||||||
cd sync/service && go run . -dbname localhost -dbport 5432 -dbname planner -dbuser test -dbpassword test -port 8092 -key testKey
|
cd sync/service && go run . -dbname localhost -dbport 5432 -dbname planner -dbuser test -dbpassword test -port 8092 -key testKey
|
||||||
|
|
||||||
sync-debug:
|
|
||||||
cd sync/service && dlv debug . -- -dbname localhost -dbport 5432 -dbname planner -dbuser test -dbpassword test -port 8092 -key testKey
|
|
||||||
|
|
||||||
database:
|
database:
|
||||||
docker run -e POSTGRES_USER=test -e POSTGRES_PASSWORD=test -e POSTGRES_DB=planner -p 5432:5432 postgres:16
|
docker run -e POSTGRES_USER=test -e POSTGRES_PASSWORD=test -e POSTGRES_DB=planner -p 5432:5432 postgres:16
|
||||||
|
|
|
@ -12,16 +12,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
confPath := os.Getenv("PLAN_CONFIG_PATH")
|
confPath, err := os.UserConfigDir()
|
||||||
if confPath == "" {
|
|
||||||
userConfigDir, err := os.UserConfigDir()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("could not get config path: %s\n", err)
|
fmt.Printf("could not get config path: %s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
confPath = filepath.Join(userConfigDir, "planner", "plan", "config.yaml")
|
conf, err := LoadConfig(filepath.Join(confPath, "planner", "plan", "config.yaml"))
|
||||||
}
|
|
||||||
conf, err := LoadConfig(confPath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("could not open config file: %s\n", err)
|
fmt.Printf("could not open config file: %s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
@ -59,18 +59,16 @@ func NewPostgres(host, port, dbname, user, password string) (*Postgres, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Postgres) Update(i item.Item, ts time.Time) error {
|
func (p *Postgres) Update(i item.Item, ts time.Time) error {
|
||||||
var recurrerJSON any
|
var recurrerJSON []byte
|
||||||
if i.Recurrer != nil {
|
|
||||||
var err error
|
var err error
|
||||||
|
if i.Recurrer != nil {
|
||||||
recurrerJSON, err = json.Marshal(i.Recurrer)
|
recurrerJSON, err = json.Marshal(i.Recurrer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
return fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
recurrerJSON = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := p.db.Exec(`
|
_, err = p.db.Exec(`
|
||||||
INSERT INTO items (id, kind, updated, deleted, body, recurrer, recur_next)
|
INSERT INTO items (id, kind, updated, deleted, body, recurrer, recur_next)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||||
ON CONFLICT (id) DO UPDATE
|
ON CONFLICT (id) DO UPDATE
|
||||||
|
@ -113,13 +111,13 @@ func (p *Postgres) Updated(ks []item.Kind, t time.Time) ([]item.Item, error) {
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var i item.Item
|
var i item.Item
|
||||||
var recurNext sql.NullTime
|
var recurNext sql.NullTime
|
||||||
var recurrerJSON sql.NullString
|
var recurrerJSON []byte
|
||||||
if err := rows.Scan(&i.ID, &i.Kind, &i.Updated, &i.Deleted, &i.Body, &recurrerJSON, &recurNext); err != nil {
|
if err := rows.Scan(&i.ID, &i.Kind, &i.Updated, &i.Deleted, &i.Body, &recurrerJSON, &recurNext); err != nil {
|
||||||
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
||||||
}
|
}
|
||||||
if recurrerJSON.Valid && recurrerJSON.String != "" {
|
if len(recurrerJSON) > 0 {
|
||||||
var recurrer item.Recur
|
var recurrer item.Recur
|
||||||
if err := json.Unmarshal([]byte(recurrerJSON.String), &recurrer); err != nil {
|
if err := json.Unmarshal(recurrerJSON, &recurrer); err != nil {
|
||||||
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
||||||
}
|
}
|
||||||
i.Recurrer = &recurrer
|
i.Recurrer = &recurrer
|
||||||
|
@ -149,13 +147,13 @@ func (p *Postgres) RecursBefore(date time.Time) ([]item.Item, error) {
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var i item.Item
|
var i item.Item
|
||||||
var recurNext sql.NullTime
|
var recurNext sql.NullTime
|
||||||
var recurrerJSON sql.NullString
|
var recurrerJSON []byte
|
||||||
if err := rows.Scan(&i.ID, &i.Kind, &i.Updated, &i.Deleted, &i.Body, &recurrerJSON, &recurNext); err != nil {
|
if err := rows.Scan(&i.ID, &i.Kind, &i.Updated, &i.Deleted, &i.Body, &recurrerJSON, &recurNext); err != nil {
|
||||||
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
||||||
}
|
}
|
||||||
if recurrerJSON.Valid && recurrerJSON.String != "" {
|
if len(recurrerJSON) > 0 {
|
||||||
var recurrer item.Recur
|
var recurrer item.Recur
|
||||||
if err := json.Unmarshal([]byte(recurrerJSON.String), &recurrer); err != nil {
|
if err := json.Unmarshal(recurrerJSON, &recurrer); err != nil {
|
||||||
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
||||||
}
|
}
|
||||||
i.Recurrer = &recurrer
|
i.Recurrer = &recurrer
|
||||||
|
|
Loading…
Reference in New Issue