2023-05-31 18:00:21 +08:00
|
|
|
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"
|
2023-05-31 18:00:21 +08:00
|
|
|
//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")
|
2023-05-31 18:00:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return db, nil
|
|
|
|
}
|