Skip to content

Commit

Permalink
create collection automaticlly if not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
baxiry committed Aug 1, 2024
1 parent e511348 commit f459005
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions engine/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,20 @@ func (db *DB) insertMany(query gjson.Result) (res string) {

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

_, err := db.db.Exec(`insert into ` + coll + `(record) values` + strData[:len(strData)-1]) // fast
_, err := db.db.Exec(`insert into ` + coll + `(record) values` + strData[:len(strData)-1]) // `+` is fast
if err != nil {
db.lastid[coll] = lid
if strings.Contains(err.Error(), "no such table") {
err = db.CreateCollection(coll)
if err != nil {
return err.Error()
}
return db.insertMany(query)
}
return err.Error()
}

return "in progress"
return "inserted"
}

// insert new record
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
var content embed.FS

func main() {
// TODO close programe greatfully.
// TODO: Close program gracefully.

db := engine.NewDB("test.db")
db.CreateCollection("users")
db.CreateCollection("test")
defer db.Close()

fmt.Printf("interacte with zaradb from %s:%s\n", Host, Port)
Expand Down

0 comments on commit f459005

Please sign in to comment.