def length(opts=None): session = Session() mi = len(str(session.query(sql.func.max(Snippet.id)).scalar())) mt = session.query(sql.func.max(Snippet._length_tag_names)).scalar() md = session.query(sql.func.max(Snippet._length_dirname)).scalar() mn = session.query(sql.func.max(Snippet._length_name)).scalar() return OrderedDict([("id", mi), ("dirname", md), ("tag_names", mt), ("name", mn)])
def get_tag(tag_names): session = Session() query = session.query(Tag) query = query.filter(cond_tags(tag_names)) query = query.outerjoin(Tag.snippets) query = query.group_by(Tag.id) query = query.order_by(sql.desc(sql.func.count(Snippet.id))) return query
def create_tags(tag_names): session = Session() for t in tag_names: session.add(Tag(name=t)) session.commit()
def tags(tag_names): session = Session() cond = sql.or_(*[compare(t) for t in tag_names]) return session.query(Tag).filter(cond).all()