mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Show custom error message if SpatiaLite needed, closes #331
This commit is contained in:
parent
17863d108b
commit
2db2ae4f21
1 changed files with 21 additions and 11 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import click
|
||||||
import collections
|
import collections
|
||||||
import hashlib
|
import hashlib
|
||||||
import itertools
|
import itertools
|
||||||
|
|
@ -261,17 +262,26 @@ class Datasette:
|
||||||
name = path.stem
|
name = path.stem
|
||||||
if name in self._inspect:
|
if name in self._inspect:
|
||||||
raise Exception("Multiple files with same stem %s" % name)
|
raise Exception("Multiple files with same stem %s" % name)
|
||||||
|
try:
|
||||||
with sqlite3.connect(
|
with sqlite3.connect(
|
||||||
"file:{}?immutable=1".format(path), uri=True
|
"file:{}?immutable=1".format(path), uri=True
|
||||||
) as conn:
|
) as conn:
|
||||||
self.prepare_connection(conn)
|
self.prepare_connection(conn)
|
||||||
self._inspect[name] = {
|
self._inspect[name] = {
|
||||||
"hash": inspect_hash(path),
|
"hash": inspect_hash(path),
|
||||||
"file": str(path),
|
"file": str(path),
|
||||||
"views": inspect_views(conn),
|
"views": inspect_views(conn),
|
||||||
"tables": inspect_tables(conn, self.metadata.get("databases", {}).get(name, {}))
|
"tables": inspect_tables(conn, self.metadata.get("databases", {}).get(name, {}))
|
||||||
}
|
}
|
||||||
|
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
|
||||||
return self._inspect
|
return self._inspect
|
||||||
|
|
||||||
def register_custom_units(self):
|
def register_custom_units(self):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue