mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-20 13:04:23 +02:00
add hack for milliseconds on postgres
This commit is contained in:
24
lnbits/db.py
24
lnbits/db.py
@@ -1,9 +1,10 @@
|
|||||||
import os
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import time
|
|
||||||
import datetime
|
import datetime
|
||||||
from typing import Optional
|
import os
|
||||||
|
import time
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy_aio.base import AsyncConnection
|
from sqlalchemy_aio.base import AsyncConnection
|
||||||
from sqlalchemy_aio.strategy import ASYNCIO_STRATEGY # type: ignore
|
from sqlalchemy_aio.strategy import ASYNCIO_STRATEGY # type: ignore
|
||||||
@@ -93,6 +94,12 @@ class Database(Compat):
|
|||||||
|
|
||||||
import psycopg2 # type: ignore
|
import psycopg2 # type: ignore
|
||||||
|
|
||||||
|
def _parse_timestamp(value, _):
|
||||||
|
f = "%Y-%m-%d %H:%M:%S.%f"
|
||||||
|
if not "." in value:
|
||||||
|
f = "%Y-%m-%d %H:%M:%S"
|
||||||
|
return time.mktime(datetime.datetime.strptime(value, f).timetuple())
|
||||||
|
|
||||||
psycopg2.extensions.register_type(
|
psycopg2.extensions.register_type(
|
||||||
psycopg2.extensions.new_type(
|
psycopg2.extensions.new_type(
|
||||||
psycopg2.extensions.DECIMAL.values,
|
psycopg2.extensions.DECIMAL.values,
|
||||||
@@ -114,11 +121,12 @@ class Database(Compat):
|
|||||||
psycopg2.extensions.new_type(
|
psycopg2.extensions.new_type(
|
||||||
(1184, 1114),
|
(1184, 1114),
|
||||||
"TIMESTAMP2INT",
|
"TIMESTAMP2INT",
|
||||||
lambda value, curs: time.mktime(
|
_parse_timestamp
|
||||||
datetime.datetime.strptime(
|
# lambda value, curs: time.mktime(
|
||||||
value, "%Y-%m-%d %H:%M:%S.%f"
|
# datetime.datetime.strptime(
|
||||||
).timetuple()
|
# value, "%Y-%m-%d %H:%M:%S.%f"
|
||||||
),
|
# ).timetuple()
|
||||||
|
# ),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
Reference in New Issue
Block a user