Esempio n. 1
0
File: dbt.py Progetto: feijilei/Eden
 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))
Esempio n. 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))
Esempio n. 3
0
File: data.py Progetto: beordle/Eden
 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')
Esempio n. 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]
Esempio n. 5
0
File: data.py Progetto: beordle/Eden
 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]
Esempio n. 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]
Esempio n. 7
0
File: data.py Progetto: beordle/Eden
    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]
Esempio n. 8
0
File: data.py Progetto: beordle/Eden
    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]
Esempio n. 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]
Esempio n. 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])
Esempio n. 11
0
File: data.py Progetto: beordle/Eden
 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])
Esempio n. 12
0
File: data.py Progetto: beordle/Eden
 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])
Esempio n. 13
0
File: data.py Progetto: beordle/Eden
 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])
Esempio n. 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')
Esempio n. 15
0
File: dbt.py Progetto: feijilei/Eden
 def q(n):
     for i in range(10):
         res = db.query('select count(*) from  users')
         self.assertEqual(99, res[0][0])
Esempio n. 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])
Esempio n. 17
0
File: data.py Progetto: beordle/Eden
 def count(self):
     return db.query('SELECT COUNT(uid) FROM users')[0][0]
Esempio n. 18
0
 def q(n):
     for i in range(10):
         res = db.query('select count(*) from  users')
         self.assertEqual(99, res[0][0])
Esempio n. 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]
Esempio n. 20
0
 def count(self):
     return db.query('SELECT COUNT(uid) FROM users')[0][0]
Esempio n. 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])
Esempio n. 22
0
File: dbt.py Progetto: feijilei/Eden
 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])
Esempio n. 23
0
File: data.py Progetto: beordle/Eden
 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]
Esempio n. 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])