Example #1
0
    def factory(cls, **kwargs):
        from ascetic.transaction import TransactionManager
        transaction = TransactionManager(kwargs['alias'], kwargs.pop('autocommit', False))
        try:
            Cls = cls._engines[kwargs['engine']]
        except KeyError:
            Cls = utils.resolve(kwargs['engine'])

        database = Cls(transaction=transaction, **kwargs)
        if 'django_alias' in kwargs:
            database.connection_factory = django_connection_factory
        return database
Example #2
0
from time import time
from functools import wraps
from sqlbuilder import smartsql
from ascetic import settings, utils

try:
    str = unicode  # Python 2.* compatible
    string_types = (basestring,)
    integer_types = (int, long)
except NameError:
    string_types = (str,)
    integer_types = (int,)

PLACEHOLDER = '%s'

utils.resolve(settings.LOGGER_INIT)(settings)


class Database(object):

    _engines = {}
    placeholder = '%s'
    compile = smartsql.compile
    connection = None

    def __init__(self, alias, engine, transaction, initial_sql, always_reconnect=False, debug=False, **kwargs):
        self.alias = alias
        self.engine = engine
        self.debug = debug
        self.initial_sql = initial_sql
        self.always_reconnect = always_reconnect
Example #3
0
 def test_resolve(self):
     from ascetic.databases import Database
     self.assertTrue(
         utils.resolve('ascetic.databases.Database') is Database)