1.sqlalchemy is an ORM framework and uses meta-programming extensively
ImportSQLAlchemy fromSQLAlchemyImportCreate_engine fromSqlalchemy.ext.declarativeImportDeclarative_base fromSQLAlchemyImportcolumn,integer,date,stringconnect_string="{}://{}:{}@{}:{}/{}". Format ('Mysql+pymysql', 'Test', '1QAZXSW2', '127.0.0.1', '3306', 'Blog') Engine= Create_engine (connect_string,echo=True) Base= Declarative_base ()#creating base classes facilitates entity class inheritanceclassStudent (Base):#Specify table name __tablename__='Student' #defining attribute corresponding fieldsid = Column (integer,primary_key=true,autoincrement=True) name= Column (String), nullable=False) age=Column (Integer)def __repr__(self):return '<{} id={},name={},age={}>'. Format (self.__class__.__name__, Self.id,self.name,self.age)#Create all tables that inherit from baseBase.metadata.create_all (Engine)
The SQLAlchemy of Python