ralsei.types

Package Contents

Classes

ToSql

Interface for an object that renders to SQL inside a jinja template

Sql

Raw SQL string, inserted into the template as-is

Identifier

A SQL identifier, like "table_name"

Table

Table identifier, like "schema_name"."table_name"

Placeholder

Placeholder for a bind parameter, like :value

ColumnBase

Base class for Column and ColumnRendered

Column

Column template class

ColumnRendered

Rendered column class

ColumnDefinition

Renders to table_name TYPE, for use in table definitions

ValueColumnBase

Column and its associated value, base class for ValueColumn and ValueColumnRendered

ValueColumn

Column template class with an associated value

ValueColumnRendered

Rendered column class with an associated value

ValueColumnSetStatement

Renders to name = value, for use in UPDATE statements

IdColumn

Column name and its associated value, used inside a WHERE clause for locating a row

API

class ralsei.types.ToSql

Bases: abc.ABC

Interface for an object that renders to SQL inside a jinja template

abstract to_sql(env: ralsei.jinja.ISqlEnvironment) str

Render to SQL string

class ralsei.types.Sql

Bases: ralsei.types.to_sql.ToSql

Raw SQL string, inserted into the template as-is

value : str = None
to_sql(env: ralsei.jinja.ISqlEnvironment) str
class ralsei.types.Identifier

Bases: ralsei.types.to_sql.ToSql

A SQL identifier, like "table_name"

value : str = None
to_sql(env: ralsei.jinja.ISqlEnvironment) str
class ralsei.types.Table

Bases: ralsei.types.to_sql.ToSql

Table identifier, like "schema_name"."table_name"

name : str = None
schema : Optional[str] = None
__str__() str
to_sql(env: ralsei.jinja.ISqlEnvironment) str
class ralsei.types.Placeholder

Bases: ralsei.types.to_sql.ToSql

Placeholder for a bind parameter, like :value

Must not any spaces or special characters

name : str = None
__post_init__()
to_sql(env: ralsei.jinja.ISqlEnvironment) str
class ralsei.types.ColumnBase(name: str)

Bases: abc.ABC

Base class for Column and ColumnRendered

Initialization

name : str = None
property identifier : ralsei.types.primitives.Identifier

name wrapped in a SQL identifier

abstract render(env: ralsei.jinja.ISqlEnvironment, /, **params: Any) ralsei.types.column.ColumnRendered

Turn into the rendered version

class ralsei.types.Column(name: str, type: str)

Bases: ralsei.types.column.ColumnBase

Column template class

Parameters:
name: str

column name

type: str

jinja template of the column type, like INT REFERENCES {{other}}(id)

Initialization

render(env: ralsei.jinja.ISqlEnvironment, /, **params: Any) ralsei.types.column.ColumnRendered

Render the type template

class ralsei.types.ColumnRendered(name: str, type: str)

Bases: ralsei.types.column.ColumnBase

Rendered column class

Parameters:
name: str

column name

type: str

column type as raw sql string, like INT REFERENCES "other"(id)

Initialization

type : ralsei.types.primitives.Sql = None
property definition : ralsei.types.column.ColumnDefinition

As column definition (name + type)

render(env: ralsei.jinja.ISqlEnvironment, /, **params: Any) ralsei.types.column.ColumnRendered
class ralsei.types.ColumnDefinition(column: ralsei.types.column.ColumnRendered)

Bases: ralsei.types.to_sql.ToSql

Renders to table_name TYPE, for use in table definitions

Initialization

column : ralsei.types.column.ColumnRendered = None
to_sql(env: ralsei.jinja.ISqlEnvironment) str
class ralsei.types.ValueColumnBase(name: str, value: Any = FROM_NAME)

Bases: ralsei.types.column.ColumnBase

Column and its associated value, base class for ValueColumn and ValueColumnRendered

Parameters:
name: str

column name

value: Any = FROM_NAME

value that will be applied to the column

By default, will be set to a ralsei.types.Placeholder with the same name as the column

Initialization

value : Any = None
property set_statement : ralsei.types.value_column.ValueColumnSetStatement

As set statement (name = value)

abstract render(env: ralsei.jinja.ISqlEnvironment, /, **params: Any) ralsei.types.value_column.ValueColumnRendered

Turn into the rendered version

class ralsei.types.ValueColumn(name: str, type: str, value: Any = FROM_NAME)

Bases: ralsei.types.column.Column, ralsei.types.value_column.ValueColumnBase

Column template class with an associated value

Parameters:
name: str

column name

type: str

jinja template of the column type, like INT REFERENCES {{other}}(id)

value: Any = FROM_NAME

value that will be applied to the column

By default, will be set to a ralsei.types.Placeholder with the same name as the column

Initialization

render(env: ralsei.jinja.ISqlEnvironment, /, **params: Any) ralsei.types.value_column.ValueColumnRendered

Render the type template

class ralsei.types.ValueColumnRendered(name: str, type: str, value: Any = FROM_NAME)

Bases: ralsei.types.column.ColumnRendered, ralsei.types.value_column.ValueColumnBase

Rendered column class with an associated value

Parameters:
name: str

column name

type: str

column type as raw sql string, like INT REFERENCES "other"(id)

value: Any = FROM_NAME

value that will be applied to the column

By default, will be set to a ralsei.types.Placeholder with the same name as the column

Initialization

render(env: ralsei.jinja.ISqlEnvironment, /, **params: Any) ralsei.types.value_column.ValueColumnRendered
class ralsei.types.ValueColumnSetStatement(value_column: ralsei.types.value_column.ValueColumnBase)

Bases: ralsei.types.to_sql.ToSql

Renders to name = value, for use in UPDATE statements

Initialization

value_column : ralsei.types.value_column.ValueColumnBase = None
to_sql(env: ralsei.jinja.ISqlEnvironment) str
class ralsei.types.IdColumn(name: str, value: Any = FROM_NAME)

Bases: ralsei.types.to_sql.ToSql

Column name and its associated value, used inside a WHERE clause for locating a row

Renders to name = value

Parameters:
name: str

column name

value: Any = FROM_NAME

value that uniquely identifies a row

By default, will be set to a ralsei.types.Placeholder with the same name as the column

Initialization

name : str = None
value : Any = None
property identifier : ralsei.types.primitives.Identifier

name wrapped in a SQL identifier

to_sql(env: ralsei.jinja.ISqlEnvironment) str