Functions
table_base (name: str = , …) |
Gets a new base object to use for OO-style tables. |
Classes
AliasedTable (alias_name: str, …) |
Represents an “aliased table”. |
PrimaryKey (…) |
Represents the primary key of a table. |
Table (**kwargs) |
The “base” class for all tables. |
TableMeta (tblname: str, tblbases: tuple, …) |
The metaclass for a table object. |
TableMetadata () |
The root class for table metadata. |
asyncqlio.orm.schema.table.
TableMetadata
[source]¶Bases: object
The root class for table metadata. This stores a registry of tables, and is responsible for calculating relationships etc.
meta = TableMetadata()
Table = table_base(metadata=meta)
tables
= None¶A registry of table name -> table object for this metadata.
bind
= None¶The DB object bound to this metadata.
register_table
(tbl: asyncqlio.orm.schema.table.TableMeta, *, autosetup_tables: bool = False) → asyncqlio.orm.schema.table.TableMeta[source]¶Registers a new table object.
Parameters: |
|
---|
asyncqlio.orm.schema.table.
TableMeta
(tblname: str, tblbases: tuple, class_body: dict, register: bool = True, *args, **kwargs)[source]¶Bases: type
The metaclass for a table object. This represents the “type” of a table class.
Creates a new Table instance.
Parameters: |
|
---|
iter_relationships
() → typing.Generator[[asyncqlio.orm.schema.relationship.Relationship, NoneType], NoneType][source]¶Returns: | A generator that yields Relationship objects for this table. |
---|
iter_columns
() → typing.Generator[[asyncqlio.orm.schema.column.Column, NoneType], NoneType][source]¶Returns: | A generator that yields Column objects for this table. |
---|
get_column
(column_name: str, *, raise_si: bool = False) → typing.Union[asyncqlio.orm.schema.column.Column, NoneType][source]¶Gets a column by name.
Parameters: | column_name – The column name to lookup.
|
---|---|
Returns: | The Column associated with that name, or None if no column was found. |
get_relationship
(relationship_name) → typing.Union[asyncqlio.orm.schema.relationship.Relationship, NoneType][source]¶Gets a relationship by name.
Parameters: | relationship_name – The name of the relationship to get. |
---|---|
Returns: | The Relationship associated with that name, or None if it doesn’t existr. |
primary_key
¶Getter: | The PrimaryKey for this table. |
---|---|
Setter: | A new PrimaryKey for this table. |
Note
A primary key will automatically be calculated from columns at define time, if any
columns have primary_key
set to True.
mro
() → list¶return a type’s method resolution order
asyncqlio.orm.schema.table.
Table
(**kwargs)[source]¶Bases: object
The “base” class for all tables. This class is not actually directly used; instead
table_base()
should be called to get a fresh clone.
table
= None¶The actual table that this object is an instance of.
get_old_value
(column: asyncqlio.orm.schema.column.Column)[source]¶Gets the old value from the specified column in this row.
get_column_value
(column: asyncqlio.orm.schema.column.Column, return_default: bool = True)[source]¶Gets the value from the specified column in this row.
Parameters: |
|
---|
store_column_value
(column: asyncqlio.orm.schema.column.Column, value: typing.Any, track_history: bool = True)[source]¶Updates the value of a column in this row.
This will also update the history of the value, if applicable.
asyncqlio.orm.schema.table.
table_base
(name: str = 'Table', meta: typing.Union[asyncqlio.orm.schema.table.TableMetadata, NoneType] = None)[source]¶Gets a new base object to use for OO-style tables. This object is the parent of all tables created in the object-oriented style; it provides some key configuration to the relationship calculator and the DB object itself.
To use this object, you call this function to create the new object, and subclass it in your table classes:
Table = table_base()
class User(Table):
...
Binding the base object to the database object is essential for querying:
# ensure the table is bound to that database
db.bind_tables(Table)
# now we can do queries
sess = db.get_session()
user = await sess.select(User).where(User.id == 2).first()
Each Table object is associated with a database interface, which it uses for special querying
inside the object, such as Table.get()
.
class User(Table):
id = Column(Integer, primary_key=True)
...
db.bind_tables(Table)
# later on, in some worker code
user = await User.get(1)
Parameters: |
|
---|---|
Returns: | A new Table class that can be used for OO tables. |
asyncqlio.orm.schema.table.
AliasedTable
(alias_name: str, table: typing.Type[asyncqlio.orm.schema.table.Table])[source]¶Bases: object
Represents an “aliased table”. This is a transparent proxy to a TableMeta
table, and
will create the right Table objects when called.
class User(Table):
id = Column(Integer, primary_key=True, autoincrement=True)
username = Column(String, nullable=False, unique=True)
password = Column(String, nullable=False)
NotUser = AliasedTable("not_user", User)
Parameters: |
|
---|
get_column
(column_name: str) → asyncqlio.orm.schema.column.Column[source]¶Gets a column by name from the specified table.
This will use the base TableMeta.get_column()
, and then search for columns via
their alias name using this table.
asyncqlio.orm.schema.table.
PrimaryKey
(*cols: asyncqlio.orm.schema.column.Column)[source]¶Bases: object
Represents the primary key of a table.
A primary key can be on any 1 to N columns in a table.
class Something(Table):
first_id = Column(Integer)
second_id = Column(Integer)
pkey = PrimaryKey(Something.first_id, Something.second_id)
Something.primary_key = pkey
Alternatively, the primary key can be automatically calculated by passing primary_key=True
to columns in their constructor:
class Something(Table):
id = Column(Integer, primary_key=True)
print(Something.primary_key)
table
= None¶The table this primary key is bound to.