psycopg2cffi.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # testing/engines.py
  2. # Copyright (C) 2005-2022 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. r"""
  8. .. dialect:: postgresql+psycopg2cffi
  9. :name: psycopg2cffi
  10. :dbapi: psycopg2cffi
  11. :connectstring: postgresql+psycopg2cffi://user:password@host:port/dbname[?key=value&key=value...]
  12. :url: https://pypi.org/project/psycopg2cffi/
  13. ``psycopg2cffi`` is an adaptation of ``psycopg2``, using CFFI for the C
  14. layer. This makes it suitable for use in e.g. PyPy. Documentation
  15. is as per ``psycopg2``.
  16. .. versionadded:: 1.0.0
  17. .. seealso::
  18. :mod:`sqlalchemy.dialects.postgresql.psycopg2`
  19. """ # noqa
  20. from .psycopg2 import PGDialect_psycopg2
  21. class PGDialect_psycopg2cffi(PGDialect_psycopg2):
  22. driver = "psycopg2cffi"
  23. supports_unicode_statements = True
  24. supports_statement_cache = True
  25. # psycopg2cffi's first release is 2.5.0, but reports
  26. # __version__ as 2.4.4. Subsequent releases seem to have
  27. # fixed this.
  28. FEATURE_VERSION_MAP = dict(
  29. native_json=(2, 4, 4),
  30. native_jsonb=(2, 7, 1),
  31. sane_multi_rowcount=(2, 4, 4),
  32. array_oid=(2, 4, 4),
  33. hstore_adapter=(2, 4, 4),
  34. )
  35. @classmethod
  36. def dbapi(cls):
  37. return __import__("psycopg2cffi")
  38. @classmethod
  39. def _psycopg2_extensions(cls):
  40. root = __import__("psycopg2cffi", fromlist=["extensions"])
  41. return root.extensions
  42. @classmethod
  43. def _psycopg2_extras(cls):
  44. root = __import__("psycopg2cffi", fromlist=["extras"])
  45. return root.extras
  46. dialect = PGDialect_psycopg2cffi