Skip to content

Commit

Permalink
feat: parse query function for execution (zurvan-lab#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
kehiy committed Nov 16, 2023
1 parent 51c7a45 commit ac6baea
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/database/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ type Element struct {
time time.Time
}

type Query struct {
Command string
Args []string
}

type (
Sets map[string]Set
Set map[string]SubSet
Expand Down
30 changes: 30 additions & 0 deletions core/execution.go
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
package core

import (
"strings"

"github.com/zurvan-lab/TimeTrace/core/database"
)

// parsing TQL queries. see: docs/TQL
func ParseQuery(query string) database.Query {
command := ""
args := []string{}

for _, word := range strings.Split(query, " ") {
if word == "" {
continue
}

if command != "" {
args = append(args, word)
} else {
command = word
}
}

return database.Query{Command: command, Args: args}
}

func Execute(query database.Query, db database.Database) string {
return ""
}
18 changes: 18 additions & 0 deletions core/execution_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package core

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestParseQuery(t *testing.T) {
query := "PUSH testSet testSubSet hello NOW"
paredQuery := ParseQuery(query)

assert.Equal(t, paredQuery.Command, "PUSH")
assert.Equal(t, paredQuery.Args[0], "testSet")
assert.Equal(t, paredQuery.Args[1], "testSubSet")
assert.Equal(t, paredQuery.Args[2], "hello")
assert.Equal(t, paredQuery.Args[3], "NOW")
}

0 comments on commit ac6baea

Please sign in to comment.