MCPcopy
hub / github.com/pocketbase/pocketbase / runSQL

Function runSQL

apis/sql.go:27–51  ·  view source on GitHub ↗
(e *core.RequestEvent)

Source from the content-addressed store, hash-verified

25}
26
27func runSQL(e *core.RequestEvent) error {
28 // extra precaution in case manually invoked from somewhere else
29 if !e.HasSuperuserAuth() {
30 return e.ForbiddenError("", nil)
31 }
32
33 form := runSQLForm{}
34
35 err := e.BindBody(&form)
36 if err != nil {
37 return firstApiError(err, e.BadRequestError("An error occurred while loading the submitted data.", err))
38 }
39
40 err = form.validate()
41 if err != nil {
42 return firstApiError(err, e.BadRequestError("An error occurred while validating the submitted data.", err))
43 }
44
45 result, err := executeQuery(e.App, form.Query, runSQLMaxRows)
46 if err != nil {
47 return firstApiError(err, e.BadRequestError("Failed to execute query. Raw error:\n"+err.Error(), nil))
48 }
49
50 return e.JSON(http.StatusOK, result)
51}
52
53type runSQLForm struct {
54 Query string `form:"query" json:"query"`

Callers

nothing calls this directly

Calls 9

validateMethod · 0.95
firstApiErrorFunction · 0.85
executeQueryFunction · 0.85
ForbiddenErrorMethod · 0.80
BindBodyMethod · 0.80
BadRequestErrorMethod · 0.80
JSONMethod · 0.80
ErrorMethod · 0.65
HasSuperuserAuthMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…