Compare commits

..

No commits in common. "3646aa096126ac2bcf1cda1aeba413c67a96a5de" and "95a847d97cd8569a26748d471310dea9a9564e0a" have entirely different histories.

3 changed files with 14 additions and 23 deletions

View File

@ -4,8 +4,5 @@ plan-deploy:
sync-run:
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:
docker run -e POSTGRES_USER=test -e POSTGRES_PASSWORD=test -e POSTGRES_DB=planner -p 5432:5432 postgres:16

View File

@ -12,16 +12,12 @@ import (
)
func main() {
confPath := os.Getenv("PLAN_CONFIG_PATH")
if confPath == "" {
userConfigDir, err := os.UserConfigDir()
if err != nil {
fmt.Printf("could not get config path: %s\n", err)
os.Exit(1)
}
confPath = filepath.Join(userConfigDir, "planner", "plan", "config.yaml")
confPath, err := os.UserConfigDir()
if err != nil {
fmt.Printf("could not get config path: %s\n", err)
os.Exit(1)
}
conf, err := LoadConfig(confPath)
conf, err := LoadConfig(filepath.Join(confPath, "planner", "plan", "config.yaml"))
if err != nil {
fmt.Printf("could not open config file: %s\n", err)
os.Exit(1)

View File

@ -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 {
var recurrerJSON any
var recurrerJSON []byte
var err error
if i.Recurrer != nil {
var err error
recurrerJSON, err = json.Marshal(i.Recurrer)
if err != nil {
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)
VALUES ($1, $2, $3, $4, $5, $6, $7)
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() {
var i item.Item
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 {
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
}
if recurrerJSON.Valid && recurrerJSON.String != "" {
if len(recurrerJSON) > 0 {
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)
}
i.Recurrer = &recurrer
@ -149,13 +147,13 @@ func (p *Postgres) RecursBefore(date time.Time) ([]item.Item, error) {
for rows.Next() {
var i item.Item
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 {
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
}
if recurrerJSON.Valid && recurrerJSON.String != "" {
if len(recurrerJSON) > 0 {
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)
}
i.Recurrer = &recurrer