IF Commons GitHub

aide/guard/mod

The guard of a query that only reads (commons lang-sql 0012-sql-guard): guard reads a text with the parser of a dialect and gives its parse only where it is exactly one statement that reads (a query, with no data change, no definition, no SELECT ... INTO, no locking clause and no call of a function that sleeps, reads a file, takes a lock or changes a sequence), and every violation with its span where it is not. A word of a write inside a string, an identifier or a comment is not a violation, which no pattern over the text can say. With a catalog, a plain SELECT is bound to the tables the connection has.

guard("SELECT 'DELETE FROM t'", postgres);            // ok
refusal("WITH x AS (DELETE FROM t RETURNING *) SELECT * FROM x", postgres); // "delete is not in the language read-only (line 1, column 14)"

Spec: 0012-sql-guard FR-001, FR-002, FR-003, FR-004, FR-005, FR-006

Source: commons/lang-sql/src/aide/guard/mod.ts

3 of 6 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

DENIED_FUNCTIONSconst
const DENIED_FUNCTIONS: readonly string[]

The functions that sleep, read or write files, take locks, change a sequence or a setting, load code or reach another host.

Imported by 10 tests of the run (10 passed, 0 failed): the library's results

GuardOptionsinterfaceno test imports it
interface GuardOptions

What a guard may be given.

MemberTypeWhat it is
allowPragma?booleanAllow a PRAGMA that reads.
deniedFunctions?readonly string[]The functions that may not be called; the default list where not given.
catalog?CatalogThe tables a plain SELECT may be bound to, and the types of their columns.
tables?readonly string[]The tables that may be read, whatever the catalog.
maxNodes?numberThe most nodes of the statement.
Guardedinterfaceno test imports it
interface Guarded

A statement that only reads.

MemberTypeWhat it is
parsedParsed
statementStatement
readOnlyProfilefunctionno test imports it
function readOnlyProfile(options?: GuardOptions): Profile

The profile of the language that only reads.

guardfunction
function guard(text: string, dialect: Dialect, options?: GuardOptions): Result<Guarded, readonly Violation[]>

The parse of a text that is exactly one statement that only reads; every violation with its span where it is not.

Imported by 10 tests of the run (10 passed, 0 failed): the library's results

refusalfunction
function refusal(text: string, dialect: Dialect, options?: GuardOptions): string | undefined

The sentence of the first violation with its place, or undefined where the text is allowed.

Imported by 10 tests of the run (10 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.