Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ansipunk
committed
Mar 3, 2024
1 parent
cdbf97f
commit 6910288
Showing
6 changed files
with
71 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from sqlalchemy.dialects.postgresql.psycopg import PGCompiler_psycopg | ||
|
||
|
||
class APGCompiler_psycopg2(PGCompiler_psycopg): | ||
def construct_params(self, *args, **kwargs): | ||
pd = super().construct_params(*args, **kwargs) | ||
|
||
for column in self.prefetch: | ||
pd[column.key] = self._exec_default(column.default) | ||
|
||
return pd | ||
|
||
def _exec_default(self, default): | ||
if default.is_callable: | ||
return default.arg(self.dialect) | ||
else: | ||
return default.arg |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
All the unique changes for the databases package | ||
with the custom Numeric as the deprecated pypostgresql | ||
for backwards compatibility and to make sure the | ||
package can go to SQLAlchemy 2.0+. | ||
""" | ||
|
||
import typing | ||
|
||
from sqlalchemy.dialects.postgresql.base import PGDialect, PGExecutionContext | ||
from sqlalchemy.engine import processors | ||
from sqlalchemy.types import Numeric | ||
|
||
|
||
class PGExecutionContext_psycopg(PGExecutionContext): | ||
... | ||
|
||
|
||
class PGNumeric(Numeric): | ||
def bind_processor( | ||
self, dialect: typing.Any | ||
) -> typing.Union[str, None]: # pragma: no cover | ||
return processors.to_str | ||
|
||
def result_processor( | ||
self, dialect: typing.Any, coltype: typing.Any | ||
) -> typing.Union[float, None]: # pragma: no cover | ||
if self.asdecimal: | ||
return None | ||
else: | ||
return processors.to_float | ||
|
||
|
||
class PGDialect_psycopg(PGDialect): | ||
colspecs = { | ||
**PGDialect.colspecs, | ||
Numeric: PGNumeric, | ||
} | ||
execution_ctx_cls = PGExecutionContext_psycopg | ||
|
||
|
||
dialect = PGDialect_psycopg |