From 6b26a4bd930f580fa59ee0e40717d7e1356c3652 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 21 Aug 2022 13:54:44 -0700 Subject: [PATCH] Add method explain which shows explain query plan. --- voussoirkit/worms.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/voussoirkit/worms.py b/voussoirkit/worms.py index 411559c..3ce863d 100644 --- a/voussoirkit/worms.py +++ b/voussoirkit/worms.py @@ -337,6 +337,10 @@ class Database(metaclass=abc.ABCMeta): row = self.select_one(query, bindings) return (row is not None) + def explain(self, query, bindings=None) -> str: + exp = self.execute('EXPLAIN QUERY PLAN ' + query, bindings) + return '\n'.join(str(tuple(x)) for x in exp.fetchall()) + def get_object_by_id(self, object_class, object_id): ''' Select an object by its ID.