Types
plateforme.core.database.types
This module provides utilities for managing database types within the Plateforme framework using SQLAlchemy features.
Engine
This module provides utilities for managing database types within the Plateforme framework using SQLAlchemy features.
TypeEngine
module-attribute
A type alias for a type engine.
TypeEngineRules
module-attribute
A type alias for the rules used to merge payloads
DefaultEngine
module-attribute
DefaultEngine: BaseTypeEngine[Any] = as_mutable(
JsonEngine()
)
Default type engine.
It should be used by fields that do not have a specific type engine defined and for which no type engine can be resolved.
BaseTypeEngine
Bases: TypeDecorator[_T]
The base type engine.
Allows the creation of type engines which add additional functionality to an existing type.
This method is preferred to direct subclassing of Plateforme's built-in type engines as it ensures that all required functionality of the underlying type is kept in place:
Examples:
>>> from plateforme.database import BaseTypeEngine, StringEngine
>>> class MyTypeEngine(BaseTypeEngine):
... '''
... Prefixes Unicode values with on the way in and
... strips it off on the way out.
... '''
... impl = StringEngine
... cache_ok = True
... @staticmethod ... def rules(): ... return {length: lambda x: min(x[0], x[1])}
... def coarse_type_engine(self): ... return BinaryEngine()
The impl
class-level attribute is required, and can reference any
BaseTypeEngine
class. Alternatively, the load_dialect_impl
method can
be used to provide different type classes based on the dialect given; in
this case, the impl
variable can reference BaseTypeEngine
as a
placeholder.
The cache_ok
class-level flag indicates if this custom BaseTypeEngine
is safe to be used as part of a cache key. This flag defaults to None
which will initially generate a warning when the SQL compiler attempts to
generate a cache key for a statement that uses this type. If the
BaseTypeEngine
is not guaranteed to produce the same bind/result behavior
and SQL generation every time, this flag should be set to False
;
otherwise if the class produces the same behavior each time, it may be set
to True
.
The rules
static-level method is required, and must return a dictionary
of rules for merging payloads from two different instances of the new type
engine. The keys of the dictionary are the names of the parameters passed
to the __init__
method, while the values are functions that take one
tuple of two elements as arguments and return the merged value.
The coarse_type_engine
instance-level method is optional, and can be
utilized to generate a more generalized representation of the current type
engine class. This method proves particularly beneficial during the lookup
process employed for merging type engines into a shared, coarser type
engine.
Types that receive a Python type that isn't similar to the ultimate type
used may want to define the coerce_compared_value
method. This is used to
give the expression system a hint when coercing Python objects into bind
parameters within expressions. Consider this expression:
Examples:
Above, if somecol
is an Integer
variant, it makes sense that we're
doing date arithmetic, where above is usually interpreted by databases as
adding a number of days to the given date. The expression system does the
right thing by not attempting to coerce the date()
value into an
integer-oriented bind parameter.
However, in the case of BaseTypeEngine
, we are usually changing an
incoming Python type to something new; BaseTypeEngine
by default will
coerce the non-typed side to be the same type as itself. Such as below, we
define an epoch
type that stores a date value as an integer:
Examples:
>>> from plateforme.database import BaseTypeEngine, IntegerEngine
>>> class MyEpochTypeEngine(BaseTypeEngine):
... impl = IntegerEngine
... epoch = datetime.date(1970, 1, 1)
... def process_bind_param(self, value, dialect): ... return (value - self.epoch).days ... def process_result_value(self, value, dialect): ... return self.epoch + timedelta(days=value)
... def copy(self, **kwargs): ... return MyEpochTypeEngine()
Our expression of somecol + date
with the above type will coerce the
date
on the right side to also be treated as MyEpochTypeEngine
.
This behavior can be overridden via the coerce_compared_value
method,
which returns a type that should be used for the value of the expression.
Below we set it such that an integer value will be treated as an
IntegerEngine
, and any other value is assumed to be a date and will be
treated as a MyEpochTypeEngine
:
Examples:
>>> def coerce_compared_value(self, op, value):
... if isinstance(value, int):
... return IntegerEngine()
... else:
... return self
The behavior of coerce_compared_value
is not inherited by default from
that of the base type. If the BaseTypeEngine
is augmenting a type that
requires special logic for certain types of operators, this method must be
overridden. A key example is when decorating the JSON
and JSONB
types;
the default rules of coerce_compared_value
method should be used in order
to deal with operators like index operations:
Examples:
>>> from plateforme.database import BaseTypeEngine, JSON
>>> class MyJsonTypeEngine(BaseTypeEngine):
... impl = JSON
... cache_ok = True
... def coerce_compared_value(self, op, value): ... return self.impl.coerce_compared_value(op, value)
Without the above step, index operations such as mycol['foo']
will
cause the index value 'foo'
to be JSON encoded. Similarly, when working
with the ARRAY
datatype, the type coercion for index operations (e.g.
mycol[5]
) is also handled by coerce_compared_value
method, where
again a simple override is sufficient unless special rules are needed for
particular operators:
Examples:
>>> from plateforme.database import BaseTypeEngine, ARRAY
>>> class MyArrayTypeEngine(BaseTypeEngine):
... impl = ARRAY
... cache_ok = True
... def coerce_compared_value(self, op, value): ... return self.impl.coerce_compared_value(op, value)
Construct a type engine.
Arguments sent here are passed to the constructor of the class assigned
to the impl
class level attribute, assuming the impl
is a callable,
and the resulting object is assigned to the self.impl
instance
attribute (thus overriding the class attribute of the same name).
If the class level impl
is not a callable (the unusual case), it will
be assigned to the same instance attribute "as-is", ignoring those
arguments passed to the constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__processors
|
TypeEngineProcessors[Any] | None
|
The type engine processors. |
None
|
*args
|
Any
|
Positional arguments passed to the constructor of the type engine. |
()
|
**kwargs
|
Any
|
Keyword arguments passed to the constructor of the type engine. |
{}
|
Note
Subclasses can override this to customize the generation of
self.impl
entirely.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
rules
staticmethod
rules() -> TypeEngineRules
The rules for merging payloads from two different type engines.
It returns a dictionary containing the selection rules for all the parameters that can be passed to the constructor of the type engine.
Each key of the dictionary is the name of a parameter and the value is a callable that takes the values of a tuple of two type engines as arguments and should return the most conservative value between the two.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
coarse_type_engine
abstractmethod
coarse_type_engine(
**kwargs: Any,
) -> BaseTypeEngine[Any] | None
Construct a coarser type engine.
Return a coarser BaseTypeEngine
object that is especially used to
resolve the most granular common type between two type engines.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs
|
Any
|
Additional keyword arguments to pass for handling the construction of the coarser type engine. |
{}
|
Returns:
Type | Description |
---|---|
BaseTypeEngine[Any] | None
|
A coarser |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
TypeEngineMeta
Bases: ABCMeta
The type engine metaclass.
The metaclass used to create a new type engines, while keeping track of the the parent and new type engine payloads arguments and keyword arguments implementations cascade.
TypeEnginePayload
BinaryEngine
BinaryEngine(
length: int | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: BaseTypeEngine[bytes]
A binary engine.
The BinaryEngine
corresponds to a large and/or unlengthed binary type for
the target platform, such as BLOB
on MySQL and BYTEA
for
PostgreSQL. It also handles the necessary conversions for the DBAPI.
Construct a binary engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
length
|
int | None
|
A length for the column for use in DDL statements, for
those binary types that accept a length, such as the MySQL
|
None
|
processors
|
TypeEngineProcessors[_T] | None
|
The type engine processors used to transform the
incoming and outgoing data values before and after they are
passed to the database. Defaults to |
None
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
BooleanEngine
BooleanEngine(
create_constraint: bool = False,
name: str | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: BaseTypeEngine[bool]
A boolean engine.
A boolean engine which typically uses BOOLEAN
or SMALLINT
on the DDL
side, and on the Python side deals in True
or False
.
The BooleanEngine
currently has two levels of assertion that the values
persisted are simple true/false values. For all backends, only the Python
values None
, True
, False
, 1
or 0
are accepted as
parameter values. For those backends that don't support a "native boolean"
datatype, an option exists to also create a CHECK
constraint on the
target column.
Construct a boolean engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
create_constraint
|
bool
|
If the boolean is generated as an |
False
|
name
|
str | None
|
If a |
None
|
processors
|
TypeEngineProcessors[_T] | None
|
The type engine processors used to transform the
incoming and outgoing data values before and after they are
passed to the database. Defaults to |
None
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
DateEngine
Bases: BaseTypeEngine[date]
A date engine.
The DateEngine
returns objects from the Python datetime.date
.
Construct a date engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
processors
|
TypeEngineProcessors[_T] | None
|
The type engine processors used to transform the
incoming and outgoing data values before and after they are
passed to the database. Defaults to |
None
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
DateTimeEngine
DateTimeEngine(
timezone: bool = False,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: BaseTypeEngine[datetime]
A datetime engine.
The DateTimeEngine
returns objects from the Python datetime
module.
Most DBAPIs have built in support for the datetime module, with the noted
exception of SQLite. In the case of SQLite, date and time types are stored
as strings which are then converted back to datetime objects when rows are
returned.
For the time representation within the datetime type, some backends include additional options, such as timezone support and fractional seconds support.
Construct a datetime engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timezone
|
bool
|
Indicates that the datetime type should enable timezone support, if available on the base date/time-holding type only. |
False
|
processors
|
TypeEngineProcessors[_T] | None
|
The type engine processors used to transform the
incoming and outgoing data values before and after they are
passed to the database. Defaults to |
None
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
EnumEngine
EnumEngine(
*enums: Any,
create_constraint: bool = False,
metadata: MetaData | None = None,
name: str | None = None,
native_enum: bool = True,
length: int | None = None,
schema: str | None = None,
quote: bool = False,
inherit_schema: bool = False,
validate_strings: bool = False,
values_callable: Callable[[Any], list[str]]
| None = None,
sort_key_function: Callable[[Any], Any] | None = None,
omit_aliases: bool = True,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: BaseTypeEngine[str | Enum]
An enumeration engine.
The EnumEngine
provides a set of possible string values which the column
is constrained towards. It will make use of the backend's native
enumeration type if one is available; otherwise, it uses a VARCHAR
datatype. An option also exists to automatically produce a CHECK
constraint when the VARCHAR
(so called "non-native") variant is produced;
see the create_constraint
flag.
It also provides in-Python validation of string values during both read and
write operations. When reading a value from the database in a result set,
the string value is always checked against the list of possible values and
a LookupError
is raised if no match is found. When passing a value to the
database as a plain string within a SQL statement, if the
validate_strings
parameter is set to True
, a LookupError
is raised
for any string value that's not located in the given list of possible
values; note that this impacts usage of LIKE
expressions with
enumerated values (an unusual use case).
When using an enumerated class, the enumerated objects are used both for input and output, rather than strings as is the case with a plain-string enumerated type:
Examples:
>>> import enum
>>> from plateforme.database import EnumEngine
>>> class MyEnum(enum.Enum):
... one = 1
... two = 2
... three = 3
>>> t = Table('data', MetaData(), Column('value', EnumEngine(MyEnum)))
>>> connection.execute(t.insert(), {'value': MyEnum.two})
>>> assert connection.scalar(t.select()) is MyEnum.two
Above, the string names of each element, e.g. one
, two
, three
,
are persisted to the database; the values of the Python enum.Enum
, here
indicated as integers, are not used; the value of each enum can therefore
be any kind of Python object whether or not it is persistable.
In order to persist the values and not the names, the values_callable
parameter may be used. The value of this parameter is a user-supplied
callable, which is intended to be used with a PEP-435-compliant enumerated
class and returns a list of string values to be persisted. For a simple
enumeration that uses string values, a callable such as
lambda x: [e.value for e in x]
is sufficient.
Construct an enum.
Keyword arguments which don't apply to a specific backend are ignored by that backend.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enums
|
Any
|
Either exactly one PEP-435 compliant enumerated type or one or more string labels. |
()
|
create_constraint
|
bool
|
When creating a non-native enumerated type, also
build a |
False
|
metadata
|
MetaData | None
|
Associates this type directly with a |
None
|
name
|
str | None
|
The name of this type. This is required for PostgreSQL and any future supported database which requires an explicitly named type, or an explicitly named constraint in order to generate the type and/or a table that uses it. If a PEP-435 enumerated class was used, its name (converted to lower case) is used by default. |
None
|
native_enum
|
bool
|
Uses the database's native enumeration type when
available. When |
True
|
length
|
int | None
|
Allows specifying a custom length for the |
None
|
schema
|
str | None
|
Schema name of this type. For types that exist on the target database as an independent schema construct (PostgreSQL), this parameter specifies the named schema in which the type is present. |
None
|
quote
|
bool
|
Sets explicit quoting preferences for the type's name. |
False
|
inherit_schema
|
bool
|
When |
False
|
validate_strings
|
bool
|
When |
False
|
values_callable
|
Callable[[Any], list[str]] | None
|
A callable which will be passed the PEP-435 compliant enumerated type, which should then return a list of string values to be persisted. This allows for alternate usages such as using the string value of an enum to be persisted to the database instead of its name. |
None
|
sort_key_function
|
Callable[[Any], Any] | None
|
A Python callable which may be used as
the |
None
|
omit_aliases
|
bool
|
A boolean that when true will remove aliases from PEP-435 enums. |
True
|
processors
|
TypeEngineProcessors[_T] | None
|
The type engine processors used to transform the
incoming and outgoing data values before and after they are
passed to the database. Defaults to |
None
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 |
|
IntegerEngine
Bases: BaseTypeEngine[int]
An integer engine.
It typically uses INTEGER
, or BIGINT
on the DDL side, and on the Python
side deals with int
integers.
Construct an integer engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
processors
|
TypeEngineProcessors[_T] | None
|
The type engine processors used to transform the
incoming and outgoing data values before and after they are
passed to the database. Defaults to |
None
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
IntervalEngine
IntervalEngine(
native: bool = True,
second_precision: int | None = None,
day_precision: int | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: BaseTypeEngine[timedelta]
An interval engine.
The IntervalEngine
deals with datetime.timedelta
objects. In
PostgreSQL, the native INTERVAL
type is used; for others, the value is
stored as a date which is relative to the epoch
(Jan. 1, 1970).
Note that the Interval
type does not currently provide date arithmetic
operations on platforms which do not support interval types natively. Such
operations usually require transformation of both sides of the expression
(such as, conversion of both sides into integer epoch values first) which
currently is a manual procedure.
Construct an interval engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
native
|
bool
|
When True, use the actual |
True
|
second_precision
|
int | None
|
For native interval types which support a "fractional seconds precision" parameter (PostgreSQL, Oracle). |
None
|
day_precision
|
int | None
|
For native interval types which support a "day precision" parameter (Oracle). |
None
|
processors
|
TypeEngineProcessors[_T] | None
|
The type engine processors used to transform the
incoming and outgoing data values before and after they are
passed to the database. Defaults to |
None
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
JsonEngine
JsonEngine(
none_as_null: bool = True,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: BaseTypeEngine[_T]
A json engine.
The JsonEngine
deals with JSON data. For some dialects, the native JSON
type is used; for others, the value is stored as a string. The compatible
database dialects with native JSON support are: PostgreSQL, MySQL, SQLite,
and SQL Server.
To allow ORM change events to propagate for elements associated with the
JsonEngine
class, use Mutable.as_mutable(JsonEngine)
.
Construct a json engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
none_as_null
|
bool
|
If |
True
|
processors
|
TypeEngineProcessors[_T] | None
|
The type engine processors used to transform the
incoming and outgoing data values before and after they are
passed to the database. Defaults to |
None
|
Examples:
Note
The parameter none_as_null
does not apply to the values passed to
Column.default
and Column.server_default
; a value of
None
passed for these parameters means "no default present".
Additionally, when used in SQL comparison expressions, the Python
value None
continues to refer to SQL null, and not JSON NULL.
The none_as_null
flag refers explicitly to the persistence of
the value within an INSERT
or UPDATE
statement. The
JSON.NULL
value should be used for SQL expressions that wish to
compare to JSON null.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
NumericEngine
NumericEngine(
precision: int | None = None,
scale: int | None = None,
asdecimal: bool = False,
decimal_return_scale: int | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: BaseTypeEngine[_TNumber]
A numeric engine.
A numeric engine for non-integer numeric types which typically uses
NUMERIC
, FLOAT
, DECIMAL
, or other variants on the DDL side, and on
the Python side deals in float
or decimal.Decimal
types.
Note
When using a NumericEngine
against a database type that returns
Python floating point values to the driver, the accuracy of the decimal
conversion indicated by asdecimal
may be limited. The behavior of
specific numeric/floating point datatypes is a product of the SQL
datatype in use, the Python DBAPI in use, as well as strategies that
may be present within the SQLAlchemy dialect in use.
Construct a numeric engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
precision
|
int | None
|
The numeric precision for use in DDL |
None
|
scale
|
int | None
|
The numeric scale for use in DDL |
None
|
asdecimal
|
bool
|
Returns whether or not values should be sent as Python
|
False
|
decimal_return_scale
|
int | None
|
Default scale to use when converting from
floats to Python decimals. Floating point values will typically
be much longer due to decimal inaccuracy, and most floating
point database types don't have a notion of |
None
|
processors
|
TypeEngineProcessors[_T] | None
|
The type engine processors used to transform the
incoming and outgoing data values before and after they are
passed to the database. Defaults to |
None
|
When using the NumericEngine
, care should be taken to ensure that the
asdecimal
setting is appropriate for the DBAPI in use. When base
Numeric
applies a conversion from decimal->float or float->decimal,
this conversion incurs an additional performance overhead for all
result columns received.
DBAPIs that return decimal.Decimal
natively (e.g. psycopg2) will have
better accuracy and higher performance with a setting of True
, as
the native translation to decimal.Decimal
reduces the amount of
floating point issues at play, and the Numeric type itself doesn't need
to apply any further conversions. However, another DBAPI which returns
floats natively will incur an additional conversion overhead, and is
still subject to floating point data loss, in which case
asdecimal=False
will at least remove the extra conversion overhead.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
StringEngine
StringEngine(
length: int | None = None,
collation: str | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: BaseTypeEngine[str]
A string engine.
A string engine which typically uses VARCHAR
, NVARCHAR
, TEXT
, or
other variants on the DDL side, and on the Python side deals with str
types.
Construct a string engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
length
|
int | None
|
A length for the column for use in DDL and |
None
|
collation
|
str | None
|
A column-level collation for use in DDL and |
None
|
processors
|
TypeEngineProcessors[_T] | None
|
The type engine processors used to transform the
incoming and outgoing data values before and after they are
passed to the database. Defaults to |
None
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
TimeEngine
Bases: BaseTypeEngine[time]
A time engine.
The TimeEngine
returns objects from the Python datetime.time
.
Construct a time engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
processors
|
TypeEngineProcessors[_T] | None
|
The type engine processors used to transform the
incoming and outgoing data values before and after they are
passed to the database. Defaults to |
None
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
UuidEngine
UuidEngine(
as_uuid: bool = True,
native_uuid: bool = True,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: BaseTypeEngine[_TUuid]
A UUID engine.
For backends that have no native
UUID datatype, the value will make use
of "CHAR(32)" and store the UUID as a 32-character alphanumeric hex string.
For backends which are known to support UUID
directly or a similar
uuid-storing datatype such as SQL Server's UNIQUEIDENTIFIER
, a
native
mode enabled by default allows these types will be used on those
backends.
In its default mode of use, the UuidEngine
datatype expects Python uuid
objects, from the Python
uuid module.
Construct a UUID engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
as_uuid
|
bool
|
If |
True
|
native_uuid
|
bool
|
If |
True
|
processors
|
TypeEngineProcessors[_T] | None
|
The type engine processors used to transform the
incoming and outgoing data values before and after they are
passed to the database. Defaults to |
None
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
combine_type_engines
combine_type_engines(
*engines: _TEngine[Any], **kwargs: Any
) -> BaseTypeEngine[Any]
Combine type engines.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
engines
|
_TEngine[Any]
|
The engines to combine. |
()
|
kwargs
|
Any
|
Additional keyword arguments to pass to the
|
{}
|
Returns:
Type | Description |
---|---|
BaseTypeEngine[Any]
|
A new type engine that is the combination of the given engines. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 |
|
Concrete
This module provides utilities for managing database types within the Plateforme framework using SQLAlchemy features.
ARRAY
ARRAY(
item_type: _TEngine[Any],
as_tuple: bool = False,
dimensions: int | None = None,
zero_indexes: bool = False,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: BaseTypeEngine[Sequence[Any]]
The SQL ARRAY concrete type.
The ARRAY
type engine serves as the basis for all ARRAY
operations.
However, currently only the PostgreSQL backend has support for SQL arrays.
To allow ORM change events to propagate for elements associated with the
ARRAY
class, use Mutable.as_mutable(ARRAY)
.
Construct an ARRAY type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item_type
|
_TEngine[Any]
|
The data type of items of this array. Note that
dimensionality is irrelevant here, so multi-dimensional arrays
like |
required |
as_tuple
|
bool
|
Specify whether return results should be converted to tuples from lists. This parameter is not generally needed as a Python list corresponds well to a SQL array. |
False
|
dimensions
|
int | None
|
If not |
None
|
zero_indexes
|
bool
|
When |
False
|
processors
|
TypeEngineProcessors[_T] | None
|
The type engine processors used to transform the
incoming and outgoing data values before and after they are
passed to the database. Defaults to |
None
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
BIGINT
Bases: IntegerEngine
The SQL BIGINT concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
BINARY
BINARY(
length: int | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: BinaryEngine
The SQL BINARY concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
BLOB
BLOB(
length: int | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: BinaryEngine
The SQL BLOB concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
BOOLEAN
BOOLEAN(
create_constraint: bool = False,
name: str | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: BooleanEngine
The SQL BOOLEAN concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
CHAR
CHAR(
length: int | None = None,
collation: str | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: StringEngine
The SQL CHAR concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
CLOB
CLOB(
length: int | None = None,
collation: str | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: StringEngine
The SQL CLOB concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
DATE
Bases: DateEngine
The SQL DATE concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
DATETIME
DATETIME(
timezone: bool = False,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: DateTimeEngine
The SQL DATETIME concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
DECIMAL
DECIMAL(
precision: int | None = None,
scale: int | None = None,
asdecimal: bool = False,
decimal_return_scale: int | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: NumericEngine[Decimal]
The SQL DECIMAL concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
DOUBLE
DOUBLE(
precision: int | None = None,
scale: int | None = None,
asdecimal: bool = False,
decimal_return_scale: int | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: NumericEngine[float]
The SQL DOUBLE concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
DOUBLE_PRECISION
DOUBLE_PRECISION(
precision: int | None = None,
scale: int | None = None,
asdecimal: bool = False,
decimal_return_scale: int | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: NumericEngine[float]
The SQL DOUBLE_PRECISION concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
FLOAT
FLOAT(
precision: int | None = None,
scale: int | None = None,
asdecimal: bool = False,
decimal_return_scale: int | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: NumericEngine[float]
The SQL FLOAT concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
INTEGER
Bases: IntegerEngine
The SQL INTEGER concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
JSON
JSON(
none_as_null: bool = True,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: JsonEngine[_T]
The SQL JSON concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
NCHAR
NCHAR(
length: int | None = None,
collation: str | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: StringEngine
The SQL NCHAR concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
NUMERIC
NUMERIC(
precision: int | None = None,
scale: int | None = None,
asdecimal: bool = False,
decimal_return_scale: int | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: NumericEngine[float]
The SQL NUMERIC concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
NVARCHAR
NVARCHAR(
length: int | None = None,
collation: str | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: StringEngine
The SQL NVARCHAR concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
REAL
REAL(
precision: int | None = None,
scale: int | None = None,
asdecimal: bool = False,
decimal_return_scale: int | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: NumericEngine[float]
The SQL REAL concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
SMALLINT
Bases: IntegerEngine
The SQL SMALLINT concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
TEXT
TEXT(
length: int | None = None,
collation: str | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: StringEngine
The SQL TEXT concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
TIME
Bases: TimeEngine
The SQL TIME concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
TIMESTAMP
TIMESTAMP(
timezone: bool = False,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: DateTimeEngine
The SQL TIMESTAMP concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
UUID
UUID(
as_uuid: bool = True,
native_uuid: bool = True,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: UuidEngine[_TUuid]
The SQL UUID concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
VARBINARY
VARBINARY(
length: int | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: BinaryEngine
The SQL VARBINARY concrete type.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/types.py
VARCHAR
VARCHAR(
length: int | None = None,
collation: str | None = None,
*,
processors: TypeEngineProcessors[_T] | None = None,
)
Bases: StringEngine
The SQL VARCHAR concrete type.