TypeScript Interface VS Type
· One min read
![38TGSY](https://cosmos-x.oss-cn-hangzhou.aliyuncs.com/DCDk95.png)
Canvas 有两种 width
和 height
:
300px
、150px。例如:
<canvas id="canvas" width="300" height="150"></canvas>
The path
element features quite a number of these commands. There are two that are relevant for our purposes:
Q
, which instructs the path to create a quadratic Bézier curve.C
, which instructs the path to create a cubic Bézier curve.Online practice site: https://bezier.method.ac
SQLAlchemy 是 Python 下著名的 ORM (Object Relational Mapping,对象关系映射)工具集,首次发布于 2006 年 2 月,并迅速在 Python 社区中广泛使用,其提供了完整的企业级持久模式,能够与 FastAPI 中的数据模型进行良好的融合,并具有高效的数据库访问特点。
图:SQLAlchemy Overview
简而言之是将类和对象转成 SQL,然后使用数据 API 执行 SQL 并获取执行结果。它的核心思想在于将关系数据库表中的记录映射成对象,以对象的形式展现,开发者可以把对数据库的操作转化为对对象的操作。
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, ForeignKey, String, DateTime
from sqlalchemy.orm import relationship
engine = create_engine( # 创建数据库连接引擎
"sqlite:///./sql_app.db",
connect_args={"check_same_thread": False}
)
LocalSession = sessionmaker(autocommit=False, bind=engine) # 创建本地会话
Base = declarative_base() # 定义数据模型基类
class User(Base): # 定义数据模型,用户
__tablename__ = 'user' # 数据库中的表名
id = Column(Integer, primary_key=True) # id列,主键
name = Column('name', String(50)) # 定义字段name,字符串型,对应数据库中的name列
phone = Column('phone', String(50)) # 定义字段phone,字符串型,对应数据库中的phone列
bookrecords = relationship('BookRecord', backref='user') # 图书列表字段
class BookRecord(Base): # 定义数据模型,图书
__tablename__ = 'book_record' # 数据库中的表名
id = Column(Integer, primary_key=True) # id列,主键
book_name = Column('book_name', String(50)) # 书名
borrow_time = Column('borrow_time', DateTime) # 借书时间
user_id = Column(Integer, ForeignKey('user.id')) # user_id ,外键
Base.metadata.create_all(bind=engine) # 在数据库中创建表结构
... # CRUD functions
if __name__ == '__main__':
session = LocalSession() # 创建会话实例
create(session)
retrieve(session)
update(session)
delete(session)