简体   繁体   English

如何遍历 UnqLite 集合并提取数据

[英]How to iterate through UnqLite collection and extract data

db = UnQLite('test.db')
data = db.collection('data')
print(data.fetch(0))

This works.这行得通。

Now, how do I fetch each record and extract the necessary fields from it?现在,我如何获取每条记录并从中提取必要的字段?

I am looking for something like我正在寻找类似的东西

db = UnQLite('test.db')
data = db.collection('data')
for i in range(data.size()???)
print(data.fetch(i))

There isn't any size() method on the collection.集合上没有任何 size() 方法。 Any help is appreciated.任何帮助表示赞赏。

A collection is itself iterable:集合本身是可迭代的:

for record in data:
    # use record
    # to save changes:
    data.update(record['__id'], record)
data.reset_cursor() # if you want to iterate again

len () Return the number of records in the database. len () 返回数据库中的记录数。

Warning: This method calculates the lengthy by iterating and counting every record.警告:此方法通过迭代和计算每条记录来计算 long。 At the time of writing, there is no C API for calculating the size of the database.在撰写本文时,没有用于计算数据库大小的 C API。

for i in range(0,len(data)):
      print data[i]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM