Skip to content
This repository was archived by the owner on Sep 7, 2024. It is now read-only.

Commit ac6baea

Browse files
authored
feat: parse query function for execution (#75)
1 parent 51c7a45 commit ac6baea

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

core/database/types.go

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ type Element struct {
77
time time.Time
88
}
99

10+
type Query struct {
11+
Command string
12+
Args []string
13+
}
14+
1015
type (
1116
Sets map[string]Set
1217
Set map[string]SubSet

core/execution.go

+30
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
11
package core
2+
3+
import (
4+
"strings"
5+
6+
"github.com/zurvan-lab/TimeTrace/core/database"
7+
)
8+
9+
// parsing TQL queries. see: docs/TQL
10+
func ParseQuery(query string) database.Query {
11+
command := ""
12+
args := []string{}
13+
14+
for _, word := range strings.Split(query, " ") {
15+
if word == "" {
16+
continue
17+
}
18+
19+
if command != "" {
20+
args = append(args, word)
21+
} else {
22+
command = word
23+
}
24+
}
25+
26+
return database.Query{Command: command, Args: args}
27+
}
28+
29+
func Execute(query database.Query, db database.Database) string {
30+
return ""
31+
}

core/execution_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package core
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestParseQuery(t *testing.T) {
10+
query := "PUSH testSet testSubSet hello NOW"
11+
paredQuery := ParseQuery(query)
12+
13+
assert.Equal(t, paredQuery.Command, "PUSH")
14+
assert.Equal(t, paredQuery.Args[0], "testSet")
15+
assert.Equal(t, paredQuery.Args[1], "testSubSet")
16+
assert.Equal(t, paredQuery.Args[2], "hello")
17+
assert.Equal(t, paredQuery.Args[3], "NOW")
18+
}

0 commit comments

Comments
 (0)