attribute does not exist
In the examples given
db_table.find_by_column_value("name", "bob"))
causes an error
AttributeError: 'Table' object has no attribute 'find_by_column_value'
I don't have the python skills to fix or suggest a fix - Can you please help resolve this?
My use case is to have a table of serial numbers and to return a description based on a search on the name column
Hello @shanevanj
I have managed to "hack-fix" solution, so search by query would work.
To search for data by column and value use
db_table.find({"name" : "bob"}) for first occurrence and
db_table.query({"name" : "bob"}) for all occurrences
Edit __return_query method to following:
found = False moved to another location and else's commented out
def __return_query(self, search_type, queries = None):
"""
Helper function to process a query and return the result.
"""
if queries:
queries = self.__scrub_data(queries)
result = []
location = os.listdir(self.path)
#Remove non-data files from our list of dirs.
location = [element for element in location if 'data' in element]
#Sort as integers so we get them in the right order.
location = sorted(location, key=lambda x: int(x.split('.')[0].split('_')[1]), reverse = True)
found = False
for f in location:
with open(self.path + '/' + f, 'r') as data:
for line in data:
#Make sure the line isn't blank (ex. if it was deleted).
if line != '\n':
found = False
current_data = json.loads(line)
for query in queries:
if current_data['data'][query] == queries[query]:
found = True
# else:
# found = False
# break
if found:
if search_type == 'find':
return current_data['data']
elif search_type == 'query':
result.append(current_data)
# else:
# break
if result:
return result
else:
return None
This solution work good on my computer python But i'm not happy with a performance on uC (esp32) of inserting data, I'm not sure will it be usable on uC