Skip to content

Commit

Permalink
Merge pull request #2 from 0311xuyang/dev
Browse files Browse the repository at this point in the history
update
  • Loading branch information
0311xuyang authored Dec 4, 2024
2 parents c564597 + 1cf3e53 commit 81d2d35
Show file tree
Hide file tree
Showing 28 changed files with 3,604 additions and 24 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ jobs:
ports:
- 8000:8000
options: --name dynamo-local
mysql-local:
image: mysql:latest
ports:
- 3306:3306
options: --name mysql-local -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_DATABASE=toolkit
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -25,5 +30,8 @@ jobs:
- name: Wait for DynamoDB Local to start
run: |
while ! nc -z localhost 8000; do sleep 1; done
- name: Wait for MySQL Local to start
run: |
while ! nc -z localhost 3306; do sleep 1; done
- name: Run tests
run: go test -v ./...
31 changes: 31 additions & 0 deletions dal/dal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dal

import (
"sync"

"gorm.io/driver/mysql"
"gorm.io/gorm"
)

var (
// DB is the database connection.
DB *gorm.DB
once sync.Once
)

func init() {
once.Do(func() {
DB = ConnectDB()
})
}

// ConnectDB connects to the database.
func ConnectDB() *gorm.DB {
dsn := "root:123456@tcp(127.0.0.1:3306)/toolkit?charset=utf8mb4&parseTime=True"
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {
panic(err)
}
Prepare(db)
return db
}
Loading

0 comments on commit 81d2d35

Please sign in to comment.