Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sxwebdev authored Jul 24, 2023
1 parent a0a3eca commit 6d0436b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
4 changes: 3 additions & 1 deletion cast_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (

func castType(value any) (string, error) {
switch v := value.(type) {
case float32, float64, int8, uint8, int16, uint16, int32, uint32, int64, uint64, int, uint:
case int8, uint8, int16, uint16, int32, uint32, int64, uint64, int, uint:
return fmt.Sprintf("%d", v), nil
case float32, float64:
return fmt.Sprintf("%f", v), nil
case string:
return fmt.Sprint("'" + v + "'"), nil
case bool:
Expand Down
14 changes: 13 additions & 1 deletion insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,23 @@ func (s *insertBuilder) Build() (string, error) {

// add tags
if len(table.tags) > 0 {
tagsKeys := make([]string, 0, len(table.tags))
tagsValues := make([]any, 0, len(table.tags))
for _, value := range table.tags {
for key, value := range table.tags {
tagsKeys = append(tagsKeys, key)
tagsValues = append(tagsValues, value)
}

b.WriteString("(")
for index, value := range tagsKeys {
b.WriteString(value)

if index != len(tagsKeys)-1 {
b.WriteString(", ")
}
}
b.WriteString(") ")

b.WriteString("TAGS (")
for index, value := range tagsValues {
v, err := castType(value)
Expand Down
8 changes: 4 additions & 4 deletions select.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,22 @@ func (s *selectBuilder) Build() (string, error) {

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

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

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

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

b.WriteString(";")
Expand Down
2 changes: 1 addition & 1 deletion tsdbbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func Test_Insert(t *testing.T) {
b.AddTable("test_table_2").
Using("s_table_name").
Tags(map[string]any{
"tag_1": 1,
"tag_1": 1.1,
"tag_2": 2,
"tag_3": 3,
}).
Expand Down

0 comments on commit 6d0436b

Please sign in to comment.