fix date sync
This commit is contained in:
parent
4d3c81d85a
commit
4ce3538202
Binary file not shown.
|
@ -39,4 +39,5 @@ var migrations = []string{
|
||||||
`INSERT INTO localids (id, local_id)
|
`INSERT INTO localids (id, local_id)
|
||||||
SELECT id, local_id FROM localids_backup`,
|
SELECT id, local_id FROM localids_backup`,
|
||||||
`DROP TABLE localids_backup`,
|
`DROP TABLE localids_backup`,
|
||||||
|
`ALTER TABLE items ADD COLUMN date TEXT NOT NULL DEFAULT ''`,
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ func NewSqliteSync(db *sql.DB) *SqliteSync {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqliteSync) FindAll() ([]item.Item, error) {
|
func (s *SqliteSync) FindAll() ([]item.Item, error) {
|
||||||
rows, err := s.db.Query("SELECT id, kind, updated, deleted, recurrer, recur_next, body FROM items")
|
rows, err := s.db.Query("SELECT id, kind, updated, deleted, date, recurrer, recur_next, body FROM items")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%w: failed to query items: %v", ErrSqliteFailure, err)
|
return nil, fmt.Errorf("%w: failed to query items: %v", ErrSqliteFailure, err)
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,8 @@ func (s *SqliteSync) FindAll() ([]item.Item, error) {
|
||||||
var items []item.Item
|
var items []item.Item
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var i item.Item
|
var i item.Item
|
||||||
var updatedStr, recurStr, recurNextStr string
|
var updatedStr, dateStr, recurStr, recurNextStr string
|
||||||
err := rows.Scan(&i.ID, &i.Kind, &updatedStr, &i.Deleted, &recurStr, &recurNextStr, &i.Body)
|
err := rows.Scan(&i.ID, &i.Kind, &updatedStr, &i.Deleted, &dateStr, &recurStr, &recurNextStr, &i.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%w: failed to scan item: %v", ErrSqliteFailure, err)
|
return nil, fmt.Errorf("%w: failed to scan item: %v", ErrSqliteFailure, err)
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ func (s *SqliteSync) FindAll() ([]item.Item, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse updated time: %v", err)
|
return nil, fmt.Errorf("failed to parse updated time: %v", err)
|
||||||
}
|
}
|
||||||
|
i.Date = item.NewDateFromString(dateStr)
|
||||||
i.Recurrer = item.NewRecurrer(recurStr)
|
i.Recurrer = item.NewRecurrer(recurStr)
|
||||||
i.RecurNext = item.NewDateFromString(recurNextStr)
|
i.RecurNext = item.NewDateFromString(recurNextStr)
|
||||||
|
|
||||||
|
@ -58,12 +59,13 @@ func (s *SqliteSync) Store(i item.Item) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := s.db.Exec(
|
_, err := s.db.Exec(
|
||||||
`INSERT OR REPLACE INTO items (id, kind, updated, deleted, recurrer, recur_next, body)
|
`INSERT OR REPLACE INTO items (id, kind, updated, deleted, date, recurrer, recur_next, body)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||||
i.ID,
|
i.ID,
|
||||||
i.Kind,
|
i.Kind,
|
||||||
i.Updated.UTC().Format(time.RFC3339),
|
i.Updated.UTC().Format(time.RFC3339),
|
||||||
i.Deleted,
|
i.Deleted,
|
||||||
|
i.Date.String(),
|
||||||
recurStr,
|
recurStr,
|
||||||
i.RecurNext.String(),
|
i.RecurNext.String(),
|
||||||
sql.NullString{String: i.Body, Valid: i.Body != ""}, // This allows empty string but not NULL
|
sql.NullString{String: i.Body, Valid: i.Body != ""}, // This allows empty string but not NULL
|
||||||
|
|
Loading…
Reference in New Issue