datakiln.metadata.script module

SQL script metadata.

exception datakiln.metadata.script.ScriptError(path: Path, message: str)[source]

Bases: ValueError

Error in a script.

class datakiln.metadata.script.ScriptMeta(path: Path, sql: str, dialect: str | Type[Dialect] = <class 'datakiln.metadata.dialect.ExtendedPostgres'>, external: bool = False)[source]

Bases: object

SQL script and the database objects it creates and uses.

classmethod from_sql(path: Path, directory: Path, dialect: str | Type[Dialect] = <class 'datakiln.metadata.dialect.ExtendedPostgres'>, external: bool = False) → ScriptMeta[source]

Load script metadata from a SQL file.

Parameters:
  • path (Path) – Path of the script.

  • directory (Path) – Directory the script path is relative to.

  • dialect (str | type[sqlglot.dialects.dialect.Dialect]) – SQLGlot dialect of the script, by name or class.

  • external (bool) – Whether another repo builds the script.

Returns:

Script metadata.

Return type:

ScriptMeta

record(session)[source]

Record of the script in the metadata, if it was built.

Parameters:

session (datakiln.metadata.database.Session) – Database Session.

Return type:

datakiln.metadata.table.Script