You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

db.go 724 B

1234567891011121314151617181920212223242526272829303132
  1. package db
  2. import (
  3. "fmt"
  4. "gitlink.org.cn/cloudream/storage/datamap/internal/config"
  5. "gorm.io/driver/mysql"
  6. "gorm.io/gorm"
  7. "gorm.io/gorm/schema"
  8. )
  9. func InitDB(cfg config.DatabaseConfig) (*gorm.DB, error) {
  10. dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local",
  11. cfg.User, cfg.Password, cfg.Host, cfg.Port, cfg.DBName)
  12. db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
  13. NamingStrategy: schema.NamingStrategy{
  14. SingularTable: true, // 禁用自动复数化表名
  15. },
  16. })
  17. if err != nil {
  18. return nil, err
  19. }
  20. //// 自动迁移表结构
  21. //db.AutoMigrate(
  22. // &models.Hub{},
  23. // &models.Storage{},
  24. // &models.HubRequest{},
  25. // &models.BlockDistribution{},
  26. //)
  27. return db, nil
  28. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。