Download Code/GraphQL/14_sqlalchemy_data_init.py from zxy0307/Python_05_Flask: direct link, hf CLI and curl.
- Browser
- Download file 702 Bytes
-
https://huggingface.co/zxy0307/Python_05_Flask/resolve/main/Code/GraphQL/14_sqlalchemy_data_init.py
- Command line
-
hf download hf://zxy0307/Python_05_Flask/Code/GraphQL/14_sqlalchemy_data_init.py
-
curl -L -o 14_sqlalchemy_data_init.py https://huggingface.co/zxy0307/Python_05_Flask/resolve/main/Code/GraphQL/14_sqlalchemy_data_init.py
702 Bytes
| from sqlalchemy import create_engine,Column,String | |
| from sqlalchemy.orm import scoped_session | |
| from sqlalchemy.orm.session import sessionmaker | |
| from sqlalchemy.ext.declarative import declarative_base | |
| from uuid import uuid4 | |
| db = create_engine('mysql+pymysql://root:123@localhost:3306/graphql') | |
| db_session = scoped_session(sessionmaker(bind=db)) | |
| Base = declarative_base() | |
| class EmployeeModel(Base): | |
| __tablename__ = 't_employee' | |
| id = Column(String(128),primary_key= True) | |
| name = Column(String(64)) | |
| # Base.metadata.create_all(bind =db) | |
| def init_db(): | |
| for i in range(10): | |
| emp = EmployeeModel(id=uuid4().hex,name=f'e{i}') | |
| db_session.add(emp) | |
| db_session.commit() | |
| init_db() |