ralsei.jinja

Package Contents

Classes

SqlAdapter

Transform values into their SQL representation

SqlTemplateModule

Represents an imported template (see jinja2.Template.module)

SqlTemplate

Compiled jinja template that can be rendered

SqlEnvironment

Type-aware jinja environment for rendering SQL

SqlEnvironmentWrapper

Layer on top of ralsei.jinja.SqlEnvironment with extra local variables

ISqlEnvironment

Interface describing a ralsei.jinja.SqlEnvironment like object

API

class ralsei.jinja.SqlAdapter

Transform values into their SQL representation

Initialization

register_type(type_: type[ralsei.jinja.adapter.SqlAdapter.register_type.T], to_sql: collections.abc.Callable[[ralsei.jinja.adapter.SqlAdapter.register_type.T], str])

Register SQL renderer function for a type

to_sql(value: Any) str

Get SQL representation of a value

format(source: str, /, *args, **kwargs) str

Similar to str.format(), but applies to_sql() to each parameter

class ralsei.jinja.SqlTemplateModule(template: jinja2.environment.Template, context: jinja2.runtime.Context, body_stream: collections.abc.Iterable[str] | None = None)

Bases: jinja2.environment.TemplateModule

Represents an imported template (see jinja2.Template.module)

All the exported names of the template are available as attributes on this object.

Initialization

render() str

Render as string

render_sql() sqlalchemy.sql.elements.TextClause

Render and wrap with sqlalchemy.sql.expression.text()

render_split() list[str]

Render as multiple statements, splitting on {%split%} tag

render_sql_split() list[sqlalchemy.sql.elements.TextClause]

Render as multiple statements, splitting on {%split%} tag, wrap with sqlalchemy.sql.expression.text()

class ralsei.jinja.SqlTemplate

Bases: jinja2.Template

Compiled jinja template that can be rendered

render_sql(*args: Any, **kwargs: Any) sqlalchemy.sql.elements.TextClause

Render and wrap in sqlalchemy.sql.expression.text()

render_split(*args: Any, **kwargs: Any) list[str]

Render as multiple statements, splitting on {%split%} tag

render_sql_split(*args: Any, **kwargs: Any) list[sqlalchemy.sql.elements.TextClause]

Render as multiple statements, splitting on {%split%} tag, wrap in sqlalchemy.sql.expression.text()

make_module(vars: dict[str, Any] | None = None, shared: bool = False, locals: collections.abc.Mapping[str, Any] | None = None) ralsei.jinja.environment.SqlTemplateModule

The template as a module, use this to access exported template variables

class ralsei.jinja.SqlEnvironment(dialect_info: ralsei.dialect.DialectInfo = BaseDialectInfo)

Bases: jinja2.Environment

Type-aware jinja environment for rendering SQL

Parameters:
dialect_info: ralsei.dialect.DialectInfo = BaseDialectInfo

dialect-specific settings

Initialization

property adapter : ralsei.jinja.adapter.SqlAdapter

Type adapter that turns values in braces (like {{value}}) into SQL strings

property dialect_info : ralsei.dialect.DialectInfo

Dialect-specific settings

from_string(source: str | jinja2.nodes.Template, globals: collections.abc.MutableMapping[str, Any] | None = None, template_class: type[jinja2.Template] | None = None) jinja2.Template

See jinja2.Environment.from_string()

By default, the template class will be SqlTemplate

render(source: str, /, *args: Any, **kwargs: Any) str

Render template once, shorthand for self.from_string().render()

render_sql(source: str, /, *args: Any, **kwargs: Any) sqlalchemy.sql.elements.TextClause

Render and wrap with sqlalchemy.sql.expression.text()

render_split(source: str, /, *args: Any, **kwargs: Any) list[str]

Render as multiple statements, splitting on {%split%} tag

render_sql_split(source: str, /, *args: Any, **kwargs: Any) list[sqlalchemy.sql.elements.TextClause]

Render as multiple statements, splitting on {%split%} tag, wrap with sqlalchemy.sql.expression.text()

property base : ralsei.jinja.environment.SqlEnvironment
class ralsei.jinja.SqlEnvironmentWrapper(env: ralsei.jinja.environment.SqlEnvironment, locals: dict[str, Any])

Layer on top of ralsei.jinja.SqlEnvironment with extra local variables

Parameters:
env: ralsei.jinja.environment.SqlEnvironment

the base environment

locals: dict[str, Any]

local variables map

Initialization

property adapter : ralsei.jinja.adapter.SqlAdapter

Type adapter that turns values in braces (like {{value}}) into SQL strings

property dialect_info : ralsei.dialect.DialectInfo

Dialect-specific settings

from_string(source: str | jinja2.nodes.Template, globals: collections.abc.MutableMapping[str, Any] | None = None, template_class: None = None) ralsei.jinja.environment.SqlTemplate

See jinja2.Environment.from_string()

By default, the template class will be SqlTemplate

render(source: str, /, *args: Any, **kwargs: Any) str

Render template once, shorthand for self.from_string().render()

render_sql(source: str, /, *args: Any, **kwargs: Any) sqlalchemy.sql.elements.TextClause

Render and wrap with sqlalchemy.sql.expression.text()

render_split(source: str, /, *args: Any, **kwargs: Any) list[str]

Render as multiple statements, splitting on {%split%} tag

render_sql_split(source: str, /, *args: Any, **kwargs: Any) list[sqlalchemy.sql.elements.TextClause]

Render as multiple statements, splitting on {%split%} tag, wrap with sqlalchemy.sql.expression.text()

property base : ralsei.jinja.environment.SqlEnvironment

The base environment

class ralsei.jinja.ISqlEnvironment

Bases: typing.Protocol

Interface describing a ralsei.jinja.SqlEnvironment like object

(including ralsei.jinja.SqlEnvironmentWrapper)

property adapter : ralsei.jinja.adapter.SqlAdapter

Type adapter that turns values in braces (like {{value}}) into SQL strings

property dialect_info : ralsei.dialect.DialectInfo

Dialect-specific settings

from_string(source: str | jinja2.nodes.Template, globals: collections.abc.MutableMapping[str, Any] | None = None, template_class: None = None) ralsei.jinja.environment.SqlTemplate

See jinja2.Environment.from_string()

By default, the template class will be SqlTemplate

render(source: str, /, *args: Any, **kwargs: Any) str

Render template once, shorthand for self.from_string().render()

render_sql(source: str, /, *args: Any, **kwargs: Any) sqlalchemy.sql.elements.TextClause

Render and wrap with sqlalchemy.sql.expression.text()

render_split(source: str, /, *args: Any, **kwargs: Any) list[str]

Render as multiple statements, splitting on {%split%} tag

render_sql_split(source: str, /, *args: Any, **kwargs: Any) list[sqlalchemy.sql.elements.TextClause]

Render as multiple statements, splitting on {%split%} tag, wrap with sqlalchemy.sql.expression.text()

property base : ralsei.jinja.environment.SqlEnvironment

The base environment