MCPcopy Create free account
hub / github.com/rilldata/rill / newBuiltinSQL

Function newBuiltinSQL

runtime/resolvers/builtin_sql.go:40–75  ·  view source on GitHub ↗

newBuiltinSQL is the resolver for the built-in /sql API. It executes a SQL query provided dynamically through the args. It errors if the user identified by the attributes is not an admin.

(ctx context.Context, opts *runtime.ResolverOptions)

Source from the content-addressed store, hash-verified

38// It executes a SQL query provided dynamically through the args.
39// It errors if the user identified by the attributes is not an admin.
40func newBuiltinSQL(ctx context.Context, opts *runtime.ResolverOptions) (runtime.Resolver, error) {
41 // Only admins can run arbitrary SQL queries.
42 if !opts.Claims.SkipChecks && !opts.Claims.Admin() {
43 return nil, errors.New("must be an admin to run arbitrary SQL queries")
44 }
45
46 // Decode the args
47 args := &builtinSQLArgs{}
48 if err := mapstructure.Decode(opts.Args, args); err != nil {
49 return nil, err
50 }
51
52 // Set the span attributes
53 span := trace.SpanFromContext(ctx)
54 if span.SpanContext().IsValid() {
55 span.SetAttributes(
56 attribute.String("sql", args.SQL),
57 attribute.String("connector", args.Connector),
58 )
59 }
60
61 // Rewrite to the regular SQL resolver
62 return newSQL(ctx, &runtime.ResolverOptions{
63 Runtime: opts.Runtime,
64 InstanceID: opts.InstanceID,
65 Properties: map[string]any{
66 "connector": args.Connector,
67 "sql": args.SQL,
68 },
69 Args: map[string]any{
70 "priority": args.Priority,
71 },
72 Claims: opts.Claims,
73 ForExport: opts.ForExport,
74 })
75}

Callers

nothing calls this directly

Calls 4

newSQLFunction · 0.85
StringMethod · 0.65
AdminMethod · 0.45
DecodeMethod · 0.45

Tested by

no test coverage detected