Skip to content

Commit

Permalink
improve matching performence
Browse files Browse the repository at this point in the history
  • Loading branch information
baxiry committed Jun 22, 2024
1 parent ab1e270 commit 3e166f8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@


**ZaraDB:** A Lightweight and Fast Document Database
**ZaraDB:** A Lightweight fast document database

ZaraDB is a lightweight, fast, open-licensed document database with no hidden restrictions.
ZaraDB is a lightweight fast open-licensed document database with no hidden restrictions.
Its goal is to be a lightweight alternative to common documentary databases.
It can also provide superior performance compared to Mongo in many common use cases.

Expand Down
10 changes: 5 additions & 5 deletions engine/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
// json:5, array:5, int:2, string:3

// match verifies that data matches the conditions
func match(filter, data string) (result bool, err error) {
func match(filter gjson.Result, data string) (result bool, err error) {
// TODO should return syntax error if op unknown

result = true

gjson.Parse(filter).ForEach(func(qk, qv gjson.Result) bool {
filter.ForEach(func(qk, qv gjson.Result) bool {

dv := gjson.Get(data, qk.String())

Expand Down Expand Up @@ -136,7 +136,7 @@ func match(filter, data string) (result bool, err error) {
if qk.Str == "$and" {

for _, v := range qv.Array() {
res, _ := match(v.String(), data)
res, _ := match(v, data)
if !res {
result = false
return result
Expand All @@ -149,7 +149,7 @@ func match(filter, data string) (result bool, err error) {

for _, v := range qv.Array() {

res, _ := match(v.String(), data)
res, _ := match(v, data)
if res {
return result
}
Expand All @@ -164,7 +164,7 @@ func match(filter, data string) (result bool, err error) {
}
})

match(qv.String(), dv.String())
match(qv, dv.String())
return result
}

Expand Down
16 changes: 8 additions & 8 deletions engine/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type matched struct {
// deletes Many items
func (db *DB) deleteMany(query string) string {

mtch := gjson.Get(query, "match").String()
mtch := gjson.Get(query, "match")

coll := gjson.Get(query, "collection").String()

Expand Down Expand Up @@ -64,7 +64,7 @@ func (db *DB) deleteMany(query string) string {
// TODO updateMany update document data
func (db *DB) updateMany(query string) (result string) {

mtch := gjson.Get(query, "match").String()
mtch := gjson.Get(query, "match")

newObj := gjson.Get(query, "data").String()

Expand Down Expand Up @@ -121,7 +121,7 @@ func (db *DB) updateMany(query string) (result string) {
// TODO updateOne one update document data
func (db *DB) updateOne(query string) (result string) {

mtch := gjson.Get(query, "match").String()
mtch := gjson.Get(query, "match")

newObj := gjson.Get(query, "data").String()

Expand Down Expand Up @@ -199,10 +199,10 @@ func (db *DB) findMany(query string) (res string) {
return `{"error":"forgot collection name "}`
}

mtch := gjson.Get(query, "match").String()
mtch := gjson.Get(query, "match")

if mtch.String() == "" {

if mtch == "" {
mtch = "{}"
}

skip := gjson.Get(query, "skip").Int()
Expand Down Expand Up @@ -271,7 +271,7 @@ func (db *DB) findMany(query string) (res string) {
func (db *DB) findOne(query string) (res string) {
coll := gjson.Get(query, "collection").String()

mtch := gjson.Get(query, "match").String()
mtch := gjson.Get(query, "match")
skip := gjson.Get(query, "skip").Int()

// TODO are skyp useful here ?
Expand Down Expand Up @@ -311,7 +311,7 @@ func (db *DB) findOne(query string) (res string) {
func (db *DB) deleteOne(query string) string {

coll := gjson.Get(query, "collection").String()
mtch := gjson.Get(query, "match").String()
mtch := gjson.Get(query, "match")

stmt := `select rowid, record from ` + coll

Expand Down

0 comments on commit 3e166f8

Please sign in to comment.