diff --git a/.coverage b/.coverage
new file mode 100644
index 0000000..bf85969
Binary files /dev/null and b/.coverage differ
diff --git a/be.db b/be.db
new file mode 100644
index 0000000..f8e1fad
Binary files /dev/null and b/be.db differ
diff --git a/be/__pycache__/__init__.cpython-38.pyc b/be/__pycache__/__init__.cpython-38.pyc
new file mode 100644
index 0000000..49c50e9
Binary files /dev/null and b/be/__pycache__/__init__.cpython-38.pyc differ
diff --git a/be/__pycache__/serve.cpython-38.pyc b/be/__pycache__/serve.cpython-38.pyc
new file mode 100644
index 0000000..100c618
Binary files /dev/null and b/be/__pycache__/serve.cpython-38.pyc differ
diff --git a/be/model/__pycache__/__init__.cpython-38.pyc b/be/model/__pycache__/__init__.cpython-38.pyc
new file mode 100644
index 0000000..c6754f3
Binary files /dev/null and b/be/model/__pycache__/__init__.cpython-38.pyc differ
diff --git a/be/model/__pycache__/buyer.cpython-38.pyc b/be/model/__pycache__/buyer.cpython-38.pyc
new file mode 100644
index 0000000..ed54eed
Binary files /dev/null and b/be/model/__pycache__/buyer.cpython-38.pyc differ
diff --git a/be/model/__pycache__/db_conn.cpython-38.pyc b/be/model/__pycache__/db_conn.cpython-38.pyc
new file mode 100644
index 0000000..d2f26d8
Binary files /dev/null and b/be/model/__pycache__/db_conn.cpython-38.pyc differ
diff --git a/be/model/__pycache__/error.cpython-38.pyc b/be/model/__pycache__/error.cpython-38.pyc
new file mode 100644
index 0000000..220e20b
Binary files /dev/null and b/be/model/__pycache__/error.cpython-38.pyc differ
diff --git a/be/model/__pycache__/seller.cpython-38.pyc b/be/model/__pycache__/seller.cpython-38.pyc
new file mode 100644
index 0000000..efae51d
Binary files /dev/null and b/be/model/__pycache__/seller.cpython-38.pyc differ
diff --git a/be/model/__pycache__/store.cpython-38.pyc b/be/model/__pycache__/store.cpython-38.pyc
new file mode 100644
index 0000000..6ce5f42
Binary files /dev/null and b/be/model/__pycache__/store.cpython-38.pyc differ
diff --git a/be/model/__pycache__/user.cpython-38.pyc b/be/model/__pycache__/user.cpython-38.pyc
new file mode 100644
index 0000000..4ae827b
Binary files /dev/null and b/be/model/__pycache__/user.cpython-38.pyc differ
diff --git a/be/view/__pycache__/__init__.cpython-38.pyc b/be/view/__pycache__/__init__.cpython-38.pyc
new file mode 100644
index 0000000..340acee
Binary files /dev/null and b/be/view/__pycache__/__init__.cpython-38.pyc differ
diff --git a/be/view/__pycache__/auth.cpython-38.pyc b/be/view/__pycache__/auth.cpython-38.pyc
new file mode 100644
index 0000000..ef8b3eb
Binary files /dev/null and b/be/view/__pycache__/auth.cpython-38.pyc differ
diff --git a/be/view/__pycache__/buyer.cpython-38.pyc b/be/view/__pycache__/buyer.cpython-38.pyc
new file mode 100644
index 0000000..bc567ca
Binary files /dev/null and b/be/view/__pycache__/buyer.cpython-38.pyc differ
diff --git a/be/view/__pycache__/seller.cpython-38.pyc b/be/view/__pycache__/seller.cpython-38.pyc
new file mode 100644
index 0000000..ddbf88e
Binary files /dev/null and b/be/view/__pycache__/seller.cpython-38.pyc differ
diff --git a/fe/__pycache__/__init__.cpython-38.pyc b/fe/__pycache__/__init__.cpython-38.pyc
new file mode 100644
index 0000000..39c9e6f
Binary files /dev/null and b/fe/__pycache__/__init__.cpython-38.pyc differ
diff --git a/fe/__pycache__/conf.cpython-38.pyc b/fe/__pycache__/conf.cpython-38.pyc
new file mode 100644
index 0000000..80380f6
Binary files /dev/null and b/fe/__pycache__/conf.cpython-38.pyc differ
diff --git a/fe/__pycache__/conftest.cpython-38-pytest-6.2.3.pyc b/fe/__pycache__/conftest.cpython-38-pytest-6.2.3.pyc
new file mode 100644
index 0000000..7b8330f
Binary files /dev/null and b/fe/__pycache__/conftest.cpython-38-pytest-6.2.3.pyc differ
diff --git a/fe/access/__pycache__/__init__.cpython-38.pyc b/fe/access/__pycache__/__init__.cpython-38.pyc
new file mode 100644
index 0000000..f09f19b
Binary files /dev/null and b/fe/access/__pycache__/__init__.cpython-38.pyc differ
diff --git a/fe/access/__pycache__/auth.cpython-38.pyc b/fe/access/__pycache__/auth.cpython-38.pyc
new file mode 100644
index 0000000..fb71742
Binary files /dev/null and b/fe/access/__pycache__/auth.cpython-38.pyc differ
diff --git a/fe/access/__pycache__/book.cpython-38.pyc b/fe/access/__pycache__/book.cpython-38.pyc
new file mode 100644
index 0000000..69e4123
Binary files /dev/null and b/fe/access/__pycache__/book.cpython-38.pyc differ
diff --git a/fe/access/__pycache__/buyer.cpython-38.pyc b/fe/access/__pycache__/buyer.cpython-38.pyc
new file mode 100644
index 0000000..41ba772
Binary files /dev/null and b/fe/access/__pycache__/buyer.cpython-38.pyc differ
diff --git a/fe/access/__pycache__/new_buyer.cpython-38.pyc b/fe/access/__pycache__/new_buyer.cpython-38.pyc
new file mode 100644
index 0000000..a7f47f4
Binary files /dev/null and b/fe/access/__pycache__/new_buyer.cpython-38.pyc differ
diff --git a/fe/access/__pycache__/new_seller.cpython-38.pyc b/fe/access/__pycache__/new_seller.cpython-38.pyc
new file mode 100644
index 0000000..5f0f77c
Binary files /dev/null and b/fe/access/__pycache__/new_seller.cpython-38.pyc differ
diff --git a/fe/access/__pycache__/seller.cpython-38.pyc b/fe/access/__pycache__/seller.cpython-38.pyc
new file mode 100644
index 0000000..6bb8c9e
Binary files /dev/null and b/fe/access/__pycache__/seller.cpython-38.pyc differ
diff --git a/fe/bench/__pycache__/__init__.cpython-38.pyc b/fe/bench/__pycache__/__init__.cpython-38.pyc
new file mode 100644
index 0000000..2ab0f6d
Binary files /dev/null and b/fe/bench/__pycache__/__init__.cpython-38.pyc differ
diff --git a/fe/bench/__pycache__/run.cpython-38.pyc b/fe/bench/__pycache__/run.cpython-38.pyc
new file mode 100644
index 0000000..19c3a6b
Binary files /dev/null and b/fe/bench/__pycache__/run.cpython-38.pyc differ
diff --git a/fe/bench/__pycache__/session.cpython-38.pyc b/fe/bench/__pycache__/session.cpython-38.pyc
new file mode 100644
index 0000000..8e74ef3
Binary files /dev/null and b/fe/bench/__pycache__/session.cpython-38.pyc differ
diff --git a/fe/bench/__pycache__/workload.cpython-38.pyc b/fe/bench/__pycache__/workload.cpython-38.pyc
new file mode 100644
index 0000000..70236e0
Binary files /dev/null and b/fe/bench/__pycache__/workload.cpython-38.pyc differ
diff --git a/fe/test/__pycache__/gen_book_data.cpython-38.pyc b/fe/test/__pycache__/gen_book_data.cpython-38.pyc
new file mode 100644
index 0000000..1eb7aff
Binary files /dev/null and b/fe/test/__pycache__/gen_book_data.cpython-38.pyc differ
diff --git a/fe/test/__pycache__/test_add_book.cpython-38-pytest-6.2.3.pyc b/fe/test/__pycache__/test_add_book.cpython-38-pytest-6.2.3.pyc
new file mode 100644
index 0000000..4b498ec
Binary files /dev/null and b/fe/test/__pycache__/test_add_book.cpython-38-pytest-6.2.3.pyc differ
diff --git a/fe/test/__pycache__/test_add_funds.cpython-38-pytest-6.2.3.pyc b/fe/test/__pycache__/test_add_funds.cpython-38-pytest-6.2.3.pyc
new file mode 100644
index 0000000..b8b3179
Binary files /dev/null and b/fe/test/__pycache__/test_add_funds.cpython-38-pytest-6.2.3.pyc differ
diff --git a/fe/test/__pycache__/test_add_stock_level.cpython-38-pytest-6.2.3.pyc b/fe/test/__pycache__/test_add_stock_level.cpython-38-pytest-6.2.3.pyc
new file mode 100644
index 0000000..01b4341
Binary files /dev/null and b/fe/test/__pycache__/test_add_stock_level.cpython-38-pytest-6.2.3.pyc differ
diff --git a/fe/test/__pycache__/test_bench.cpython-38-pytest-6.2.3.pyc b/fe/test/__pycache__/test_bench.cpython-38-pytest-6.2.3.pyc
new file mode 100644
index 0000000..e5e5dc1
Binary files /dev/null and b/fe/test/__pycache__/test_bench.cpython-38-pytest-6.2.3.pyc differ
diff --git a/fe/test/__pycache__/test_create_store.cpython-38-pytest-6.2.3.pyc b/fe/test/__pycache__/test_create_store.cpython-38-pytest-6.2.3.pyc
new file mode 100644
index 0000000..383af12
Binary files /dev/null and b/fe/test/__pycache__/test_create_store.cpython-38-pytest-6.2.3.pyc differ
diff --git a/fe/test/__pycache__/test_login.cpython-38-pytest-6.2.3.pyc b/fe/test/__pycache__/test_login.cpython-38-pytest-6.2.3.pyc
new file mode 100644
index 0000000..6f3c7c8
Binary files /dev/null and b/fe/test/__pycache__/test_login.cpython-38-pytest-6.2.3.pyc differ
diff --git a/fe/test/__pycache__/test_new_order.cpython-38-pytest-6.2.3.pyc b/fe/test/__pycache__/test_new_order.cpython-38-pytest-6.2.3.pyc
new file mode 100644
index 0000000..efe0981
Binary files /dev/null and b/fe/test/__pycache__/test_new_order.cpython-38-pytest-6.2.3.pyc differ
diff --git a/fe/test/__pycache__/test_password.cpython-38-pytest-6.2.3.pyc b/fe/test/__pycache__/test_password.cpython-38-pytest-6.2.3.pyc
new file mode 100644
index 0000000..8bcaf8f
Binary files /dev/null and b/fe/test/__pycache__/test_password.cpython-38-pytest-6.2.3.pyc differ
diff --git a/fe/test/__pycache__/test_payment.cpython-38-pytest-6.2.3.pyc b/fe/test/__pycache__/test_payment.cpython-38-pytest-6.2.3.pyc
new file mode 100644
index 0000000..d41caf6
Binary files /dev/null and b/fe/test/__pycache__/test_payment.cpython-38-pytest-6.2.3.pyc differ
diff --git a/fe/test/__pycache__/test_register.cpython-38-pytest-6.2.3.pyc b/fe/test/__pycache__/test_register.cpython-38-pytest-6.2.3.pyc
new file mode 100644
index 0000000..f8cb5e0
Binary files /dev/null and b/fe/test/__pycache__/test_register.cpython-38-pytest-6.2.3.pyc differ
diff --git a/figure_require/DB_struct_origin.drawio b/figure_require/DB_struct_origin.drawio
new file mode 100644
index 0000000..2e203ba
--- /dev/null
+++ b/figure_require/DB_struct_origin.drawio
@@ -0,0 +1,195 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/figure_require/DB_struct_origin.svg b/figure_require/DB_struct_origin.svg
new file mode 100644
index 0000000..1d3766f
--- /dev/null
+++ b/figure_require/DB_struct_origin.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/figure_require/add_naive_userdata.png b/figure_require/add_naive_userdata.png
new file mode 100644
index 0000000..596126a
Binary files /dev/null and b/figure_require/add_naive_userdata.png differ
diff --git a/figure_require/conn_test.png b/figure_require/conn_test.png
new file mode 100644
index 0000000..b0c55ed
Binary files /dev/null and b/figure_require/conn_test.png differ
diff --git a/modified/be/Config.py b/modified/be/Config.py
new file mode 100644
index 0000000..e69de29
diff --git a/modified/be/__init__.py b/modified/be/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/modified/be/__pycache__/creatTB.cpython-38.pyc b/modified/be/__pycache__/creatTB.cpython-38.pyc
new file mode 100644
index 0000000..0f84905
Binary files /dev/null and b/modified/be/__pycache__/creatTB.cpython-38.pyc differ
diff --git a/modified/be/__pycache__/postgreSQLORM.cpython-38.pyc b/modified/be/__pycache__/postgreSQLORM.cpython-38.pyc
new file mode 100644
index 0000000..58d8155
Binary files /dev/null and b/modified/be/__pycache__/postgreSQLORM.cpython-38.pyc differ
diff --git a/modified/be/__pycache__/serve.cpython-38.pyc b/modified/be/__pycache__/serve.cpython-38.pyc
new file mode 100644
index 0000000..3693091
Binary files /dev/null and b/modified/be/__pycache__/serve.cpython-38.pyc differ
diff --git a/modified/be/__pycache__/testconn.cpython-38.pyc b/modified/be/__pycache__/testconn.cpython-38.pyc
new file mode 100644
index 0000000..7e5d273
Binary files /dev/null and b/modified/be/__pycache__/testconn.cpython-38.pyc differ
diff --git a/modified/be/app.py b/modified/be/app.py
new file mode 100644
index 0000000..9b9699a
--- /dev/null
+++ b/modified/be/app.py
@@ -0,0 +1,4 @@
+import serve
+
+if __name__ == "__main__":
+ serve.be_run()
diff --git a/modified/be/creatTB.py b/modified/be/creatTB.py
new file mode 100644
index 0000000..d0f51f0
--- /dev/null
+++ b/modified/be/creatTB.py
@@ -0,0 +1,5 @@
+from postgreSQLORM import Base,engine
+
+def createTable():
+ # 创建所有继承于Base的类对应的表
+ Base.metadata.create_all(engine)
diff --git a/modified/be/model/store.py b/modified/be/model/store.py
new file mode 100644
index 0000000..e69de29
diff --git a/modified/be/postgreSQLORM.py b/modified/be/postgreSQLORM.py
new file mode 100644
index 0000000..7f3ef54
--- /dev/null
+++ b/modified/be/postgreSQLORM.py
@@ -0,0 +1,121 @@
+from sqlalchemy import create_engine,MetaData
+from sqlalchemy import Integer,String,ForeignKey,Column,TEXT
+from sqlalchemy.orm import relationship
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy.orm import sessionmaker
+from sqlalchemy import PrimaryKeyConstraint,UniqueConstraint
+import sqlalchemy
+Base=declarative_base()
+class con:
+ def connect():
+ '''Returns a connection and a metadata object'''
+ # We connect with the help of the PostgreSQL URL
+
+ url = 'postgresql://stu10205501415:Stu10205501415@dase-cdms-2022-pub.pg.rds.aliyuncs.com:5432/stu10205501415'
+
+ # The return value of create_engine() is our connection object
+ con = create_engine(url, client_encoding='utf8')
+
+ # We then bind the connection to MetaData()
+ meta = MetaData(bind=con)
+
+ return con, meta
+
+
+class User(Base):
+ __tablename__ = 'user'
+ user_id = Column(TEXT, primary_key=True, comment="主键")
+ password = Column(TEXT, nullable=False, comment="密码")
+ balance = Column(Integer, nullable=False, comment="")
+ token = Column(TEXT, comment="缓存的令牌")
+ terminal = Column(TEXT, comment="终端代码")
+
+class Store(Base):
+ __tablename__ = 'store'
+ store_id = Column(TEXT, primary_key=True,comment="主键")
+ stock_level = Column(Integer, comment = "货存")
+
+class Store_Book(Base):
+ __tablename__ = 'store_book'
+ store_id = Column(TEXT, comment="主键")
+ book_id = Column(TEXT, comment="主键")
+ book_info = Column(TEXT, comment="书籍信息")
+ stock_level = Column(Integer, comment = "货存")
+
+ __table_args__ = (
+ PrimaryKeyConstraint('store_id', 'book_id'),
+ )
+
+class User_Store(Base):
+ __tablename__ = 'user_store'
+
+ id = Column(Integer, primary_key=True, autoincrement=True, comment="主键")
+
+ fk_user_id = Column(
+ TEXT,
+ ForeignKey(
+ "user.user_id",
+ ondelete="CASCADE",
+ onupdate="CASCADE",
+ ),
+ nullable=False,
+ comment="user外键"
+ )
+ fk_store_id = Column(
+ TEXT,
+ ForeignKey(
+ "store.store_id",
+ ondelete="CASCADE",
+ onupdate="CASCADE",
+ ),
+ nullable=False,
+ comment="store外键"
+ )
+ # 多对多关系的中间表必须使用联合唯一约束,防止出现重复数据
+ __table_args__ = (
+ UniqueConstraint("fk_user_id", "fk_store_id"),
+ )
+
+class New_Order(Base):
+ __tablename__ = 'new_order'
+ order_id = Column(TEXT, primary_key = True, comment = '订单id')
+
+ fk_user_id = Column(
+ TEXT,
+ ForeignKey(
+ "user.user_id",
+ ondelete="CASCADE",
+ onupdate="CASCADE",
+ ),
+ nullable=False,
+ comment="user外键"
+ )
+ fk_store_id = Column(
+ TEXT,
+ ForeignKey(
+ "store.store_id",
+ ondelete="CASCADE",
+ onupdate="CASCADE",
+ ),
+ nullable=False,
+ comment="store外键"
+ )
+
+class New_Order_Detail(Base):
+ __tablename__ = 'new_order_detail'
+ order_id = Column(TEXT, comment='订单id')
+ book_id = Column(TEXT, comment='订单书籍')
+ count = Column(Integer, comment='购买书籍数')
+ price = Column(Integer, comment='单价')
+
+ __table_args__ = (
+ PrimaryKeyConstraint('order_id','book_id'),
+ )
+
+engine, meta = con.connect()
+
+Base.metadata.bind = engine
+
+DBSession = sessionmaker(bind=engine)
+
+session = DBSession()
diff --git a/modified/be/serve.py b/modified/be/serve.py
new file mode 100644
index 0000000..76ddc52
--- /dev/null
+++ b/modified/be/serve.py
@@ -0,0 +1,12 @@
+from flask import Flask
+from flask import Blueprint
+from flask import request
+import testconn
+from creatTB import createTable
+
+
+def be_run():
+ app = Flask(__name__)
+ createTable()
+ app.register_blueprint(testconn.bp_testconn)
+ app.run(port=5000)
\ No newline at end of file
diff --git a/modified/be/testconn.py b/modified/be/testconn.py
new file mode 100644
index 0000000..a43855a
--- /dev/null
+++ b/modified/be/testconn.py
@@ -0,0 +1,22 @@
+from flask import Blueprint
+from flask import Flask, abort, request, jsonify
+import json
+from flask import jsonify
+from sqlalchemy.ext.serializer import loads, dumps
+import postgreSQLORM
+from postgreSQLORM import User,Store,Store_Book,User_Store,New_Order,New_Order_Detail
+
+bp_testconn = Blueprint("testconn",__name__,url_prefix="/testconn")
+
+@bp_testconn.route("/test",methods=['GET'])
+def test():
+ user_id: str = request.args.get("user_id")
+ print(user_id)
+ try:
+ ss = postgreSQLORM.session.query(User).filter(User.user_id==user_id).all()
+ for i in ss:
+ print('user_id',i.user_id)
+ except:
+ print("error")
+ return "connect success"
+
diff --git a/modified/be/view/auth.py b/modified/be/view/auth.py
new file mode 100644
index 0000000..e69de29
diff --git a/modified/be/view/buyer.py b/modified/be/view/buyer.py
new file mode 100644
index 0000000..e69de29
diff --git a/modified/be/view/seller.py b/modified/be/view/seller.py
new file mode 100644
index 0000000..e69de29
diff --git a/report.md b/report.md
new file mode 100644
index 0000000..78da27e
--- /dev/null
+++ b/report.md
@@ -0,0 +1,213 @@
+##
华东师范大学数据科学与工程学院实验报告
+
+| **课程名称:当代数据库管理系统** |**年级** :2020级 |**上机实践成绩**: |
+| --- | --- | --- |
+| **指导教师** :高明 | **姓名** :杨舜、姚嘉和 | **学号** :10205501415、10205501436 |
+| **上机实践名称** :BookStore ||**上机实践日期**:2022.11.28 —— 2022.12.10 |
+| **上机实践编号** : | **组号 :21** |**上机实践时间**:2022.11.28 —— 2022.12.10 |
+
+### 实验过程
+
+#### 一. 分析原有的数据库结构
+
+ 分析demo中/be/model/store.py中创建数据库表的sql语句可知原有数据库的结构的ER图大致如下
+ ![avatar](./figure_require/DB_struct_origin.svg)
+
+ 有上述ER图可以得到原有数据库表如下
+
+ user表:
+ |user_id|password|balance|token|terminal|
+ |---|---|---|---|---|
+ 主键为user_id
+
+ store表:
+ |store_id|stock_level|
+ |---|---|
+ 主键为store_id
+
+ store_book表:
+ |store_id|book_id|book_info|stock_level|
+ |---|---|---|---|
+ 主键为联合主键(store_id,book_id)
+
+ user_store表:
+ |user_id|store_id|
+ |---|---|
+ 外键为(user_id,store_id)
+
+ new_order表:
+ |order_id|user_id|store_id|
+ |---|---|---|
+ 主键为(order_id)
+
+ new_order_detail表:
+ |oeder_id|book_id|count|price|
+ |---|---|---|---|
+ 主键为联合主键(order_id,book_id)
+
+
+
+#### 二. 依据上述分析构建数据库table
+ 1. 利用sqlalchemy连接远程的aliyun数据库并创建上述table [postgreSQLORM.py](./modified/be/postgreSQLORM.py)
+ ```python
+ class con:
+ def connect():
+ '''Returns a connection and a metadata object'''
+ # We connect with the help of the PostgreSQL URL
+
+ url = 'postgresql://stu10205501415:Stu10205501415@dase-cdms-2022-pub.pg.rds.aliyuncs.com:5432/stu10205501415'
+
+ # The return value of create_engine() is our connection object
+ con = create_engine(url, client_encoding='utf8')
+
+ # We then bind the connection to MetaData()
+ meta = MetaData(bind=con)
+
+ return con, meta
+
+ class User(Base):
+ __tablename__ = 'user'
+ user_id = Column(TEXT, primary_key=True, comment="主键")
+ password = Column(TEXT, nullable=False, comment="密码")
+ balance = Column(Integer, nullable=False, comment="")
+ token = Column(TEXT, comment="缓存的令牌")
+ terminal = Column(TEXT, comment="终端代码")
+
+ class Store(Base):
+ __tablename__ = 'store'
+ store_id = Column(TEXT, primary_key=True,comment="主键")
+ stock_level = Column(Integer, comment = "货存")
+
+ class Store_Book(Base):
+ __tablename__ = 'store_book'
+ store_id = Column(TEXT, comment="主键")
+ book_id = Column(TEXT, comment="主键")
+ book_info = Column(TEXT, comment="书籍信息")
+ stock_level = Column(Integer, comment = "货存")
+
+ __table_args__ = (
+ PrimaryKeyConstraint('store_id', 'book_id'),
+ )
+
+ class User_Store(Base):
+ __tablename__ = 'user_store'
+
+ id = Column(Integer, primary_key=True, autoincrement=True, comment="主键")
+
+ fk_user_id = Column(
+ TEXT,
+ ForeignKey(
+ "user.user_id",
+ ondelete="CASCADE",
+ onupdate="CASCADE",
+ ),
+ nullable=False,
+ comment="user外键"
+ )
+ fk_store_id = Column(
+ TEXT,
+ ForeignKey(
+ "store.store_id",
+ ondelete="CASCADE",
+ onupdate="CASCADE",
+ ),
+ nullable=False,
+ comment="store外键"
+ )
+ # 多对多关系的中间表必须使用联合唯一约束,防止出现重复数据
+ __table_args__ = (
+ UniqueConstraint("fk_user_id", "fk_store_id"),
+ )
+
+ class New_Order(Base):
+ __tablename__ = 'new_order'
+ order_id = Column(TEXT, primary_key = True, comment = '订单id')
+
+ fk_user_id = Column(
+ TEXT,
+ ForeignKey(
+ "user.user_id",
+ ondelete="CASCADE",
+ onupdate="CASCADE",
+ ),
+ nullable=False,
+ comment="user外键"
+ )
+ fk_store_id = Column(
+ TEXT,
+ ForeignKey(
+ "store.store_id",
+ ondelete="CASCADE",
+ onupdate="CASCADE",
+ ),
+ nullable=False,
+ comment="store外键"
+ )
+
+ class New_Order_Detail(Base):
+ __tablename__ = 'new_order_detail'
+ order_id = Column(TEXT, comment='订单id')
+ book_id = Column(TEXT, comment='订单书籍')
+ count = Column(Integer, comment='购买书籍数')
+ price = Column(Integer, comment='单价')
+
+ __table_args__ = (
+ PrimaryKeyConstraint('order_id','book_id'),
+ )
+
+ engine, meta = con.connect()
+ Base.metadata.bind = engine
+ DBSession = sessionmaker(bind=engine)
+ session = DBSession()
+ ```
+ 2. 在上述创建的table中添加初始数据并利用该数据测试后端服务器与数据库的连接
+ ![avatar](./figure_require/add_naive_userdata.png)
+ ![avatar](./figure_require/conn_test.png)
+
+ 3. 类比原有demo分别为不同的路由绑定不同的蓝图
+ ```python
+ app.register_blueprint(auth.bp_auth)
+ app.register_blueprint(seller.bp_seller)
+ app.register_blueprint(buyer.bp_buyer)
+ ```
+
+ 4. 在/be/model目录下创建User类用书实现User对于数据库的一些交互功能
+ 5. 修改[model/db_conn.py](./be/model/db_conn.py)中查询的操作为orm操作
+ ```python
+ from model import postgreSQLORM
+ from model.postgreSQLORM import User, Store_Book, User_Store
+
+ class DBConn:
+ def __init__(self):
+ return
+ # self.conn = store.get_db_conn()
+
+ def user_id_exist(self, user_id):
+ row = postgreSQLORM.session.query(User).filter(User.user_id==user_id).one()
+ # cursor = self.conn.execute("SELECT user_id FROM user WHERE user_id = ?;", (user_id,))
+ # row = cursor.fetchone()
+ if row is None:
+ return False
+ else:
+ return True
+
+ def book_id_exist(self, store_id, book_id):
+ row = postgreSQLORM.session.query(Store_Book).filter(Store_Book.book_id==book_id and Store_Book.store_id==store_id).one()
+ # cursor = self.conn.execute("SELECT book_id FROM store WHERE store_id = ? AND book_id = ?;", (store_id, book_id))
+ # row = cursor.fetchone()
+ if row is None:
+ return False
+ else:
+ return True
+
+ def store_id_exist(self, store_id):
+ row = postgreSQLORM.session.query(User_Store).filter(User_Store.fk_store_id==store_id).one()
+ # cursor = self.conn.execute("SELECT store_id FROM user_store WHERE store_id = ?;", (store_id,))
+ # row = cursor.fetchone()
+ if row is None:
+ return False
+ else:
+ return True
+
+ ```
+ 6.
\ No newline at end of file