fix postgres type translation bug and add some logs.
This commit is contained in:
+14
-1
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import trio
|
||||
import time
|
||||
import datetime
|
||||
from typing import Optional
|
||||
from contextlib import asynccontextmanager
|
||||
from sqlalchemy import create_engine # type: ignore
|
||||
@@ -101,13 +102,25 @@ class Database(Compat):
|
||||
)
|
||||
psycopg2.extensions.register_type(
|
||||
psycopg2.extensions.new_type(
|
||||
psycopg2.extensions.TIME.values + psycopg2.extensions.DATE.values,
|
||||
psycopg2.extensions.DATE.values + psycopg2.extensions.TIME.values,
|
||||
"DATE2INT",
|
||||
lambda value, curs: time.mktime(value.timetuple())
|
||||
if value is not None
|
||||
else None,
|
||||
)
|
||||
)
|
||||
|
||||
psycopg2.extensions.register_type(
|
||||
psycopg2.extensions.new_type(
|
||||
(1184, 1114),
|
||||
"TIMESTAMP2INT",
|
||||
lambda value, curs: time.mktime(
|
||||
datetime.datetime.strptime(
|
||||
value, "%Y-%m-%d %H:%M:%S.%f"
|
||||
).timetuple()
|
||||
),
|
||||
)
|
||||
)
|
||||
else:
|
||||
self.path = os.path.join(LNBITS_DATA_FOLDER, f"{self.name}.sqlite3")
|
||||
database_uri = f"sqlite:///{self.path}"
|
||||
|
||||
Reference in New Issue
Block a user