本文整理匯總了Python中db.DB.where方法的典型用法代碼示例。如果您正苦於以下問題:Python DB.where方法的具體用法?Python DB.where怎麽用?Python DB.where使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類db.DB
的用法示例。
在下文中一共展示了DB.where方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: execute
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import where [as 別名]
def execute(cols=None, where=None, limit=100, offset=0, order_by=[]):
"""select header"""
db = DB(cached_db(state)).limit(limit).offset(offset)
if cols:
db.select(cols)
if where:
db.where(where)
if order_by:
db.order_by(*order_by)
records = db.execute()
return json.dumps(dict(
schema=db.schema,
records=records
))
示例2: TestDB
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import where [as 別名]
class TestDB(TestCase):
def setUp(self):
self.db = DB([
dict(
name="John",
login_count=2
),
dict(
name="Bob",
login_count=1
)
])
def test_select_all(self):
self.assertSequenceEqual(
self.db.select().execute(),
[
(2, "John"),
(1,"Bob")
]
)
def test_select_name(self):
self.assertSequenceEqual(
self.db.select('name').execute(),
[
("John",),
("Bob",)
]
)
def test_create_aggregate(self):
self.db.create_aggregate(
name="bogus",
function=lambda state: state + 1,
initial=0
)
self.db.select("count()")
eq_(len(self.db.reducers),1)
self.db.select("name, count()")
eq_(len(self.db.reducers),1)
self.db.select("count(), bogus(login_count)")
eq_(len(self.db.reducers),2)
def test_select_count(self):
self.assertSequenceEqual(
self.db.select('count()').execute(),
[
(2,),
]
)
def test_select_col_with_count(self):
self.assertSequenceEqual(
self.db.select('name,count()').group_by("name").execute(),
[
('Bob',1),
('John', 1)
]
)
def test_where(self):
self.assertSequenceEqual(
self.db.where("login_count == 2").execute(),
[
(2, "John")
]
)
self.assertSequenceEqual(
self.db.where("login_count != 1").execute(),
[
(2, "John")
]
)
self.assertSequenceEqual(
self.db.where("login_count != None").execute(),
[
(2, "John"),
(1, "Bob")
]
)
def test_select_where(self):
self.assertSequenceEqual(
#.........這裏部分代碼省略.........