mirror of
https://github.com/aljazceru/nutshell.git
synced 2026-01-11 12:44:19 +01:00
Postgres with Dockerfile changes (#148)
* added postgres support * added libpq-dev
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
FROM python:3.9-slim
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y curl python3-dev autoconf g++
|
||||
RUN apt-get install -y libpq-dev
|
||||
RUN curl -sSL https://install.python-poetry.org | python3 -
|
||||
ENV PATH="/root/.local/bin:$PATH"
|
||||
WORKDIR /app
|
||||
|
||||
@@ -84,38 +84,38 @@ class Database(Compat):
|
||||
self.db_location = db_location
|
||||
self.db_location_is_url = "://" in self.db_location
|
||||
if self.db_location_is_url:
|
||||
raise Exception("Remote databases not supported. Use SQLite.")
|
||||
# database_uri = self.db_location
|
||||
# raise Exception("Remote databases not supported. Use SQLite.")
|
||||
database_uri = self.db_location
|
||||
|
||||
# if database_uri.startswith("cockroachdb://"):
|
||||
# self.type = COCKROACH
|
||||
# else:
|
||||
# self.type = POSTGRES
|
||||
if database_uri.startswith("cockroachdb://"):
|
||||
self.type = COCKROACH
|
||||
else:
|
||||
self.type = POSTGRES
|
||||
|
||||
# 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())
|
||||
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.new_type(
|
||||
# psycopg2.extensions.DECIMAL.values,
|
||||
# "DEC2FLOAT",
|
||||
# lambda value, curs: float(value) if value is not None else None,
|
||||
# )
|
||||
# )
|
||||
# psycopg2.extensions.register_type(
|
||||
# psycopg2.extensions.new_type(
|
||||
# (1082, 1083, 1266),
|
||||
# "DATE2INT",
|
||||
# lambda value, curs: time.mktime(value.timetuple())
|
||||
# if value is not None
|
||||
# else None,
|
||||
# )
|
||||
# )
|
||||
psycopg2.extensions.register_type(
|
||||
psycopg2.extensions.new_type(
|
||||
psycopg2.extensions.DECIMAL.values,
|
||||
"DEC2FLOAT",
|
||||
lambda value, curs: float(value) if value is not None else None,
|
||||
)
|
||||
)
|
||||
psycopg2.extensions.register_type(
|
||||
psycopg2.extensions.new_type(
|
||||
(1082, 1083, 1266),
|
||||
"DATE2INT",
|
||||
lambda value, curs: time.mktime(value.timetuple())
|
||||
if value is not None
|
||||
else None,
|
||||
)
|
||||
)
|
||||
|
||||
# psycopg2.extensions.register_type(
|
||||
# psycopg2.extensions.new_type(
|
||||
|
||||
Reference in New Issue
Block a user