IF Commons GitHub

aide/introspect/mod

Introspection (commons lang-sql 0008-sql-introspect): SQL over the syntax tree. introspect parses a text and gives an Introspection whose query answers a small SQL over the relations of the parse (statements, nodes, attributes, ancestors, tokens, comments, names, calls, parameters, common table expressions, diagnostics and the language of the dialect), and whose diagnostics are the errors of the parse and the rows of the rules, which are queries too. A helper of aide: it runs its queries on the engine of aide/relational.

const i = introspect("DELETE FROM t; SELECT * FROM u", postgres);
i.query("SELECT name, access FROM table_ref");   // t write, u read
i.diagnostics().map((d) => d.code);              // ["delete-without-where", "select-star"]

Spec: 0008-sql-introspect FR-001, FR-004, FR-007

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

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

IntrospectOptionsinterfaceno test imports it
interface IntrospectOptions

What introspection may be given.

MemberTypeWhat it is
functions?readonly FunctionSpec[]The functions of the function relation.
Diagnosticinterfaceno test imports it
interface Diagnostic

A diagnostic: where, how bad, and why.

MemberTypeWhat it is
severity"error" | "info" | "warning"
codestring
messagestring
startnumber
endnumber
rulestring
nodenumberThe id of the node in the node relation, 0 for a parse error.
Introspectioninterfaceno test imports it
interface Introspection

The introspection of a parse.

MemberTypeWhat it is
parsedParsed
query(sql: string, params?: readonly Value[] | undefined) => Result<Table, QueryError>Answers a query over the relations.
tables() => Readonly<Record<string, readonly string[]>>The relations and their columns.
built() => readonly string[]The relations built so far.
diagnostics() => readonly Diagnostic[]The errors of the parse and the findings of the rules.
addRule(rule: Rule) => Result<Rule, QueryError>Adds a rule; an error value where its query does not run or has no node column.
introspectfunction
function introspect(text: string, dialect: Dialect, options?: IntrospectOptions): Introspection

Reads a text in a dialect and gives its introspection.

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

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