38 lines
774 B
Go
38 lines
774 B
Go
package database
|
|
|
|
import (
|
|
"database/sql"
|
|
"time"
|
|
)
|
|
|
|
const CacheTypeAllCardsBulkData = "AllCardsBulkData"
|
|
|
|
func GetCacheTimestampByType(db *sql.DB, cacheType string) (string, error) {
|
|
var timestamp string
|
|
|
|
query := "SELECT Stamp FROM CacheTimestamp WHERE CacheType = ?;"
|
|
err := db.QueryRow(query, cacheType).Scan(×tamp)
|
|
|
|
return timestamp, err
|
|
}
|
|
|
|
func InsertOrUpdateCacheTimestampByType(db *sql.DB, cacheType string, stamp time.Time) error {
|
|
query := `INSERT INTO CacheTimestamp (CacheType, Stamp)
|
|
VALUES (?, ?)
|
|
ON DUPLICATE KEY
|
|
UPDATE Stamp = ?;`
|
|
|
|
insertOrUpdate, err := db.Prepare(query)
|
|
defer insertOrUpdate.Close()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = insertOrUpdate.Exec(cacheType, stamp, stamp)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|