A libpg_query wrapper written in elixir.
Useful for parsing postgresql queries.
Fingerprints queries will ignoring formatting and concrete values.
iex> PgQuery.fingerprint_query("SELECT count(*) from users where age > 50")
{:ok, "02dd673649193e38c3e5afb638f51614fee858ab1e"}
iex> PgQuery.fingerprint_query("SELECT count(*) from users where age < 50")
{:ok, "02dd673649193e38c3e5afb638f51614fee858ab1e"}
iex> PgQuery.fingerprint_query("SELECT 1 + 2")
{:ok, "025a33db2ae7cbfce37fa78c34b32e75b376eb6d16"}iex> PgQuery.parse_query("SELECT name, age from users")
{:ok,
[
%{
"RawStmt" => %{
"stmt" => %{
"SelectStmt" => %{
"fromClause" => [
%{
"RangeVar" => %{
"inh" => true,
"location" => 22,
"relname" => "users",
"relpersistence" => "p"
}
}
],
"op" => 0,
"targetList" => [
%{
"ResTarget" => %{
"location" => 7,
"val" => %{
"ColumnRef" => %{
"fields" => [%{"String" => %{"str" => "name"}}],
"location" => 7
}
}
}
},
%{
"ResTarget" => %{
"location" => 13,
"val" => %{
"ColumnRef" => %{
"fields" => [%{"String" => %{"str" => "age"}}],
"location" => 13
}
}
}
}
]
}
}
}
}
]}If available in Hex, the package can be installed
by adding pg_query to your list of dependencies in mix.exs:
def deps do
[
{:pg_query, "~> 0.1.0"}
]
endDocumentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/pg_query.