Add method explain which shows explain query plan.

This commit is contained in:
voussoir 2022-08-21 13:54:44 -07:00
parent 1fe6de793c
commit 6b26a4bd93
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -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.