Wykres commitów

2571 Commity (b8711988b903cafaeb0d8b07a7f98d75084f1c2b)

Autor SHA1 Wiadomość Data
Simon Willison fd3a33989a Implemented new database view and template
Closes #53 - see comments there for screenshots.
2017-11-11 17:50:21 -08:00
Simon Willison 2366a016f2 Added links to .json and .jsono representations
Closes #62
2017-11-11 14:40:44 -08:00
Simon Willison fa42a56c6a Bulked out table test a bit
I'm closing #50 - more tests will be added in the future, but the framework
is neatly in place for them now.
2017-11-11 14:22:47 -08:00
Simon Willison e9e1def4c0 Revised JSON design a bit
Closes #63
2017-11-11 14:20:00 -08:00
Simon Willison e4bf66d9b0 Added header with breadcrumbs and footer
Also cleaned up titles on various pages.

Closes #61
2017-11-11 12:36:20 -08:00
Simon Willison 40a563ebac Reworked metadata building options
Building metadata is now optional. If you want to do it, do this:

    datasette build *.db --metadata=metadata.json

Then when you run the server you can tell it to read from metadata:

    datasette serve *.db --metadata=metadata.json

The Dockerfile generated by datasette publish now uses this mechanism.

Closes #60
2017-11-11 12:11:51 -08:00
Simon Willison ad8b5d3bd2 JSON version of our homepage
Now available at http://localhost:8006/.json

Tested by tests added in 407795b612
2017-11-11 09:49:47 -08:00
Simon Willison 407795b612 Initial unit tests against our Sanic app
Refs #50

I had to disable the build metadata function to get these tests to work
sensibly. I need to completely rethink how that mechanism works.
2017-11-11 09:47:59 -08:00
Simon Willison 3280972c89 Fixed tests I broke earlier
Broke these tests in 21c9c04310
2017-11-11 08:52:17 -08:00
Simon Willison 3863a30b5d publish command checks 'now' is installed
Closes #58
2017-11-11 08:00:00 -08:00
Simon Willison 65e350ca2a Implemented 'datasette publish one.db two.db' command
Closes #26
2017-11-10 23:25:22 -08:00
Simon Willison 7d81083d40 Implemented responsive tables, removed bootstrap
No need for all of bootstrap since we only need to style a few elements.

Implemented responsive table pattern from here:
https://css-tricks.com/responsive-data-tables/

Refs #16
2017-11-10 21:55:50 -08:00
Simon Willison 21c9c04310 Implemented cursor-based pagination for table view
Closes #5
2017-11-10 12:41:14 -08:00
Simon Willison e9fce44195 Don't serve cache headers in debug or refresh modes 2017-11-10 12:26:37 -08:00
Simon Willison a8a293cd71 Refactored util functions into new utils module 2017-11-10 11:25:54 -08:00
Simon Willison 1c57bd202f Replaced app_factory with new Datasette class
This should make it easier to add unit tests.
2017-11-10 11:05:57 -08:00
Simon Willison 03c58fb350 Show databases in alphabetical order on index page 2017-11-10 11:04:56 -08:00
Simon Willison 40d3b3eae6 Refactored tests into new tests/ folder
Guided by https://docs.pytest.org/en/latest/goodpractices.html
2017-11-10 10:48:16 -08:00
Simon Willison e06b011771 Updated tests
Refs #23
2017-11-10 10:43:54 -08:00
Simon Willison e7e50875d3 Renamed to 'datasette' 2017-11-10 10:38:35 -08:00
Simon Willison 292f140a4f Explicitly order by pk (or by rowid)
Refs #5
2017-11-09 08:11:14 -08:00
Simon Willison bc9871c935 gt/lt/gte/lte now treat numeric arguments as numeric
This now works:

    https://immutabase-dlmggyoepw.now.sh/northwind-40d049b/Products?UnitsInStock__gt=100

Previously the input value of 100 would be treated as a string.

Also fixed a bug where filter arguments had stopped working entirely.

Refs #23
2017-11-09 08:09:55 -08:00
Simon Willison d9fa2bf7ba Use rowid if no primary key available
Allows us to link to individual records even for tables that do not have a primary key.

Refs #5
2017-11-09 06:39:50 -08:00
Simon Willison b2dee11fcd Databases now get distinct colours
A left border based on their content hash.

Closes #31
2017-11-09 06:14:40 -08:00
Simon Willison abb591d832 Added --reload argument to 'immutabase serve' command
Uses hupper to restart the server when the code changes. Useful for development.

Depends on https://pypi.python.org/pypi/hupper
2017-11-09 06:14:26 -08:00
Simon Willison 8af7bc100c Added a MANIFEST.in
Now python setup.py bdist_wheel creates a .whl that includes the CSS.
2017-11-08 18:39:42 -08:00
Simon Willison 7e0cedae3d Now using bootstrap 4 beta
Refs #16
2017-11-05 18:49:07 -08:00
Simon Willison 9e9e961390 Fixed error in RowView 2017-11-05 18:38:06 -08:00
Simon Willison 25c241fa5a Renamed project to immutabase 2017-11-05 18:32:13 -08:00
Simon Willison a0bb9da17f Now requires DB files to be passed as arguments
Refs #40
2017-11-05 18:24:43 -08:00
Simon Willison 186c513a61 Support parameterized SQL and block potentially harmful queries
You can now call arbitrary SQL like this:

    /flights?sql=select%20*%20from%20airports%20where%20country%20like%20:c&c=iceland

Unescaped, those querystring params look like this:

    sql = select * from airports where country like :c
    c = iceland

So SQL can be constructed with named parameters embedded in it, which will
then be read from the querystring and correctly escaped.

This means we can aggressively filter the SQL parameter for potentially
dangerous syntax. For the moment we enforce that it starts with a SELECT
statement and we ban the sequence "pragma" from it entirely.

If you need to use pragma in a query, you can use the new named parameter
mechanism.

Fixes #39
2017-11-04 19:49:18 -07:00
Simon Willison 31b21f5c5e Moved all SQLite queries to threads
SQLite operations are blocking, but we're running everything in Sanic, an
asyncio web framework, so blocking operations are bad - a long-running DB
operation could hold up the entire server.

Instead, I've moved all SQLite operations into threads. These are managed by a
concurrent.futures ThreadPoolExecutor. This means I can run up to X queries in
parallel, and I can continue to queue up additional incoming HTTP traffic
while the threadpool is busy.

Each thread is responsible for managing its own SQLite connections - one per
database. These are cached in a threadlocal.

Since we are working with immutable, read-only SQLite databases it should be
safe to share SQLite objects across threads. On this assumption I'm using the
check_same_thread=False option. Opening a database connection looks like this:

    conn = sqlite3.connect(
        'file:filename.db?immutable=1',
        uri=True,
        check_same_thread=False,
    )

The following articles were helpful in figuring this out:

* https://pymotw.com/3/asyncio/executors.html
* https://marlinux.wordpress.com/2017/05/19/python-3-6-asyncio-sqlalchemy/

Closes #45. Refs #38.
2017-11-04 19:21:44 -07:00
Simon Willison 1fc75809a6 Refactored everything into a factory function
I now call a factory function to construct the Sanic app:

    app = app_factory(files)

This allows me to pass additional arguments to it, e.g. the files to serve.

Also refactored my class-based views to accept jinja as an argument, e.g:

    app.add_route(
        TableView.as_view(jinja),
        '/<db_name:[^/]+>/<table:[^/]+?><as_json:(.jsono?)?$>'
    )
2017-11-04 19:13:44 -07:00
Simon Willison 0ac8bbce2e Default subcommand is now serve
Using click-default-group: https://github.com/click-contrib/click-default-group

Also removed requirements.txt in favour of setup.py
2017-11-04 16:53:50 -07:00
Simon Willison edaa10587e Configured Travis CI 2017-11-04 16:47:46 -07:00
Simon Willison be768f26d0 python setup.py test now runs the tests 2017-11-04 16:40:27 -07:00
Simon Willison 2c625e31ed Fixed bug on Row page with tables containing spaces
We were attempting to run this SQL:

    select * from "Order%20Details" where ...

On this page:

    http://0.0.0.0:8877/northwind-40d049b/Order%20Details/10250,41
2017-10-27 00:16:18 -07:00
Simon Willison 1592fd0419 Started work on cli, which also meant adding setup.py
I'm using click, and click recommends using a setup.py - so I've added one of
those. I also refactored code into a new datasite package. It's not quite
deploying to now properly at the moment though - I seem to have messed up the
path handling a bit.

Also snuck in a new template for the "Row" view.

Refs #40
2017-10-27 00:08:24 -07:00
Simon Willison 2a9799bae6 Implemented database summary on index page
Closes #41
2017-10-26 21:05:17 -07:00
Simon Willison 3cce63b598 URL to allow direct database download
It's just the database URL with .db on the end, e.g. /flights.db

Closes #19
2017-10-25 08:19:32 -07:00
Simon Willison f1b0521810 Preserve .json through redirects 2017-10-25 08:01:22 -07:00
Simon Willison d94d4465d7 Double quote around column names
This means filters still work even with column names that contain spaces
2017-10-25 07:47:20 -07:00
Simon Willison e55bc3b2fa th align left for all tables 2017-10-25 07:46:38 -07:00
Simon Willison 1c5977961f Added glob and like lookups - refs #23 2017-10-24 18:53:01 -07:00
Simon Willison 630b40038e Added support for gt, gte, lt, lte lookups
Refs #23
2017-10-24 18:46:55 -07:00
Simon Willison 6823b09406 Set time limit of 1000ms on SQL queries
Using the (undocumented in the Python docs) fact that if you return 1 from a
set_progress_handler callback, SQLite will cancel the current query.

Closes #35
2017-10-24 18:34:54 -07:00
Simon Willison 2fe94641b0 Don't try to show row counts for views
Also handle tables/views with spaces in their name in the URL.
2017-10-24 18:33:12 -07:00
Simon Willison bd5f3b2ba1 Show time taken at bottom of table page 2017-10-24 18:31:54 -07:00
Simon Willison 3eb79e1a5f Show total row count at top of table page 2017-10-24 18:31:43 -07:00
Simon Willison eef213ab4d Show total number of rows in table 2017-10-24 17:11:36 -07:00