本文整理汇总了Python中tinydb.TinyDB.all方法的典型用法代码示例。如果您正苦于以下问题:Python TinyDB.all方法的具体用法?Python TinyDB.all怎么用?Python TinyDB.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tinydb.TinyDB
的用法示例。
在下文中一共展示了TinyDB.all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Test_005_Search_Not_existing_data_by_valid_query_Function
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import all [as 别名]
class Test_005_Search_Not_existing_data_by_valid_query_Function(unittest.TestCase):
def setUp(self):
self.db = TinyDB('db.json')
def tearDown(self):
self.db.purge()
self.db.all()
def test_simple_search_not_exist(self):
print("case 5 search Non-existing data by valid query")
result=self.db.search(where('Name') == 'Wendy')
self.assertEqual(result,[])
示例2: Test_006_Modify_Not_existing_data_by_valid_query_Function
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import all [as 别名]
class Test_006_Modify_Not_existing_data_by_valid_query_Function(unittest.TestCase):
def setUp(self):
self.db = TinyDB('db.json')
def tearDown(self):
self.db.purge()
self.db.all()
def test_simple_modify_not_exist(self):
print("case 6 modify Non-existing data by valid query")
result=self.db.update({'int': 10}, where('Name') == 'Wendy')
self.assertEqual(result,None)
示例3: Test_007_Delete_Not_existing_data_by_valid_query_Function
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import all [as 别名]
class Test_007_Delete_Not_existing_data_by_valid_query_Function(unittest.TestCase):
def setUp(self):
self.db = TinyDB('db.json')
def tearDown(self):
self.db.purge()
self.db.all()
def test_simple_delete_not_exist(self):
print("case 7 Delete Non-existing data by valid query")
result=self.db.remove(where('Name') == 'Wendy')
self.assertEqual(result,None)
示例4: Test_001_Insert_by_valid_query_Function
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import all [as 别名]
class Test_001_Insert_by_valid_query_Function(unittest.TestCase):
def setUp(self):
self.db = TinyDB('db.json')
def tearDown(self):
self.db.purge()
self.db.all()
def test_simple_insert_valid_exist(self):
print("case 1 insert data by valid query")
self.db.insert({'Name': 'Greg', 'Email': '[email protected]', 'int' : 1, 'char':1})
result=self.db.search(where('Name') == 'Greg')
self.assertEqual(result,[{'Name': 'Greg', 'Email': '[email protected]', 'int' : 1, 'char':1}])
示例5: index
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import all [as 别名]
def index():
form = SearchForm()
query = request.args.get('query', '').strip()
db = TinyDB(recipyGui.config.get('tinydb'))
if not query:
runs = db.all()
else:
# Search run outputs using the query string
runs = db.search(
where('outputs').any(lambda x: listsearch(query, x)) |
where('inputs').any(lambda x: listsearch(query, x)) |
where('script').search(query) |
where('notes').search(query) |
where('unique_id').search(query))
runs = sorted(runs, key = lambda x: parse(x['date'].replace('{TinyDate}:', '')) if x['date'] is not None else x['eid'], reverse=True)
run_ids = []
for run in runs:
if 'notes' in run.keys():
run['notes'] = str(escape(run['notes']))
run_ids.append(run.eid)
db.close()
return render_template('list.html', runs=runs, query=query, form=form,
run_ids=str(run_ids),
dbfile=recipyGui.config.get('tinydb'))
示例6: test_serialisation_of_pandas_dataframe
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import all [as 别名]
def test_serialisation_of_pandas_dataframe(tmpdir):
from sacred.observers.tinydb_hashfs import (DataFrameSerializer,
SeriesSerializer)
from tinydb_serialization import SerializationMiddleware
import numpy as np
import pandas as pd
# Setup Serialisation object for non list/dict objects
serialization_store = SerializationMiddleware()
serialization_store.register_serializer(DataFrameSerializer(),
'TinyDataFrame')
serialization_store.register_serializer(SeriesSerializer(),
'TinySeries')
db = TinyDB(os.path.join(tmpdir.strpath, 'metadata.json'),
storage=serialization_store)
df = pd.DataFrame(np.eye(3), columns=list('ABC'))
series = pd.Series(np.ones(5))
document = {
'foo': 'bar',
'some_dataframe': df,
'nested': {
'ones': series
}
}
db.insert(document)
returned_doc = db.all()[0]
assert returned_doc['foo'] == 'bar'
assert (returned_doc['some_dataframe'] == df).all().all()
assert (returned_doc['nested']['ones'] == series).all()
示例7: test_serialisation_of_numpy_ndarray
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import all [as 别名]
def test_serialisation_of_numpy_ndarray(tmpdir):
from sacred.observers.tinydb_hashfs import NdArraySerializer
from tinydb_serialization import SerializationMiddleware
import numpy as np
# Setup Serialisation object for non list/dict objects
serialization_store = SerializationMiddleware()
serialization_store.register_serializer(NdArraySerializer(), 'TinyArray')
db = TinyDB(os.path.join(tmpdir.strpath, 'metadata.json'),
storage=serialization_store)
eye_mat = np.eye(3)
ones_array = np.ones(5)
document = {
'foo': 'bar',
'some_array': eye_mat,
'nested': {
'ones': ones_array
}
}
db.insert(document)
returned_doc = db.all()[0]
assert returned_doc['foo'] == 'bar'
assert (returned_doc['some_array'] == eye_mat).all()
assert (returned_doc['nested']['ones'] == ones_array).all()
示例8: get_coffees
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import all [as 别名]
def get_coffees(active):
name = ''
name_link = ''
nav_links = []
description = ''
db = TinyDB('db/coffee.json')
coffee = db.all()
count = 0
coffee_id = 0
for i in coffee:
if active == -1 and count == 0:
nav_links.append(("/"+str(i['id']),"active",i['name']))
name = i['name']
description = i['description']
coffee_id = i['id']
name_link = '/'+str(i['id'])
elif active == -1 and count > 0:
nav_links.append(("/"+str(i['id']),"",i['name']))
elif active == i['id']:
nav_links.append(("/"+str(i['id']),"active",i['name']))
name = i['name']
description = i['description']
coffee_id = i['id']
name_link = '/'+str(i['id'])
else:
nav_links.append(("/"+str(i['id']),"",i['name']))
count = count+1
for i in nav_links:
print i
print name
print name_link
return nav_links, name, name_link, description, coffee_id
示例9: __init__
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import all [as 别名]
class DB:
def __init__(self,db_path):
self.db = TinyDB(db_path)
def add(self, data):
# Only add it if you can't find it
Track = Query()
if not self.db.get(Track.display_id == data['display_id']):
return self.db.insert(data)
def searchById(self, video_id):
Track = Query()
return self.db.get(Track.display_id == video_id)
def search(self, text):
pattern = re.compile(text,re.IGNORECASE)
def test(txt):
return pattern.search(txt)
Track = Query()
q = Track.title.test(test) | Track.description.test(test)
return self.db.search(q)
def all(self):
return self.db.all()
示例10: test_write_first_cache
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import all [as 别名]
def test_write_first_cache(self):
"""test write behavior on first pass (cache-buster mode)"""
self.test_clear_existing_cache() #blowup existing cache again
dummy_data = forecast_utils.parse_emd_data(DEMO_DATA['result'])
forecast_utils.write_prediction_cache(
self.region_id,
self.type_id,
dummy_data,
cache_path=self.cache_path
)
assert path.isfile(self.cache_filepath)
tdb = TinyDB(self.cache_filepath)
data = tdb.all()[0]
keys_list = [
'cache_date',
'region_id',
'type_id',
'lastWrite',
'prediction'
]
assert set(keys_list) == set(data.keys())
dummy_str_data = dummy_data.to_json(
date_format='iso',
orient='records'
)
cached_data = pd.read_json(data['prediction'])
assert data['prediction'] == dummy_str_data
tdb.close()
示例11: __init__
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import all [as 别名]
class pcDB:
def __init__(self,table="default"):
#'/path/to/db.json'
path=''
self.table=table
self.db = TinyDB(path).table(table)
def insert(self,_dict):
'''
:return:
'''
self.db.insert(_dict)
# db.insert({'int': 1, 'char': 'a'})
# db.insert({'int': 1, 'char': 'b'})
pass
def getAll(self):
'''
not param just get all data
:return:
'''
return self.db.all()
#db.search()
pass
pass
#
# from tinydb.storages import JSONStorage
# from tinydb.middlewares import CachingMiddleware
# db = TinyDB('/path/to/db.json', storage=CachingMiddleware(JSONStorage))
示例12: update_statistic
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import all [as 别名]
def update_statistic():
db = TinyDB("data/db.json")
rows = db.all()
rows.sort(key=lambda x: int(x['rid']), reverse=True)
levels = {1: [], 2: [], 3: []}
for row in rows:
levels[row['level']].append(row)
out = []
header = '|%-35s|%-40s|%-6s|%-10s|%5s|%10s|' % ("round", "problem", "solved", "ave_pts",
"rate", "submission")
for k, v in levels.items():
out.append('# LEVEL %d' % k)
out.append('-' * len(header))
out.append(header)
out.append('-' * len(header))
v.sort(key=lambda x: difficulty(x), reverse=True)
for i in v:
out.append('|%-35s|%-40s|%-6s|%-10.2lf|%-4.3lf|%10s|' % (i['round'], i['name'], i['solved'],
i['average_pts'], i['correct_rate'], i['submissions']))
out.append('*' * len(header))
with open("data/statistic.txt", 'w') as f:
for i in out:
f.write(i + '\n')
print '>>>> data/statistic.txt has been updated.'
示例13: NumberStore
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import all [as 别名]
class NumberStore():
def __init__(self, filename):
self.db = TinyDB(filename)
def initNumber(self, number):
if not self.getNumberDict(number):
self.db.insert({'number': number, 'accesses': [], 'info': '#yolo'})
def touchNumber(self, number):
self.initNumber(number)
#print(self.getNumberDict(number))
#accesses = self.getNumberDict(number)['accesses'].append(datetime.datetime.now())
#self.db.update({'accesses': accesses}, where('number') == number)
def getNumberDict(self, number):
return self.db.get(where('number') == number)
def getNumberList(self):
return (entry['number'] for entry in self.db.all())
def getAccesses(self, number):
# if not number in self.db['numbers']:
# return None
# if not 'info' in self.db['numbers'][number]:
# return None
#
# return self.db['numbers'][number]['info']
return []
def getInfo(self, number):
return self.getNumberDict(number)['info']
def setInfo(self, number, info):
self.initNumber(number)
self.db.update({'info': info}, where('number') == number)
print(self.db.all())
def deleteNumber(self, number):
self.db.remove(where('number') == number)
print(self.db.all())
def close(self):
self.db.close()
示例14: test_gc
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import all [as 别名]
def test_gc(tmpdir):
# See https://github.com/msiemens/tinydb/issues/92
path = str(tmpdir.join('db.json'))
table = TinyDB(path).table('foo')
table.insert({'something': 'else'})
table.insert({'int': 13})
assert len(table.search(where('int') == 13)) == 1
assert table.all() == [{'something': 'else'}, {'int': 13}]
示例15: Test_008_Insert_exits_data_Function
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import all [as 别名]
class Test_008_Insert_exits_data_Function(unittest.TestCase):
def setUp(self):
self.db = TinyDB('db.json')
def tearDown(self):
self.db.purge()
self.db.all()
def test_simple_insert_by_query(self):
print("case 8 can insert existing data")
self.db.insert({'Name': 'Yingyu Wu', 'Email': '[email protected]', 'int' : 1, 'char':1})
self.db.insert({'Name': 'Yingyu Wu', 'Email': '[email protected]', 'int' : 1, 'char':1})
result_array = self.db.search(where('Name') == 'Yingyu Wu')
num = len(result_array)
#print (result_array)
#print("search one key,get %d result" %(num))
self.assertEqual(2,num)