bill-server-go/internal/infrastructure/sqlite.go

18 lines
313 B
Go
Raw Normal View History

package infrastructure
import (
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func ConnectToSqlite() (*gorm.DB, error) {
2023-06-01 17:55:41 +08:00
dsn := "bill.db"
//dsn := "file::memory:?cache=shared"
db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{})
if err != nil {
2023-06-01 17:55:41 +08:00
panic("failed to connect database.\n")
}
return db, nil
}