Beispiel #1
0
 def test_query(self):
     res = db.query('select name from users limit 5')
     self.assertEqual(len(res), 5)
     res = db.query('select name from users limit %s', (100,), many=20)
     rows = []
     for r in res:
         rows.append(r)
     self.assertTrue(100, len(rows))
Beispiel #2
0
 def test_query(self):
     res = db.query('select name from users limit 5')
     self.assertEqual(len(res), 5)
     res = db.query('select name from users limit %s', (100, ), many=20)
     rows = []
     for r in res:
         rows.append(r)
     self.assertTrue(100, len(rows))
Beispiel #3
0
 def paginate(self, page=1, perpage=10):
     count = self.count()
     results = db.query(
         self.SELECT + ' ORDER BY created DESC LIMIT %s OFFSET %s',
         (perpage, (page - 1) * perpage))
     users = [self._load(user) for user in results]
     return Paginator(users, count, page, perpage, '/user')
Beispiel #4
0
 def claim(self, limit, age=None):
     age= age or datetime.now()
     task_id = gen_task_id()
     db.execute('UPDATE cron SET task_id=%s, status=%s WHERE task_id IS NULL and next_run<=%s and status<%s LIMIT %s', 
         (task_id, Task.RUNNING, age, Task.RUNNING, limit))
     tasks = db.query('SELECT * FROM cron WHERE  task_id=%s', (task_id,))
     return [self._load(task) for task in tasks]
Beispiel #5
0
 def claim(self, limit, age=None):
     age = age or datetime.now()
     task_id = gen_task_id()
     db.execute(
         'UPDATE cron SET task_id=%s, status=%s WHERE task_id IS NULL and next_run<=%s and status<%s LIMIT %s',
         (task_id, Task.RUNNING, age, Task.RUNNING, limit))
     tasks = db.query('SELECT * FROM cron WHERE  task_id=%s', (task_id, ))
     return [self._load(task) for task in tasks]
Beispiel #6
0
    def count(self, name, status):
        select  = 'SELECT COUNT(cron_id) FROM cron'
        where = []
        args = []
        if status:
            args.append(status)
            where.append('status=%s')
        if name:
            args.append(name)
            where.append(' name like %s')

        if where:
            where = ' WHERE ' + ' AND '.join(where)
        else:
            where = ''
        return db.query(select + where , args)[0][0]
Beispiel #7
0
    def count(self, name, status):
        select = 'SELECT COUNT(cron_id) FROM cron'
        where = []
        args = []
        if status:
            args.append(status)
            where.append('status=%s')
        if name:
            args.append(name)
            where.append(' name like %s')

        if where:
            where = ' WHERE ' + ' AND '.join(where)
        else:
            where = ''
        return db.query(select + where, args)[0][0]
Beispiel #8
0
    def take(self, name, status=0, page=1, perpage=10):
        select = 'SELECT * FROM cron'
        where = []
        args = []
        if status:
            args.append(status)
            where.append('status=%s')
        if name:
            args.append(name)
            where.append(' name like %s')

        if where:
            where = ' WHERE ' + ' AND '.join(where)
        else:
            where = ''

        args.extend([perpage, (page - 1) * perpage])
        results = db.query(select + where + ' LIMIT %s OFFSET %s', args)
        return [self._load(task) for task in results]
Beispiel #9
0
    def take(self, name, status=0, page=1, perpage=10):
        select  = 'SELECT * FROM cron'
        where = []
        args = []
        if status:
            args.append(status)
            where.append('status=%s')
        if name:
            args.append(name)
            where.append(' name like %s')

        if where:
            where = ' WHERE ' + ' AND '.join(where)
        else:
            where = ''

        args.extend([perpage, (page - 1) * perpage])
        results = db.query(select + where + ' LIMIT %s OFFSET %s', args)
        return [self._load(task) for task in results]
Beispiel #10
0
 def find_by_username(self, username):
     """Return user by username if find in database otherwise None"""
     data = db.query(self.SELECT + 'WHERE username=%s', (username,))
     if data:
         return self._load(data[0])
Beispiel #11
0
 def find_by_username(self, username):
     """Return user by username if find in database otherwise None"""
     data = db.query(self.SELECT + 'WHERE username=%s', (username, ))
     if data:
         return self._load(data[0])
Beispiel #12
0
 def find_by_email(self, email):
     """Return user by email if find in database otherwise None"""
     data = db.query(self.SELECT + 'WHERE email=%s', (email, ))
     if data:
         return self._load(data[0])
Beispiel #13
0
 def find(self, uid):
     """Find and load the user from database by uid(user id)"""
     data = db.query(self.SELECT + 'WHERE uid=%s', (uid, ))
     if data:
         return self._load(data[0])
Beispiel #14
0
 def paginate(self, page=1, perpage=10):
     count = self.count()
     results = db.query(self.SELECT + ' ORDER BY created DESC LIMIT %s OFFSET %s', (perpage, (page - 1) * perpage))
     users = [self._load(user) for user in results]
     return Paginator(users, count, page, perpage, '/user')
Beispiel #15
0
 def q(n):
     for i in range(10):
         res = db.query('select count(*) from  users')
         self.assertEqual(99, res[0][0])
Beispiel #16
0
 def find_by_email(self, email):
     """Return user by email if find in database otherwise None"""
     data = db.query(self.SELECT + 'WHERE email=%s', (email,))
     if data:
         return self._load(data[0])
Beispiel #17
0
 def count(self):
     return db.query('SELECT COUNT(uid) FROM users')[0][0]
Beispiel #18
0
 def q(n):
     for i in range(10):
         res = db.query('select count(*) from  users')
         self.assertEqual(99, res[0][0])
Beispiel #19
0
 def find_by_task_id(self, task_id):
     results = db.query('SELECT * FROM cron WHERE task_id=%s', (task_id,))
     return [self._load(data) for data in results]
Beispiel #20
0
 def count(self):
     return db.query('SELECT COUNT(uid) FROM users')[0][0]
Beispiel #21
0
 def test_excute(self):
     res = db.execute('insert into users values(%s, %s)', [(10L, 'thomas'),
                                                           (11L, 'animer')],
                      key='test')
     res = db.query('SELECT count(*) FROM users WHERE uid>=10', key='test')
     self.assertEqual(2, res[0][0])
Beispiel #22
0
 def test_excute(self):
     res = db.execute('insert into users values(%s, %s)', [(100L, 'thomas'), (101L, 'animer')])
     res = db.query('SELECT count(*) FROM users WHERE uid>=100')
     self.assertEqual(2, res[0][0])
Beispiel #23
0
 def find_by_task_id(self, task_id):
     results = db.query('SELECT * FROM cron WHERE task_id=%s', (task_id, ))
     return [self._load(data) for data in results]
Beispiel #24
0
 def find(self, uid):
     """Find and load the user from database by uid(user id)"""
     data = db.query(self.SELECT + 'WHERE uid=%s', (uid,))
     if data:
         return self._load(data[0])