48 lines
1005 B
Go
48 lines
1005 B
Go
package operations
|
|
|
|
import (
|
|
"database/sql"
|
|
"sevenkeys/scryfall/types"
|
|
"time"
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
func InsertOrUpdateSet(db *sql.DB, set types.Set) error {
|
|
query := `INSERT INTO ExpansionSet (SetCode, Name, CardCount, IconSvgUri)
|
|
VALUES (?, ?, ?, ?)
|
|
ON DUPLICATE KEY
|
|
Update Name = ?, CardCount = ?, IconSvgUri = ?;`
|
|
|
|
insertOrUpdate, err := db.Prepare(query)
|
|
defer insertOrUpdate.Close()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = insertOrUpdate.Exec(set.Code, set.Name, set.CardCount, set.IconSvgUri, set.Name, set.CardCount, set.IconSvgUri)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|