Skip to content

Commit

Permalink
trying sql query
Browse files Browse the repository at this point in the history
  • Loading branch information
baxiry committed Jul 7, 2024
1 parent 95eef3d commit df4d2eb
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions engine/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ func HandleQueries(query string) string {
parsedQuery := gjson.Parse(query)

switch parsedQuery.Get("action").String() { // action

// database actions
case "findOne":
return db.findOne(parsedQuery)
Expand Down Expand Up @@ -51,15 +50,33 @@ func HandleQueries(query string) string {

// manage database
case "create_collection":
return createCollection(parsedQuery.Get("collection").String())
return createCollection(parsedQuery.Get("collection"))

case "delete_collection":
return deleteCollection(parsedQuery.Get("collection").String())
return deleteCollection(parsedQuery.Get("collection"))

case "getCollections":
//return showCollections(db.path)
return getCollections()

// trying sqlite query
case "sql":
return querySql(parsedQuery)

default:
return "unknowen action"
}
}

// hmmmmm sql
func querySql(query gjson.Result) string {
qr := query.Get("query").Str
res, _ := db.db.Query(qr)
record := ""
result := "["
for res.Next() {
res.Scan(&record)
result += record + ","
}
return result[:len(result)-1] + "]"
}

0 comments on commit df4d2eb

Please sign in to comment.