Skip to content

Commit 4e44b81

Browse files
committed
♻️ refactor: updated codebase #9
1 parent 8f26029 commit 4e44b81

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

example/govm_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"testing"
55

66
"github.com/sivaosorg/govm/bot/telegram"
7+
"github.com/sivaosorg/govm/logger"
8+
"github.com/sivaosorg/govm/query"
79
"github.com/sivaosorg/govm/timex"
810
)
911

@@ -28,3 +30,10 @@ func TestCardNotification(t *testing.T) {
2830
svc := createTelegramService()
2931
svc.SendWarning("Kafka Stream", "Kafka Streams is a part of the Apache Kafka project that enables developers to build real-time processing applications, where data can be ingested, processed, and transformed in real-time as it flows through the Kafka cluster. Kafka Streams is a library for building scalable and fault-tolerant stream processing applications without the need for a separate processing cluster.")
3032
}
33+
34+
func TestDecisionModify(t *testing.T) {
35+
m := query.NewModify().
36+
Add("username_column", *query.WithDecision(true).SetValue(1)).
37+
Add("password_column", *query.NewDecision().SetEnabled(true).SetValue("123"))
38+
logger.Infof("modifies: %v", m.Transform())
39+
}

query/query.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ func (i *decision) SetValue(value interface{}) *decision {
172172
return i
173173
}
174174

175+
func (i *decision) SetValueFunc(value interface{}, fnc func() bool) *decision {
176+
i.SetEnabled(fnc())
177+
i.SetValue(value)
178+
return i
179+
}
180+
175181
func (i *decision) SetOn(value time.Time) *decision {
176182
i.on = value
177183
return i
@@ -235,6 +241,10 @@ func (m Modify) Transform() map[string]interface{} {
235241
return values.Build()
236242
}
237243

244+
func (m Modify) Json() string {
245+
return utils.ToJson(m)
246+
}
247+
238248
func GetTotalPages(totalCount int, size int) int {
239249
d := float64(totalCount) / float64(size)
240250
return int(math.Ceil(d))

0 commit comments

Comments
 (0)