Commit graph

242 commits

Author SHA1 Message Date
Simon Willison
172da009d8 Added ?_through= table argument, closes #355
Also added much more interesting many-to-many fixtures - roadside attractions!
2019-05-22 22:45:12 -07:00
Simon Willison
967230c90e Facet by date, closes #481 2019-05-20 23:09:22 -07:00
Simon Willison
2d14f21f85 Updated tests for date(...) lookup 2019-05-20 23:06:19 -07:00
Simon Willison
f4eefdf193 Do not allow downloads of mutable databases - closes #474 2019-05-19 13:41:09 -07:00
Simon Willison
7d8573d672 Rename "datasette publish now" to "datasette publish nowv1"
Also added an alias so "datasette publish now" continues to work.

Closes #472
2019-05-19 11:06:51 -07:00
Simon Willison
db9dbfb816 ?_hash=1 no longer respected for mutable databases
Closes #471, refs #419
2019-05-16 08:10:25 -07:00
Simon Willison
0dad111d24 New introspection endpoint: /-/databases - closes #470
Refs #419 and #465
2019-05-16 07:49:34 -07:00
Simon Willison
21b57cdf9a serve --inspect-file=X now populates cached table counts
Closes #462
2019-05-16 07:30:32 -07:00
Simon Willison
909e66dfdb Removed .inspect() and /-/inspect.json
Refs #462

/-/inspect.json may return in some shape in #465
2019-05-16 07:15:24 -07:00
Simon Willison
faf33515b2 Sometimes sort tables by number of relationships, closes #460 2019-05-15 20:23:33 -07:00
Simon Willison
689cf9c139 Index page only shows row counts for smaller databases
The index page now only shows row counts for immutable databases OR for
databases with less than 30 tables provided it could get a count for
each of those tables in less than 10ms.

Closes #467, Refs #460
2019-05-15 20:02:33 -07:00
Simon Willison
79303163b2 Row count fix + sort index page databases alphabetically
Sorting alphabetically should fix a test failure in Python 3.5

Refs #460
2019-05-15 17:40:10 -07:00
Simon Willison
5d6b2c30f1 Include views on homepage, fix table counts
If we have less than 5 tables we now also show one or more views in the
summary on the homepage.

Also corrected the logic for the row counts - we now count hidden and
visible tables separately.

Closes #373, Refs #460
2019-05-15 17:28:07 -07:00
Simon Willison
e04511410f Don't show hidden tables on index page, closes #455
Refs #460. Also bulked out HTML index page unit tests.
2019-05-14 08:46:57 -07:00
Simon Willison
24bf79d2f0 Run sanity checks, not .inspect(), on startup
Also fixes tests that did NOT like a call to run_until_complete in the Datasette() constructor.
2019-05-11 16:22:55 -07:00
Simon Willison
da0b3ce2b7 New run_sanity_checks mechanism, for SpatiLite
Moved VirtualSpatialIndex check into a new mechanism that should allow
us to add further sanity checks in the future.

To test this I've had to commit a binary sample SpatiaLite database to
the repository. I included a build script for creating that database.

Closes #466
2019-05-11 15:55:30 -07:00
Simon Willison
c692cd2911 Fix test ordering 2019-05-11 15:03:52 -07:00
Simon Willison
a187c81e0c Black + fix broken test 2019-05-11 14:45:59 -07:00
Simon Willison
c0d1b4c322 "datasette inspect foo.db" now just calculates table counts
Refs #462

* inspect command now just outputs table counts
* test_inspect.py is now only tests for that CLI command
* Updated some relevant documentation
* Removed docs for /-/inspect since that is about to change
2019-05-11 14:36:57 -07:00
Simon Willison
ce09e5d2d3 Fixed tests relating to #459 2019-05-11 13:58:22 -07:00
Simon Willison
05cabaebd9 Pass --token to now alias, refs #459 2019-05-11 13:35:34 -07:00
Simon Willison
09ef305c68 Fixed "datasette publish now ... --alias=x"
The --alias argument can now be passed more than once.

Also updated our Travis configuration to use this.

Fixes #459
2019-05-11 13:20:36 -07:00
Simon Willison
a0d444837f Finished implementation of ?_trace=1 debug tool
I redesigned the JSON output and added a handy "traceback" key showing
three relevant lines of the current traceback for each logged query.

Closes #435
2019-05-11 12:06:22 -07:00
Simon Willison
2db977d8f3 tests/fixtures.py can now write out plugins too
This command:

    python tests/fixtures.py \
        fixtures.db \
        metadata.json \
        fixtures-plugins/

Will now create the fixtures.db and metadata.json files, AND create
a folder called fixtures-plugins/ containing two test plugins.

You can then run it like this:

    datasette fixtures.db \
        -m metadata.json --plugins-dir=fixtures-plugins/
2019-05-09 09:44:21 -07:00
Simon Willison
9fdb47ca95 New encode/decode_path_component functions
ASGI cannot differentiate between / and %2F in a URL, so we need an
alternative scheme for encoding the names of tables that contain special
characters such as /

For background, see
    https://github.com/django/asgiref/issues/51#issuecomment-450603464

Some examples:

    "table/and/slashes" => "tableU+002FandU+002Fslashes"
    "~table" => "U+007Etable"
    "+bobcats!" => "U+002Bbobcats!"
    "U+007Etable" => "UU+002B007Etable"
2019-05-09 09:44:21 -07:00
Simon Willison
ec2db345e9 Fixed crash on /:memory: page 2019-05-05 14:01:14 -04:00
Simon Willison
831515b834 Respect --cors for error pages, closes #453 2019-05-05 08:12:03 -04:00
Simon Willison
35d6ee2790
Apply black to everything, enforce via unit tests (#449)
I've run the black code formatting tool against everything:

    black tests datasette setup.py

I also added a new unit test, in tests/test_black.py, which will fail if the code does not
conform to black's exacting standards.

This unit test only runs on Python 3.6 or higher, because black itself doesn't run on 3.5.
2019-05-03 22:15:14 -04:00
Simon Willison
93c65d29ba Fixed 500 error on /-/metadata page 2019-05-03 16:42:59 -04:00
Simon Willison
01b3de5b66 Unit test for binary data display, refs #442 2019-05-03 12:45:06 -04:00
Simon Willison
bade9daeb2 Docs for 'datasette publish cloudrun', refs #434 2019-05-03 12:16:58 -04:00
Romain Primet
75a21fc2a1 datasette publish cloudrun (#434) - thanks, @rprimet
New publish subcommand that publishes using the
new Google Cloud Run platform.

    datasette publish cloudrun database.db
2019-05-03 09:59:01 -04:00
Simon Willison
53d2f00b73 Implemented ArrayFacet, closes #359 2019-05-02 20:21:27 -04:00
Simon Willison
ea66c45df9
Extract facet code out into a new plugin hook, closes #427 (#445)
Datasette previously only supported one type of faceting: exact column value counting.

With this change, faceting logic is extracted out into one or more separate classes which can implement other patterns of faceting - this is discussed in #427, but potential upcoming facet types include facet-by-date, facet-by-JSON-array, facet-by-many-2-many and more.

A new plugin hook, register_facet_classes, can be used by plugins to add in additional facet classes.

Each class must implement two methods: suggest(), which scans columns in the table to decide if they might be worth suggesting for faceting, and facet_results(), which executes the facet operation and returns results ready to be displayed in the UI.
2019-05-02 17:11:26 -07:00
Simon Willison
efc93b8ab5 Entirely removed table_rows_count table property
We were not displaying this anywhere, and it is now expensive to calculate.

Refs #419, #420
2019-05-01 22:29:47 -07:00
Simon Willison
ad9de774f7 Added missing file, refs #438 2019-05-01 22:10:23 -07:00
Simon Willison
f553a67021 Don't load setuptools plugins during test runs
Uses pattern from https://docs.pytest.org/en/latest/example/simple.html#detect-if-running-from-within-a-pytest-run

Closes #438
2019-05-01 22:09:03 -07:00
Simon Willison
50d2d1aac9 Fixed bug where metadata.json hidden tables were ignored 2019-05-01 17:54:48 -07:00
Simon Willison
e7151ccccf Index page no longer uses inspect data - refs #420
Also introduced a mechanism whereby table counts are calculated against a time limit
but immutable databases have their table counts calculated on server startup.
2019-05-01 17:39:39 -07:00
Simon Willison
669fa21a71 Include request duration in traces 2019-05-01 16:27:14 -07:00
Russ Garrett
cf406c0754 New plugin hook: register_output_renderer hook (#441)
Thanks @russss!

* Add register_output_renderer hook

This changeset refactors out the JSON renderer and then adds a hook and
dispatcher system to allow custom output renderers to be registered.

The CSV output renderer is untouched because supporting streaming
renderers through this system would be significantly more complex, and
probably not worthwhile.

We can't simply allow hooks to be called at request time because we need
a list of supported file extensions when the request is being routed in
order to resolve ambiguous database/table names. So, renderers need to
be registered at startup.

I've tried to make this API independent of Sanic's request/response
objects so that this can remain stable during the switch to ASGI. I'm
using dictionaries to keep it simple and to make adding additional
options in the future easy.

Fixes #440
2019-05-01 16:01:56 -07:00
Simon Willison
e4e73a537a Test for ?_trace=1, refs #435 2019-04-21 10:46:56 -07:00
Simon Willison
9c77e6e355 Support multiple filters of the same type
Closes #288
2019-04-15 16:44:17 -07:00
Simon Willison
583b22aa28 New ?column__date=yyyy-mm-dd filter 2019-04-15 15:54:54 -07:00
Simon Willison
1c6649b19b New colname__in=x,y,z filter, closes #433 2019-04-15 15:43:22 -07:00
Simon Willison
2c19a27d15 Documentation for filters, plus new documentation unit test
https://simonwillison.net/2018/Jul/28/documentation-unit-tests/
2019-04-15 15:41:11 -07:00
Simon Willison
6da567dda9 Extract and refactor filters into filters.py
This will help in implementing __in as a filter, refs #433
2019-04-15 14:51:20 -07:00
Simon Willison
bc6a9b4564
?_where= parameter on table views, closes #429
From pull request #430
2019-04-12 18:37:22 -07:00
Simon Willison
e11cb4c664 Persist show/hide state better, closes #425 2019-04-11 22:00:47 -07:00
Simon Willison
db74cf0144 ?_fts_table= and ?_fts_pk= arguments, closes #428 2019-04-11 21:21:17 -07:00