Skip to content

Instantly share code, notes, and snippets.

@ods
ods / PublicQuery.py
Last active December 12, 2015 09:49
from sqlalchemy.orm.query import Query
from sqlalchemy.sql import ClauseElement
from sqlalchemy import cast, Boolean
class PublicQuery(Query):
'''
Filters all queries by publicity condition for each participating mapped
class. Attribute "public" of mapped class (if present) should be either
@riffm
riffm / db_tools.py
Created January 25, 2012 19:50
Gentle `drop tables` using sqlalchemy
# -*- coding: utf-8 -*-
from sqlalchemy import create_engine
from sqlalchemy.types import SchemaType
from sqlalchemy.engine import reflection
from sqlalchemy.schema import (
MetaData,
Table,
DropTable,
ForeignKeyConstraint,
from itertools import izip
def chunkify(iterable, chunk_size):
r"""
>>> chunkify(range(1, 11), 2)
[(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]
"""
_iterable = iter(iterable)
return izip(*[_iterable] * chunk_size)