From f1bbed6066b985d73e4ad2e0edc44c1614b55d78 Mon Sep 17 00:00:00 2001 From: roger_home_pc Date: Tue, 27 Jun 2023 22:26:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=E4=B8=80=E7=82=B9?= =?UTF-8?q?=EF=BC=8C=E6=B2=A1=E6=80=9D=E8=B7=AF=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- orm/blue_forecast.py | 12 ++++++++++++ orm/orm_db.py | 7 ++----- orm/real_index.py | 2 ++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/orm/blue_forecast.py b/orm/blue_forecast.py index e69de29..c324bd1 100644 --- a/orm/blue_forecast.py +++ b/orm/blue_forecast.py @@ -0,0 +1,12 @@ +from orm_db import * +from sqlalchemy import select, desc + +try: + get_last_data_stmt = select(History).order_by(desc('id')).limit(1) + last_data_result = db_session.execute(get_last_data_stmt).scalar() + print(last_data_result) +except Exception as e: + print(e) + +last_blue = last_data_result.blue +print(last_blue) \ No newline at end of file diff --git a/orm/orm_db.py b/orm/orm_db.py index 8a8e1b3..75ef3a8 100644 --- a/orm/orm_db.py +++ b/orm/orm_db.py @@ -1,6 +1,6 @@ import sqlalchemy from sqlalchemy import create_engine -from sqlalchemy.orm import declarative_base +from sqlalchemy.orm import declarative_base, sessionmaker from sqlalchemy import Column, Integer, String, DATE # 创建数据引擎 @@ -72,8 +72,5 @@ class RedForecastAll(Base): # 创建数据表,下面部分没有联想 Base.metadata.create_all(engine) - -from sqlalchemy.orm import sessionmaker - Session_class = sessionmaker(bind=engine) # 创建与数据引擎的绑定会话类 -session = Session_class() # 实例化session连接 +db_session = Session_class() # 实例化session连接 diff --git a/orm/real_index.py b/orm/real_index.py index e69de29..7f711cf 100644 --- a/orm/real_index.py +++ b/orm/real_index.py @@ -0,0 +1,2 @@ +from orm_db import * +