1
0
Fork 0

Get latest update for given file

main
Daniele Tricoli 7 years ago
parent eb485363e2
commit 8958d67026
  1. 22
      sql/sql.go

@ -3,6 +3,7 @@ package sql // import "eriol.xyz/piken/sql"
import (
"database/sql"
"os"
"time"
_ "github.com/mattn/go-sqlite3"
)
@ -47,6 +48,7 @@ const (
simple_lowercase_mapping,
simple_titlecase_mapping)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
getLastUpdateQuery = `SELECT date FROM last_update WHERE filename = ?`
)
type Store struct {
@ -118,3 +120,23 @@ func (s *Store) LoadFromRecords(records [][]string) error {
return nil
}
// Get latest update for given file.
func (s *Store) GetLastUpdate(filename string) (time.Time, error) {
var t string
s.db.QueryRow(getLastUpdateQuery, filename).Scan(&t)
// If the query is empty return the beginning of time.
if t == "" {
return time.Unix(0, 0), nil
}
tp, err := time.Parse(time.RFC3339Nano, t)
if err != nil {
return time.Unix(0, 0), err
}
return tp, nil
}

Loading…
Cancel
Save