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

feat: parse query function for execution #75

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}