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

Commit

Permalink
feat: TQL documentation and specification
Browse files Browse the repository at this point in the history
  • Loading branch information
kehiy committed Nov 16, 2023
1 parent ac6baea commit 61b8872
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
12 changes: 6 additions & 6 deletions core/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (db *Database) AddSet(name string) string {
func (db *Database) AddSubSet(set, name string) string {
s, ok := db.Sets[set]
if !ok {
return "SETNF"
return "SNF"
}

s[name] = make(SubSet, 0)
Expand All @@ -36,7 +36,7 @@ func (db *Database) AddSubSet(set, name string) string {
func (db *Database) PushElement(set, subset string, e Element) string {
_, ok := db.Sets[set][subset]
if !ok {
return "SUBSETNF"
return "SSNF"
}

db.Sets[set][subset] = append(db.Sets[set][subset], e)
Expand All @@ -47,7 +47,7 @@ func (db *Database) PushElement(set, subset string, e Element) string {
func (db *Database) DropSet(name string) string {
_, ok := db.Sets[name]
if !ok {
return "SETNF"
return "SNF"
}

delete(db.Sets, name)
Expand All @@ -58,7 +58,7 @@ func (db *Database) DropSet(name string) string {
func (db *Database) DropSubSet(set, subset string) string {
_, ok := db.Sets[set][subset]
if !ok {
return "SUBSETNF"
return "SSNF"
}

delete(db.Sets[set], subset)
Expand All @@ -75,7 +75,7 @@ func (db *Database) CleanSets() string {
func (db *Database) CleanSet(name string) string {
_, ok := db.Sets[name]
if !ok {
return "SETNF"
return "SNF"
}

db.Sets[name] = make(Set)
Expand All @@ -86,7 +86,7 @@ func (db *Database) CleanSet(name string) string {
func (db *Database) CleanSubSet(set, subset string) string {
_, ok := db.Sets[set][subset]
if !ok {
return "SUBSETNF"
return "SSNF"
}

db.Sets[set][subset] = make(SubSet, 0)
Expand Down
12 changes: 6 additions & 6 deletions core/database/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestDataBase(t *testing.T) {

result = db.AddSubSet("testInvalidSet", "testSubSet")

assert.Equal(t, "SETNF", result)
assert.Equal(t, "SNF", result)
})

t.Run("pushElementTest", func(t *testing.T) {
Expand All @@ -43,7 +43,7 @@ func TestDataBase(t *testing.T) {

result = db.PushElement("invalidTestSet", "invalidTestSubSet", Element{value: []byte("testValue"), time: time})

assert.Equal(t, "SUBSETNF", result)
assert.Equal(t, "SSNF", result)
assert.Equal(t, 1, len(db.Sets["testSet"]["testSubSet"]))
assert.Equal(t, []byte("testValue"), db.Sets["testSet"]["testSubSet"][0].value)
assert.Equal(t, time, db.Sets["testSet"]["testSubSet"][0].time)
Expand All @@ -61,7 +61,7 @@ func TestDataBase(t *testing.T) {

result = db.DropSet("inavlidTestSet")

assert.Equal(t, "SETNF", result)
assert.Equal(t, "SNF", result)
assert.Equal(t, 2, len(db.Sets))
})

Expand All @@ -80,7 +80,7 @@ func TestDataBase(t *testing.T) {

result = db.DropSubSet("secondTestSet", "subSetOne")

assert.Equal(t, "SUBSETNF", result)
assert.Equal(t, "SSNF", result)
})

t.Run("cleanTest", func(t *testing.T) {
Expand Down Expand Up @@ -116,9 +116,9 @@ func TestDataBase(t *testing.T) {
assert.Equal(t, 0, len(db.Sets))

result = db.CleanSet("invalidSet")
assert.Equal(t, "SETNF", result)
assert.Equal(t, "SNF", result)

result = db.CleanSubSet("invalidSet", "invalidSubSet")
assert.Equal(t, "SUBSETNF", result)
assert.Equal(t, "SSNF", result)
})
}
Empty file removed doc/TQL/.keep
Empty file.
33 changes: 33 additions & 0 deletions doc/TQL/TQL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# TQL (Time Query Language)

Time trace is using a query language called TQL. Here is documentation and specification for TQL.


# Commands and Operations

| Command | Action | Arguments |
|----------|:-------------|:------|
| CON | to make a connection and access to database | username - password |
| SET | make a new set | set-name |
| SSET | make a new subset | set-name - subset-name |
| PUSH | push an element to a subset | set-name - subset-name - value-of-element - time(unix-timestamp) |
| GET | get elements of a subset | set-name - subset-name - [last n elements (optional)] - [regex filter] - [unix-timestamp]|
| CNTSS | returns count of subsets | set-name |
| CNTE | returns count of elements | set-name - subset-name |
| CLNS | cleans all sub-sets of a set | set-name |
| CLNSS | cleans all elements of a subset | set-name - subset-name |
| DRPS | drops a set | set-name |
| DRPSS | drops a subset | set-name - subset-name |
| SS | takes a sanp-shot | file-name(example.ttrace) |


# A TQL Server Responses

| Message | reason |
|----------|:-------------|
| DONE | everything is ok |
| INVALID | invalid user and password to make a connection OR not enough args for a command |
| SNF | set is not found |
| SSNF | subset is not found |
| ENF | element(s) is not found |
| [DATA separated by space] (key-time key-time key-time) | GET successful response |

0 comments on commit 61b8872

Please sign in to comment.