db.go 321 B

1234567891011121314151617181920212223
  1. package utils
  2. import (
  3. "gorm.io/driver/sqlite"
  4. "gorm.io/gorm"
  5. "gorm.io/gorm/logger"
  6. )
  7. func InitDB() (db *gorm.DB) {
  8. var err error
  9. db, err = gorm.Open(sqlite.Open("/tmp/my.db"), &gorm.Config{})
  10. if err != nil {
  11. panic(err)
  12. }
  13. db.Logger.LogMode(logger.Info)
  14. return
  15. }
  16. type Page struct {
  17. ID int
  18. Name string
  19. }