MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / userDataFind

Function userDataFind

cmd/cql-proxy/api/user_data.go:32–99  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

30)
31
32func userDataFind(c *gin.Context) {
33 r := struct {
34 Table string `json:"table" form:"table" uri:"table" binding:"required,max=128"`
35 Filter map[string]interface{} `json:"filter" form:"filter"`
36 Projection map[string]interface{} `json:"projection" form:"projection"`
37 OrderBy map[string]interface{} `json:"order" form:"order"`
38 Skip *int64 `json:"skip" form:"skip" binding:"omitempty,gte=0"`
39 Limit *int64 `json:"limit" form:"limit" binding:"omitempty,gte=0"`
40 }{}
41
42 _ = c.ShouldBindUri(&r)
43
44 if err := c.ShouldBind(&r); err != nil {
45 abortWithError(c, http.StatusBadRequest, err)
46 return
47 }
48
49 resolver.CheckAndBindParams(c, &r.Filter, "filter")
50 resolver.CheckAndBindParams(c, &r.Projection, "projection")
51 resolver.CheckAndBindParams(c, &r.OrderBy, "order")
52
53 db, uid, userState, vars, rules, fieldMap, adminMode, err := buildExecuteContext(c, r.Table)
54 if err != nil {
55 _ = c.Error(err)
56 if err != ErrProjectIsDisabled {
57 err = ErrPrepareExecutionContextFailed
58 }
59 abortWithError(c, http.StatusInternalServerError, err)
60 return
61 }
62
63 var filter map[string]interface{}
64
65 if !adminMode {
66 filter, err = rules.EnforceRulesOnFilter(r.Filter, r.Table, uid, userState, vars, resolver.RuleQueryFind)
67 if err != nil {
68 _ = c.Error(err)
69 abortWithError(c, http.StatusForbidden, ErrEnforceRuleOnQueryFailed)
70 return
71 }
72 } else {
73 filter = r.Filter
74 }
75
76 stmt, args, _, err := resolver.Find(r.Table, fieldMap, filter, r.Projection, r.OrderBy, r.Skip, r.Limit)
77 if err != nil {
78 abortWithError(c, http.StatusBadRequest, err)
79 return
80 }
81
82 var rows *sql.Rows
83 rows, err = db.Query(stmt, args...)
84 if err != nil {
85 _ = c.Error(err)
86 abortWithError(c, http.StatusBadRequest, ErrExecuteQueryFailed)
87 return
88 }
89

Callers

nothing calls this directly

Calls 9

CheckAndBindParamsFunction · 0.92
FindFunction · 0.92
abortWithErrorFunction · 0.85
buildExecuteContextFunction · 0.85
scanRowsFunction · 0.85
responseWithDataFunction · 0.85
ErrorMethod · 0.80
EnforceRulesOnFilterMethod · 0.80
QueryMethod · 0.65

Tested by

no test coverage detected