mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-12-23 06:42:41 +00:00
Fix db.go
This commit is contained in:
parent
f0eca194e2
commit
97e9aca156
1 changed files with 25 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path"
|
||||
|
|
@ -71,3 +72,27 @@ func SeedAdmin() error {
|
|||
}
|
||||
return db.Create(&admin).Error
|
||||
}
|
||||
|
||||
// IsNotFound reports whether err is gorm's record-not-found.
|
||||
func IsNotFound(err error) bool {
|
||||
return errors.Is(err, gorm.ErrRecordNotFound)
|
||||
}
|
||||
|
||||
// IsSQLiteDB reports whether current DB dialector is sqlite.
|
||||
func IsSQLiteDB() bool {
|
||||
if db == nil {
|
||||
return false
|
||||
}
|
||||
return db.Dialector.Name() == "sqlite"
|
||||
}
|
||||
|
||||
// Checkpoint runs WAL checkpoint for SQLite to compact the WAL file.
|
||||
// No-op for non-SQLite databases.
|
||||
func Checkpoint() error {
|
||||
if !IsSQLiteDB() {
|
||||
return nil
|
||||
}
|
||||
// FULL/TRUNCATE — в зависимости от нужной семантики.
|
||||
// TRUNCATE чаще используется, чтобы обрезать WAL-файл.
|
||||
return db.Exec("PRAGMA wal_checkpoint(TRUNCATE);").Error
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue