Classes
BigInt () |
Represents a BIGINT type. |
Boolean () |
Represents a BOOL type. |
ColumnType () |
Implements some underlying mechanisms for a Column . |
Integer () |
Represents an INTEGER type. |
SmallInt () |
Represents a SMALLINT type. |
String (size: int = -1) |
Represents a VARCHAR() type. |
Text () |
Represents a TEXT type. |
Timestamp () |
Represents a TIMESTAMP type. |
Exceptions
ColumnValidationError |
Raised when a column fails validation. |
asyncqlio.orm.schema.types.
ColumnValidationError
[source]¶Bases: asyncqlio.exc.DatabaseException
Raised when a column fails validation.
with_traceback
()¶Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
asyncqlio.orm.schema.types.
ColumnType
[source]¶Bases: abc.ABC
Implements some underlying mechanisms for a Column
.
The only method that is required to be implemented on children is ColumnType.sql()
-
which is used in CREATE TABLE declarations, etc. ColumnType.on_set()
,
ColumnType.on_get()
and so on are not required to be implemented - the defaults will
work fine.
The ColumnType is responsible for actually loading the data from the row’s internal storage and to the user code.
# we hate fun
def on_get(self, row, column):
return "lol"
...
# row is a random row object
# load the `fun` column which has this weird type
value = row.fun
print(value) # "lol", regardless of what was stored in the database.
Accordingly, it is also responsible for storing the data into the row’s internal storage.
def on_set(*args, **kwargs):
return None
row.not_fun = 1
print(row.not_fun) # None - no value was stored in the row
To actually insert a value into the row’s storage table, use ColumnType.store_value()
.
Correspondingly, loading a value from the row’s storage table can be achieved with
ColumnType.load_value()
. These functions should be used, as they are guarenteed to work
across all versions.
Columns will proxy bad attribute accesses from the Column object to this type object - meaning types can implement custom operators, if applicable.
class User(Table):
id = Column(MyWeirdType())
...
# MyWeirdType implements `.contains`
# the contains call is proxied to (MyWeirdType instance).contains("heck")
q = await sess.select(User).where(User.id.contains("heck")).first()
column
¶The column this type object is associated with.
validate_set
(row: asyncqlio.orm.schema.table.Table, value: typing.Any) → bool[source]¶Validates that the item being set is valid.
This is called by the default on_set
.
Parameters: |
|
---|---|
Returns: | A bool indicating if this is valid or not. |
store_value
(row: asyncqlio.orm.schema.table.Table, value: typing.Any)[source]¶Stores a value in the row’s storage table.
This is for internal usage only.
Parameters: |
|
---|
on_set
(row: asyncqlio.orm.schema.table.Table, value: typing.Any) → typing.Any[source]¶Called when a value is a set on this column.
This is the default method - it will call ColumnType.validate_set()
to validate the
type before storing it. This is useful for simple column types.
Parameters: |
|
---|
on_get
(row: asyncqlio.orm.schema.table.Table) → typing.Any[source]¶Called when a value is retrieved from this column.
Parameters: | row – The row that is being retrieved. |
---|---|
Returns: | The value of the row’s internal storage. |
asyncqlio.orm.schema.types.
String
(size: int = -1)[source]¶Bases: asyncqlio.orm.schema.types.ColumnType
Represents a VARCHAR() type.
size
= None¶The max size of this String.
like
(other: str) → asyncqlio.orm.operators.Like[source]¶Returns a LIKE operator, checking if this column is LIKE another string.
Parameters: | other – The other string to check. |
---|
ilike
(other: str) → typing.Union[asyncqlio.orm.operators.ILike, asyncqlio.orm.operators.HackyILike][source]¶Returns an ILIKE operator, checking if this column is case-insensitive LIKE another string.
Warning
This is not supported in all DB backends.
Parameters: | other – The other string to check. |
---|
create_default
() → asyncqlio.orm.schema.types.ColumnType¶Creates the default object for this table in the event that a type is passed to a column, instead of an instance.
in_
(*args) → asyncqlio.orm.operators.In¶Returns an IN operator, checking if a value in this column is in a tuple of items.
Parameters: | args – The items to check. |
---|
on_get
(row: asyncqlio.orm.schema.table.Table) → typing.Any¶Called when a value is retrieved from this column.
Parameters: | row – The row that is being retrieved. |
---|---|
Returns: | The value of the row’s internal storage. |
on_set
(row: asyncqlio.orm.schema.table.Table, value: typing.Any) → typing.Any¶Called when a value is a set on this column.
This is the default method - it will call ColumnType.validate_set()
to validate the
type before storing it. This is useful for simple column types.
Parameters: |
|
---|
store_value
(row: asyncqlio.orm.schema.table.Table, value: typing.Any)¶Stores a value in the row’s storage table.
This is for internal usage only.
Parameters: |
|
---|
asyncqlio.orm.schema.types.
Text
[source]¶Bases: asyncqlio.orm.schema.types.String
Represents a TEXT type. TEXT type columns are very similar to String type objects, except that they have no size limit.
Note
This is preferable to the String type in some databases.
Warning
This is deprecated in MSSQL.
create_default
() → asyncqlio.orm.schema.types.ColumnType¶Creates the default object for this table in the event that a type is passed to a column, instead of an instance.
ilike
(other: str) → typing.Union[asyncqlio.orm.operators.ILike, asyncqlio.orm.operators.HackyILike]¶Returns an ILIKE operator, checking if this column is case-insensitive LIKE another string.
Warning
This is not supported in all DB backends.
Parameters: | other – The other string to check. |
---|
in_
(*args) → asyncqlio.orm.operators.In¶Returns an IN operator, checking if a value in this column is in a tuple of items.
Parameters: | args – The items to check. |
---|
like
(other: str) → asyncqlio.orm.operators.Like¶Returns a LIKE operator, checking if this column is LIKE another string.
Parameters: | other – The other string to check. |
---|
on_get
(row: asyncqlio.orm.schema.table.Table) → typing.Any¶Called when a value is retrieved from this column.
Parameters: | row – The row that is being retrieved. |
---|---|
Returns: | The value of the row’s internal storage. |
on_set
(row: asyncqlio.orm.schema.table.Table, value: typing.Any) → typing.Any¶Called when a value is a set on this column.
This is the default method - it will call ColumnType.validate_set()
to validate the
type before storing it. This is useful for simple column types.
Parameters: |
|
---|
store_value
(row: asyncqlio.orm.schema.table.Table, value: typing.Any)¶Stores a value in the row’s storage table.
This is for internal usage only.
Parameters: |
|
---|
asyncqlio.orm.schema.types.
Boolean
[source]¶Bases: asyncqlio.orm.schema.types.ColumnType
Represents a BOOL type.
create_default
() → asyncqlio.orm.schema.types.ColumnType¶Creates the default object for this table in the event that a type is passed to a column, instead of an instance.
in_
(*args) → asyncqlio.orm.operators.In¶Returns an IN operator, checking if a value in this column is in a tuple of items.
Parameters: | args – The items to check. |
---|
on_get
(row: asyncqlio.orm.schema.table.Table) → typing.Any¶Called when a value is retrieved from this column.
Parameters: | row – The row that is being retrieved. |
---|---|
Returns: | The value of the row’s internal storage. |
on_set
(row: asyncqlio.orm.schema.table.Table, value: typing.Any) → typing.Any¶Called when a value is a set on this column.
This is the default method - it will call ColumnType.validate_set()
to validate the
type before storing it. This is useful for simple column types.
Parameters: |
|
---|
store_value
(row: asyncqlio.orm.schema.table.Table, value: typing.Any)¶Stores a value in the row’s storage table.
This is for internal usage only.
Parameters: |
|
---|
asyncqlio.orm.schema.types.
Integer
[source]¶Bases: asyncqlio.orm.schema.types.ColumnType
Represents an INTEGER type.
Warning
This represents a 32-bit integer (2**31-1 to -2**32)
create_default
() → asyncqlio.orm.schema.types.ColumnType¶Creates the default object for this table in the event that a type is passed to a column, instead of an instance.
in_
(*args) → asyncqlio.orm.operators.In¶Returns an IN operator, checking if a value in this column is in a tuple of items.
Parameters: | args – The items to check. |
---|
on_get
(row: asyncqlio.orm.schema.table.Table) → typing.Any¶Called when a value is retrieved from this column.
Parameters: | row – The row that is being retrieved. |
---|---|
Returns: | The value of the row’s internal storage. |
store_value
(row: asyncqlio.orm.schema.table.Table, value: typing.Any)¶Stores a value in the row’s storage table.
This is for internal usage only.
Parameters: |
|
---|
asyncqlio.orm.schema.types.
SmallInt
[source]¶Bases: asyncqlio.orm.schema.types.Integer
Represents a SMALLINT type.
create_default
() → asyncqlio.orm.schema.types.ColumnType¶Creates the default object for this table in the event that a type is passed to a column, instead of an instance.
in_
(*args) → asyncqlio.orm.operators.In¶Returns an IN operator, checking if a value in this column is in a tuple of items.
Parameters: | args – The items to check. |
---|
on_get
(row: asyncqlio.orm.schema.table.Table) → typing.Any¶Called when a value is retrieved from this column.
Parameters: | row – The row that is being retrieved. |
---|---|
Returns: | The value of the row’s internal storage. |
store_value
(row: asyncqlio.orm.schema.table.Table, value: typing.Any)¶Stores a value in the row’s storage table.
This is for internal usage only.
Parameters: |
|
---|
asyncqlio.orm.schema.types.
BigInt
[source]¶Bases: asyncqlio.orm.schema.types.Integer
Represents a BIGINT type.
create_default
() → asyncqlio.orm.schema.types.ColumnType¶Creates the default object for this table in the event that a type is passed to a column, instead of an instance.
in_
(*args) → asyncqlio.orm.operators.In¶Returns an IN operator, checking if a value in this column is in a tuple of items.
Parameters: | args – The items to check. |
---|
on_get
(row: asyncqlio.orm.schema.table.Table) → typing.Any¶Called when a value is retrieved from this column.
Parameters: | row – The row that is being retrieved. |
---|---|
Returns: | The value of the row’s internal storage. |
store_value
(row: asyncqlio.orm.schema.table.Table, value: typing.Any)¶Stores a value in the row’s storage table.
This is for internal usage only.
Parameters: |
|
---|
asyncqlio.orm.schema.types.
Timestamp
[source]¶Bases: asyncqlio.orm.schema.types.ColumnType
Represents a TIMESTAMP type.
create_default
() → asyncqlio.orm.schema.types.ColumnType¶Creates the default object for this table in the event that a type is passed to a column, instead of an instance.
in_
(*args) → asyncqlio.orm.operators.In¶Returns an IN operator, checking if a value in this column is in a tuple of items.
Parameters: | args – The items to check. |
---|
on_get
(row: asyncqlio.orm.schema.table.Table) → typing.Any¶Called when a value is retrieved from this column.
Parameters: | row – The row that is being retrieved. |
---|---|
Returns: | The value of the row’s internal storage. |
on_set
(row: asyncqlio.orm.schema.table.Table, value: typing.Any) → typing.Any¶Called when a value is a set on this column.
This is the default method - it will call ColumnType.validate_set()
to validate the
type before storing it. This is useful for simple column types.
Parameters: |
|
---|
store_value
(row: asyncqlio.orm.schema.table.Table, value: typing.Any)¶Stores a value in the row’s storage table.
This is for internal usage only.
Parameters: |
|
---|