Example #1
0
from sqlalchemy import event, MetaData
import sqlalchemy.sql.operators

from camelot.core.auto_reload import auto_reload
from camelot.core.conf import settings

LOGGER = logging.getLogger('camelot.core.sql')

#
# Singleton metadata object, to be used together with elixir or in SQLAlchemy
# setups with only a single database
#
metadata = MetaData()
metadata.autoflush = False
metadata.transactional = False

event.listen( auto_reload, 'before_reload', metadata.clear )
    
def like_op(column, string):
    return sqlalchemy.sql.operators.like_op(column, '%%%s%%'%string)    
        
def transaction( original_function ):
    """Decorator to make methods or functions transactional"""
    
    from camelot.core.orm import SessionTransaction
    
    @functools.wraps( original_function )
    def decorated_function( *args, **kwargs ):
        
        with SessionTransaction():
Example #2
0
#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#  ============================================================================
"""
This module complements the sqlalchemy sql module, and contains the `metadata` 
variable, which is a global :class:`sqlalchemy.Metadata` object to which all 
tables of the application can be added.
"""

import logging

from sqlalchemy import MetaData
import sqlalchemy.sql.operators

LOGGER = logging.getLogger('camelot.core.sql')

#
# Singleton metadata object, to be used in SQLAlchemy
# setups with only a single database
#
metadata = MetaData()
metadata.autoflush = False
metadata.transactional = False


def like_op(column, string):
    return sqlalchemy.sql.operators.like_op(column, '%%%s%%' % string)