DENIED_FUNCTIONSconstconst 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.
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
DENIED_FUNCTIONSconstconst 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.
GuardOptionsinterfaceno test imports itinterface GuardOptionsWhat a guard may be given.
| Member | Type | What it is |
|---|---|---|
allowPragma? | boolean | Allow a PRAGMA that reads. |
deniedFunctions? | readonly string[] | The functions that may not be called; the default list where not given. |
catalog? | Catalog | The 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? | number | The most nodes of the statement. |
Guardedinterfaceno test imports itinterface GuardedA statement that only reads.
| Member | Type | What it is |
|---|---|---|
parsed | Parsed | |
statement | Statement |
readOnlyProfilefunctionno test imports itfunction readOnlyProfile(options?: GuardOptions): ProfileThe profile of the language that only reads.
guardfunctionfunction 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.
refusalfunctionfunction refusal(text: string, dialect: Dialect, options?: GuardOptions): string | undefinedThe sentence of the first violation with its place, or undefined where the text is allowed.