Skip to content

PgSettings

Namespace: Ankus

Assembly: Ankus.Runtime.dll

Changes PostgreSQL configuration settings for the duration of a callback.

public static class PgSettings

PostgreSQL applies the values as it does a function’s SET clause: at a new nest level, with the current user’s privileges, and restored when the callback returns or throws. When a PostgreSQL error aborts the enclosing transaction or subtransaction, that rollback restores them instead. A plain SET inside the callback outlasts it, as it does inside such a function.

Inheritance: object

Run(IEnumerable<KeyValuePair<string, string>>, Action)

Section titled “Run(IEnumerable<KeyValuePair<string, string>>, Action)”

Runs synchronous work with several settings changed.

public static void Run(IEnumerable<KeyValuePair<string, string>> settings, Action action)

Parameters:

settings — IEnumerable<KeyValuePair<string, string>>

The setting names and values, applied in order.

action — Action

The work to run on the active backend thread.

See Run<TResult>(IEnumerable<KeyValuePair<string, string>>, Func<TResult>).

Runs synchronous work with one setting changed.

public static void Run(string name, string value, Action action)

Parameters:

name — string

The setting’s name, such as lock_timeout.

value — string

The value, in the text form SET accepts.

action — Action

The work to run on the active backend thread.

See Run<TResult>(IEnumerable<KeyValuePair<string, string>>, Func<TResult>).

Run<TResult>(IEnumerable<KeyValuePair<string, string>>, Func<TResult>)

Section titled “Run<TResult>(IEnumerable<KeyValuePair<string, string>>, Func<TResult>)”

Runs synchronous work with several settings changed and returns its result.

public static TResult Run<TResult>(IEnumerable<KeyValuePair<string, string>> settings, Func<TResult> action)

Type parameters:

TResult

The callback result type.

Parameters:

settings — IEnumerable<KeyValuePair<string, string>>

The setting names and values, applied in order.

action — Func<TResult>

The work to run on the active backend thread.

Returns: TResult

The callback’s result.

PostgreSQL checks every name, value and privilege before the callback runs. A rejected one throws PgException, such as SQLSTATE 42704 for an unknown setting or 22023 for an invalid value, and leaves the transaction usable. Where PostgreSQL cannot start a subtransaction, such as in a transaction callback, a rejection requires rollback like any other error there. Values use the text form of SET, including units such as 100ms. Do not perform transaction control or asynchronous work in the callback.

Run<TResult>(string, string, Func<TResult>)

Section titled “Run<TResult>(string, string, Func<TResult>)”

Runs synchronous work with one setting changed and returns its result.

public static TResult Run<TResult>(string name, string value, Func<TResult> action)

Type parameters:

TResult

The callback result type.

Parameters:

name — string

The setting’s name, such as lock_timeout.

value — string

The value, in the text form SET accepts.

action — Func<TResult>

The work to run on the active backend thread.

Returns: TResult

The callback’s result.

See Run<TResult>(IEnumerable<KeyValuePair<string, string>>, Func<TResult>).