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.

db2.go 707 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package db2
  2. import (
  3. _ "github.com/go-sql-driver/mysql"
  4. "github.com/sirupsen/logrus"
  5. "gitlink.org.cn/cloudream/storage2/common/pkgs/db2/config"
  6. "gorm.io/driver/mysql"
  7. "gorm.io/gorm"
  8. )
  9. type DB struct {
  10. db *gorm.DB
  11. }
  12. func NewDB(cfg *config.Config) (*DB, error) {
  13. mydb, err := gorm.Open(mysql.Open(cfg.MakeSourceString()), &gorm.Config{})
  14. if err != nil {
  15. logrus.Fatalf("failed to connect to database: %v", err)
  16. }
  17. return &DB{
  18. db: mydb,
  19. }, nil
  20. }
  21. func (db *DB) DoTx(do func(tx SQLContext) error) error {
  22. return db.db.Transaction(func(tx *gorm.DB) error {
  23. return do(SQLContext{tx})
  24. })
  25. }
  26. type SQLContext struct {
  27. *gorm.DB
  28. }
  29. func (db *DB) DefCtx() SQLContext {
  30. return SQLContext{db.db}
  31. }

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