sql queries T.T

This commit is contained in:
Fenny
2020-11-05 06:01:59 +01:00
parent 2458ab7395
commit 5571999805
6 changed files with 31 additions and 1 deletions

View File

@@ -76,7 +76,7 @@ func New(config ...Config) *Storage {
gcInterval: cfg.GCInterval,
db: db,
sqlSelect: fmt.Sprintf("SELECT data, exp FROM %s WHERE id=?;", cfg.Table),
sqlInsert: fmt.Sprintf("INSERT OR REPLACE INTO %s (id, data, exp) VALUES (?,?,?)", cfg.Table),
sqlInsert: fmt.Sprintf("INSERT INTO %s (id, data, exp) VALUES (?,?,?)", cfg.Table),
sqlDelete: fmt.Sprintf("DELETE FROM %s WHERE id=?", cfg.Table),
sqlClear: fmt.Sprintf("DELETE FROM %s;", cfg.Table),
sqlGC: fmt.Sprintf("DELETE FROM %s WHERE exp <= ?", cfg.Table),
@@ -142,6 +142,11 @@ func (s *Storage) Clear() error {
return err
}
// Close the storage
func (s *Storage) Close() error {
return s.db.Close()
}
// Garbage collector to delete expired keys
func (s *Storage) gc() {
tick := time.NewTicker(s.gcInterval)