MyTetra Share
Делитесь знаниями!
Retrieving raw tuples / dictionaries / Получение словарей данных
Время создания: 12.05.2017 17:07
Раздел: Python - Модули - peewee
Запись: xintrea/mytetra_db_mcold/master/base/14945980297q2p3xjuzp/text.html на raw.githubusercontent.com

Retrieving raw tuples / dictionaries

Sometimes you do not need the overhead of creating model instances and simply want to iterate over the row tuples. To do this, call SelectQuery.tuples() or RawQuery.tuples():

stats = Stat.select(Stat.url, fn.Count(Stat.url)).group_by(Stat.url).tuples()

# iterate over a list of 2-tuples containing the url and count
for stat_url, stat_count in stats:
    print stat_url, stat_count

Similarly, you can return the rows from the cursor as dictionaries using SelectQuery.dicts() or RawQuery.dicts():

stats = Stat.select(Stat.url, fn.Count(Stat.url).alias('ct')).group_by(Stat.url).dicts()

# iterate over a list of 2-tuples containing the url and count
for stat in stats:
    print stat['url'], stat['ct']
Так же в этом разделе:
 
MyTetra Share v.0.59
Яндекс индекс цитирования