]> git.notmuchmail.org Git - notmuch/commitdiff
Add Database.create_query() as a shorthand for db=Database();q=Query(db,"")
authorSebastian Spaeth <sebastian@sspaeth.de>
Fri, 19 Mar 2010 09:55:06 +0000 (10:55 +0100)
committerSebastian Spaeth <sebastian@sspaeth.de>
Fri, 19 Mar 2010 09:55:06 +0000 (10:55 +0100)
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().

cnotmuch/database.py
docs/source/index.rst

index cad73c69089272e8bdd7bdad9aa42a0aa62105c3..c815e440364e0af2983bbb1aafb10fd1b6f16db3 100644 (file)
@@ -293,6 +293,28 @@ class Database(object):
             raise NotmuchError(STATUS.NULL_POINTER)
         return Tags(tags_p, self)
 
             raise NotmuchError(STATUS.NULL_POINTER)
         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):
         return "'Notmuch DB " + self.get_path() + "'"
 
     def __repr__(self):
         return "'Notmuch DB " + self.get_path() + "'"
 
index 6d0d5fa3f99165dbb1efb7ecc32b69215e38694d..e04bc843e59721850f3ffb9c6e68e2d55f56b9f3 100644 (file)
@@ -61,6 +61,7 @@ or::
 
    .. automethod:: get_all_tags
 
 
    .. automethod:: get_all_tags
 
+   .. automethod:: create_query
 
    .. attribute:: Database.MODE
 
 
    .. attribute:: Database.MODE