# Path: dbsync/utils.py
# def get_pk(sa_variant):
#     "Returns the primary key name for the given mapped class or object."
#     mapper = class_mapper(sa_variant) if inspect.isclass(sa_variant) \
#         else object_mapper(sa_variant)
#     return mapper.primary_key[0].key
# 
# def query_model(session, sa_class, only_pk=False):
#     """
#     Returns a query for *sa_class* that doesn't load any relationship
#     attribute.
#     """
#     opts = (noload('*'),)
#     if only_pk:
#         pk = get_pk(sa_class)
#         opts += tuple(
#             defer(prop.key)
#             for prop in class_mapper(sa_class).iterate_properties
#             if isinstance(prop, ColumnProperty)
#             if prop.key != pk)
#     return session.query(sa_class).options(*opts)
# 
# def properties_dict(sa_object):
#     """
#     Returns a dictionary of column-properties for the given SQLAlchemy
#     mapped object.
#     """
#     mapper = object_mapper(sa_object)
#     return dict((prop.key, getattr(sa_object, prop.key))
#                 for prop in mapper.iterate_properties
#                 if isinstance(prop, ColumnProperty))
# 
# Path: dbsync/logs.py
# def get_logger(name):
#     logger = logging.getLogger(name)
#     logger.setLevel(logging.WARNING)
#     loggers.add(logger)
#     if log_handler is not None:
#         logger.addHandler(log_handler)
#     return logger


from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, BigInteger
from sqlalchemy.orm import relationship, backref, validates
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.declarative.api import DeclarativeMeta
from dbsync.lang import *
from dbsync.utils import get_pk, query_model, properties_dict
from dbsync.logs import get_logger
                                                              operation.row_id))
                else:
                    raise OperationError(
                        u"insert attempted when the object already existed: "
                        u"model {0} pk {1}".format(model.__name__,
                                                   operation.row_id))

        elif operation.command == 'u':
            obj = query_model(session, model).\
                filter(getattr(model, get_pk(model)) == operation.row_id).first()
            if obj is None:
                # For now, the record will be created again, but is an
                # error because nothing should be deleted without
                # using dbsync
                # raise OperationError(
                #     "the referenced object doesn't exist in database", operation)
                logger.warning(
                    u"The referenced object doesn't exist in database. "
                    u"Node %s. Operation %s",
                    node_id,
                    operation)

            pull_obj = container.query(model).\
                filter(attr('__pk__') == operation.row_id).first()
            if pull_obj is None:
                raise OperationError(
                    "no object backing the operation in container", operation)
            session.merge(pull_obj)

        elif operation.command == 'd':

# Path: dbsync/utils.py
# def get_pk(sa_variant):
#     "Returns the primary key name for the given mapped class or object."
#     mapper = class_mapper(sa_variant) if inspect.isclass(sa_variant) \
#         else object_mapper(sa_variant)
#     return mapper.primary_key[0].key
# 
# def query_model(session, sa_class, only_pk=False):
#     """
#     Returns a query for *sa_class* that doesn't load any relationship
#     attribute.
#     """
#     opts = (noload('*'),)
#     if only_pk:
#         pk = get_pk(sa_class)
#         opts += tuple(
#             defer(prop.key)
#             for prop in class_mapper(sa_class).iterate_properties
#             if isinstance(prop, ColumnProperty)
#             if prop.key != pk)
#     return session.query(sa_class).options(*opts)
# 
# def properties_dict(sa_object):
#     """
#     Returns a dictionary of column-properties for the given SQLAlchemy
#     mapped object.
#     """
#     mapper = object_mapper(sa_object)
#     return dict((prop.key, getattr(sa_object, prop.key))
#                 for prop in mapper.iterate_properties
#                 if isinstance(prop, ColumnProperty))
# 
# Path: dbsync/logs.py
# def get_logger(name):
#     logger = logging.getLogger(name)
#     logger.setLevel(logging.WARNING)
#     loggers.add(logger)
#     if log_handler is not None:
#         logger.addHandler(log_handler)
#     return logger


# Path: dbsync/models.py
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, BigInteger
from sqlalchemy.orm import relationship, backref, validates
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.declarative.api import DeclarativeMeta
from dbsync.lang import *
from dbsync.utils import get_pk, query_model, properties_dict
from dbsync.logs import get_logger

                                                              operation.row_id))
                else:
                    raise OperationError(
                        u"insert attempted when the object already existed: "
                        u"model {0} pk {1}".format(model.__name__,
                                                   operation.row_id))

        elif operation.command == 'u':
            obj = query_model(session, model).\
                filter(getattr(model, get_pk(model)) == operation.row_id).first()
            if obj is None:
                # For now, the record will be created again, but is an
                # error because nothing should be deleted without
                # using dbsync
                # raise OperationError(
                #     "the referenced object doesn't exist in database", operation)
                logger.warning(
                    u"The referenced object doesn't exist in database. "
                    u"Node %s. Operation %s",
                    node_id,
                    operation)

            pull_obj = container.query(model).\
                filter(attr('__pk__') == operation.row_id).first()
            if pull_obj is None:
                raise OperationError(
                    "no object backing the operation in container", operation)
            session.merge(pull_obj)

        elif operation.command == 'd':

            obj = query_model(session, model, only_pk=True).\