asyncqlio.orm.schema.column

Classes for column objects.

Classes

AliasedColumn(alias_table, column) Represents a column on an aliased table.
Column(type_, *[, primary_key, nullable, …]) Represents a column in a table in a database.
class asyncqlio.orm.schema.column.AliasedColumn(alias_table, column)[source]

Bases: object

Represents a column on an aliased table.

Parameters:
  • alias_table (AliasedTable) – The alias table this column is a member of.
  • column (Column) – The Column object this aliased column proxies.
class asyncqlio.orm.schema.column.Column(type_, *, primary_key=False, nullable=False, default=<object object>, index=True, unique=False, foreign_key=None, table=None)[source]

Bases: object

Represents a column in a table in a database.

class MyTable(Table):
    id = Column(Integer, primary_key=True)

The id column will mirror the ID of records in the table when fetching, etc. and can be set on a record when storing in a table.

sess = db.get_session()
user = await sess.select(User).where(User.id == 2).first()

print(user.id)  # 2
Parameters:
  • type (Union[ColumnType, Type[ColumnType]]) – The ColumnType that represents the type of this column.
  • primary_key (bool) – Is this column the table’s Primary Key (the unique identifier that identifies each row)?
  • nullable (bool) – Can this column be NULL?
  • default (Any) – The client-side default for this column. If no value is provided when inserting, this value will automatically be added to the insert query.
  • index (bool) – Should this column be indexed?
  • unique (bool) – Is this column unique?
  • foreign_key (Optional[ForeignKey]) – The ForeignKey associated with this column.
name = None

The name of the column. This can be manually set, or automatically set when set on a table.

table = None

The Table instance this Column is associated with.

type = None

The ColumnType that represents the type of this column.

default = None

The default for this column.

primary_key = None

If this Column is a primary key.

nullable = None

If this Column is nullable.

indexed = None

If this Column is indexed.

unique = None

If this Column is unique.

foreign_key = None

The foreign key associated with this column.

table_name

The name of this column’s table.

Return type:str
autoincrement

Whether this column is set to autoincrement.

Return type:bool
classmethod with_name(name, *args, **kwargs)[source]

Creates this column with a name already set.

Return type:Column
get_ddl_sql()[source]

Gets the DDL SQL for this column.

Return type:str
generate_schema(fp=None)[source]

Generates the library schema for this column.

Return type:str
eq(other)[source]

Checks if this column is equal to something else.

Note

This is the easy way to check if a column equals another column in a WHERE clause, because the default __eq__ behaviour returns a bool rather than an operator.

Return type:Eq
ne(other)[source]

Checks if this column is not equal to something else.

Note

This is the easy way to check if a column doesn’t equal another column in a WHERE clause, because the default __ne__ behaviour returns a bool rather than an operator.

Return type:NEq
asc()[source]

Returns the ascending sorter operator for this column.

Return type:AscSorter
desc()[source]

Returns the descending sorter operator for this column.

Return type:DescSorter
set(value)[source]

Sets this column in a bulk update.

Return type:ValueSetter
incr(value)[source]

Increments this column in a bulk update.

Return type:IncrementSetter
decr(value)[source]

Decrements this column in a bulk update.

Return type:DecrementSetter
quoted_fullname_with_table(table)[source]

Gets the quoted fullname with a table. This is used for columns with alias tables.

Parameters:table (TableMeta) – The Table or AliasedTable to use.
Return type:str
Returns:
quoted_name

Gets the quoted name for this column.

This returns the column name in “column” format.

quoted_fullname

Gets the full quoted name for this column.

This returns the column name in “table”.”column” format.

foreign_column
Return type:Column
Returns:The foreign Column this is associated with, or None otherwise.
alias_name(table=None, quoted=False)[source]

Gets the alias name for a column, given the table.

This is in the format of t_<table name>_<column_name>.

Parameters:
  • table – The Table to use to generate the alias name. This is useful for aliased tables.
  • quoted (bool) – Should the name be quoted?
Return type:

str

Returns:

A str representing the alias name.