psycopg2cffi.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # dialects/postgresql/psycopg2cffi.py
  2. # Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
  3. # <see AUTHORS file>
  4. #
  5. # This module is part of SQLAlchemy and is released under
  6. # the MIT License: https://www.opensource.org/licenses/mit-license.php
  7. # mypy: ignore-errors
  8. r"""
  9. .. dialect:: postgresql+psycopg2cffi
  10. :name: psycopg2cffi
  11. :dbapi: psycopg2cffi
  12. :connectstring: postgresql+psycopg2cffi://user:password@host:port/dbname[?key=value&key=value...]
  13. :url: https://pypi.org/project/psycopg2cffi/
  14. ``psycopg2cffi`` is an adaptation of ``psycopg2``, using CFFI for the C
  15. layer. This makes it suitable for use in e.g. PyPy. Documentation
  16. is as per ``psycopg2``.
  17. .. seealso::
  18. :mod:`sqlalchemy.dialects.postgresql.psycopg2`
  19. """ # noqa
  20. from .psycopg2 import PGDialect_psycopg2
  21. from ... import util
  22. class PGDialect_psycopg2cffi(PGDialect_psycopg2):
  23. driver = "psycopg2cffi"
  24. supports_unicode_statements = True
  25. supports_statement_cache = True
  26. # psycopg2cffi's first release is 2.5.0, but reports
  27. # __version__ as 2.4.4. Subsequent releases seem to have
  28. # fixed this.
  29. FEATURE_VERSION_MAP = dict(
  30. native_json=(2, 4, 4),
  31. native_jsonb=(2, 7, 1),
  32. sane_multi_rowcount=(2, 4, 4),
  33. array_oid=(2, 4, 4),
  34. hstore_adapter=(2, 4, 4),
  35. )
  36. @classmethod
  37. def import_dbapi(cls):
  38. return __import__("psycopg2cffi")
  39. @util.memoized_property
  40. def _psycopg2_extensions(cls):
  41. root = __import__("psycopg2cffi", fromlist=["extensions"])
  42. return root.extensions
  43. @util.memoized_property
  44. def _psycopg2_extras(cls):
  45. root = __import__("psycopg2cffi", fromlist=["extras"])
  46. return root.extras
  47. dialect = PGDialect_psycopg2cffi