@@ -75,6 +75,7 @@ func SetupPersistence(file string) error {
|
||||
_, _ = db.Exec("pragma temp_store = memory")
|
||||
_, _ = db.Exec("pragma wal_checkpoint(full)")
|
||||
|
||||
tables.CreateConfigTable(db)
|
||||
tables.CreateWebhooksTable(db)
|
||||
tables.CreateUsersTable(db)
|
||||
tables.CreateAccessTokenTable(db)
|
||||
|
||||
@@ -107,19 +107,11 @@ func (ds *Datastore) Save(e models.ConfigEntry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Setup will create the datastore table and perform initial initialization.
|
||||
// Setup will perform initial initialization.
|
||||
func (ds *Datastore) Setup() {
|
||||
ds.cache = make(map[string][]byte)
|
||||
ds.DB = GetDatabase()
|
||||
ds.DbLock = &sync.Mutex{}
|
||||
|
||||
createTableSQL := `CREATE TABLE IF NOT EXISTS datastore (
|
||||
"key" string NOT NULL PRIMARY KEY,
|
||||
"value" BLOB,
|
||||
"timestamp" DATE DEFAULT CURRENT_TIMESTAMP NOT NULL
|
||||
);`
|
||||
|
||||
ds.MustExec(createTableSQL)
|
||||
}
|
||||
|
||||
// Reset will delete all config entries in the datastore and start over.
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package data
|
||||
|
||||
// GetMessagesCount will return the number of messages in the database.
|
||||
func GetMessagesCount() int64 {
|
||||
query := `SELECT COUNT(*) FROM messages`
|
||||
rows, err := _db.Query(query)
|
||||
if err != nil || rows.Err() != nil {
|
||||
return 0
|
||||
}
|
||||
defer rows.Close()
|
||||
var count int64
|
||||
for rows.Next() {
|
||||
if err := rows.Scan(&count); err != nil {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
Reference in New Issue
Block a user