Skip to content

Commit 6d0436b

Browse files
authored
fixes
1 parent a0a3eca commit 6d0436b

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

cast_types.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import (
88

99
func castType(value any) (string, error) {
1010
switch v := value.(type) {
11-
case float32, float64, int8, uint8, int16, uint16, int32, uint32, int64, uint64, int, uint:
11+
case int8, uint8, int16, uint16, int32, uint32, int64, uint64, int, uint:
1212
return fmt.Sprintf("%d", v), nil
13+
case float32, float64:
14+
return fmt.Sprintf("%f", v), nil
1315
case string:
1416
return fmt.Sprint("'" + v + "'"), nil
1517
case bool:

insert.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,23 @@ func (s *insertBuilder) Build() (string, error) {
8989

9090
// add tags
9191
if len(table.tags) > 0 {
92+
tagsKeys := make([]string, 0, len(table.tags))
9293
tagsValues := make([]any, 0, len(table.tags))
93-
for _, value := range table.tags {
94+
for key, value := range table.tags {
95+
tagsKeys = append(tagsKeys, key)
9496
tagsValues = append(tagsValues, value)
9597
}
9698

99+
b.WriteString("(")
100+
for index, value := range tagsKeys {
101+
b.WriteString(value)
102+
103+
if index != len(tagsKeys)-1 {
104+
b.WriteString(", ")
105+
}
106+
}
107+
b.WriteString(") ")
108+
97109
b.WriteString("TAGS (")
98110
for index, value := range tagsValues {
99111
v, err := castType(value)

select.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,22 @@ func (s *selectBuilder) Build() (string, error) {
116116

117117
// add limit
118118
if s.limit != nil {
119-
b.WriteString(fmt.Sprintf("%d", *s.limit) + " ")
119+
b.WriteString(fmt.Sprintf("LIMIT %d", *s.limit) + " ")
120120
}
121121

122122
// add slimit
123123
if s.slimit != nil {
124-
b.WriteString(fmt.Sprintf("%d", *s.slimit) + " ")
124+
b.WriteString(fmt.Sprintf("SLIMIT %d", *s.slimit) + " ")
125125
}
126126

127127
// add offset
128128
if s.offset != nil {
129-
b.WriteString(fmt.Sprintf("%d", *s.offset) + " ")
129+
b.WriteString(fmt.Sprintf("OFFSET %d", *s.offset) + " ")
130130
}
131131

132132
// add soffset
133133
if s.soffset != nil {
134-
b.WriteString(fmt.Sprintf("%d", *s.soffset) + " ")
134+
b.WriteString(fmt.Sprintf("SOFFSET %d", *s.soffset) + " ")
135135
}
136136

137137
b.WriteString(";")

tsdbbuilder_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func Test_Insert(t *testing.T) {
4949
b.AddTable("test_table_2").
5050
Using("s_table_name").
5151
Tags(map[string]any{
52-
"tag_1": 1,
52+
"tag_1": 1.1,
5353
"tag_2": 2,
5454
"tag_3": 3,
5555
}).

0 commit comments

Comments
 (0)