ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dankilman <...@git.apache.org>
Subject [GitHub] incubator-ariatosca pull request #33: Genericize-storage-models
Date Thu, 22 Dec 2016 12:05:25 GMT
Github user dankilman commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/33#discussion_r93608539
  
    --- Diff: aria/storage/structure.py ---
    @@ -0,0 +1,180 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +Aria's storage.structures module
    +Path: aria.storage.structures
    +
    +models module holds aria's models.
    +
    +classes:
    +    * Field - represents a single field.
    +    * IterField - represents an iterable field.
    +    * PointerField - represents a single pointer field.
    +    * IterPointerField - represents an iterable pointers field.
    +    * Model - abstract model implementation.
    +"""
    +
    +from sqlalchemy.orm import relationship, backref
    +from sqlalchemy.ext import associationproxy
    +from sqlalchemy import (
    +    Column,
    +    ForeignKey,
    +    Integer,
    +    Text
    +)
    +
    +
    +class ModelMixin(object):
    +
    +    @classmethod
    +    def id_column_name(cls):
    +        raise NotImplementedError
    +
    +    @classmethod
    +    def name_column_name(cls):
    +        raise NotImplementedError
    +
    +    @classmethod
    +    def _get_cls_by_tablename(cls, tablename):
    +        """Return class reference mapped to table.
    +
    +         :param tablename: String with name of table.
    +         :return: Class reference or None.
    +         """
    +        if tablename in (cls.__name__, cls.__tablename__):
    +            return cls
    +
    +        for table_cls in cls._decl_class_registry.values():
    +            if tablename in (getattr(table_cls, '__name__', None),
    +                             getattr(table_cls, '__tablename__', None)):
    +                return table_cls
    +
    +    @classmethod
    +    def foreign_key(cls, table, nullable=False):
    +        """Return a ForeignKey object with the relevant
    +
    +        :param table: Unique id column in the parent table
    +        :param nullable: Should the column be allowed to remain empty
    +        """
    +        table = cls._get_cls_by_tablename(table.__tablename__)
    --- End diff --
    
    table_cls


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message