31 lines
802 B
Python
31 lines
802 B
Python
#!/usr/bin/env python
|
|
# -*- encoding: utf-8 -*-
|
|
'''
|
|
@File : db_init.py
|
|
@Author : liuyihui
|
|
@Email : liuyihui02@gmail.com
|
|
'''
|
|
|
|
# here put the import lib
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy import Column, Integer, String, Float
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
|
|
Base = declarative_base()
|
|
|
|
class Person(Base):
|
|
__tablename__ = 'persons'
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
name = Column(String)
|
|
work = Column(String)
|
|
rate = Column(Float, default=1400)
|
|
|
|
def __repr__(self):
|
|
return "<Person(name='%s', work='%s', rate='%f')>" % (self.name, self.work, self.rate)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
engine = create_engine('sqlite:///data.db', echo=True)
|
|
Base.metadata.create_all(engine, checkfirst=True)
|