X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=cnotmuch%2Fdatabase.py;h=c815e440364e0af2983bbb1aafb10fd1b6f16db3;hp=cad73c69089272e8bdd7bdad9aa42a0aa62105c3;hb=0b57cb8ed9850d1315a60ff23113e343b531170e;hpb=c90c28ded713936080b9862d4bc8502bc47da83a diff --git a/cnotmuch/database.py b/cnotmuch/database.py index cad73c69..c815e440 100644 --- a/cnotmuch/database.py +++ b/cnotmuch/database.py @@ -293,6 +293,28 @@ class Database(object): 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() + "'"