Skip to content

Commit

Permalink
slow sql log no (#252)
Browse files Browse the repository at this point in the history
* slow sql log no

* stdOut

* fix
  • Loading branch information
Lawliet-Chan authored Dec 18, 2024
1 parent a8ec2c9 commit 9f19d28
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
10 changes: 9 additions & 1 deletion infra/storage/sql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ import (
"github.com/yu-org/yu/infra/storage"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"log"
"os"
"time"
)

type Mysql struct {
*gorm.DB
}

func NewMysql(dsn string) (*Mysql, error) {
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
newLogger := logger.New(
log.New(os.Stdout, "/r/n", log.LstdFlags), logger.Config{SlowThreshold: time.Second})
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
Logger: newLogger,
})
if err != nil {
return nil, err
}
Expand Down
10 changes: 9 additions & 1 deletion infra/storage/sql/postgre.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ import (
"github.com/yu-org/yu/infra/storage"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"log"
"os"
"time"
)

type PostgreSql struct {
*gorm.DB
}

func NewPostgreSql(dsn string) (*PostgreSql, error) {
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
newLogger := logger.New(
log.New(os.Stdout, "/r/n", log.LstdFlags), logger.Config{SlowThreshold: time.Second})
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{
Logger: newLogger,
})
if err != nil {
return nil, err
}
Expand Down
11 changes: 10 additions & 1 deletion infra/storage/sql/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@ import (
"github.com/yu-org/yu/infra/storage"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"log"
"os"
"time"
)

type Sqlite struct {
*gorm.DB
}

func NewSqlite(dsn string) (*Sqlite, error) {
db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{CreateBatchSize: 50000})
newLogger := logger.New(
log.New(os.Stdout, "/r/n", log.LstdFlags), logger.Config{SlowThreshold: time.Second})
db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{
Logger: newLogger,
CreateBatchSize: 50000,
})
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 9f19d28

Please sign in to comment.