本文整理汇总了Python中tinydb.TinyDB.purge_table方法的典型用法代码示例。如果您正苦于以下问题:Python TinyDB.purge_table方法的具体用法?Python TinyDB.purge_table怎么用?Python TinyDB.purge_table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tinydb.TinyDB
的用法示例。
在下文中一共展示了TinyDB.purge_table方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_purge_table
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import purge_table [as 别名]
def test_purge_table():
db = TinyDB(storage=MemoryStorage)
assert [TinyDB.DEFAULT_TABLE] == list(db.tables())
db.purge_table(TinyDB.DEFAULT_TABLE)
assert [] == list(db.tables())
table_name = 'some-other-table'
db = TinyDB(storage=MemoryStorage)
db.table(table_name)
assert set([TinyDB.DEFAULT_TABLE, table_name]) == db.tables()
db.purge_table(table_name)
assert set([TinyDB.DEFAULT_TABLE]) == db.tables()
db.purge_table('non-existent-table-name')
assert set([TinyDB.DEFAULT_TABLE]) == db.tables()
示例2: TinyRunDB
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import purge_table [as 别名]
#.........这里部分代码省略.........
res_idx = res_list[0][0]
resources = res_list[0][1]
if "resources" in value[0]:
de = defaultdict(list, resources["resources"])
for i, j in value[0]["resources"].items():
de[i].extend(j)
de = {"resources": de}
tx_rec[res_idx] = de
return t.update(tinySet(key, [de]), eids=[run_id])
return t.update(add(key, value), eids=[run_id])
@usedb
def get_tx_record(self, tx_id):
t = self.db.table(name='linchpin')
return t.get(eid=tx_id)
@usedb
def get_tx_records(self, tx_ids):
txs = {}
t = self.db.table(name='linchpin')
for tx_id in tx_ids:
txs[tx_id] = t.get(eid=tx_id)
return txs
@usedb
def get_record(self, table, action='up', run_id=None):
t = self.db.table(name=table)
if not run_id:
run_id = len(t.all())
if not run_id:
return (None, 0)
for rid in range(int(run_id), 0, -1):
record = t.get(eid=int(rid))
if record and record['action'] == action:
return (record, int(rid))
else:
record = t.get(eid=int(run_id))
if record:
return(record, int(run_id))
return (None, 0)
@usedb
def get_records(self, table, count=10):
records = {}
if table in self.db.tables():
t = self.db.table(name=table)
if len(t.all()):
start = len(t)
if count == 'all':
end = 0
else:
end = start - count
for i in xrange(start, end, -1):
records[i] = t.get(doc_id=i)
return records
@usedb
def get_tables(self):
tables = self.db.tables()
tables.remove(self.default_table)
return tables
def remove_record(self, table, key, value):
pass
def search(self, table, key=None):
t = self.db.table(name=table)
if key:
return t.search(key)
return t.all()
def query(self, table, query):
pass
def purge(self, table=None):
if table:
return self.db.purge_table(table)
return self.db.purge_tables()
def _closedb(self):
self.db.close()