Coverage for python/lsst/daf/butler/core/sqlDatabaseDict.py : 94%

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/>.
String, Integer, Boolean, LargeBinary, DateTime, Float
"""A DatabaseDict backed by a SQL database.
Configuration for SqlDatabaseDict must have the following entries:
``db`` A database connection URI of the form accepted by SQLAlchemy. Ignored if the ``engine`` argument is not None. ``table`` Name of the database table used to store the data in the dictionary.
Parameters ---------- config : `Config` Configuration used to identify this subclass and connect to a database. types : `dict` A dictionary mapping `str` field names to type objects, containing all fields to be held in the database. The supported type objects are the keys of the `COLUMN_TYPES` attribute. SQLAlchemy column type objects may also be passed directly, though of course this not portable to other `DatabaseDict` subclasses. key : `str` The name of the field to be used as the dictionary key. Must not be present in ``value._fields``. value : `type` (`~collections.namedtuple`) The type used for the dictionary's values, typically a `~collections.namedtuple`. Must have a ``_fields`` class attribute that is a tuple of field names (i.e. as defined by `~collections.namedtuple`); these field names must also appear in the ``types`` arg, and a `_make` attribute to construct it from a sequence of values (again, as defined by `~collections.namedtuple`). engine : `sqlalchemy.engine.Engine` A SQLAlchemy connection object. If not None, ``config["db"]`` is ignored. """
bool: Boolean, bytes: LargeBinary, datetime: DateTime}
raise TypeError("No type provided for key {}".format(key))
# Try insert first, as we expect that to be the most commmon usage # pattern.
# If we fail due to an IntegrityError (i.e. duplicate primary key # values), try to do an update instead. except StatementError as err: # n.b. we can't rely on a failure in the insert attempt above # to have caught this case, because we trap for IntegrityError # first. And we have to do that because IntegrityError is a # StatementError. raise TypeError("Bad data types in value: {}".format(err))
# TODO: add custom view objects for at views() and items(), so we don't # invoke a __getitem__ call for every key. |