# -*- coding: utf-8 -*-
from sqlalchemy import create_engine
from sqlalchemy import Column, Integer, String
<<<<<<< HEAD
=======
from sqlalchemy.orm import sessionmaker
>>>>>>> 735d39eb4d0c3134b62bf4fe1b7a2ca0ea8da1ca
from sqlalchemy.ext.declarative import declared_attr, declarative_base

class BaseModelMixin(object):
    @declared_attr
    def __tablename__(self):
        return self.__name__.lower()

    # __table_args__ = {'mysql_engine': 'InnoDB'}

    id = Column(Integer, primary_key=True)

BaseModel = declarative_base(cls=BaseModelMixin)

class MyMixin(object):
    @declared_attr
    def __tablename__(self):
        return self.__name__.lower()

    # __table_args__ = {'mysql_engine': 'InnoDB'}
    __mapper_args__= {'always_refresh': True}

    id = Column(Integer, primary_key=True)

# example:
class MyModel(MyMixin, BaseModel):
<<<<<<< HEAD
    name = Column(String(1000))
=======
    __tablename__ = 'mymodel'
    name = Column(String(20))
    fullname = Column(String(32))
    password = Column(String(32))


# if __name__ == "__main__":
engine = create_engine('sqlite:///test.db')

BaseModel.metadata.create_all(engine, checkfirst=True)

Session = sessionmaker(bind=engine)
session = Session()

ed_user = MyModel(name='ed', fullname='Ed Jones', password='edspassword')
session.add(ed_user)


session.add_all(
    [
        MyModel(name='wendy', fullname='Wendy Williams', password='foobar'),
        MyModel(name='mary', fullname='Mary Contrary', password='xxg527'),
        MyModel(name='fred', fullname='Fred Flinstone', password='blah')
    ]
)
session.commit()

# our_user = session.query(MyModel).filter_by(name='ed').first()
# print(our_user)
>>>>>>> 735d39eb4d0c3134b62bf4fe1b7a2ca0ea8da1ca
