Contents
Fields¶
This package adds some fields that are specific to PostgreSQL.
Columns¶
Jsonb¶
-
class
anyblok_postgres.column.
Jsonb
(*args, **kwargs) Bases:
anyblok.column.Column
PostgreSQL JSONB column
from anyblok.declarations import Declarations from anyblok_postgres.column import Jsonb @Declarations.register(Declarations.Model) class Test: x = Jsonb()
LargeObject¶
-
class
anyblok_postgres.column.
LargeObject
(*args, **kwargs) Bases:
anyblok.column.Column
PostgreSQL JSONB column
from anyblok.declarations import Declarations from anyblok_postgres.column import LargeObject @Declarations.register(Declarations.Model) class Test: x = LargeObject() ----------------------------- test = Test.insert() test.x = hugefile test.x # get the huge file
-
sqlalchemy_type
alias of
sqlalchemy.dialects.postgresql.base.OID
-
wrap_getter_column
(fieldname) Return a default getter for the field
Parameters: fieldname – name of the field
-
Ranges¶
Since version 9.2, PostgreSQL supports a flexible range types system, with a few predefined ones, that can be used within AnyBlok.
See also
Range Types in PostgreSQL documentation
-
class
anyblok_postgres.column.
Int4Range
(*args, **kwargs) Bases:
anyblok.column.Column
PostgreSQL int4range column.
Example usage, with this declaration:
from anyblok.declarations import Declarations from anyblok_postgres.column import Jsonb @Declarations.register(Declarations.Model) class Test: col = Int4Range()
one can perfom these:
Test.insert(col="[1,3)") Test.insert(col="(4,8)") Test.query().filter(Test.col.contains(2)) Test.query().filter(Test.col.contains([5, 6))
-
class
anyblok_postgres.column.
Int8Range
(*args, **kwargs) Bases:
anyblok.column.Column
PostgreSQL int8range column.
Usage is similar to see
Int4Range
. See also https://www.postgresql.org/docs/current/rangetypes.htmlCaveat (at least with psycopg2):
In containment queries, passing integers that are within PostgreSQL’s regular ‘integer’ type doesn’t work because it lacks the
::bigint
cast. One workaround is to pass it as an inclusive 0 length range in string form such as:Test.query(Test.col.contains('[1, 1]')
-
class
anyblok_postgres.column.
NumRange
(*args, **kwargs) Bases:
anyblok.column.Column
PostgreSQL numrange column.
Usage is similar to see
Int4Range
, withdecimal.Decimal
instances instead of integers.Caveat (at least with psycopg2):
In containment queries, passing values that are integers or
Decimal
instances equal to integers, such asDecimal('1')
doesn’t work because they end up as litteral SQL integers, without the::numeric
cast.One workaround is to pass them as inclusive 0 length ranges in string representation, such as:
Test.query(Test.col.contains('[1, 1]')
-
class
anyblok_postgres.column.
DateRange
(*args, **kwargs) Bases:
anyblok.column.Column
PostgreSQL daterange column.
This range column can be used with Python
date
instances.Example usage, with this declaration:
from anyblok.declarations import Declarations from anyblok_postgres.column import Jsonb @Declarations.register(Declarations.Model) class Test: col = DateRange()
one can perform these:
Test.insert(col="['2001-03-12', '2002-01-01']") Test.insert(col="['2018-01-01', '2019-01-01')") Test.query().filter(Test.col.contains(date(2001, 4, 7))) Test.query().filter(Test.col.contains("['2018-02-01', '2018-03-01']")
-
class
anyblok_postgres.column.
TsRange
(*args, **kwargs) Bases:
anyblok.column.Column
PostgreSQL tsrange column (timestamps without time zones).
This range column can be used with “naive” Python
datetime
instances. Apart from that, usage is similar toDateRange
-
class
anyblok_postgres.column.
TsTzRange
(*args, **kwargs) Bases:
anyblok.column.Column
PostgreSQL tstzrange column (timestamps with time zones).
See also https://www.postgresql.org/docs/current/rangetypes.html
This range column can be used with “non-naive” (i.e., with explicit
tzinfo
) Pythondatetime`instances. Apart from taht, usage is similar to :class:`DateRange