api: i hope all should work

This commit is contained in:
2025-06-21 22:07:24 +03:00
parent 2435088eef
commit e3e874249c
2 changed files with 19 additions and 13 deletions
+13 -10
View File
@@ -272,21 +272,24 @@ func main() {
//}
log.Println("connecting...")
var db *gorm.DB
var err error
// switch dbType {
// case "sqlite":
db, err = gorm.Open(sqlite.Open(DATA_DIR+"./YaBL.db"), &gorm.Config{
dbPath := DATA_DIR + "/YaBL.db"
if _, err := os.Stat(dbPath); err != nil {
file, err := os.Create(dbPath)
if err != nil {
log.Panicln("Cannot create db file")
}
file.Close()
log.Println("Created empty db file")
}
db, err := gorm.Open(sqlite.Open(DATA_DIR+"/YaBL.db"), &gorm.Config{
Logger: logger.Default.LogMode(logger.Error),
})
// case "posgresql":
// db, err = gorm.Open(postgres.Open(dbLink), &gorm.Config{
// Logger: logger.Default.LogMode(logger.Error),
// })
// }
if err != nil {
panic(err)
}
log.Println("connected!")
db.AutoMigrate(
&schemas.Book{},