db: separate SQL from db_init function

testing
Michael D. M. Dryden 2023-11-13 21:51:47 -05:00
rodzic 573359efc1
commit 97af778748
3 zmienionych plików z 8 dodań i 7 usunięć

Wyświetl plik

@ -16,6 +16,7 @@ Changed
- Updated to SQLAlchemy 2.0
- Updated to pandas 2.1
- Updated other dependencies
- Separate SQL code from db_init function
Fixed
-----

Wyświetl plik

@ -22,7 +22,7 @@
import logging
from sqlalchemy import Column, Table, MetaData, text
from sqlalchemy.engine import Engine
from sqlalchemy.engine import Connection
from sqlalchemy.dialects import postgresql
from sqlalchemy.types import TIMESTAMP, BigInteger
@ -35,9 +35,7 @@ messages = Table('messages_utc', metadata,
Column('from_user', BigInteger),
Column('text_index_col', postgresql.TSVECTOR))
def init_dbs(engine: Engine):
sql = """
db_sql = sql = """
create table if not exists messages_utc
(
message_id bigint,
@ -98,5 +96,6 @@ def init_dbs(engine: Engine):
"""
with engine.connect() as con:
con.execute(text(sql))
def init_dbs(con: Connection):
con.execute(text(db_sql))

Wyświetl plik

@ -89,7 +89,8 @@ class PostgresStore(object):
result_proxy.close()
engine.dispose()
init_dbs(self.engine)
with self.engine.connect() as con:
init_dbs(con)
def append_data(self, name: str, data: MessageDict):
data['date'] = str(data['date'])