Example #1
0
def setup(entities):
    """
        Setup the database based on a list of user's entities
    """
    
    elixir.setup_entities(entities)
    elixir.create_all()
Example #2
0
def setup(entities):
    """
        Setup the database based on a list of user's entities
    """

    elixir.setup_entities(entities)
    elixir.create_all()
Example #3
0
 def __init__(self, url, modelfile, echo=False):
     self.url = url
     self.session = sqlalchemy.orm.scoped_session(
         sqlalchemy.orm.sessionmaker())
     self.metadata = sqlalchemy.MetaData(bind=url)
     self.collection = elixir.GlobalEntityCollection()
     self.metadata.bind.echo = echo
     self.import_model(modelfile)
     elixir.setup_entities(self.collection)
Example #4
0
    elixir.using_options(tablename="phone_number")
    elixir.using_table_options(mysql_engine="InnoDB")

    number = Field(types.String(20))

    person = ManyToOne("Person")

    @classmethod
    def create_resource(self, session, value, related_instance=None):
        assert isinstance(related_instance, Person)
        return PhoneNumber(number=value, person=related_instance)


# print [ "%s.%s" % (e.__module__, e.__name__) for e in entity_set ]

elixir.setup_entities(entity_set)

###############################################
#
# UnitTest
#
class ElementTest(DinoTest):
    def test_invalid_attr(self):
        self.failUnlessRaises(RuntimeError, lambda: Person(foo="123"))

    def test_regex(self):
        m = Person.element_name_re().match("Person/foo")

        self.assertEquals(m.group(1), "Person/foo")
        self.assertEquals(m.group(2), "Person")
        self.assertEquals(m.group(3), "foo")
Example #5
0
        if self.os is not None:
            return "%s(%s)" % (self.name, self.os.derive_name())
        


class Chassis(Element):
    INSTANCE_NAME_ATTRIBUTE = "name"
    
    #
    # Metadata Options
    #
    elixir.using_options(tablename='chassis')
    elixir.using_table_options(mysql_engine='InnoDB')
    
    #
    # Fields
    #     
    name = Field(types.String(128), nullable=False)
    vendor = Field(types.String(128), nullable=False)
    product = Field(types.String(128), nullable=False)
    racksize = Field(types.Integer, nullable=False, default=2) # values: 0-48
    description = Field(types.String(255), nullable=False, default="")



elixir.setup_entities(__entity_collection__)  




Example #6
0
import sqlalchemy
from elixir import (Entity, Field, Unicode, Integer, setup_entities,
                    GlobalEntityCollection)

__session__ = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker())
__metadata__ = sqlalchemy.MetaData(bind="sqlite:///db.sqlite")
__collection__ = GlobalEntityCollection()


class User(Entity):
    name = Field(Unicode)
    age = Field(Integer)


if __name__ == '__main__':
    setup_entities(__collection__)
    __metadata__.create_all()