indexes = [elem['name'] for elem in insp.get_indexes('nodes')]
if 'idx_nodes_path' not in indexes:
explicit_length = '(%s)' %path_length if self.engine.name == 'mysql' else ''
- s = text('CREATE INDEX idx_nodes_path ON nodes (path%s)' %explicit_length)
+ s = text('CREATE UNIQUE INDEX idx_nodes_path ON nodes (path%s)' %explicit_length)
self.conn.execute(s).close()
s = self.nodes.select().where(and_(self.nodes.c.node == ROOTNODE,
def latest_version_list(self, parent, prefix='', delimiter=None,
start='', limit=10000, before=inf,
- except_cluster=0, pathq=[], domain=None, filterq=[]):
+ except_cluster=0, pathq=[], domain=None, filterq=[], sizeq=None):
"""Return a (list of (path, serial) tuples, list of common prefixes)
for the current versions of the paths with the given parent,
matching the following criteria.
key ?op value
the attribute with this key satisfies the value
where ?op is one of ==, != <=, >=, <, >.
+
+ h. the size is in the range set by sizeq
The list of common prefixes includes the prefixes
matching up to the first delimiter after prefix,
conj = []
for x in pathq:
conj.append(n.c.path.like(self.escape_like(x) + '%', escape='\\'))
-
if conj:
s = s.where(or_(*conj))
+ if sizeq and len(sizeq) == 2:
+ if sizeq[0]:
+ s = s.where(v.c.size >= sizeq[0])
+ if sizeq[1]:
+ s = s.where(v.c.size < sizeq[1])
+
if domain and filterq:
a = self.attributes.alias('a')
included, excluded, opers = parse_filters(filterq)
if included:
subs = select([1])
- subs = subs.where(a.c.serial == v.c.serial)
+ subs = subs.where(a.c.serial == v.c.serial).correlate(v)
subs = subs.where(a.c.domain == domain)
subs = subs.where(or_(*[a.c.key.op('=')(x) for x in included]))
- print '---', str(subs)
s = s.where(exists(subs))
if excluded:
subs = select([1])
- subs = subs.where(a.c.serial == v.c.serial)
+ subs = subs.where(a.c.serial == v.c.serial).correlate(v)
subs = subs.where(a.c.domain == domain)
subs = subs.where(or_(*[a.c.key.op('=')(x) for x in excluded]))
- print '---', str(subs)
s = s.where(not_(exists(subs)))
if opers:
- subs = select([1])
- subs = subs.where(a.c.serial == v.c.serial)
- subs = subs.where(a.c.domain == domain)
- subs = subs.where(and_(*[a.c.key == k and a.c.value.op(o)(v) for k, o, v in opers]))
- print '---', str(subs)
- s = s.where(exists(subs))
+ for k, o, val in opers:
+ subs = select([1])
+ subs = subs.where(a.c.serial == v.c.serial).correlate(v)
+ subs = subs.where(a.c.domain == domain)
+ subs = subs.where(and_(a.c.key.op('=')(k), a.c.value.op(o)(val)))
+ s = s.where(exists(subs))
s = s.order_by(n.c.path)