本文整理汇总了Python中tinydb.TinyDB.purge_tables方法的典型用法代码示例。如果您正苦于以下问题:Python TinyDB.purge_tables方法的具体用法?Python TinyDB.purge_tables怎么用?Python TinyDB.purge_tables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tinydb.TinyDB
的用法示例。
在下文中一共展示了TinyDB.purge_tables方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: db_smartcache
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import purge_tables [as 别名]
def db_smartcache():
db_ = TinyDB(storage=MemoryStorage)
db_.purge_tables()
db_.table_class = SmartCacheTable
db_ = db_.table('_default')
db_.insert_multiple({'int': 1, 'char': c} for c in 'abc')
return db_
示例2: test_non_default_table
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import purge_tables [as 别名]
def test_non_default_table():
db = TinyDB(storage=MemoryStorage)
assert [TinyDB.DEFAULT_TABLE] == list(db.tables())
db = TinyDB(storage=MemoryStorage, default_table='non-default')
assert set(['non-default']) == db.tables()
db.purge_tables()
TinyDB.DEFAULT_TABLE = 'non-default'
db = TinyDB(storage=MemoryStorage)
assert set(['non-default']) == db.tables()
示例3: db
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import purge_tables [as 别名]
def db():
db_ = TinyDB(storage=MemoryStorage)
db_.purge_tables()
db_.insert_multiple({'int': 1, 'char': c} for c in 'abc')
return db_
示例4: StarredDB
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import purge_tables [as 别名]
class StarredDB(object):
def __init__(self, my_stars_home, mode):
self._db = TinyDB(os.path.join(my_stars_home, 'mystars.db'), storage=CachingMiddleware(JSONStorage))
if mode == 't':
self._db.purge_tables()
self._idx = self._db.table('index')
if not self._idx.contains(Query().name == 'language'):
self._idx.insert({
'name': 'language',
'docs': {}
})
if not self._idx.contains(Query().name == 'keyword'):
self._idx.insert({
'name': 'keyword',
'docs': {}
})
def __enter__(self):
return self
def __exit__(self, exception_type, exception_value, traceback):
self._db.close()
def _get_index_docs(self, name):
return self._idx.get(Query().name == name).get('docs', {})
def update(self, repo_list):
if repo_list:
self._db.table('latest_repo').purge()
self._db.table('latest_repo').insert(repo_list[0])
language_docs = self._get_index_docs('language')
keyword_docs = self._get_index_docs('keyword')
for repo in repo_list:
# save repo data
doc_id = self._db.insert(repo)
# update index
name = repo.get('name')
language = repo.get('language')
description = repo.get('description')
if language:
for lang in language.split():
update_inverted_index(language_docs, lang.lower(), doc_id)
keywords = split_repo_name(name)
if description:
keywords += split_repo_desc(description)
for keyword in split_keywords(keywords):
update_inverted_index(keyword_docs, keyword.lower(), doc_id)
self._idx.update(operations.set('docs', language_docs), Query().name == 'language')
self._idx.update(operations.set('docs', keyword_docs), Query().name == 'keyword')
def get_latest_repo_full_name(self):
latest_repo = self._db.table('latest_repo').all()
if len(latest_repo) > 0:
return latest_repo[0].get('full_name')
def search(self, languages, keywords):
# self._build_index()
language_docs = self._get_index_docs('language')
keyword_docs = self._get_index_docs('keyword')
if not language_docs and not language_docs:
raise EmptyIndexWarning('empty index')
language_results = []
if languages:
for search in languages:
language_results += language_docs.get(search.lower(), [])
keywords_results = []
if keywords:
for keyword in keywords:
for term in split_repo_name(keyword):
results = keyword_docs.get(term.lower(), [])
keywords_results.append(results)
if languages and keywords:
# python > 2.6
search_results = list(set(language_results).intersection(*keywords_results))
else:
if len(keywords_results) > 1:
# python > 2.6
final_keywords_results = list(set(keywords_results[0]).intersection(*keywords_results[1:]))
else:
final_keywords_results = []
for results in keywords_results:
for r in results:
final_keywords_results.append(r)
#.........这里部分代码省略.........
示例5: TinyRunDB
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import purge_tables [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()
示例6: len
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import purge_tables [as 别名]
resultado = "perderam"
emoticon = u"\U0001F629"
message = default_party_message.format(party, resultado, end_time, emoticon, duration, kdas)
return message
else:
winning_names_and_heroes = ["\"%s (%s)\"" % (i['personaname'], i['hero']) for i in info]
losing_names_and_heroes = ["\"%s (%s)\"" % (i['personaname'], i['hero']) for i in info]
kda_list = ["{}/{}/{}".format(i['kills'], i['deaths'], i['assists']) for i in winning_side+losing_side]
resultado = ['ganharam' if len(winning_side)>1 else 'ganhou']
message = default_versus_message.format(winning_names_and_heroes,resultado,losing_names_and_heroes,end_time,duration,kda_list)
return message
#Database Config
db = TinyDB(c.db_path)
matches_table = db.table('matches')
matches_info_table = db.table('matches_info')
db.purge_tables()
for accountId in c.accounts:
matches = match_history.matches(account_id=accountId, matches_requested=10, language="en_us")
for m in matches:
print "Creating registry for match %s, account %s"% (m.match_id,accountId)
currentMatchDetails = match_details.match(m.match_id)
matchInfo = fill_match_info(currentMatchDetails,accountId)
matches_table.insert(
{'account_id': accountId, 'match_id': m.match_id,
'message': create_message([matchInfo]), 'date_added': str(datetime.now())}
)
matches_info_table.insert(matchInfo)
print "Fim!"