Coverage for python/lsst/daf/butler/registry/ddl.py : 61%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# This file is part of daf_butler. # # Developed for the LSST Data Management System. # This product includes software developed by the LSST Project # (http://www.lsst.org). # See the COPYRIGHT file at the top-level directory of this distribution # for details of code ownership. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>.
"""A SQLAlchemy custom type that maps Python `bytes` to a base64-encoded `sqlalchemy.String`. """
length = 4*ceil(nbytes/3) super().__init__(*args, length=length, **kwds) self.nbytes = nbytes
# 'value' is native `bytes`. We want to encode that to base64 `bytes` # and then ASCII `str`, because `str` is what SQLAlchemy expects for # String fields. if value is None: return None if not isinstance(value, bytes): raise TypeError( f"Base64Bytes fields require 'bytes' values; got '{value}' with type {type(value)}." ) return b64encode(value).decode("ascii")
# 'value' is a `str` that must be ASCII because it's base64-encoded. # We want to transform that to base64-encoded `bytes` and then # native `bytes`. return b64decode(value.encode("ascii")) if value is not None else None
"""A SQLAlchemy custom type that maps Python `sphgeom.ConvexPolygon` to a base64-encoded `sqlalchemy.String`. """
if value is None: return None return super().process_bind_param(value.encode(), dialect)
if value is None: return None return ConvexPolygon.decode(super().process_result_value(value, dialect))
class FieldSpec: """A struct-like class used to define a column in a logical `Registry` table. """
"""Name of the column."""
"""Type of the column; usually a `type` subclass provided by SQLAlchemy that defines both a Python type and a corresponding precise SQL type. """
"""Length of the type in the database, for variable-length types."""
"""Natural length used for hash and encoded-region columns, to be converted into the post-encoding length. """
"""Whether this field is (part of) its table's primary key."""
"""Whether the database should insert automatically incremented values when no value is provided in an INSERT. """
"""Whether this field is allowed to be NULL."""
"""Documentation for this field."""
return self.name == other.name
return hash(self.name)
"""Return a sized version of the column type, utilizing either (or neither) of ``self.length`` and ``self.nbytes``.
Returns ------- dtype : `sqlalchemy.types.TypeEngine` A SQLAlchemy column type object. """ if self.length is not None: return self.dtype(length=self.length) if self.nbytes is not None: return self.dtype(nbytes=self.nbytes) return self.dtype
class ForeignKeySpec: """A struct-like class used to define a foreign key constraint in a logical `Registry` table. """
"""Name of the target table."""
"""Tuple of source table column names."""
"""Tuple of target table column names."""
If not `None` (which indicates that a constraint violation exception should be raised), should be either "SET NULL" or "CASCADE". """
class TableSpec: """A struct-like class used to define a table or table-like query interface. """
"""Specifications for the columns in this table."""
"""Non-primary-key unique constraints for the table."""
"""Indexes for the table."""
"""Foreign key constraints for the table."""
"""Documentation for the table."""
|