-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: replace the folders and files by the matters
- Loading branch information
Showing
25 changed files
with
578 additions
and
553 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,36 @@ | ||
package dao | ||
|
||
import ( | ||
"gorm.io/gorm" | ||
|
||
"github.com/saltbo/zpan/internal/app/model" | ||
"github.com/saltbo/zpan/internal/pkg/gormutil" | ||
) | ||
|
||
func Init(driver, dsn string) { | ||
gormutil.Init(gormutil.Config{ | ||
var gdb *gorm.DB | ||
|
||
func Ready() bool { | ||
return gdb != nil | ||
} | ||
|
||
func Init(driver, dsn string) error { | ||
conf := gormutil.Config{ | ||
Driver: driver, | ||
DSN: dsn, | ||
}, true) | ||
gormutil.AutoMigrate(model.Tables()) | ||
} | ||
db, err := gormutil.New(conf) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
gdb = db.Debug() | ||
if err := gdb.AutoMigrate(model.Tables()...); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func Transaction(fc func(tx *gorm.DB) error) error { | ||
return gdb.Transaction(fc) | ||
} |
Oops, something went wrong.