Packages

An Elixir interface to the libpg_query postgres query parser. Converts a valid PostgreSQL query into a Protobuf based AST.

Current section

Files

Jump to
pg_query_ex lib pg_query proto pg_query_json_table.ex
Raw

lib/pg_query/proto/pg_query_json_table.ex

# Code generated by protox. Don't edit.
# credo:disable-for-this-file
defmodule PgQuery.JsonTable do
@moduledoc false
if function_exported?(Protox, :check_generator_version, 1) do
Protox.check_generator_version(1)
else
raise "This code was generated with protox 2 but the runtime is using an older version of protox."
end
@type t :: %__MODULE__{
location: integer(),
lateral: boolean(),
alias: PgQuery.Alias.t() | nil,
on_error: PgQuery.JsonBehavior.t() | nil,
columns: [PgQuery.Node.t()],
passing: [PgQuery.Node.t()],
pathspec: PgQuery.JsonTablePathSpec.t() | nil,
context_item: PgQuery.JsonValueExpr.t() | nil,
__uf__: [{non_neg_integer(), Protox.Types.tag(), binary()}]
}
defstruct location: 0,
lateral: false,
alias: nil,
on_error: nil,
columns: [],
passing: [],
pathspec: nil,
context_item: nil,
__uf__: []
(
(
@spec encode(t()) :: {:ok, iodata(), non_neg_integer()} | {:error, any()}
def encode(msg) do
msg |> encode!() |> Tuple.insert_at(0, :ok)
rescue
e in [Protox.EncodingError, Protox.RequiredFieldsError] -> {:error, e}
end
@spec encode!(t()) :: {iodata(), non_neg_integer()} | no_return()
def encode!(msg) do
{_acc = [], _acc_size = 0}
|> encode_location(msg)
|> encode_lateral(msg)
|> encode_alias(msg)
|> encode_on_error(msg)
|> encode_columns(msg)
|> encode_passing(msg)
|> encode_pathspec(msg)
|> encode_context_item(msg)
|> encode_unknown_fields(msg)
end
)
defp encode_location({acc, acc_size}, msg) do
if msg.location == 0 do
{acc, acc_size}
else
{value_bytes, value_bytes_size} = Protox.Encode.encode_int32(msg.location)
{["@", value_bytes | acc], acc_size + 1 + value_bytes_size}
end
rescue
ArgumentError ->
reraise Protox.EncodingError.new(:location, "invalid field value"), __STACKTRACE__
end
defp encode_lateral({acc, acc_size}, msg) do
if msg.lateral == false do
{acc, acc_size}
else
{value_bytes, value_bytes_size} = Protox.Encode.encode_bool(msg.lateral)
{["8", value_bytes | acc], acc_size + 1 + value_bytes_size}
end
rescue
ArgumentError ->
reraise Protox.EncodingError.new(:lateral, "invalid field value"), __STACKTRACE__
end
defp encode_alias({acc, acc_size}, msg) do
if msg.alias == nil do
{acc, acc_size}
else
{value_bytes, value_bytes_size} = Protox.Encode.encode_message(msg.alias)
{["2", value_bytes | acc], acc_size + 1 + value_bytes_size}
end
rescue
ArgumentError ->
reraise Protox.EncodingError.new(:alias, "invalid field value"), __STACKTRACE__
end
defp encode_on_error({acc, acc_size}, msg) do
if msg.on_error == nil do
{acc, acc_size}
else
{value_bytes, value_bytes_size} = Protox.Encode.encode_message(msg.on_error)
{["*", value_bytes | acc], acc_size + 1 + value_bytes_size}
end
rescue
ArgumentError ->
reraise Protox.EncodingError.new(:on_error, "invalid field value"), __STACKTRACE__
end
defp encode_columns({acc, acc_size}, msg) do
case msg.columns do
[] ->
{acc, acc_size}
values ->
{value_bytes, value_size} =
(
{value_bytes, value_size} =
Enum.reduce(values, {_local_acc = [], _local_acc_size = 0}, fn value,
{local_acc,
local_acc_size} ->
{value_bytes, value_bytes_size} = Protox.Encode.encode_message(value)
{[value_bytes, "\"" | local_acc], local_acc_size + 1 + value_bytes_size}
end)
{Enum.reverse(value_bytes), value_size}
)
{[value_bytes | acc], acc_size + value_size}
end
rescue
ArgumentError ->
reraise Protox.EncodingError.new(:columns, "invalid field value"), __STACKTRACE__
end
defp encode_passing({acc, acc_size}, msg) do
case msg.passing do
[] ->
{acc, acc_size}
values ->
{value_bytes, value_size} =
(
{value_bytes, value_size} =
Enum.reduce(values, {_local_acc = [], _local_acc_size = 0}, fn value,
{local_acc,
local_acc_size} ->
{value_bytes, value_bytes_size} = Protox.Encode.encode_message(value)
{[value_bytes, "\x1A" | local_acc], local_acc_size + 1 + value_bytes_size}
end)
{Enum.reverse(value_bytes), value_size}
)
{[value_bytes | acc], acc_size + value_size}
end
rescue
ArgumentError ->
reraise Protox.EncodingError.new(:passing, "invalid field value"), __STACKTRACE__
end
defp encode_pathspec({acc, acc_size}, msg) do
if msg.pathspec == nil do
{acc, acc_size}
else
{value_bytes, value_bytes_size} = Protox.Encode.encode_message(msg.pathspec)
{["\x12", value_bytes | acc], acc_size + 1 + value_bytes_size}
end
rescue
ArgumentError ->
reraise Protox.EncodingError.new(:pathspec, "invalid field value"), __STACKTRACE__
end
defp encode_context_item({acc, acc_size}, msg) do
if msg.context_item == nil do
{acc, acc_size}
else
{value_bytes, value_bytes_size} = Protox.Encode.encode_message(msg.context_item)
{["\n", value_bytes | acc], acc_size + 1 + value_bytes_size}
end
rescue
ArgumentError ->
reraise Protox.EncodingError.new(:context_item, "invalid field value"), __STACKTRACE__
end
defp encode_unknown_fields({acc, acc_size}, msg) do
Enum.reduce(msg.__uf__, {acc, acc_size}, fn {tag, wire_type, bytes}, {acc, acc_size} ->
case wire_type do
0 ->
{key_bytes, key_size} = Protox.Encode.make_key_bytes(tag, :int32)
{[acc, <<key_bytes::binary, bytes::binary>>], acc_size + key_size + byte_size(bytes)}
1 ->
{key_bytes, key_size} = Protox.Encode.make_key_bytes(tag, :double)
{[acc, <<key_bytes::binary, bytes::binary>>], acc_size + key_size + byte_size(bytes)}
2 ->
{len_bytes, len_size} = bytes |> byte_size() |> Protox.Varint.encode()
{key_bytes, key_size} = Protox.Encode.make_key_bytes(tag, :packed)
{[acc, <<key_bytes::binary, len_bytes::binary, bytes::binary>>],
acc_size + key_size + len_size + byte_size(bytes)}
5 ->
{key_bytes, key_size} = Protox.Encode.make_key_bytes(tag, :float)
{[acc, <<key_bytes::binary, bytes::binary>>], acc_size + key_size + byte_size(bytes)}
end
end)
end
)
(
(
@spec decode(binary()) :: {:ok, t()} | {:error, any()}
def decode(bytes) do
{:ok, decode!(bytes)}
rescue
e in [Protox.DecodingError, Protox.IllegalTagError, Protox.RequiredFieldsError] ->
{:error, e}
end
(
@spec decode!(binary()) :: t() | no_return()
def decode!(bytes) do
parse_key_value(bytes, struct(PgQuery.JsonTable))
end
)
)
(
@spec parse_key_value(binary(), struct()) :: struct()
defp parse_key_value(<<>>, msg) do
msg
end
defp parse_key_value(bytes, msg) do
{field, rest} =
case bytes do
<<_::5, 3::3, _rest::binary>> ->
raise Protox.DecodingError.new(bytes, "invalid wire type 3")
<<_::5, 4::3, _rest::binary>> ->
raise Protox.DecodingError.new(bytes, "invalid wire type 4")
<<_::5, 6::3, _rest::binary>> ->
raise Protox.DecodingError.new(bytes, "invalid wire type 6")
<<_::5, 7::3, _rest::binary>> ->
raise Protox.DecodingError.new(bytes, "invalid wire type 7")
<<0::5, _::3, _rest::binary>> ->
raise %Protox.IllegalTagError{}
<<8::5, _wire_type::3, bytes::binary>> ->
{value, rest} = Protox.Decode.parse_int32(bytes)
{[location: value], rest}
<<7::5, _wire_type::3, bytes::binary>> ->
{value, rest} = Protox.Decode.parse_bool(bytes)
{[lateral: value], rest}
<<6::5, _wire_type::3, bytes::binary>> ->
{len, bytes} = Protox.Varint.decode(bytes)
{delimited, rest} = Protox.Decode.parse_delimited(bytes, len)
{[alias: Protox.MergeMessage.merge(msg.alias, PgQuery.Alias.decode!(delimited))],
rest}
<<5::5, _wire_type::3, bytes::binary>> ->
{len, bytes} = Protox.Varint.decode(bytes)
{delimited, rest} = Protox.Decode.parse_delimited(bytes, len)
{[
on_error:
Protox.MergeMessage.merge(
msg.on_error,
PgQuery.JsonBehavior.decode!(delimited)
)
], rest}
<<4::5, _wire_type::3, bytes::binary>> ->
{len, bytes} = Protox.Varint.decode(bytes)
{delimited, rest} = Protox.Decode.parse_delimited(bytes, len)
{[columns: msg.columns ++ [PgQuery.Node.decode!(delimited)]], rest}
<<3::5, _wire_type::3, bytes::binary>> ->
{len, bytes} = Protox.Varint.decode(bytes)
{delimited, rest} = Protox.Decode.parse_delimited(bytes, len)
{[passing: msg.passing ++ [PgQuery.Node.decode!(delimited)]], rest}
<<2::5, _wire_type::3, bytes::binary>> ->
{len, bytes} = Protox.Varint.decode(bytes)
{delimited, rest} = Protox.Decode.parse_delimited(bytes, len)
{[
pathspec:
Protox.MergeMessage.merge(
msg.pathspec,
PgQuery.JsonTablePathSpec.decode!(delimited)
)
], rest}
<<1::5, _wire_type::3, bytes::binary>> ->
{len, bytes} = Protox.Varint.decode(bytes)
{delimited, rest} = Protox.Decode.parse_delimited(bytes, len)
{[
context_item:
Protox.MergeMessage.merge(
msg.context_item,
PgQuery.JsonValueExpr.decode!(delimited)
)
], rest}
<<bytes::binary>> ->
{tag, wire_type, rest} = Protox.Decode.parse_key(bytes)
{value, rest} = Protox.Decode.parse_unknown(tag, wire_type, rest)
{[__uf__: msg.__uf__ ++ [value]], rest}
end
msg_updated = struct(msg, field)
parse_key_value(rest, msg_updated)
end
)
)
(
@spec unknown_fields(struct()) :: [{non_neg_integer(), Protox.Types.tag(), binary()}]
def unknown_fields(msg) do
msg.__uf__
end
@spec unknown_fields_name() :: :__uf__
def unknown_fields_name() do
:__uf__
end
@spec clear_unknown_fields(struct) :: struct
def clear_unknown_fields(msg) do
struct!(msg, __uf__: [])
end
)
(
@spec default(atom()) ::
{:ok, boolean() | integer() | String.t() | float()}
| {:error, :no_such_field | :no_default_value}
def default(:location) do
{:ok, 0}
end
def default(:lateral) do
{:ok, false}
end
def default(:alias) do
{:ok, nil}
end
def default(:on_error) do
{:ok, nil}
end
def default(:columns) do
{:error, :no_default_value}
end
def default(:passing) do
{:error, :no_default_value}
end
def default(:pathspec) do
{:ok, nil}
end
def default(:context_item) do
{:ok, nil}
end
def default(_) do
{:error, :no_such_field}
end
)
@spec schema() :: Protox.MessageSchema.t()
def schema() do
%{
__struct__: Protox.MessageSchema,
fields: %{
alias: %{
__struct__: Protox.Field,
extender: nil,
kind: %{__struct__: Protox.Scalar, default_value: nil},
label: :optional,
name: :alias,
tag: 6,
type: {:message, PgQuery.Alias}
},
columns: %{
__struct__: Protox.Field,
extender: nil,
kind: :unpacked,
label: :repeated,
name: :columns,
tag: 4,
type: {:message, PgQuery.Node}
},
context_item: %{
__struct__: Protox.Field,
extender: nil,
kind: %{__struct__: Protox.Scalar, default_value: nil},
label: :optional,
name: :context_item,
tag: 1,
type: {:message, PgQuery.JsonValueExpr}
},
lateral: %{
__struct__: Protox.Field,
extender: nil,
kind: %{__struct__: Protox.Scalar, default_value: false},
label: :optional,
name: :lateral,
tag: 7,
type: :bool
},
location: %{
__struct__: Protox.Field,
extender: nil,
kind: %{__struct__: Protox.Scalar, default_value: 0},
label: :optional,
name: :location,
tag: 8,
type: :int32
},
on_error: %{
__struct__: Protox.Field,
extender: nil,
kind: %{__struct__: Protox.Scalar, default_value: nil},
label: :optional,
name: :on_error,
tag: 5,
type: {:message, PgQuery.JsonBehavior}
},
passing: %{
__struct__: Protox.Field,
extender: nil,
kind: :unpacked,
label: :repeated,
name: :passing,
tag: 3,
type: {:message, PgQuery.Node}
},
pathspec: %{
__struct__: Protox.Field,
extender: nil,
kind: %{__struct__: Protox.Scalar, default_value: nil},
label: :optional,
name: :pathspec,
tag: 2,
type: {:message, PgQuery.JsonTablePathSpec}
}
},
file_options: nil,
name: PgQuery.JsonTable,
syntax: :proto3
}
end
end