mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-23 03:18:08 +01:00
Add Database.create_query() as a shorthand for db=Database();q=Query(db,"")
This is a convenience extension to the C API. I hardly saves any typing, but let's us automatically free the top-level Database() object when we delete the Query().
This commit is contained in:
parent
c90c28ded7
commit
0b57cb8ed9
2 changed files with 23 additions and 0 deletions
|
@ -293,6 +293,28 @@ class Database(object):
|
||||||
raise NotmuchError(STATUS.NULL_POINTER)
|
raise NotmuchError(STATUS.NULL_POINTER)
|
||||||
return Tags(tags_p, self)
|
return Tags(tags_p, self)
|
||||||
|
|
||||||
|
def create_query(self, querystring):
|
||||||
|
"""Returns a :class:`Query` derived from this database
|
||||||
|
|
||||||
|
This is a shorthand method for doing::
|
||||||
|
# short version
|
||||||
|
# Automatically frees the Database() when 'q' is deleted
|
||||||
|
|
||||||
|
q = Database(dbpath).create_query('from:"Biene Maja"')
|
||||||
|
|
||||||
|
# long version, which is functionally equivalent but will keep the
|
||||||
|
# Database in the 'db' variable around after we delete 'q':
|
||||||
|
|
||||||
|
db = Database(dbpath)
|
||||||
|
q = Query(db,'from:"Biene Maja"')
|
||||||
|
|
||||||
|
This function is a python extension and not in the underlying C API.
|
||||||
|
"""
|
||||||
|
# Raise a NotmuchError if not initialized
|
||||||
|
self._verify_initialized_db()
|
||||||
|
|
||||||
|
return Query(self._db, querystring)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "'Notmuch DB " + self.get_path() + "'"
|
return "'Notmuch DB " + self.get_path() + "'"
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,7 @@ or::
|
||||||
|
|
||||||
.. automethod:: get_all_tags
|
.. automethod:: get_all_tags
|
||||||
|
|
||||||
|
.. automethod:: create_query
|
||||||
|
|
||||||
.. attribute:: Database.MODE
|
.. attribute:: Database.MODE
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue