feat: abstract database drivers

This commit is contained in:
Steven
2023-12-17 13:56:41 +08:00
parent 6350b19478
commit 9173c8f19a
39 changed files with 1707 additions and 1356 deletions

View File

@ -1,7 +1,6 @@
package store
import (
"database/sql"
"sync"
"github.com/yourselfhosted/slash/server/profile"
@ -9,8 +8,8 @@ import (
// Store provides database access to all raw objects.
type Store struct {
db *sql.DB
profile *profile.Profile
driver Driver
workspaceSettingCache sync.Map // map[string]*WorkspaceSetting
userCache sync.Map // map[int]*User
@ -19,14 +18,14 @@ type Store struct {
}
// New creates a new instance of Store.
func New(db *sql.DB, profile *profile.Profile) *Store {
func New(driver Driver, profile *profile.Profile) *Store {
return &Store{
db: db,
driver: driver,
profile: profile,
}
}
// Close closes the database connection.
func (s *Store) Close() error {
return s.db.Close()
return s.driver.Close()
}