mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
More SpatiaLite details on /-/versions, closes #1607
This commit is contained in:
parent
1b2f0ab6bb
commit
458f03ad3a
3 changed files with 65 additions and 0 deletions
|
|
@ -46,6 +46,7 @@ from .database import Database, QueryInterrupted
|
||||||
|
|
||||||
from .utils import (
|
from .utils import (
|
||||||
PrefixedUrlString,
|
PrefixedUrlString,
|
||||||
|
SPATIALITE_FUNCTIONS,
|
||||||
StartupError,
|
StartupError,
|
||||||
add_cors_headers,
|
add_cors_headers,
|
||||||
async_call_with_supported_arguments,
|
async_call_with_supported_arguments,
|
||||||
|
|
@ -724,6 +725,17 @@ class Datasette:
|
||||||
sqlite_extensions[extension] = None
|
sqlite_extensions[extension] = None
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
# More details on SpatiaLite
|
||||||
|
if "spatialite" in sqlite_extensions:
|
||||||
|
spatialite_details = {}
|
||||||
|
for fn in SPATIALITE_FUNCTIONS:
|
||||||
|
try:
|
||||||
|
result = conn.execute("select {}()".format(fn))
|
||||||
|
spatialite_details[fn] = result.fetchone()[0]
|
||||||
|
except Exception as e:
|
||||||
|
spatialite_details[fn] = {"error": str(e)}
|
||||||
|
sqlite_extensions["spatialite"] = spatialite_details
|
||||||
|
|
||||||
# Figure out supported FTS versions
|
# Figure out supported FTS versions
|
||||||
fts_versions = []
|
fts_versions = []
|
||||||
for fts in ("FTS5", "FTS4", "FTS3"):
|
for fts in ("FTS5", "FTS4", "FTS3"):
|
||||||
|
|
|
||||||
|
|
@ -52,9 +52,41 @@ SPATIALITE_PATHS = (
|
||||||
"/usr/local/lib/mod_spatialite.dylib",
|
"/usr/local/lib/mod_spatialite.dylib",
|
||||||
"/usr/local/lib/mod_spatialite.so",
|
"/usr/local/lib/mod_spatialite.so",
|
||||||
)
|
)
|
||||||
|
# Used to display /-/versions.json SpatiaLite information
|
||||||
|
SPATIALITE_FUNCTIONS = (
|
||||||
|
"spatialite_version",
|
||||||
|
"spatialite_target_cpu",
|
||||||
|
"check_strict_sql_quoting",
|
||||||
|
"freexl_version",
|
||||||
|
"proj_version",
|
||||||
|
"geos_version",
|
||||||
|
"rttopo_version",
|
||||||
|
"libxml2_version",
|
||||||
|
"HasIconv",
|
||||||
|
"HasMathSQL",
|
||||||
|
"HasGeoCallbacks",
|
||||||
|
"HasProj",
|
||||||
|
"HasProj6",
|
||||||
|
"HasGeos",
|
||||||
|
"HasGeosAdvanced",
|
||||||
|
"HasGeosTrunk",
|
||||||
|
"HasGeosReentrant",
|
||||||
|
"HasGeosOnlyReentrant",
|
||||||
|
"HasMiniZip",
|
||||||
|
"HasRtTopo",
|
||||||
|
"HasLibXML2",
|
||||||
|
"HasEpsg",
|
||||||
|
"HasFreeXL",
|
||||||
|
"HasGeoPackage",
|
||||||
|
"HasGCP",
|
||||||
|
"HasTopology",
|
||||||
|
"HasKNN",
|
||||||
|
"HasRouting",
|
||||||
|
)
|
||||||
# Length of hash subset used in hashed URLs:
|
# Length of hash subset used in hashed URLs:
|
||||||
HASH_LENGTH = 7
|
HASH_LENGTH = 7
|
||||||
|
|
||||||
|
|
||||||
# Can replace this with Column from sqlite_utils when I add that dependency
|
# Can replace this with Column from sqlite_utils when I add that dependency
|
||||||
Column = namedtuple(
|
Column = namedtuple(
|
||||||
"Column", ("cid", "name", "type", "notnull", "default_value", "is_pk", "hidden")
|
"Column", ("cid", "name", "type", "notnull", "default_value", "is_pk", "hidden")
|
||||||
|
|
|
||||||
21
tests/test_spatialite.py
Normal file
21
tests/test_spatialite.py
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
from datasette.app import Datasette
|
||||||
|
from datasette.utils import find_spatialite, SpatialiteNotFound, SPATIALITE_FUNCTIONS
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
def has_spatialite():
|
||||||
|
try:
|
||||||
|
find_spatialite()
|
||||||
|
return True
|
||||||
|
except SpatialiteNotFound:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
@pytest.mark.skipif(not has_spatialite(), reason="Requires SpatiaLite")
|
||||||
|
async def test_spatialite_version_info():
|
||||||
|
ds = Datasette(sqlite_extensions=["spatialite"])
|
||||||
|
response = await ds.client.get("/-/versions.json")
|
||||||
|
assert response.status_code == 200
|
||||||
|
spatialite = response.json()["sqlite"]["extensions"]["spatialite"]
|
||||||
|
assert set(SPATIALITE_FUNCTIONS) == set(spatialite)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue