Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write an external dialect for SQLAlchemy?

Tags:

sqlalchemy

I wrote a minimal database dialect for SQLAlchemy that doesn't really belong in the core. How do I make it work as its own Python package?

like image 658
joeforker Avatar asked Nov 04 '09 16:11

joeforker


People also ask

What is a SQLAlchemy dialect?

The dialect is the system SQLAlchemy uses to communicate with various types of DBAPI implementations and databases. The sections that follow contain reference documentation and notes specific to the usage of each backend, as well as notes for the various DBAPIs.

What is DB dialect?

A database dialect is a configuration setting for platform independent software (JPA, Hibernate, etc) which allows such software to translate its generic SQL statements into vendor specific DDL, DML.

What is SQLAlchemy URI?

SQLAlchemy indicates the source of an Engine as a URI combined with optional keyword arguments to specify options for the Engine. The form of the URI is: dialect+driver://username:password@host:port/database. Many of the parts in the string are optional.


1 Answers

As of SQLAlchemy 0.8, you can register the dialects in-process without needing to have a separate install.

from sqlalchemy.dialects import registry
registry.register("mysql.foodialect", "myapp.dialect", "MyMySQLDialect")

The above will respond to create_engine("mysql+foodialect://") and load the MyMySQLDialect class from the myapp.dialect module.

See: https://docs.sqlalchemy.org/en/latest/core/connections.html#registering-new-dialects

like image 198
Sean Lynch Avatar answered Oct 18 '22 13:10

Sean Lynch