BukuDB: Adding New Functions (#120)

* Adds functions to BukuDB - for getting all records and to delete all records

* Refactors get all records function name

* Some minor refactors
This commit is contained in:
Kishore Narendran 2017-02-18 18:43:58 -08:00 committed by Arun Prakash Jana
parent d26e2f5571
commit e5395b5528

24
buku.py
View File

@ -451,6 +451,15 @@ class BukuDb:
return (conn, cur)
def get_all_rec(self):
''' Get all the bookmarks in the database
:return: a list of tuples each of which is a bookmark along with its parameters
'''
self.cur.execute('SELECT * FROM bookmarks')
return self.cur.fetchall()
def get_rec_by_id(self, index):
'''Get a bookmark from database by its ID.
@ -1091,6 +1100,21 @@ class BukuDb:
return True
def delete_all_rec(self, delay_commit=False):
'''Removes all records in the Bookmarks table
:param delay_commit: do not commit to DB, caller responsibility
:return: True on success, False on failure
'''
try:
self.cur.execute('DELETE FROM bookmarks')
if not delay_commit:
self.conn.commit()
return True
except Exception as e:
logerr('delete_rec_all(): %s', e)
return False
def cleardb(self):
'''Drops the bookmark table if it exists