__init__.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # dialects/__init__.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. __all__ = (
  8. "firebird",
  9. "mssql",
  10. "mysql",
  11. "oracle",
  12. "postgresql",
  13. "sqlite",
  14. "sybase",
  15. )
  16. from .. import util
  17. def _auto_fn(name):
  18. """default dialect importer.
  19. plugs into the :class:`.PluginLoader`
  20. as a first-hit system.
  21. """
  22. if "." in name:
  23. dialect, driver = name.split(".")
  24. else:
  25. dialect = name
  26. driver = "base"
  27. try:
  28. if dialect == "firebird":
  29. try:
  30. module = __import__("sqlalchemy_firebird")
  31. except ImportError:
  32. module = __import__("sqlalchemy.dialects.firebird").dialects
  33. module = getattr(module, dialect)
  34. elif dialect == "sybase":
  35. try:
  36. module = __import__("sqlalchemy_sybase")
  37. except ImportError:
  38. module = __import__("sqlalchemy.dialects.sybase").dialects
  39. module = getattr(module, dialect)
  40. elif dialect == "mariadb":
  41. # it's "OK" for us to hardcode here since _auto_fn is already
  42. # hardcoded. if mysql / mariadb etc were third party dialects
  43. # they would just publish all the entrypoints, which would actually
  44. # look much nicer.
  45. module = __import__(
  46. "sqlalchemy.dialects.mysql.mariadb"
  47. ).dialects.mysql.mariadb
  48. return module.loader(driver)
  49. else:
  50. module = __import__("sqlalchemy.dialects.%s" % (dialect,)).dialects
  51. module = getattr(module, dialect)
  52. except ImportError:
  53. return None
  54. if hasattr(module, driver):
  55. module = getattr(module, driver)
  56. return lambda: module.dialect
  57. else:
  58. return None
  59. registry = util.PluginLoader("sqlalchemy.dialects", auto_fn=_auto_fn)
  60. plugins = util.PluginLoader("sqlalchemy.plugins")