Skip to content

Commit

Permalink
Add more methods to zdb
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaslopezf committed Oct 19, 2023
1 parent 17f8616 commit dba4570
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cmd/demo-metrics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package main

import (
"github.com/zondax/golem/pkg/cli"
"github.com/zondax/golem/pkg/constants"
"github.com/zondax/golem/pkg/metrics"
"github.com/zondax/golem/pkg/runner"
)

func main() {
println("[Demo] Microservice example")

_, _ = cli.InitGlobalLogger(cli.DebugLevel)
_, _ = cli.InitGlobalLogger(constants.DebugLevel)

r := runner.NewRunner()

Expand Down
3 changes: 2 additions & 1 deletion cmd/demo-panic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package main

import (
"github.com/zondax/golem/pkg/cli"
"github.com/zondax/golem/pkg/constants"
"github.com/zondax/golem/pkg/metrics"
"github.com/zondax/golem/pkg/runner"
)

func main() {
println("[Demo] Panic handler")

_, _ = cli.InitGlobalLogger(cli.DebugLevel)
_, _ = cli.InitGlobalLogger(constants.DebugLevel)

r := runner.NewRunner()

Expand Down
3 changes: 2 additions & 1 deletion pkg/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/zondax/golem/pkg/constants"
"go.uber.org/zap"
"os"
)
Expand Down Expand Up @@ -69,7 +70,7 @@ func (c *CLI) init() {

// TODO: We can make this optional? and more configurable if we see the need
// Initialize logger
_, _ = InitGlobalLogger(DebugLevel)
_, _ = InitGlobalLogger(constants.DebugLevel)
setupCloseHandler(nil)
// Set Configuration Defaults
setupDefaultConfiguration(func() {
Expand Down
12 changes: 12 additions & 0 deletions pkg/zdb/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ func (z *zDatabase) Clauses(conds ...clause.Expression) ZDatabase {
return wrap(z.db.Clauses(conds...))
}

func (z *zDatabase) Select(query interface{}, args ...interface{}) ZDatabase {
return wrap(z.db.Select(query, args...))
}

func (z *zDatabase) Where(query interface{}, args ...interface{}) ZDatabase {
return wrap(z.db.Where(query, args...))
}

func (z *zDatabase) Limit(limit int) ZDatabase {
return wrap(z.db.Limit(limit))
}

func (z *zDatabase) Transaction(fc func(tx ZDatabase) error, opts ...*sql.TxOptions) (err error) {
return z.db.Transaction(func(tx *gorm.DB) error {
return fc(wrap(tx))
Expand Down
15 changes: 15 additions & 0 deletions pkg/zdb/mock_zdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ func (m *MockZDatabase) Raw(sql string, values ...interface{}) ZDatabase {
return args.Get(0).(ZDatabase)
}

func (m *MockZDatabase) Select(query interface{}, values ...interface{}) ZDatabase {
args := m.Called(query, values[0])
return args.Get(0).(ZDatabase)
}

func (m *MockZDatabase) Where(query interface{}, values ...interface{}) ZDatabase {
args := m.Called(query, values[0])
return args.Get(0).(ZDatabase)
}

func (m *MockZDatabase) Limit(limit int) ZDatabase {
args := m.Called(limit)
return args.Get(0).(ZDatabase)
}

func (m *MockZDatabase) Exec(sql string, values ...interface{}) ZDatabase {
m.Called(sql, values)
return m
Expand Down
3 changes: 3 additions & 0 deletions pkg/zdb/zdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ type ZDatabase interface {
Scan(dest interface{}) ZDatabase
Rows() (*sql.Rows, error)
ScanRows(rows *sql.Rows, result interface{}) error
Select(query interface{}, args ...interface{}) ZDatabase
Where(query interface{}, args ...interface{}) ZDatabase
Limit(limit int) ZDatabase
Create(value interface{}) ZDatabase
Delete(value interface{}, where ...interface{}) ZDatabase
Raw(sql string, values ...interface{}) ZDatabase
Expand Down

0 comments on commit dba4570

Please sign in to comment.