Browse Source

完成数据库的初步设计,连接成功,修改demo在modeified目录下的be备份中,不影响原有工作

master
杨舜 1 year ago
parent
commit
04d7856c00
60 changed files with 573 additions and 0 deletions
  1. BIN
      .coverage
  2. BIN
      be.db
  3. BIN
      be/__pycache__/__init__.cpython-38.pyc
  4. BIN
      be/__pycache__/serve.cpython-38.pyc
  5. BIN
      be/model/__pycache__/__init__.cpython-38.pyc
  6. BIN
      be/model/__pycache__/buyer.cpython-38.pyc
  7. BIN
      be/model/__pycache__/db_conn.cpython-38.pyc
  8. BIN
      be/model/__pycache__/error.cpython-38.pyc
  9. BIN
      be/model/__pycache__/seller.cpython-38.pyc
  10. BIN
      be/model/__pycache__/store.cpython-38.pyc
  11. BIN
      be/model/__pycache__/user.cpython-38.pyc
  12. BIN
      be/view/__pycache__/__init__.cpython-38.pyc
  13. BIN
      be/view/__pycache__/auth.cpython-38.pyc
  14. BIN
      be/view/__pycache__/buyer.cpython-38.pyc
  15. BIN
      be/view/__pycache__/seller.cpython-38.pyc
  16. BIN
      fe/__pycache__/__init__.cpython-38.pyc
  17. BIN
      fe/__pycache__/conf.cpython-38.pyc
  18. BIN
      fe/__pycache__/conftest.cpython-38-pytest-6.2.3.pyc
  19. BIN
      fe/access/__pycache__/__init__.cpython-38.pyc
  20. BIN
      fe/access/__pycache__/auth.cpython-38.pyc
  21. BIN
      fe/access/__pycache__/book.cpython-38.pyc
  22. BIN
      fe/access/__pycache__/buyer.cpython-38.pyc
  23. BIN
      fe/access/__pycache__/new_buyer.cpython-38.pyc
  24. BIN
      fe/access/__pycache__/new_seller.cpython-38.pyc
  25. BIN
      fe/access/__pycache__/seller.cpython-38.pyc
  26. BIN
      fe/bench/__pycache__/__init__.cpython-38.pyc
  27. BIN
      fe/bench/__pycache__/run.cpython-38.pyc
  28. BIN
      fe/bench/__pycache__/session.cpython-38.pyc
  29. BIN
      fe/bench/__pycache__/workload.cpython-38.pyc
  30. BIN
      fe/test/__pycache__/gen_book_data.cpython-38.pyc
  31. BIN
      fe/test/__pycache__/test_add_book.cpython-38-pytest-6.2.3.pyc
  32. BIN
      fe/test/__pycache__/test_add_funds.cpython-38-pytest-6.2.3.pyc
  33. BIN
      fe/test/__pycache__/test_add_stock_level.cpython-38-pytest-6.2.3.pyc
  34. BIN
      fe/test/__pycache__/test_bench.cpython-38-pytest-6.2.3.pyc
  35. BIN
      fe/test/__pycache__/test_create_store.cpython-38-pytest-6.2.3.pyc
  36. BIN
      fe/test/__pycache__/test_login.cpython-38-pytest-6.2.3.pyc
  37. BIN
      fe/test/__pycache__/test_new_order.cpython-38-pytest-6.2.3.pyc
  38. BIN
      fe/test/__pycache__/test_password.cpython-38-pytest-6.2.3.pyc
  39. BIN
      fe/test/__pycache__/test_payment.cpython-38-pytest-6.2.3.pyc
  40. BIN
      fe/test/__pycache__/test_register.cpython-38-pytest-6.2.3.pyc
  41. +195
    -0
      figure_require/DB_struct_origin.drawio
  42. +1
    -0
      figure_require/DB_struct_origin.svg
  43. BIN
      figure_require/add_naive_userdata.png
  44. BIN
      figure_require/conn_test.png
  45. +0
    -0
      modified/be/Config.py
  46. +0
    -0
      modified/be/__init__.py
  47. BIN
      modified/be/__pycache__/creatTB.cpython-38.pyc
  48. BIN
      modified/be/__pycache__/postgreSQLORM.cpython-38.pyc
  49. BIN
      modified/be/__pycache__/serve.cpython-38.pyc
  50. BIN
      modified/be/__pycache__/testconn.cpython-38.pyc
  51. +4
    -0
      modified/be/app.py
  52. +5
    -0
      modified/be/creatTB.py
  53. +0
    -0
      modified/be/model/store.py
  54. +121
    -0
      modified/be/postgreSQLORM.py
  55. +12
    -0
      modified/be/serve.py
  56. +22
    -0
      modified/be/testconn.py
  57. +0
    -0
      modified/be/view/auth.py
  58. +0
    -0
      modified/be/view/buyer.py
  59. +0
    -0
      modified/be/view/seller.py
  60. +213
    -0
      report.md

BIN
.coverage View File


BIN
be.db View File


BIN
be/__pycache__/__init__.cpython-38.pyc View File


BIN
be/__pycache__/serve.cpython-38.pyc View File


BIN
be/model/__pycache__/__init__.cpython-38.pyc View File


BIN
be/model/__pycache__/buyer.cpython-38.pyc View File


BIN
be/model/__pycache__/db_conn.cpython-38.pyc View File


BIN
be/model/__pycache__/error.cpython-38.pyc View File


BIN
be/model/__pycache__/seller.cpython-38.pyc View File


BIN
be/model/__pycache__/store.cpython-38.pyc View File


BIN
be/model/__pycache__/user.cpython-38.pyc View File


BIN
be/view/__pycache__/__init__.cpython-38.pyc View File


BIN
be/view/__pycache__/auth.cpython-38.pyc View File


BIN
be/view/__pycache__/buyer.cpython-38.pyc View File


BIN
be/view/__pycache__/seller.cpython-38.pyc View File


BIN
fe/__pycache__/__init__.cpython-38.pyc View File


BIN
fe/__pycache__/conf.cpython-38.pyc View File


BIN
fe/__pycache__/conftest.cpython-38-pytest-6.2.3.pyc View File


BIN
fe/access/__pycache__/__init__.cpython-38.pyc View File


BIN
fe/access/__pycache__/auth.cpython-38.pyc View File


BIN
fe/access/__pycache__/book.cpython-38.pyc View File


BIN
fe/access/__pycache__/buyer.cpython-38.pyc View File


BIN
fe/access/__pycache__/new_buyer.cpython-38.pyc View File


BIN
fe/access/__pycache__/new_seller.cpython-38.pyc View File


BIN
fe/access/__pycache__/seller.cpython-38.pyc View File


BIN
fe/bench/__pycache__/__init__.cpython-38.pyc View File


BIN
fe/bench/__pycache__/run.cpython-38.pyc View File


BIN
fe/bench/__pycache__/session.cpython-38.pyc View File


BIN
fe/bench/__pycache__/workload.cpython-38.pyc View File


BIN
fe/test/__pycache__/gen_book_data.cpython-38.pyc View File


BIN
fe/test/__pycache__/test_add_book.cpython-38-pytest-6.2.3.pyc View File


BIN
fe/test/__pycache__/test_add_funds.cpython-38-pytest-6.2.3.pyc View File


BIN
fe/test/__pycache__/test_add_stock_level.cpython-38-pytest-6.2.3.pyc View File


BIN
fe/test/__pycache__/test_bench.cpython-38-pytest-6.2.3.pyc View File


BIN
fe/test/__pycache__/test_create_store.cpython-38-pytest-6.2.3.pyc View File


BIN
fe/test/__pycache__/test_login.cpython-38-pytest-6.2.3.pyc View File


BIN
fe/test/__pycache__/test_new_order.cpython-38-pytest-6.2.3.pyc View File


BIN
fe/test/__pycache__/test_password.cpython-38-pytest-6.2.3.pyc View File


BIN
fe/test/__pycache__/test_payment.cpython-38-pytest-6.2.3.pyc View File


BIN
fe/test/__pycache__/test_register.cpython-38-pytest-6.2.3.pyc View File


+ 195
- 0
figure_require/DB_struct_origin.drawio View File

@ -0,0 +1,195 @@
<mxfile host="65bd71144e">
<diagram id="7UV1QSxvfCCaCf5dNHmy" name="第 1 页">
<mxGraphModel dx="911" dy="428" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="40" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;fontFamily=Helvetica;fontSize=13;" edge="1" parent="1" source="3" target="23">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="41" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;fontFamily=Helvetica;fontSize=13;" edge="1" parent="1" source="3" target="22">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="3" value="user" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Helvetica;fontSize=18;" vertex="1" parent="1">
<mxGeometry x="270" y="310" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="46" style="edgeStyle=none;html=1;exitX=1;exitY=0;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;fontFamily=Helvetica;fontSize=13;" edge="1" parent="1" source="4" target="32">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="47" style="edgeStyle=none;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;fontFamily=Helvetica;fontSize=13;" edge="1" parent="1" source="4">
<mxGeometry relative="1" as="geometry">
<mxPoint x="660" y="300" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="48" style="edgeStyle=none;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;fontFamily=Helvetica;fontSize=13;" edge="1" parent="1" source="4" target="34">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="49" style="edgeStyle=none;html=1;exitX=1;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0;entryDx=0;entryDy=0;fontFamily=Helvetica;fontSize=13;" edge="1" parent="1" source="4" target="35">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="4" value="store" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Helvetica;fontSize=18;" vertex="1" parent="1">
<mxGeometry x="510" y="310" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="43" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;fontFamily=Helvetica;fontSize=13;" edge="1" parent="1" source="5" target="37">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="44" style="edgeStyle=none;html=1;exitX=0.75;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;fontFamily=Helvetica;fontSize=13;" edge="1" parent="1" source="5" target="38">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="5" value="new_order" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Helvetica;fontSize=18;" vertex="1" parent="1">
<mxGeometry x="390" y="410" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="10" value="" style="endArrow=none;html=1;entryX=0;entryY=0.5;entryDx=0;entryDy=0;exitX=1;exitY=0.5;exitDx=0;exitDy=0;fontFamily=Helvetica;fontSize=18;" edge="1" parent="1" source="25" target="26">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="515" y="220" as="sourcePoint"/>
<mxPoint x="565" y="180" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="11" value="" style="endArrow=none;html=1;entryX=0;entryY=0.5;entryDx=0;entryDy=0;entryPerimeter=0;exitX=1;exitY=0.5;exitDx=0;exitDy=0;fontFamily=Helvetica;fontSize=18;" edge="1" parent="1" source="27" target="25">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="350" y="220" as="sourcePoint"/>
<mxPoint x="385" y="220" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="14" value="购买" style="rhombus;whiteSpace=wrap;html=1;fontFamily=Helvetica;fontSize=18;" vertex="1" parent="1">
<mxGeometry x="290" y="400" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="15" value="出售" style="rhombus;whiteSpace=wrap;html=1;fontFamily=Helvetica;fontSize=18;" vertex="1" parent="1">
<mxGeometry x="530" y="400" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="16" value="" style="endArrow=none;html=1;entryX=0.5;entryY=1;entryDx=0;entryDy=0;fontFamily=Helvetica;fontSize=18;" edge="1" parent="1" target="4">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="570" y="400" as="sourcePoint"/>
<mxPoint x="620" y="350" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="17" value="" style="endArrow=none;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;fontFamily=Helvetica;fontSize=18;" edge="1" parent="1" source="5" target="15">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="580" y="380" as="sourcePoint"/>
<mxPoint x="630" y="330" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="18" value="" style="endArrow=none;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;fontFamily=Helvetica;fontSize=18;" edge="1" parent="1" source="14" target="3">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="580" y="380" as="sourcePoint"/>
<mxPoint x="630" y="330" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="19" value="" style="endArrow=none;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;fontFamily=Helvetica;fontSize=18;" edge="1" parent="1" source="14" target="5">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="640" y="450" as="sourcePoint"/>
<mxPoint x="690" y="400" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="21" value="user_id" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;" vertex="1" parent="1">
<mxGeometry x="150" y="240" width="60" height="60" as="geometry"/>
</mxCell>
<mxCell id="22" value="password" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;" vertex="1" parent="1">
<mxGeometry x="161" y="390" width="60" height="60" as="geometry"/>
</mxCell>
<mxCell id="23" value="balance" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;" vertex="1" parent="1">
<mxGeometry x="111" y="310" width="60" height="60" as="geometry"/>
</mxCell>
<mxCell id="50" style="edgeStyle=none;html=1;exitX=0.25;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;fontFamily=Helvetica;fontSize=13;" edge="1" parent="1" source="25" target="30">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="51" style="edgeStyle=none;html=1;exitX=0.75;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;fontFamily=Helvetica;fontSize=13;" edge="1" parent="1" source="25" target="31">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="25" value="user_store" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Helvetica;fontSize=18;" vertex="1" parent="1">
<mxGeometry x="390" y="190" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="26" value="店主" style="rhombus;whiteSpace=wrap;html=1;fontFamily=Helvetica;fontSize=18;" vertex="1" parent="1">
<mxGeometry x="530" y="180" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="27" value="开店" style="rhombus;whiteSpace=wrap;html=1;fontFamily=Helvetica;fontSize=18;" vertex="1" parent="1">
<mxGeometry x="290" y="180" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="28" value="" style="endArrow=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;fontFamily=Helvetica;fontSize=18;" edge="1" parent="1" source="26" target="4">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="520" y="380" as="sourcePoint"/>
<mxPoint x="570" y="330" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="29" value="" style="endArrow=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;fontFamily=Helvetica;fontSize=18;" edge="1" parent="1" source="27" target="3">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="520" y="380" as="sourcePoint"/>
<mxPoint x="570" y="330" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="30" value="user_id" style="ellipse;whiteSpace=wrap;html=1;fontFamily=Helvetica;fontSize=12;" vertex="1" parent="1">
<mxGeometry x="370" y="90" width="60" height="60" as="geometry"/>
</mxCell>
<mxCell id="31" value="&lt;font style=&quot;font-size: 13px&quot;&gt;store_id&lt;/font&gt;" style="ellipse;whiteSpace=wrap;html=1;fontFamily=Helvetica;fontSize=18;" vertex="1" parent="1">
<mxGeometry x="470" y="90" width="60" height="60" as="geometry"/>
</mxCell>
<mxCell id="32" value="store_id" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;" vertex="1" parent="1">
<mxGeometry x="661" y="180" width="60" height="60" as="geometry"/>
</mxCell>
<mxCell id="33" value="book_id" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;" vertex="1" parent="1">
<mxGeometry x="661" y="270" width="60" height="60" as="geometry"/>
</mxCell>
<mxCell id="34" value="book_info" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;" vertex="1" parent="1">
<mxGeometry x="661" y="350" width="60" height="60" as="geometry"/>
</mxCell>
<mxCell id="35" value="stock_level" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;" vertex="1" parent="1">
<mxGeometry x="661" y="440" width="60" height="60" as="geometry"/>
</mxCell>
<mxCell id="36" value="order_id" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;" vertex="1" parent="1">
<mxGeometry x="270" y="500" width="60" height="60" as="geometry"/>
</mxCell>
<mxCell id="37" value="user_id" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;" vertex="1" parent="1">
<mxGeometry x="340" y="510" width="60" height="60" as="geometry"/>
</mxCell>
<mxCell id="38" value="store_id" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;" vertex="1" parent="1">
<mxGeometry x="414" y="510" width="60" height="60" as="geometry"/>
</mxCell>
<mxCell id="39" value="" style="endArrow=classic;startArrow=classic;html=1;fontFamily=Helvetica;fontSize=13;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="3" target="21">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="390" y="410" as="sourcePoint"/>
<mxPoint x="440" y="360" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="42" value="" style="endArrow=classic;startArrow=classic;html=1;fontFamily=Helvetica;fontSize=13;exitX=0.25;exitY=1;exitDx=0;exitDy=0;entryX=1;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="5" target="36">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="280" y="350" as="sourcePoint"/>
<mxPoint x="211.21320343559637" y="301.21320343559637" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="62" style="edgeStyle=none;html=1;exitX=0.75;exitY=0;exitDx=0;exitDy=0;entryX=0.313;entryY=1.007;entryDx=0;entryDy=0;entryPerimeter=0;fontFamily=Helvetica;fontSize=18;" edge="1" parent="1" source="53" target="60">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="53" value="&lt;font style=&quot;font-size: 18px&quot;&gt;book&lt;/font&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Helvetica;fontSize=13;" vertex="1" parent="1">
<mxGeometry x="620" y="520" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="54" value="关于" style="rhombus;whiteSpace=wrap;html=1;fontFamily=Helvetica;fontSize=18;" vertex="1" parent="1">
<mxGeometry x="510" y="490" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="56" value="" style="endArrow=none;html=1;fontFamily=Helvetica;fontSize=18;exitX=1;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="5" target="54">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="400" y="540" as="sourcePoint"/>
<mxPoint x="450" y="490" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="58" value="" style="endArrow=none;html=1;fontFamily=Helvetica;fontSize=18;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="53" target="54">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="400" y="540" as="sourcePoint"/>
<mxPoint x="450" y="490" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="59" value="book_id" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;" vertex="1" parent="1">
<mxGeometry x="767" y="450" width="60" height="60" as="geometry"/>
</mxCell>
<mxCell id="60" value="book_info" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;" vertex="1" parent="1">
<mxGeometry x="740" y="380" width="60" height="60" as="geometry"/>
</mxCell>
<mxCell id="63" value="" style="endArrow=classic;startArrow=classic;html=1;fontFamily=Helvetica;fontSize=18;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="53" target="59">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="530" y="460" as="sourcePoint"/>
<mxPoint x="580" y="410" as="targetPoint"/>
</mxGeometry>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

+ 1
- 0
figure_require/DB_struct_origin.svg
File diff suppressed because it is too large
View File


BIN
figure_require/add_naive_userdata.png View File

Before After
Width: 786  |  Height: 341  |  Size: 22 KiB

BIN
figure_require/conn_test.png View File

Before After
Width: 656  |  Height: 113  |  Size: 9.7 KiB

+ 0
- 0
modified/be/Config.py View File


+ 0
- 0
modified/be/__init__.py View File


BIN
modified/be/__pycache__/creatTB.cpython-38.pyc View File


BIN
modified/be/__pycache__/postgreSQLORM.cpython-38.pyc View File


BIN
modified/be/__pycache__/serve.cpython-38.pyc View File


BIN
modified/be/__pycache__/testconn.cpython-38.pyc View File


+ 4
- 0
modified/be/app.py View File

@ -0,0 +1,4 @@
import serve
if __name__ == "__main__":
serve.be_run()

+ 5
- 0
modified/be/creatTB.py View File

@ -0,0 +1,5 @@
from postgreSQLORM import Base,engine
def createTable():
# 创建所有继承于Base的类对应的表
Base.metadata.create_all(engine)

+ 0
- 0
modified/be/model/store.py View File


+ 121
- 0
modified/be/postgreSQLORM.py View File

@ -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()

+ 12
- 0
modified/be/serve.py View File

@ -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)

+ 22
- 0
modified/be/testconn.py View File

@ -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"

+ 0
- 0
modified/be/view/auth.py View File


+ 0
- 0
modified/be/view/buyer.py View File


+ 0
- 0
modified/be/view/seller.py View File


+ 213
- 0
report.md View File

@ -0,0 +1,213 @@
## <center> 华东师范大学数据科学与工程学院实验报告
| **课程名称:当代数据库管理系统** |**年级** :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)
&nbsp;
#### 二. 依据上述分析构建数据库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.

Loading…
Cancel
Save