Skip to content

Module stac_fastapi.sqlalchemy.models.database

SQLAlchemy ORM models.

Classes

BaseModel

class BaseModel(
    **kwargs
)

The base class of the class hierarchy.

When called, it accepts no arguments and returns a new featureless instance that has no instance attributes and cannot be given any.

Descendants

  • stac_fastapi.sqlalchemy.models.database.Collection
  • stac_fastapi.sqlalchemy.models.database.Item
  • stac_fastapi.sqlalchemy.models.database.PaginationToken

Class variables

metadata

Collection

class Collection(
    **kwargs
)

Collection orm model.

Ancestors (in MRO)

  • stac_fastapi.sqlalchemy.models.database.Base

Class variables

children
description
extent
id
keywords
license
links
metadata
providers
stac_extensions
stac_version
summaries
title
type
version

GeojsonGeometry

class GeojsonGeometry(
    geometry_type='GEOMETRY',
    srid=-1,
    dimension=2,
    spatial_index=True,
    use_N_D_index=False,
    management=False,
    use_typmod=None,
    from_text=None,
    name=None,
    nullable=True
)

Custom geoalchemy type which returns GeoJSON.

Ancestors (in MRO)

  • geoalchemy2.types.Geometry
  • geoalchemy2.types._GISType
  • sqlalchemy.sql.type_api.UserDefinedType
  • sqlalchemy.sql.type_api.TypeEngine
  • sqlalchemy.sql.visitors.Visitable

Class variables

Comparator
ElementType
as_binary
cache_ok
comparator_factory
ensure_kwarg
from_text
hashable
name
should_evaluate_none
sort_key_function

Static methods

check_ctor_args

def check_ctor_args(
    geometry_type,
    srid,
    dimension,
    management,
    use_typmod,
    nullable
)

Instance variables

python_type

Return the Python type object expected to be returned

by instances of this type, if known.

Basically, for those types which enforce a return type, or are known across the board to do such for all common DBAPIs (like int for example), will return that type.

If a return type is not defined, raises NotImplementedError.

Note that any type also accommodates NULL in SQL which means you can also get back None from any type in practice.

Methods

adapt

def adapt(
    self,
    cls,
    **kw
)

Produce an "adapted" form of this type, given an "impl" class

to work with.

This method is used internally to associate generic types with "implementation" types that are specific to a particular dialect.

bind_expression

def bind_expression(
    self,
    bindvalue
)

Specific bind_expression that automatically adds a conversion function

bind_processor

def bind_processor(
    self,
    dialect
)

Specific bind_processor that automatically process spatial elements

coerce_compared_value

def coerce_compared_value(
    self,
    op,
    value
)

Suggest a type for a 'coerced' Python value in an expression.

Default behavior for :class:.UserDefinedType is the same as that of :class:.TypeDecorator; by default it returns self, assuming the compared value should be coerced into the same type as this one. See

column_expression

def column_expression(
    self,
    col
)

Specific column_expression that automatically adds a conversion function

compare_against_backend

def compare_against_backend(
    self,
    dialect,
    conn_type
)

Compare this type against the given backend type.

This function is currently not implemented for SQLAlchemy types, and for all built in types will return None. However, it can be implemented by a user-defined type where it can be consumed by schema comparison tools such as Alembic autogenerate.

A future release of SQLAlchemy will potentially implement this method for builtin types as well.

The function should return True if this type is equivalent to the given type; the type is typically reflected from the database so should be database specific. The dialect in use is also passed. It can also return False to assert that the type is not equivalent.

Parameters:

Name Type Description Default
dialect None a :class:.Dialect that is involved in the comparison. None
conn_type None the type object reflected from the backend.
.. versionadded:: 1.0.3
None

compare_values

def compare_values(
    self,
    x,
    y
)

Compare two values for equality.

compile

def compile(
    self,
    dialect=None
)

Produce a string-compiled form of this :class:.TypeEngine.

When called with no arguments, uses a "default" dialect to produce a string result.

Parameters:

Name Type Description Default
dialect None a :class:.Dialect instance. None

copy

def copy(
    self,
    **kw
)

copy_value

def copy_value(
    self,
    value
)

dialect_impl

def dialect_impl(
    self,
    dialect
)

Return a dialect-specific implementation for this

evaluates_none

def evaluates_none(
    self
)

Return a copy of this type which has the :attr:.should_evaluate_none

flag set to True.

E.g.::

    Table(
        'some_table', metadata,
        Column(
            String(50).evaluates_none(),
            nullable=True,
            server_default='no value')
    )

The ORM uses this flag to indicate that a positive value of None is passed to the column in an INSERT statement, rather than omitting the column from the INSERT statement which has the effect of firing off column-level defaults. It also allows for types which have special behavior associated with the Python None value to indicate that the value doesn't necessarily translate into SQL NULL; a prime example of this is a JSON type which may wish to persist the JSON value 'null'.

In all cases, the actual NULL SQL value can be always be persisted in any column by using the :obj:_expression.null SQL construct in an INSERT statement or associated with an ORM-mapped attribute.

.. note::

The "evaluates none" flag does **not** apply to a value
of ``None`` passed to :paramref:`_schema.Column.default` or
:paramref:`_schema.Column.server_default`; in these cases,
``None``
still means "no default".

.. versionadded:: 1.1

.. seealso::

:ref:`session_forcing_null` - in the ORM documentation

:paramref:`.postgresql.JSON.none_as_null` - PostgreSQL JSON
interaction with this flag.

:attr:`.TypeEngine.should_evaluate_none` - class-level flag

get_col_spec

def get_col_spec(
    self
)

get_dbapi_type

def get_dbapi_type(
    self,
    dbapi
)

Return the corresponding type object from the underlying DB-API, if

any.

This can be useful for calling setinputsizes(), for example.

literal_processor

def literal_processor(
    self,
    dialect
)

Return a conversion function for processing literal values that are

to be rendered directly without using binds.

This function is used when the compiler makes use of the "literal_binds" flag, typically used in DDL generation as well as in certain scenarios where backends don't accept bound parameters.

.. versionadded:: 0.9.0

result_processor

def result_processor(
    self,
    dialect: str,
    coltype
)

Override default processer to return GeoJSON.

with_variant

def with_variant(
    self,
    type_,
    dialect_name
)

Produce a new type object that will utilize the given

type when applied to the dialect of the given name.

e.g.::

from sqlalchemy.types import String
from sqlalchemy.dialects import mysql

s = String()

s = s.with_variant(mysql.VARCHAR(collation='foo'), 'mysql')

The construction of :meth:.TypeEngine.with_variant is always from the "fallback" type to that which is dialect specific. The returned type is an instance of :class:.Variant, which itself provides a :meth:.Variant.with_variant that can be called repeatedly.

Parameters:

Name Type Description Default
type_ None a :class:.TypeEngine that will be selected
as a variant from the originating type, when a dialect
of the given name is in use.
None
dialect_name None base name of the dialect which uses
this type. (i.e. 'postgresql', 'mysql', etc.)
None

Item

class Item(
    **kwargs
)

Item orm model.

Ancestors (in MRO)

  • stac_fastapi.sqlalchemy.models.database.Base

Class variables

assets
bbox
collection_id
datetime
geometry
id
links
metadata
parent_collection
properties
stac_extensions
stac_version

Static methods

get_field

def get_field(
    field_name
)

Get a model field.

PaginationToken

class PaginationToken(
    **kwargs
)

Pagination orm model.

Ancestors (in MRO)

  • stac_fastapi.sqlalchemy.models.database.Base

Class variables

id
keyset
metadata