Exemplo n.º 1
0
def main():

    start_mapper()

    # create all tables
    metadata.create_all(bind=engine)

    # initiate repository
    user_repo = SqlRepository(session)

    user = User("ed", "secret")
    profile = Profile("John", "Doe", "*****@*****.**")

    user.profile = profile

    # add user and profile to database
    user_repo.add(user)

    # save
    session.commit()

    # query database
    user = user_repo.get(username="******")

    print(user, user.profile)
Exemplo n.º 2
0
def main():

    start_mapper()

    metadata.create_all(bind=engine)

    service.create_user("john", "secret", "admin")
Exemplo n.º 3
0
def main():

    start_mapper()
    metadata.create_all(bind=engine)
    try:
        evn = event.NewUserEvent("john", "secret", "admin")
        uow = unit_of_work.SqlAlchemyUnitOfWork()
        result = messagebuss.handle(evn, uow)
        print(result)
    except ValueError:
        pass
Exemplo n.º 4
0
def main():

    start_mapper()

    # create all the tables

    metadata.create_all(bind=engine)

    # profile = create_profile("John", "Doe", "*****@*****.**")
    # create_user("john", "secret", "admin", profile)

    user = get_user_by_username("john")
    print(user)
Exemplo n.º 5
0
    def setUp(self):
        from sqlalchemy import create_engine
        from sqlalchemy.orm import sessionmaker

        # In-memory SQLite DB:
        self.engine = create_engine('sqlite:///:memory:', echo=False)

        # Create tables:
        metadata.create_all(self.engine)

        self.connection = self.engine.connect()

        # Make a sessionmaker:
        self.Session = sessionmaker(bind=self.engine)
        self.session = self.Session(bind=self.connection)
Exemplo n.º 6
0
    def setUp(self):
        from sqlalchemy import create_engine
        from sqlalchemy.orm import sessionmaker

        # In-memory SQLite DB:
        self.engine = create_engine('sqlite:///:memory:', echo=False)

        # Create tables:
        metadata.create_all(self.engine)

        self.connection = self.engine.connect()

        # Make a sessionmaker:
        self.Session = sessionmaker(bind=self.engine)
        self.session = self.Session(bind=self.connection)
Exemplo n.º 7
0
def main():

    start_mapper()

    # create all the tables
    metadata.create_all(bind=engine)

    # initiate uow
    uow = SqlAlchemyUnitOfWork()

    # user service
    create_post("My Blog", "Post 1", ["python", "programming"], uow)

    with uow:
        blog = uow.repo.get("My Blog")
        print("blog", blog)
        print("posts", blog.posts)
        print("Post 1, tags", blog.posts[0].tags)
Exemplo n.º 8
0
def main():

    start_mapper()

    # create all the tables
    metadata.create_all(bind=engine)

    order = Order("ORD-1", "John Doe")
    line1 = Line(order, "Product-1", 10)
    line2 = Line(order, "Product-2", 20)
    line3 = Line(order, "Product-3", 12)

    # save
    uow = SqlAlchemyUnitOfWork()

    with uow:
        uow.repo.add(order)

    with uow:
        order = uow.repo.get("ORD-1")
        print(order.lines)
Exemplo n.º 9
0
def main():

    start_mapper()
    metadata.create_all(bind=engine)
    try:
        lines = [
            model.Line("Product 1", 10, 250),
            model.Line("Product 2", 23, 350),
            model.Line("Product 3", 14, 150),
        ]
        cmd = command.CreateNewOrder(
            firstname="John",
            lastname="Doe",
            country="Romania",
            city="Bucharest",
        )

        uow = unit_of_work.SqlAlchemyUnitOfWork()
        result = messagebus.handle(cmd, uow)
        print(result)
    except ValueError as err:
        print(ValueError)
Exemplo n.º 10
0
def in_memory_db():
    engine = create_engine('sqlite:///:memory:')
    metadata.create_all(engine)
    return engine
Exemplo n.º 11
0
def the_db():
    # engine = create_engine('sqlite+pysqlite:///test.db', echo=True)
    engine = create_engine('sqlite+pysqlite:///:memory:', echo=True)

    metadata.create_all(engine)
    return engine
Exemplo n.º 12
0
#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
#   USA

from sqlalchemy import create_engine
engine = create_engine('sqlite:///:memory:', echo=True)
#engine = create_engine('sqlite:///:memory:')
#engine = create_engine('sqlite:///test.sql', echo=True)

# Verify the connection to the DB:
engine.execute("select 1").scalar()

from orm import metadata
from firehose.model import Analysis, Issue, Failure, Info

# Create tables:
metadata.create_all(engine)

############################################################################

# Make a sessionmaker:
from sqlalchemy.orm import sessionmaker
Session = sessionmaker(bind=engine)

############################################################################

# Make a session:
session = Session()


# Use them
def simple_tests():
Exemplo n.º 13
0
def postgres_db():
    engine = create_engine(config.get_postgres_uri())
    wait_for_postgres_to_come_up(engine)
    metadata.create_all(engine)
    return engine
Exemplo n.º 14
0
def in_memory_db():
    engine = create_engine('sqlite://', echo=True)
    metadata.create_all(engine)
    return engine
Exemplo n.º 15
0
def sqllite_db():
    engine = create_engine(config.get_sqllite_uri())
    wait_for_sqllite_to_come_up(engine)
    metadata.create_all(engine)
    return engine