Rows page for rows that linked to the same table in more
than one columns were display incorrectly. Fixed that and added a test.
Also introduced /db/table/row-pk.json?_extras=foreign_key_tables
This is used by the new unit test, but is the first example of a new
?_extras=comma-separated-list pattern I am introducing.
This:
?_filter_column_1=name&_filter_op_1=contains&_filter_value_1=hello
&_filter_column_2=age&_filter_op_2=gte&_filter_value_2=12
Now redirects to this:
?name__contains=hello&age__gte=12
This is needed for the filter editing interface, refs #86
URL shortcut for counting rows grouped by one or more columns.
?_group_count=column1&_group_count=column2 works as well.
SQL generated looks like this:
select "qSpecies", count(*) as "count"
from Street_Tree_List
group by "qSpecies"
order by "count" desc limit 100
Or for two columns like this:
select "qSpecies", "qSiteInfo", count(*) as "count"
from Street_Tree_List
group by "qSpecies", "qSiteInfo"
order by "count" desc limit 100
Refs #44
Still todo: clean up code a bunch (it currently fakes being a 'view'), get
foreign key expansion working.
if filter_op contains a __ the value is set to the right hand side.
e.g.
?_filter_column=col&_filter_op=isnull__1&_filter_value=x
Redirects to:
?col__isnull=1
Refs #86
Part of implementing the filters UI (refs #86) - the following:
/trees/Trees?_filter_column=SiteOrder&_filter_op=gt&_filter_value=2
Now redirects to this;
/trees/Trees?SiteOrder__gt=2
The `datasette publish` and `datasette package` commands both now accept an
optional `--build` argument. If provided, this can be used to specify a branch
published to GitHub that should be built into the container.
This makes it easier to test code that has not yet been officially released to
PyPI, e.g.:
datasette publish now mydb.db --branch=master
If a table has foreign key columns, and those foreign key tables have
label_columns, the TableView will now query those other tables for the
corresponding values and display those values as links in the corresponding
table cells.
label_columns are currently detected by the inspect() function, which looks
for any table that has just two columns - an ID column and one other - and
sets the label_column to be that second non-ID column.
It turns out it is possible for a SQLite table to define a foreign key
relationship to a table that does not actually exist
We should still be able to handle these databases.
I tesed this by first building and running a container using the new
Dockerfile from #114:
docker build .
docker run -it -p 8001:8001 6c9ca7e29181 /bin/sh
Then I ran this inside the container itself:
apt update && apt-get install wget -y \
&& wget http://www.gaia-gis.it/spatialite-2.3.1/test-2.3.sqlite.gz \
&& gunzip test-2.3.sqlite.gz \
&& mv test-2.3.sqlite test23.sqlite \
&& datasette -h 0.0.0.0 test23.sqlite
I visited this URL to confirm I got an error due to spatialite not being
loaded:
http://localhost:8001/test23-c88bc35?sql=select+ST_AsText%28Geometry%29+from+HighWays+limit+1
Then I checked that loading it with `--load-extension` worked correctly:
datasette -h 0.0.0.0 test23.sqlite \
--load-extension=/usr/lib/x86_64-linux-gnu/mod_spatialite.so
Then, finally, I tested it with the new environment variable option:
SQLITE_EXTENSIONS=/usr/lib/x86_64-linux-gnu/mod_spatialite.so \
datasette -h 0.0.0.0 test23.sqlite
Running it with an invalid environment variable option shows an error:
$ SQLITE_EXTENSIONS=/usr/lib/x86_64-linux-gnu/blah.so datasette \
-h 0.0.0.0 test23.sqlite
Usage: datasette -h [OPTIONS] [FILES]...
Error: Invalid value for "--load-extension": Path "/usr/lib/x86_64-linux-gnu/blah.so" does not exist.
Closes#112