from sqlalchemy import create_engine
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base

engine = create_engine ('sqlite:///blog.sqlite')

db_session = scoped_session(sessionmaker(bind=engine))

Base = declarative_base()
Base.query = db_session.query_property()

class User(Base):
	__tablename__ = 'users'
	id = Column(Integer, primary_key = True)
	first_name = Column(String(50))
	last_name = Column(String(50))
	email = Column(String(120), unique=True) #unique проверка на уникальность

	def  __init__(self, first_name=None, email=None):
		self.first_name = first_name
		self.last_name = last_name
		self.email = email

	def __repr__(self):
		return '<User {} {}>'.format(self.first_name, self.last_name)

if  __name__ == '__main__':
	Base.metadata.create_all(bind=engine)