PgRest.RPC.Args (PgRest v0.2.0)

Copy Markdown View Source

Splits an RPC request into function arguments and row filters, as PostgREST's pRequestFilter/isRpcRead do, and builds the arguments of the call.

On a read (GET/HEAD) the query string carries both: a key is a filter when it is reserved or PgRest.Grammar.Filter.parse_condition/2 accepts its value, and an argument otherwise. On a POST every query parameter is a filter and the arguments are the keys of the JSON body (an array body: the keys its objects share), or the columns= list when given. A parameter without a value (?a) is dropped, as PostgREST's nonemptyParams does.

Summary

Functions

The body media type of a conn (its Content-Type): :text, :xml, :bytea, or :json for anything else, as PostgREST defaults to JSON.

The arguments of the call of function (PgRest.Plan.Call args). A read passes the function's parameters the query string names (a variadic one every value in order, any other the last). A JSON POST passes the raw body once, to json_to_recordset, or whole to a single unnamed parameter; a non-JSON POST always reaches a single unnamed parameter.

Checks a JSON RPC body before resolution: an array must hold objects that all have the same keys (PGRST102), as a bulk write's rows must. A columns= list must parse.

How the request calls its function, for PgRest.RPC.Resolver.resolve/5.

Returns {argument_keys, filter_params} for an invocation (invocation/1). Argument keys are deduplicated; the resolver matches them as a set.

Functions

body_media(conn)

@spec body_media(Plug.Conn.t()) :: :json | :text | :xml | :bytea

The body media type of a conn (its Content-Type): :text, :xml, :bytea, or :json for anything else, as PostgREST defaults to JSON.

call_args(request, function)

The arguments of the call of function (PgRest.Plan.Call args). A read passes the function's parameters the query string names (a variadic one every value in order, any other the last). A JSON POST passes the raw body once, to json_to_recordset, or whole to a single unnamed parameter; a non-JSON POST always reaches a single unnamed parameter.

check_body(request)

@spec check_body(PgRest.Request.t()) :: :ok | {:error, PgRest.Error.t()}

Checks a JSON RPC body before resolution: an array must hold objects that all have the same keys (PGRST102), as a bulk write's rows must. A columns= list must parse.

invocation(request)

How the request calls its function, for PgRest.RPC.Resolver.resolve/5.

split(request, arg2)

Returns {argument_keys, filter_params} for an invocation (invocation/1). Argument keys are deduplicated; the resolver matches them as a set.