Skip to content

Commit

Permalink
constants some vars
Browse files Browse the repository at this point in the history
  • Loading branch information
baxiry committed Jul 13, 2024
1 parent 1fa72a8 commit b1df78c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
6 changes: 2 additions & 4 deletions engine/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func getIds(query gjson.Result) (string, error) {
}

if rowids == "" {
return "", fmt.Errorf("str zero val rowids")
return "", fmt.Errorf("zero value")
}

return rowids[:len(rowids)-1], nil
Expand Down Expand Up @@ -303,7 +303,7 @@ func (db *DB) findMany(query gjson.Result) (res string) {
listData := make([]string, 0)

for rows.Next() {
fmt.Println("next")

if limit == 0 {
break
}
Expand All @@ -323,8 +323,6 @@ func (db *DB) findMany(query gjson.Result) (res string) {
return err.Error()
}

fmt.Println("record: ", record)

if ok {
listData = append(listData, record)
limit--
Expand Down
10 changes: 7 additions & 3 deletions engine/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewDB(dbName string) *DB {

// InsertMany inserts list of object at one time
func (db *DB) insertMany(query gjson.Result) (res string) {
coll := query.Get("collection").String()
coll := query.Get("collection").Str
data := query.Get("data").Array()

//d := strings.TrimLeft(obj, " ")
Expand All @@ -63,10 +63,11 @@ func (db *DB) insertMany(query gjson.Result) (res string) {
strData := ""
for _, obj := range data {
db.lastid[coll]++
// strconv for per
strData += `('{"_id":` + fmt.Sprint(db.lastid[coll]) + ", " + obj.String()[1:] + `'),`
}

fmt.Println("bulk data: ", strData[:len(strData)-1])
//fmt.Println("bulk data: ", strData[:len(strData)-1])

_, err := db.db.Exec(`insert into ` + coll + `(record) values` + strData[:len(strData)-1]) // fast
if err != nil {
Expand All @@ -88,7 +89,8 @@ func (db *DB) insert(collection, obj string) error {
data := `{"_id":` + fmt.Sprint(db.lastid[collection]) + ", " + d[1:]
fmt.Println("data: ", data)
fmt.Println("coll: ", collection)
_, err := db.db.Exec(`insert into ` + collection + `(record) values('` + data + `');`) // fast
// + s faster then format
_, err := db.db.Exec(`insert into ` + collection + `(record) values('` + data + `');`)
if err != nil {
fmt.Println(err)
db.lastid[collection]--
Expand All @@ -110,3 +112,5 @@ func check(hint string, err error) {
//return
}
}

// end
17 changes: 17 additions & 0 deletions engine/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@ package engine

import "errors"

const (
fOne = "findOne" // fo
fMany = "findMany" // fm
upOne = "updateOne" // uo
upMany = "updateMany" // um
dOne = "deleteOne" // do
dMany = "deleteMany" // dm

//
mtch = "match" // m
sQery = "subQuery" // sq
orderby = "orderBy" // ob
fields = "fields" // f
skip = "skip" // s
limit = "limit" // l
)

var (
ErrDuplicate = errors.New("record already exists")
ErrNotExists = errors.New("row not exists")
Expand Down

0 comments on commit b1df78c

Please sign in to comment.