moskytw / mosql

Build SQL with native Python data structure smoothly.
http://mosql.mosky.tw
MIT License
140 stars 17 forks source link

Alternative implementation for patching #26

Closed uranusjr closed 10 years ago

uranusjr commented 10 years ago

See also #24 #25.

A slightly complicated version of context manager patching mechanism. Introduce mosql.patch to handle all (well, both) engines. The idea is mostly the same, only the function names are different:

from mosql import patch

with patch.mysql():
    select(...)         # MySQL
    with patch.sqlite():
        select(...)     # SQLite
    select(...)         # MySQL again
select(...)             # Standard

For perminante overriding, use mysql.load() and sqlite.load(). They also return a dict of replaced functions.

An important aspect of this version is that it is backward compatible. Both import mosql.mysql and import mosql.sqlite will continue to work, although I recommand deprecation.

Some docs and tests are attached, but consider them incomplete because there're more structural changes in this version.

moskytw commented 10 years ago

This feature is implemented in a different way. I will release it in next version.