Ejemplo n.º 1
0
def test_bench():
    import time

    testQuery = BaseQuery(['autoid', 'k', 'v', 'ctime'], 'test1')

    LOOP = 10000
    st = time.time()
    for i in xrange(LOOP):
        print testQuery.delete().and_equal_to('autoid', 1).limit(10)
    et = time.time()
    ct = et-st
    print "Cost %.2fs, rps %.2f" % (ct, LOOP/ct)

    testQuery.update({'k': 1, 'v': 2}).and_greater_equal("k", 1).and_less_than("k", 10).sql()
    testQuery.insert([{'k': 1, 'v': 2}, {'k': 2, 'v': "3'\""}]).sql()
    testQuery.select().and_less_than('k', 2).sql()
Ejemplo n.º 2
0
def test_generate_sql():
    testQuery = BaseQuery(['autoid', 'k', 'v', 'ctime'], 'test1')
    assert_equal(testQuery.delete().and_equal_to('autoid', 1).limit(10).sql(),
                 r'''DELETE FROM `test1` WHERE `autoid`=1 LIMIT 10''')

    assert_equal(testQuery.update({'k': 1, 'v': 2}).and_greater_equal("k", 1).and_less_than("k", 10).sql(),
                 r'''UPDATE `test1` SET `k`=1,`v`=2 WHERE `k`>=1 AND `k`<10''')

    assert_equal(testQuery.insert([{'k': 1, 'v': 2}, {'k': 2, 'v': "3'\""}]).sql(),
                 r'''INSERT INTO `test1`(`k`,`v`) VALUES (1,2),(2,'3\'\"')''')

    assert_equal(testQuery.select().and_less_than('k', 2).sql(),
                 r'''SELECT `autoid`,`k`,`v`,`ctime` FROM `test1` WHERE `k`<2''')