pypi datasette 1.0a46

one hour ago

CSV and TSV imports of any size

  • "Create table from data" can now import CSV and TSV files of any size. A file larger than 1MB is no longer loaded into the dialog's textarea, or into memory: it is read a piece at a time and its rows are inserted in batches, with a progress bar and a button to stop. The preview shows the first 100 rows and detects column types from the first 1,000, with a menu on each column for changing its type. If a row cannot be imported the dialog asks whether to skip it, skip every row like it or stop, and an import that does not finish offers to drop the table it created, given the drop-table permission. JSON files are still read whole, and are limited to 50MB. (#3160)
  • "Insert multiple rows" can import CSV and TSV files of any size in the same way, into a table that exists already. Its preview shows the first 100 rows, and it asks what to do about a row that cannot be inserted instead of stopping.
  • Integers too large for JavaScript, such as 64 bit IDs, are no longer rounded when they are imported from CSV or TSV.
  • Creating a table from pasted or uploaded CSV or TSV no longer loses the leading zeros of values such as the ZIP code 01234, or stores 0x1A as 26: a column with a value like those is now a text column.
  • With "Skip existing rows", the insert multiple rows dialog now says how many rows were inserted and how many existed already. The insert API returns these as "inserted" and "ignored" when "ignore": true is used.
  • The code for importing data is only fetched when one of those dialogs is switched to "Create table from data" or "Insert multiple rows".

Related rows on the row page

  • The row page's "Referenced by" list of row counts has been replaced. Tables with a foreign key that points at the row are now shown in the "Related rows" section, after the many-to-many relationships, each under a heading such as "reviews where movie_id = this" with an "N total" link and pills for up to 20 of those rows, most recent first. A pill shows the row's label column, or for a table without one the label of the row its other foreign key points to. Tables with no rows that point at this one are listed together in one sentence. Many-to-many headings now say "through movie_actors" instead of "via movie_actors". Custom row.html templates can use the new referenced_by template variable, as the row-referenced-by section is gone. (#3138, #3156)
  • A table with two foreign keys and four or more other columns, such as an assets table with an uploader, a release and columns of its own, is no longer detected as a junction table. Its rows are shown on the row page as a table that points at the row instead. The m2m configuration can still name such a table as a relationship. See How relationships are detected. (#3156)
  • Split pills no longer cut a short related row label down to an ellipsis, such as "v0.…" for "v0.1.2", when the values on their right are too wide to fit. (#3156)

Breaking changes

  • Backwards incompatible: the create table API now applies the max_insert_rows limit to its rows, as the insert API does. A request with more than 100 rows, by default, is a 400 error and no table is created. Previously the only limit was the size of the request body.
  • Backwards incompatible: the pks of update-row and delete-row events sent by the row update and row delete APIs now hold the primary key values as SQLite stores them, such as [1] for an integer primary key, instead of the strings from the row's URL, such as ["1"]. This matches the events sent for rows changed by many-to-many edits and clear_references. The ResolvedRowreturned by datasette.resolve_row() has a new row_pk_values property with these values. Thanks, Shian Michael. (#3150, #3159)

Other features

  • The create table API, and the add_foreign_key and set_foreign_keys operations of the alter table API, now create an index named idx_<table>_<column> on each new foreign key column, unless the column is the table's primary key or already starts an index. This also applies to tables and foreign keys created with the create table and alter table dialogs. (#3144, #3152)
  • The insert and upsert APIs accept a new compact form for larger batches of rows: a columns list of column names, with each of the rows as a list of values. This form is limited by max_post_body_bytes rather than max_insert_rows.
  • The create table and alter table dialogs now have a drag handle on each column for reordering them, like the column chooser, in place of their four move buttons. The handles work with touch, and from the keyboard: with a handle focused the up and down arrow keys move its column, and Home and End move it as far as it can go. The column chooser's handles can be used from the keyboard in the same way. (#3157)

Bug fixes

  • A table created with the create table API is now listed on its database page straight away. It could be missing for up to a second.
  • Refreshing the internal catalog is much faster for databases with thousands of tables. Working out which tables are hidden re-read the type of every table for each table, which took around two minutes for each refresh of a database with 10,000 tables. (#3148, #3151)
  • Negative ?_m2m. filters no longer omit rows whose linking column is null. ?_m2m.table__not= and __notin= used column not in (subquery), which is unknown when the column is null, so those rows were dropped even though they have no relationship to the filtered value. Thanks, Tehilla Obanor. (#3153, #3154)

Don't miss a new datasette release

NewReleases is sending notifications on new releases.