Exemplo n.º 1
0
    def load(self, job, guid):
        for data, timestamp, tries, etag in CacheEntry.query(self.db, CacheEntry.c.data // CacheEntry.c.timestamp // CacheEntry.c.tries // CacheEntry.c.etag,
                                                             order_by=minidb.columns(CacheEntry.c.timestamp.desc, CacheEntry.c.tries.desc),
                                                             where=CacheEntry.c.guid == guid, limit=1):
            return data, timestamp, tries, etag

        return None, None, 0, None
Exemplo n.º 2
0
    def load(self, job, guid):
        for data, timestamp, tries, etag in CacheEntry.query(self.db, CacheEntry.c.data // CacheEntry.c.timestamp // CacheEntry.c.tries // CacheEntry.c.etag,
                                                             order_by=minidb.columns(CacheEntry.c.timestamp.desc, CacheEntry.c.tries.desc),
                                                             where=CacheEntry.c.guid == guid, limit=1):
            return data, timestamp, tries, etag

        return None, None, 0, None
Exemplo n.º 3
0
 def get_history_data(self, guid, count=1):
     history = {}
     if count < 1:
         return history
     for data, timestamp in CacheEntry.query(self.db, CacheEntry.c.data // CacheEntry.c.timestamp,
                                             order_by=minidb.columns(CacheEntry.c.timestamp.desc, CacheEntry.c.tries.desc),
                                             where=(CacheEntry.c.guid == guid)
                                             & ((CacheEntry.c.tries == 0) | (CacheEntry.c.tries == None))):  # noqa
         if data not in history:
             history[data] = timestamp
             if len(history) >= count:
                 break
     return history
Exemplo n.º 4
0
 def get_history_data(self, guid, count=1):
     history = {}
     if count < 1:
         return history
     for data, timestamp in CacheEntry.query(self.db, CacheEntry.c.data // CacheEntry.c.timestamp,
                                             order_by=minidb.columns(CacheEntry.c.timestamp.desc, CacheEntry.c.tries.desc),
                                             where=(CacheEntry.c.guid == guid)
                                             & ((CacheEntry.c.tries == 0) | (CacheEntry.c.tries == None))):  # noqa
         if data not in history:
             history[data] = timestamp
             if len(history) >= count:
                 break
     return history
Exemplo n.º 5
0
    print('select with query builder')
    print('columns:', Person.c)
    query = (Person.c.id < 1000) & Person.c.username.like('%foo%') & (
        Person.c.username != None)
    # Person.load(db, Person.id < 1000 & Person.username.like('%foo%'))
    print('query:', query)
    print({p.id: p for p in Person.load(db, query)(FooObject())})
    print('deleting all persons with a short username')
    print(Person.delete_where(db, Person.c.username.length <= 3))

    print('what is left')
    for p in Person.load(db)(FooObject()):
        uu = next(
            Person.query(db,
                         minidb.columns(Person.c.username.upper('up'),
                                        Person.c.username.lower('down'),
                                        Person.c.foo('foox'), Person.c.foo),
                         where=(Person.c.id == p.id),
                         order_by=minidb.columns(Person.c.id.desc,
                                                 Person.c.username.length.asc),
                         limit=1))
        print(p.id, p.username, p.mail, uu)

    print('=' * 30)
    print('queries')
    print('=' * 30)

    highest_id = next(Person.query(db, Person.c.id.max('max'))).max
    print('highest id:', highest_id)

    average_age = next(
Exemplo n.º 6
0
        print('Index access:', row[0], row[1])
        print('As dict:', dict(row))

    print('select with query builder')
    print('columns:', Person.c)
    query = (Person.c.id < 1000) & Person.c.username.like('%foo%') & (Person.c.username != None)
    # Person.load(db, Person.id < 1000 & Person.username.like('%foo%'))
    print('query:', query)
    print({p.id: p for p in Person.load(db, query)(FooObject())})
    print('deleting all persons with a short username')
    print(Person.delete_where(db, Person.c.username.length <= 3))

    print('what is left')
    for p in Person.load(db)(FooObject()):
        uu = next(Person.query(db, minidb.columns(Person.c.username.upper('up'),
                                                  Person.c.username.lower('down'),
                                                  Person.c.foo('foox'),
                                                  Person.c.foo),
                               where=(Person.c.id == p.id),
                               order_by=minidb.columns(Person.c.id.desc,
                                                       Person.c.username.length.asc),
                               limit=1))
        print(p.id, p.username, p.mail, uu)

    print('=' * 30)
    print('queries')
    print('=' * 30)

    highest_id = next(Person.query(db, Person.c.id.max('max'))).max
    print('highest id:', highest_id)

    average_age = next(WithoutConstructor.query(db, WithoutConstructor.c.age.avg('average'))).average