Skip to content

Commit

Permalink
Database back-end createDbCallback()
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Dec 26, 2023
1 parent c7eeee2 commit 61e5b37
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
49 changes: 49 additions & 0 deletions backend/database/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,52 @@ func createDbCallback(apiKey string, args []string) func(*sql.DB) {
proc.ShowSuccessResponse()
}
}

func getByNameCallback(apiKey string, args []string) func(*sql.DB) {
return func(d *sql.DB) {
name := args[2]
query, err := d.Query("SELECT id FROM " + apiKey + "_database WHERE name=\"" + name + "\"")

if err != nil {
proc.ShowFailedResponse("Internal error occured.")
query.Close()

return
}

count := 0
for query.Next() {
id := 0
query.Scan(&id)

count++
}

if count != 0 {
proc.ShowFailedResponse("Database name already in use.")
query.Close()

return
}

query, err = d.Query("SELECT mode, content FROM " + apiKey + "_database WHERE name=\"" + name + "\"")
if err != nil {
proc.ShowFailedResponse("Internal error occured.")
query.Close()

return
}

mode := ""
content := ""

for query.Next() {
query.Scan(&mode, &content)
}

proc.ShowResult("[\"" + mode + "\", \"" + content + "\"]")
query.Close()

return
}
}
12 changes: 12 additions & 0 deletions backend/database/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ func main() {
case "create":
failOnUmatchedArgSize(5, args)
createDbCallback(apiKey, args)

case "get_by_name":
break

case "set_db_mode":
break

case "get_db_mode":
break

case "fetch_all":
break
}

DispatchWithCallback(callback)
Expand Down

0 comments on commit 61e5b37

Please sign in to comment.