Column types.
Classes
BigInt () |
Represents a BIGINT type. |
BigSerial () |
Represents a BIGSERIAL type. |
Boolean () |
Represents a BOOL type. |
ColumnType () |
Implements some underlying mechanisms for a Column . |
Integer () |
Represents an INTEGER type. |
Numeric ([precision, scale, asdecimal]) |
Represents a NUMERIC type. |
Real () |
Represents a REAL type. |
Serial () |
Represents a SERIAL type. |
SmallInt () |
Represents a SMALLINT type. |
SmallSerial () |
Represents a SMALLSERIAL type. |
String ([size]) |
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.
schema
()[source]¶Return type: | str |
---|---|
Returns: | The library schema of this object. |
If this is not defined, any arguments given to the type will not persist across schema generation.
validate_set
(row, value)[source]¶Validates that the item being set is valid.
This is called by the default on_set
.
Parameters: | |
---|---|
Return type: | |
Returns: | A bool indicating if this is valid or not. |
store_value
(row, value)[source]¶Stores a value in the row’s storage table.
This is for internal usage only.
Parameters: |
---|
on_set
(row, value)[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: | |
---|---|
Return type: |
on_get
(row)[source]¶Called when a value is retrieved from this column.
Parameters: | row (Table ) – The row that is being retrieved. |
---|---|
Return type: | Any |
Returns: | The value of the row’s internal storage. |
create_default
()[source]¶Creates the default object for this table in the event that a type is passed to a column, instead of an instance.
Return type: | ColumnType |
---|
asyncqlio.orm.schema.types.
String
(size=-1)[source]¶Bases: asyncqlio.orm.schema.types.ColumnType
Represents a VARCHAR() type.
size
= None¶The max size of this String.
schema
()[source]¶Returns: | The library schema of this object. |
---|
If this is not defined, any arguments given to the type will not persist across schema generation.
validate_set
(row, value)[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. |
like
(other)[source]¶Returns a LIKE operator, checking if this column is LIKE another string.
Parameters: | other (str ) – The other string to check. |
---|---|
Return type: | Like |
ilike
(other)[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 (str ) – The other string to check. |
---|---|
Return type: | Union [ILike , HackyILike ] |
create_default
()¶Creates the default object for this table in the event that a type is passed to a column, instead of an instance.
Return type: | ColumnType |
---|
in_
(*args)¶Returns an IN operator, checking if a value in this column is in a tuple of items.
Parameters: | args – The items to check. |
---|---|
Return type: | In |
on_get
(row)¶Called when a value is retrieved from this column.
Parameters: | row (Table ) – The row that is being retrieved. |
---|---|
Return type: | Any |
Returns: | The value of the row’s internal storage. |
on_set
(row, value)¶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: | |
---|---|
Return type: |
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
()¶Creates the default object for this table in the event that a type is passed to a column, instead of an instance.
Return type: | ColumnType |
---|
ilike
(other)¶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 (str ) – The other string to check. |
---|---|
Return type: | Union [ILike , HackyILike ] |
in_
(*args)¶Returns an IN operator, checking if a value in this column is in a tuple of items.
Parameters: | args – The items to check. |
---|---|
Return type: | In |
like
(other)¶Returns a LIKE operator, checking if this column is LIKE another string.
Parameters: | other (str ) – The other string to check. |
---|---|
Return type: | Like |
on_get
(row)¶Called when a value is retrieved from this column.
Parameters: | row (Table ) – The row that is being retrieved. |
---|---|
Return type: | Any |
Returns: | The value of the row’s internal storage. |
on_set
(row, value)¶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: | |
---|---|
Return type: |
schema
()¶Returns: | The library schema of this object. |
---|
If this is not defined, any arguments given to the type will not persist across schema generation.
store_value
(row, value)¶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.
validate_set
(row, value)[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. |
create_default
()¶Creates the default object for this table in the event that a type is passed to a column, instead of an instance.
Return type: | ColumnType |
---|
in_
(*args)¶Returns an IN operator, checking if a value in this column is in a tuple of items.
Parameters: | args – The items to check. |
---|---|
Return type: | In |
on_get
(row)¶Called when a value is retrieved from this column.
Parameters: | row (Table ) – The row that is being retrieved. |
---|---|
Return type: | Any |
Returns: | The value of the row’s internal storage. |
on_set
(row, value)¶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: | |
---|---|
Return type: |
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)
on_set
(row, value)[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: |
|
---|
create_default
()¶Creates the default object for this table in the event that a type is passed to a column, instead of an instance.
Return type: | ColumnType |
---|
in_
(*args)¶Returns an IN operator, checking if a value in this column is in a tuple of items.
Parameters: | args – The items to check. |
---|---|
Return type: | In |
on_get
(row)¶Called when a value is retrieved from this column.
Parameters: | row (Table ) – The row that is being retrieved. |
---|---|
Return type: | Any |
Returns: | The value of the row’s internal storage. |
asyncqlio.orm.schema.types.
SmallInt
[source]¶Bases: asyncqlio.orm.schema.types.Integer
Represents a SMALLINT type.
create_default
()¶Creates the default object for this table in the event that a type is passed to a column, instead of an instance.
Return type: | ColumnType |
---|
in_
(*args)¶Returns an IN operator, checking if a value in this column is in a tuple of items.
Parameters: | args – The items to check. |
---|---|
Return type: | In |
on_get
(row)¶Called when a value is retrieved from this column.
Parameters: | row (Table ) – The row that is being retrieved. |
---|---|
Return type: | Any |
Returns: | The value of the row’s internal storage. |
on_set
(row, value)¶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: |
|
---|
asyncqlio.orm.schema.types.
BigInt
[source]¶Bases: asyncqlio.orm.schema.types.Integer
Represents a BIGINT type.
create_default
()¶Creates the default object for this table in the event that a type is passed to a column, instead of an instance.
Return type: | ColumnType |
---|
in_
(*args)¶Returns an IN operator, checking if a value in this column is in a tuple of items.
Parameters: | args – The items to check. |
---|---|
Return type: | In |
on_get
(row)¶Called when a value is retrieved from this column.
Parameters: | row (Table ) – The row that is being retrieved. |
---|---|
Return type: | Any |
Returns: | The value of the row’s internal storage. |
on_set
(row, value)¶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: |
|
---|
asyncqlio.orm.schema.types.
Serial
[source]¶Bases: asyncqlio.orm.schema.types.Integer
Represents a SERIAL type.
This type does not exist in SQLite; integer primary keys autoincrement already.
create_default
()¶Creates the default object for this table in the event that a type is passed to a column, instead of an instance.
Return type: | ColumnType |
---|
in_
(*args)¶Returns an IN operator, checking if a value in this column is in a tuple of items.
Parameters: | args – The items to check. |
---|---|
Return type: | In |
on_get
(row)¶Called when a value is retrieved from this column.
Parameters: | row (Table ) – The row that is being retrieved. |
---|---|
Return type: | Any |
Returns: | The value of the row’s internal storage. |
on_set
(row, value)¶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: |
|
---|
schema
()¶Return type: | str |
---|---|
Returns: | The library schema of this object. |
If this is not defined, any arguments given to the type will not persist across schema generation.
store_value
(row, value)¶Stores a value in the row’s storage table.
This is for internal usage only.
Parameters: |
---|
validate_set
(row, value)¶Checks if this int is in range for the type.
asyncqlio.orm.schema.types.
BigSerial
[source]¶Bases: asyncqlio.orm.schema.types.Serial
, asyncqlio.orm.schema.types.BigInt
Represents a BIGSERIAL type.
create_default
()¶Creates the default object for this table in the event that a type is passed to a column, instead of an instance.
Return type: | ColumnType |
---|
in_
(*args)¶Returns an IN operator, checking if a value in this column is in a tuple of items.
Parameters: | args – The items to check. |
---|---|
Return type: | In |
on_get
(row)¶Called when a value is retrieved from this column.
Parameters: | row (Table ) – The row that is being retrieved. |
---|---|
Return type: | Any |
Returns: | The value of the row’s internal storage. |
on_set
(row, value)¶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: |
|
---|
schema
()¶Return type: | str |
---|---|
Returns: | The library schema of this object. |
If this is not defined, any arguments given to the type will not persist across schema generation.
store_value
(row, value)¶Stores a value in the row’s storage table.
This is for internal usage only.
Parameters: |
---|
validate_set
(row, value)¶Checks if this int is in range for the type.
asyncqlio.orm.schema.types.
SmallSerial
[source]¶Bases: asyncqlio.orm.schema.types.Serial
, asyncqlio.orm.schema.types.SmallInt
Represents a SMALLSERIAL type.
create_default
()¶Creates the default object for this table in the event that a type is passed to a column, instead of an instance.
Return type: | ColumnType |
---|
in_
(*args)¶Returns an IN operator, checking if a value in this column is in a tuple of items.
Parameters: | args – The items to check. |
---|---|
Return type: | In |
on_get
(row)¶Called when a value is retrieved from this column.
Parameters: | row (Table ) – The row that is being retrieved. |
---|---|
Return type: | Any |
Returns: | The value of the row’s internal storage. |
on_set
(row, value)¶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: |
|
---|
schema
()¶Return type: | str |
---|---|
Returns: | The library schema of this object. |
If this is not defined, any arguments given to the type will not persist across schema generation.
store_value
(row, value)¶Stores a value in the row’s storage table.
This is for internal usage only.
Parameters: |
---|
validate_set
(row, value)¶Checks if this int is in range for the type.
asyncqlio.orm.schema.types.
Real
[source]¶Bases: asyncqlio.orm.schema.types.ColumnType
Represents a REAL type.
validate_set
(row, value)[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. |
create_default
()¶Creates the default object for this table in the event that a type is passed to a column, instead of an instance.
Return type: | ColumnType |
---|
in_
(*args)¶Returns an IN operator, checking if a value in this column is in a tuple of items.
Parameters: | args – The items to check. |
---|---|
Return type: | In |
on_get
(row)¶Called when a value is retrieved from this column.
Parameters: | row (Table ) – The row that is being retrieved. |
---|---|
Return type: | Any |
Returns: | The value of the row’s internal storage. |
on_set
(row, value)¶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: | |
---|---|
Return type: |
asyncqlio.orm.schema.types.
Timestamp
[source]¶Bases: asyncqlio.orm.schema.types.ColumnType
Represents a TIMESTAMP type.
validate_set
(row, value)[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. |
create_default
()¶Creates the default object for this table in the event that a type is passed to a column, instead of an instance.
Return type: | ColumnType |
---|
in_
(*args)¶Returns an IN operator, checking if a value in this column is in a tuple of items.
Parameters: | args – The items to check. |
---|---|
Return type: | In |
on_get
(row)¶Called when a value is retrieved from this column.
Parameters: | row (Table ) – The row that is being retrieved. |
---|---|
Return type: | Any |
Returns: | The value of the row’s internal storage. |
on_set
(row, value)¶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: | |
---|---|
Return type: |
asyncqlio.orm.schema.types.
Numeric
(precision=10, scale=0, asdecimal=True)[source]¶Bases: asyncqlio.orm.schema.types.ColumnType
Represents a NUMERIC type.
Note
Numeric
type columns are similar to Real
objects, except Numeric
represents an explicit known value (DECIMAL
, NUMERIC
, DOUBLE
, etc) and not
a floating point type like REAL
, or FLOAT
. Use Real
for floating points.
Parameters: |
---|
schema
()[source]¶Returns: | The library schema of this object. |
---|
If this is not defined, any arguments given to the type will not persist across schema generation.
on_get
(row)[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. |
on_set
(row, value)[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: |
|
---|
create_default
()¶Creates the default object for this table in the event that a type is passed to a column, instead of an instance.
Return type: | ColumnType |
---|
in_
(*args)¶Returns an IN operator, checking if a value in this column is in a tuple of items.
Parameters: | args – The items to check. |
---|---|
Return type: | In |
store_value
(row, value)¶Stores a value in the row’s storage table.
This is for internal usage only.
Parameters: |
---|