Refactored run_sanity_checks to check_connection(conn), refs #674

This commit is contained in:
Simon Willison 2020-02-15 09:56:48 -08:00
commit d3f2fade88
4 changed files with 60 additions and 21 deletions

View file

@ -216,26 +216,6 @@ class Datasette:
def remove_database(self, name):
self.databases.pop(name)
async def run_sanity_checks(self):
# Only one check right now, for Spatialite
for database_name, database in self.databases.items():
# Run pragma_info on every table
for table in await database.table_names():
try:
await self.execute(
database_name,
"PRAGMA table_info({});".format(escape_sqlite(table)),
)
except sqlite3.OperationalError as e:
if e.args[0] == "no such module: VirtualSpatialIndex":
raise click.UsageError(
"It looks like you're trying to load a SpatiaLite"
" database without first loading the SpatiaLite module."
"\n\nRead more: https://datasette.readthedocs.io/en/latest/spatialite.html"
)
else:
raise
def config(self, key):
return self._config.get(key, None)