From 2762c36435bd3acad1f8161735c9eefc88f9537f Mon Sep 17 00:00:00 2001 From: sxwebdev Date: Sat, 15 Jul 2023 14:29:53 +0300 Subject: [PATCH] fix for stable (#1) --- stable.go | 5 ++++- tsdbbuilder_test.go | 4 ++-- tsfuncs/binary.go | 13 +++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tsfuncs/binary.go diff --git a/stable.go b/stable.go index efdf486..a97054d 100644 --- a/stable.go +++ b/stable.go @@ -64,8 +64,10 @@ func (s *sTableBuilder) Build() (string, error) { // add tags if len(s.tags) > 0 { + tagsKeys := make([]string, 0, len(s.tags)) tagsValues := make([]any, 0, len(s.tags)) - for _, value := range s.tags { + for key, value := range s.tags { + tagsKeys = append(tagsKeys, key) tagsValues = append(tagsValues, value) } @@ -75,6 +77,7 @@ func (s *sTableBuilder) Build() (string, error) { if err != nil { return "", err } + b.WriteString(tagsKeys[index] + " ") b.WriteString(v) if index != len(tagsValues)-1 { diff --git a/tsdbbuilder_test.go b/tsdbbuilder_test.go index 4a727bb..f63531a 100644 --- a/tsdbbuilder_test.go +++ b/tsdbbuilder_test.go @@ -13,8 +13,8 @@ func Test_Create(t *testing.T) { TableName("test_table"). STable("s_table_name"). Tags(map[string]any{ - "test": 1, - "test2": 2, + "test": tsfuncs.Binary("16"), + "test2": tsfuncs.Binary("24"), "test3": 3, }) diff --git a/tsfuncs/binary.go b/tsfuncs/binary.go new file mode 100644 index 0000000..f4e4367 --- /dev/null +++ b/tsfuncs/binary.go @@ -0,0 +1,13 @@ +package tsfuncs + +type binary struct { + expr string +} + +func Binary(expr string) TDEngineFunc { + return &binary{expr} +} + +func (s binary) String() string { + return "BINARY(" + s.expr + ")" +}