PostgresSigil (postgres_sigil v0.4.0)

A sigil (~q) to make it easier to compose together SQL expressions. A SQL expression consists of a statement and interpolated variables. Expressions themselves can be interpolated and will be flattened.

Link to this section Summary

Functions

Append the given variable to the SQL expression. It will be added as position parameter and the value will go into bindings. Non boolean atoms will be converted into strings.

Appends a DB identifier (i.e. a column name) to the query. It is enclosed in double quotes so any quotes within the name are escaped.

Escape hatch for appending arbitrary data to the query without any escaping Obviously doing this can lead to SQL injection vulnerabilities so be careful but there are legitimate reasons to want to do this from time to time.

Append variable(s) to the SQL query enclosed in brackets, for inserts / updates. Multiple variables can be passed by using a tuple. Lists are interpreted to be bulk inserts, so will generate multiple bracket-enclosed sequences.

Lift a plain string into a SQL expression with no variables

This macro rewrites interpolated values into calls to Siql.append For inserts and updates you can wrap the variables in values()

Turn the SQL into a tuple of the statement & bindings

Link to this section Functions

Link to this function

append(sql, var)

@spec append(PostgresSigil.Sql.t(), any()) :: PostgresSigil.Sql.t()

Append the given variable to the SQL expression. It will be added as position parameter and the value will go into bindings. Non boolean atoms will be converted into strings.

Link to this function

append_identifier(sql, col)

@spec append_identifier(PostgresSigil.Sql.t(), any()) :: PostgresSigil.Sql.t()

Appends a DB identifier (i.e. a column name) to the query. It is enclosed in double quotes so any quotes within the name are escaped.

Link to this function

append_unsafe(sql, item)

@spec append_unsafe(PostgresSigil.Sql.t(), any()) :: PostgresSigil.Sql.t()

Escape hatch for appending arbitrary data to the query without any escaping Obviously doing this can lead to SQL injection vulnerabilities so be careful but there are legitimate reasons to want to do this from time to time.

Link to this function

append_values(sql, tuple)

@spec append_values(PostgresSigil.Sql.t(), any()) :: PostgresSigil.Sql.t()

Append variable(s) to the SQL query enclosed in brackets, for inserts / updates. Multiple variables can be passed by using a tuple. Lists are interpreted to be bulk inserts, so will generate multiple bracket-enclosed sequences.

@spec lift(binary()) :: PostgresSigil.Sql.t()

Lift a plain string into a SQL expression with no variables

Link to this macro

sigil_q(arg, list)

(macro)

This macro rewrites interpolated values into calls to Siql.append For inserts and updates you can wrap the variables in values()

Turn the SQL into a tuple of the statement & bindings