Article From:
from sqlalchemy import create_engine,Column,Integer,String
from sqlalchemy.ext.declarative import declarative_base


PORT = 3306

DATABASE = 'first_sqlalchemy'

USERNAME = 'root'

PASSWORD = '123456'

DB_URI = "mysql+pymysql://{username}:{password}@{host}:{port}/" \

engine = create_engine(DB_URI)

Base = declarative_base(engine)

# create table person(id int primary key autoincrement, name varchar(32) unique,age smallint unsigende)

#1.Create a ORM model. This ORM model must inherit Sqlalchemy to provide our base class.

class Person(Base):
    __tablename__ = 'person'

#2.Create some properties in the ORM model to map the fields in the table one by one. These properties must be
#sqlalchemyProvide us with good data types.
    id = Column(Integer,primary_key=True,autoincrement=True)
    name = Column(String(32))
    age = Column(Integer)

#3.The created ORM model is mapped to the data.


Link of this Article: Sqlalchemy mapping database

Leave a Reply

Your email address will not be published. Required fields are marked *