chore(go): new chat message db repository. Closes #3081 (#4161)

This commit is contained in:
Gabe Kangas
2025-01-20 16:32:25 -08:00
committed by GitHub
parent db0ddfe009
commit c1f4096e11
15 changed files with 604 additions and 507 deletions

View File

@@ -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)

View File

@@ -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.

View File

@@ -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
}