This repository was archived by the owner on Sep 7, 2024. It is now read-only.
Commit ac6baea 1 parent 51c7a45 commit ac6baea Copy full SHA for ac6baea
File tree 3 files changed +53
-0
lines changed
3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,11 @@ type Element struct {
7
7
time time.Time
8
8
}
9
9
10
+ type Query struct {
11
+ Command string
12
+ Args []string
13
+ }
14
+
10
15
type (
11
16
Sets map [string ]Set
12
17
Set map [string ]SubSet
Original file line number Diff line number Diff line change 1
1
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments