Changelog¶
4.0a0 (2025-05-08)¶
Upsert operations now use SQLite’s
INSERT ... ON CONFLICT SETsyntax on all SQLite versions later than 3.23.1. This is a very slight breaking change for apps that depend on the previousINSERT OR IGNOREfollowed byUPDATEbehavior. (#652)Python library users can opt-in to the previous implementation by passing
use_old_upsert=Trueto theDatabase()constructor, see Alternative upserts using INSERT OR IGNORE.Dropped support for Python 3.8, added support for Python 3.13. (#646)
sqlite-utils tuiis now provided by the sqlite-utils-tui plugin. (#648)Test suite now also runs against SQLite 3.23.1, the last version (from 2018-04-10) before the new
INSERT ... ON CONFLICT SETsyntax was added. (#654)
3.38 (2024-11-23)¶
Plugins can now reuse the implementation of the
sqlite-utils memoryCLI command with the newreturn_db=Trueparameter. (#643)table.transform()now recreates indexes after transforming a table. A newsqlite_utils.db.TransformErrorexception is raised if these indexes cannot be recreated due to conflicting changes to the table such as a column rename. Thanks, Mat Miller. (#633)table.search()now accepts ainclude_rank=Trueparameter, causing the resulting rows to have arankcolumn showing the calculated relevance score. Thanks, liunux4odoo. (#628)Fixed an error that occurred when creating a strict table with at least one floating point column. These
FLOATcolumns are now correctly created asREALas well, but only for strict tables. (#644)
3.37 (2024-07-18)¶
The
create-tableandinsert-filescommands all now accept multiple--pkoptions for compound primary keys. (#620)Now tested against Python 3.13 pre-release. (#619)
Fixed a crash that can occur in environments with a broken
numpyinstallation, producing amodule 'numpy' has no attribute 'int8'. (#632)
3.36 (2023-12-07)¶
- Support for creating tables in SQLite STRICT mode. Thanks, Taj Khattra. (#344)
CLI commands
create-table,insertandupsertall now accept a--strictoption.Python methods that can create a table -
table.create()andinsert/upsert/insert_all/upsert_allall now accept an optionalstrict=Trueparameter.The
transformcommand andtable.transform()method preserve strict mode when transforming a table.
The
sqlite-utils create-tablecommand now acceptsstr,intandbytesas aliases fortext,integerandblobrespectively. (#606)
3.35.2 (2023-11-03)¶
The
--load-extension=spatialiteoption and find_spatialite() utility function now both work correctly onarm64Linux. Thanks, Mike Coats. (#599)Fix for bug where
sqlite-utils insertcould cause your terminal cursor to disappear. Thanks, Luke Plant. (#433)datetime.timedeltavalues are now stored asTEXTcolumns. Thanks, Harald Nezbeda. (#522)Test suite is now also run against Python 3.12.
3.35.1 (2023-09-08)¶
Fixed a bug where table.transform() would sometimes re-assign the
rowidvalues for a table rather than keeping them consistent across the operation. (#592)
3.35 (2023-08-17)¶
Adding foreign keys to a table no longer uses PRAGMA writable_schema = 1 to directly manipulate the sqlite_master table. This was resulting in errors in some Python installations where the SQLite library was compiled in a way that prevented this from working, in particular on macOS. Foreign keys are now added using the table transformation mechanism instead. (#577)
This new mechanism creates a full copy of the table, so it is likely to be significantly slower for large tables, but will no longer trigger table sqlite_master may not be modified errors on platforms that do not support PRAGMA writable_schema = 1.
A new plugin, sqlite-utils-fast-fks, is now available for developers who still want to use that faster but riskier implementation.
Other changes:
The table.transform() method has two new parameters:
foreign_keys=allows you to replace the foreign key constraints defined on a table, andadd_foreign_keys=lets you specify new foreign keys to add. These complement the existingdrop_foreign_keys=parameter. (#577)The sqlite-utils transform command has a new
--add-foreign-keyoption which can be called multiple times to add foreign keys to a table that is being transformed. (#585)sqlite-utils convert now has a
--pdboption for opening a debugger on the first encountered error in your conversion script. (#581)Fixed a bug where
sqlite-utils install -e '.[test]'option did not work correctly.
3.34 (2023-07-22)¶
This release introduces a new plugin system. Read more about this in sqlite-utils now supports plugins. (#567)
Documentation describing how to build a plugin.
Plugin hook: register_commands(cli), for plugins to add extra commands to
sqlite-utils. (#569)Plugin hook: prepare_connection(conn). Plugins can use this to help prepare the SQLite connection to do things like registering custom SQL functions. Thanks, Alex Garcia. (#574)
sqlite_utils.Database(..., execute_plugins=False)option for disabling plugin execution. (#575)sqlite-utils install -e path-to-directoryoption for installing editable code. This option is useful during the development of a plugin. (#570)table.create(...)method now acceptsreplace=Trueto drop and replace an existing table with the same name, orignore=Trueto silently do nothing if a table already exists with the same name. (#568)sqlite-utils insert ... --stop-after 10option for stopping the insert after a specified number of records. Works for theupsertcommand as well. (#561)The
--csvand--tsvmodes forinsertnow accept a--empty-nulloption, which causes empty strings in the CSV file to be stored asnullin the database. (#563)New
db.rename_table(table_name, new_name)method for renaming tables. (#565)sqlite-utils rename-table my.db table_name new_namecommand for renaming tables. (#565)The
table.transform(...)method now takes an optionalkeep_table=new_table_nameparameter, which will cause the original table to be renamed tonew_table_namerather than being dropped at the end of the transformation. (#571)Documentation now notes that calling
table.transform()without any arguments will reformat the SQL schema stored by SQLite to be more aesthetically pleasing. (#564)
3.33 (2023-06-25)¶
sqlite-utilswill now use sqlean.py in place ofsqlite3if it is installed in the same virtual environment. This is useful for Python environments with either an outdated version of SQLite or with restrictions on SQLite such as disabled extension loading or restrictions resulting in thesqlite3.OperationalError: table sqlite_master may not be modifiederror. (#559)New
with db.ensure_autocommit_off()context manager, which ensures that the database is in autocommit mode for the duration of a block of code. This is used bydb.enable_wal()anddb.disable_wal()to ensure they work correctly withpysqlite3andsqlean.py.New
db.iterdump()method, providing an iterator over SQL strings representing a dump of the database. This usessqlite-dumpif it is available, otherwise falling back on theconn.iterdump()method fromsqlite3. Bothpysqlite3andsqlean.pyomit support foriterdump()- this method helps paper over that difference.
3.32.1 (2023-05-21)¶
Examples in the CLI documentation can now all be copied and pasted without needing to remove a leading
$. (#551)Documentation now covers Setting up shell completion for
bashandzsh. (#552)
3.32 (2023-05-21)¶
New experimental
sqlite-utils tuiinterface for interactively building command-line invocations, powered by Trogon. This requires an optional dependency, installed usingsqlite-utils install trogon. (#545)sqlite-utils analyze-tablescommand (documentation) now has a--common-limit 20option for changing the number of common/least-common values shown for each column. (#544)sqlite-utils analyze-tables --no-mostand--no-leastoptions for disabling calculation of most-common and least-common values.If a column contains only
nullvalues,analyze-tableswill no longer attempt to calculate the most common and least common values for that column. (#547)Calling
sqlite-utils analyze-tableswith non-existent columns in the-c/--columnoption now results in an error message. (#548)The
table.analyze_column()method (documented here) now acceptsmost_common=Falseandleast_common=Falseoptions for disabling calculation of those values.
3.31 (2023-05-08)¶
Dropped support for Python 3.6. Tests now ensure compatibility with Python 3.11. (#517)
Automatically locates the SpatiaLite extension on Apple Silicon. Thanks, Chris Amico. (#536)
New
--raw-linesoption for thesqlite-utils queryandsqlite-utils memorycommands, which outputs just the raw value of the first column of every row. (#539)Fixed a bug where
table.upsert_all()failed if thenot_null=option was passed. (#538)Fixed a
ResourceWarningwhen usingsqlite-utils insert. (#534)Now shows a more detailed error message when
sqlite-utils insertis called with invalid JSON. (#532)table.convert(..., skip_false=False)andsqlite-utils convert --no-skip-falseoptions, for avoiding a misfeature where the convert() mechanism skips rows in the database with a falsey value for the specified column. Fixing this by default would be a backwards-incompatible change and is under consideration for a 4.0 release in the future. (#527)Tables can now be created with self-referential foreign keys. Thanks, Scott Perry. (#537)
sqlite-utils transformno longer breaks if a table defines default values for columns. Thanks, Kenny Song. (#509)Fixed a bug where repeated calls to
table.transform()did not work correctly. Thanks, Martin Carpenter. (#525)Improved error message if
rows_from_file()is passed a non-binary-mode file-like object. (#520)
3.30 (2022-10-25)¶
Now tested against Python 3.11. (#502)
New
table.search_sql(include_rank=True)option, which adds arankcolumn to the generated SQL. Thanks, Jacob Chapman. (#480)Progress bars now display for newline-delimited JSON files using the
--nloption. Thanks, Mischa Untaga. (#485)New
db.close()method. (#504)Conversion functions passed to table.convert(…) can now return lists or dictionaries, which will be inserted into the database as JSON strings. (#495)
sqlite-utils installandsqlite-utils uninstallcommands for installing packages into the same virtual environment assqlite-utils, described here. (#483)New sqlite_utils.utils.flatten() utility function. (#500)
Documentation on using Just to run tests, linters and build documentation.
Documentation now covers the Release process for this package.
3.29 (2022-08-27)¶
The
sqlite-utils query,memoryandbulkcommands now all accept a new--functionsoption. This can be passed a string of Python code, and any callable objects defined in that code will be made available to SQL queries as custom SQL functions. See Defining custom SQL functions for details. (#471)db[table].create(...)method now accepts a newtransform=Trueparameter. If the table already exists it will be transformed to match the schema configuration options passed to the function. This may result in columns being added or dropped, column types being changed, column order being updated or not null and default values for columns being set. (#467)Related to the above, the
sqlite-utils create-tablecommand now accepts a--transformoption.New introspection property:
table.default_valuesreturns a dictionary mapping each column name with a default value to the configured default value. (#475)The
--load-extensionoption can now be provided a path to a compiled SQLite extension module accompanied by the name of an entrypoint, separated by a colon - for example--load-extension ./lines0:sqlite3_lines0_noread_init. This feature is modelled on code first contributed to Datasette by Alex Garcia. (#470)Functions registered using the db.register_function() method can now have a custom name specified using the new
db.register_function(fn, name=...)parameter. (#458)sqlite-utils rows has a new
--orderoption for specifying the sort order for the returned rows. (#469)All of the CLI options that accept Python code blocks can now all be used to define functions that can access modules imported in that same block of code without needing to use the
globalkeyword. (#472)Fixed bug where
table.extract()would not behave correctly for columns containing null values. Thanks, Forest Gregg. (#423)New tutorial: Cleaning data with sqlite-utils and Datasette shows how to use
sqlite-utilsto import and clean an example CSV file.Datasette and
sqlite-utilsnow have a Discord community. Join the Discord here.
3.28 (2022-07-15)¶
New table.duplicate(new_name) method for creating a copy of a table with a matching schema and row contents. Thanks, David. (#449)
New
sqlite-utils duplicate data.db table_name new_nameCLI command for Duplicating tables. (#454)sqlite_utils.utils.rows_from_file()is now a documented API. It can be used to read a sequence of dictionaries from a file-like object containing CSV, TSV, JSON or newline-delimited JSON. It can be passed an explicit format or can attempt to detect the format automatically. (#443)sqlite_utils.utils.TypeTrackeris now a documented API for detecting the likely column types for a sequence of string rows, see Detecting column types using TypeTracker. (#445)sqlite_utils.utils.chunks()is now a documented API for splitting an iterator into chunks. (#451)sqlite-utils enable-ftsnow has a--replaceoption for replacing the existing FTS configuration for a table. (#450)The
create-index,add-columnandduplicatecommands all now take a--ignoreoption for ignoring errors should the database not be in the right state for them to operate. (#450)
3.27 (2022-06-14)¶
See also the annotated release notes for this release.
Code examples in documentation now have a “copy to clipboard” button. (#436)
sqlite_utils.utils.utils.rows_from_file()is now a documented API, see Reading rows from a file. (#443)rows_from_file()has two new parameters to help handle CSV files with rows that contain more values than are listed in that CSV file’s headings:ignore_extras=Trueandextras_key="name-of-key". (#440)sqlite_utils.utils.maximize_csv_field_size_limit()helper function for increasing the field size limit for reading CSV files to its maximum, see Setting the maximum CSV field size limit. (#442)table.search(where=, where_args=)parameters for adding additionalWHEREclauses to a search query. Thewhere=parameter is available ontable.search_sql(...)as well. See Searching with table.search(). (#441)Fixed bug where
table.detect_fts()and other search-related functions could fail if two FTS-enabled tables had names that were prefixes of each other. (#434)
3.26.1 (2022-05-02)¶
Now depends on click-default-group-wheel, a pure Python wheel package. This means you can install and use this package with Pyodide, which can run Python entirely in your browser using WebAssembly. (#429)
Try that out using the Pyodide REPL:
>>> import micropip >>> await micropip.install("sqlite-utils") >>> import sqlite_utils >>> db = sqlite_utils.Database(memory=True) >>> list(db.query("select 3 * 5")) [{'3 * 5': 15}]
3.26 (2022-04-13)¶
New
errors=r.IGNORE/r.SET_NULLparameter for ther.parsedatetime()andr.parsedate()convert recipes. (#416)Fixed a bug where
--multicould not be used in combination with--dry-runfor the convert command. (#415)New documentation: Defining a convert() function. (#420)
More robust detection for whether or not
deterministic=Trueis supported. (#425)
3.25.1 (2022-03-11)¶
Improved display of type information and parameters in the API reference documentation. (#413)
3.25 (2022-03-01)¶
New
hash_id_columns=parameter for creating a primary key that’s a hash of the content of specific columns - see Setting an ID based on the hash of the row contents for details. (#343)New db.sqlite_version property, returning a tuple of integers representing the version of SQLite, for example
(3, 38, 0).Fixed a bug where register_function(deterministic=True) caused errors on versions of SQLite prior to 3.8.3. (#408)
New documented hash_record(record, keys=…) function.
3.24 (2022-02-15)¶
SpatiaLite helpers for the
sqlite-utilscommand-line tool - thanks, Chris Amico. (#398)sqlite-utils create-database
--init-spatialiteoption for initializing SpatiaLite on a newly created database.sqlite-utils add-geometry-column command for adding geometry columns.
sqlite-utils create-spatial-index command for adding spatial indexes.
db[table].create(..., if_not_exists=True)option for creating a table only if it does not already exist. (#397)Database(memory_name="my_shared_database")parameter for creating a named in-memory database that can be shared between multiple connections. (#405)Documentation now describes how to add a primary key to a rowid table using
sqlite-utils transform. (#403)
3.23 (2022-02-03)¶
This release introduces four new utility methods for working with SpatiaLite. Thanks, Chris Amico. (#385)
sqlite_utils.utils.find_spatialite()finds the location of the SpatiaLite module on disk.db.init_spatialite()initializes SpatiaLite for the given database.table.add_geometry_column(...)adds a geometry column to an existing table.table.create_spatial_index(...)creates a spatial index for a column.sqlite-utils batchnow accepts a--batch-sizeoption. (#392)
3.22.1 (2022-01-25)¶
All commands now include example usage in their
--help- see CLI reference. (#384)Python library documentation has a new Getting started section. (#387)
Documentation now uses Plausible analytics. (#389)
3.22 (2022-01-11)¶
New CLI reference documentation page, listing the output of
--helpfor every one of the CLI commands. (#383)sqlite-utils rowsnow has--limitand--offsetoptions for paginating through data. (#381)sqlite-utils rowsnow has--whereand-poptions for filtering the table using aWHEREquery, see Returning all rows in a table. (#382)
3.21 (2022-01-10)¶
CLI and Python library improvements to help run ANALYZE after creating indexes or inserting rows, to gain better performance from the SQLite query planner when it runs against indexes.
Three new CLI commands: create-database, analyze and bulk.
More details and examples can be found in the annotated release notes.
New
sqlite-utils create-databasecommand for creating new empty database files. (#348)New Python methods for running
ANALYZEagainst a database, table or index:db.analyze()andtable.analyze(), see Optimizing index usage with ANALYZE. (#366)New sqlite-utils analyze command for running
ANALYZEusing the CLI. (#379)The
create-index,insertandupsertcommands now have a new--analyzeoption for runningANALYZEafter the command has completed. (#379)New sqlite-utils bulk command which can import records in the same way as
sqlite-utils insert(from JSON, CSV or TSV) and use them to bulk execute a parametrized SQL query. (#375)The CLI tool can now also be run using
python -m sqlite_utils. (#368)Using
--fmtnow implies--table, so you don’t need to pass both options. (#374)The
--convertfunction applied to rows can now modify the row in place. (#371)The insert-files command supports two new columns:
stemandsuffix. (#372)The
--nlimport option now ignores blank lines in the input. (#376)Fixed bug where streaming input to the
insertcommand with--batch-size 1would appear to only commit after several rows had been ingested, due to unnecessary input buffering. (#364)
3.20 (2022-01-05)¶
sqlite-utils insert ... --linesto insert the lines from a file into a table with a singlelinecolumn, see Inserting unstructured data with --lines and --text.sqlite-utils insert ... --textto insert the contents of the file into a table with a singletextcolumn and a single row.sqlite-utils insert ... --convertallows a Python function to be provided that will be used to convert each row that is being inserted into the database. See Applying conversions while inserting data, including details on special behavior when combined with--linesand--text. (#356)sqlite-utils convertnow accepts a code value of-to read code from standard input. (#353)sqlite-utils convertalso now accepts code that defines a namedconvert(value)function, see Converting data in columns.db.supports_strictproperty showing if the database connection supports SQLite strict tables.table.strictproperty (see .strict) indicating if the table uses strict mode. (#344)Fixed bug where
sqlite-utils upsert ... --detect-typesignored the--detect-typesoption. (#362)
3.19 (2021-11-20)¶
The table.lookup() method now accepts keyword arguments that match those on the underlying
table.insert()method:foreign_keys=,column_order=,not_null=,defaults=,extracts=,conversions=andcolumns=. You can also now passpk=to specify a different column name to use for the primary key. (#342)
3.18 (2021-11-14)¶
The
table.lookup()method now has an optional second argument which can be used to populate columns only the first time the record is created, see Working with lookup tables. (#339)sqlite-utils memorynow has a--flattenoption for flattening nested JSON objects into separate columns, consistent withsqlite-utils insert. (#332)table.create_index(..., find_unique_name=True)parameter, which finds an available name for the created index even if the default name has already been taken. This means thatindex-foreign-keyswill work even if one of the indexes it tries to create clashes with an existing index name. (#335)Added
py.typedto the module, so mypy should now correctly pick up the type annotations. Thanks, Andreas Longo. (#331)Now depends on
python-dateutilinstead of depending ondateutils. Thanks, Denys Pavlov. (#324)table.create()(see Explicitly creating a table) now handlesdict,listandtupletypes, mapping them toTEXTcolumns in SQLite so that they can be stored encoded as JSON. (#338)Inserted data with square braces in the column names (for example a CSV file containing a
item[price]) column now have the braces converted to underscores:item_price_. Previously such columns would be rejected with an error. (#329)Now also tested against Python 3.10. (#330)
3.17.1 (2021-09-22)¶
sqlite-utils memory now works if files passed to it share the same file name. (#325)
sqlite-utils query now returns
[]in JSON mode if no rows are returned. (#328)
3.17 (2021-08-24)¶
The sqlite-utils memory command has a new
--analyzeoption, which runs the equivalent of the analyze-tables command directly against the in-memory database created from the incoming CSV or JSON data. (#320)sqlite-utils insert-files now has the ability to insert file contents in to
TEXTcolumns in addition to the defaultBLOB. Pass the--textoption or usecontent_textas a column specifier. (#319)
3.16 (2021-08-18)¶
Type signatures added to more methods, including
table.resolve_foreign_keys(),db.create_table_sql(),db.create_table()andtable.create(). (#314)New
db.quote_fts(value)method, see Quoting characters for use in search - thanks, Mark Neumann. (#246)table.search()now accepts an optionalquote=Trueparameter. (#296)CLI command
sqlite-utils searchnow accepts a--quoteoption. (#296)Fixed bug where
--no-headersand--tsvoptions to sqlite-utils insert could not be used together. (#295)Various small improvements to API reference documentation.
3.15.1 (2021-08-10)¶
Python library now includes type annotations on almost all of the methods, plus detailed docstrings describing each one. (#311)
New API reference documentation page, powered by those docstrings.
Fixed bug where
.add_foreign_keys()failed to raise an error if called against aView. (#313)Fixed bug where
.delete_where()returned a[]instead of returningselfif called against a non-existent table. (#315)
3.15 (2021-08-09)¶
sqlite-utils insert --flattenoption for flattening nested JSON objects to create tables with column names liketopkey_nestedkey. (#310)Fixed several spelling mistakes in the documentation, spotted using codespell.
Errors that occur while using the
sqlite-utilsCLI tool now show the responsible SQL and query parameters, if possible. (#309)
3.14 (2021-08-02)¶
This release introduces the new sqlite-utils convert command (#251) and corresponding table.convert(…) Python method (#302). These tools can be used to apply a Python conversion function to one or more columns of a table, either updating the column in place or using transformed data from that column to populate one or more other columns.
This command-line example uses the Python standard library textwrap module to wrap the content of the content column in the articles table to 100 characters:
$ sqlite-utils convert content.db articles content \
'"\n".join(textwrap.wrap(value, 100))' \
--import=textwrap
The same operation in Python code looks like this:
import sqlite_utils, textwrap
db = sqlite_utils.Database("content.db")
db["articles"].convert("content", lambda v: "\n".join(textwrap.wrap(v, 100)))
See the full documentation for the sqlite-utils convert command and the table.convert(…) Python method for more details.
Also in this release:
The new
table.count_where(...)method, for counting rows in a table that match a specific SQLWHEREclause. (#305)New
--silentoption for the sqlite-utils insert-files command to hide the terminal progress bar, consistent with the--silentoption forsqlite-utils convert. (#301)
3.13 (2021-07-24)¶
sqlite-utils schema my.db table1 table2command now accepts optional table names. (#299)sqlite-utils memory --helpnow describes the--schemaoption.
3.12 (2021-06-25)¶
New db.query(sql, params) method, which executes a SQL query and returns the results as an iterator over Python dictionaries. (#290)
This project now uses
flake8and has started to usemypy. (#291)New documentation on contributing to this project. (#292)
3.11 (2021-06-20)¶
New
sqlite-utils memory data.csv --schemaoption, for outputting the schema of the in-memory database generated from one or more files. See --schema, --analyze, --dump and --save. (#288)Added installation instructions. (#286)
3.10 (2021-06-19)¶
This release introduces the sqlite-utils memory command, which can be used to load CSV or JSON data into a temporary in-memory database and run SQL queries (including joins across multiple files) directly against that data.
Also new: sqlite-utils insert --detect-types, sqlite-utils dump, table.use_rowid plus some smaller fixes.
sqlite-utils memory¶
This example of sqlite-utils memory retrieves information about the all of the repositories in the Dogsheep organization on GitHub using this JSON API, sorts them by their number of stars and outputs a table of the top five (using -t):
$ curl -s 'https://api.github.com/users/dogsheep/repos' \
| sqlite-utils memory - '
select full_name, forks_count, stargazers_count
from stdin order by stargazers_count desc limit 5
' -t
full_name forks_count stargazers_count
--------------------------------- ------------- ------------------
dogsheep/twitter-to-sqlite 12 225
dogsheep/github-to-sqlite 14 139
dogsheep/dogsheep-photos 5 116
dogsheep/dogsheep.github.io 7 90
dogsheep/healthkit-to-sqlite 4 85
The tool works against files on disk as well. This example joins data from two CSV files:
$ cat creatures.csv
species_id,name
1,Cleo
2,Bants
2,Dori
2,Azi
$ cat species.csv
id,species_name
1,Dog
2,Chicken
$ sqlite-utils memory species.csv creatures.csv '
select * from creatures join species on creatures.species_id = species.id
'
[{"species_id": 1, "name": "Cleo", "id": 1, "species_name": "Dog"},
{"species_id": 2, "name": "Bants", "id": 2, "species_name": "Chicken"},
{"species_id": 2, "name": "Dori", "id": 2, "species_name": "Chicken"},
{"species_id": 2, "name": "Azi", "id": 2, "species_name": "Chicken"}]
Here the species.csv file becomes the species table, the creatures.csv file becomes the creatures table and the output is JSON, the default output format.
You can also use the --attach option to attach existing SQLite database files to the in-memory database, in order to join data from CSV or JSON directly against your existing tables.
Full documentation of this new feature is available in Querying data directly using an in-memory database. (#272)
sqlite-utils insert --detect-types¶
The sqlite-utils insert command can be used to insert data from JSON, CSV or TSV files into a SQLite database file. The new --detect-types option (shortcut -d), when used in conjunction with a CSV or TSV import, will automatically detect if columns in the file are integers or floating point numbers as opposed to treating everything as a text column and create the new table with the corresponding schema. See Inserting CSV or TSV data for details. (#282)
Other changes¶
Bug fix:
table.transform(), when run against a table without explicit primary keys, would incorrectly create a new version of the table with an explicit primary key column calledrowid. (#284)New
table.use_rowidintrospection property, see .use_rowid. (#285)The new
sqlite-utils dump file.dbcommand outputs a SQL dump that can be used to recreate a database. (#274)-hnow works as a shortcut for--help, thanks Loren McIntyre. (#276)Now using pytest-cov and Codecov to track test coverage - currently at 96%. (#275)
SQL errors that occur when using
sqlite-utils queryare now displayed as CLI errors.
3.9.1 (2021-06-12)¶
Fixed bug when using
table.upsert_all()to create a table with only a single column that is treated as the primary key. (#271)
3.9 (2021-06-11)¶
New
sqlite-utils schemacommand showing the full SQL schema for a database, see Showing the schema (CLI). (#268)db.schemaintrospection property exposing the same feature to the Python library, see Showing the schema (Python library).
3.8 (2021-06-02)¶
New
sqlite-utils indexescommand to list indexes in a database, see Listing indexes. (#263)table.xindexesintrospection property returning more details about that table’s indexes, see .xindexes. (#261)
3.7 (2021-05-28)¶
New
table.pks_and_rows_where()method returning(primary_key, row_dictionary)tuples - see Listing rows with their primary keys. (#240)Fixed bug with
table.add_foreign_key()against columns containing spaces. (#238)table_or_view.drop(ignore=True)option for avoiding errors if the table or view does not exist. (#237)sqlite-utils drop-view --ignoreandsqlite-utils drop-table --ignoreoptions. (#237)Fixed a bug with inserts of nested JSON containing non-ascii strings - thanks, Dylan Wu. (#257)
Suggest
--alterif an error occurs caused by a missing column. (#259)Support creating indexes with columns in descending order, see API documentation and CLI documentation. (#260)
Correctly handle CSV files that start with a UTF-8 BOM. (#250)
3.6 (2021-02-18)¶
This release adds the ability to execute queries joining data from more than one database file - similar to the cross database querying feature introduced in Datasette 0.55.
The
db.attach(alias, filepath)Python method can be used to attach extra databases to the same connection, see db.attach() in the Python API documentation. (#113)The
--attachoption attaches extra aliased databases to run SQL queries against directly on the command-line, see attaching additional databases in the CLI documentation. (#236)
3.5 (2021-02-14)¶
sqlite-utils insert --sniffoption for detecting the delimiter and quote character used by a CSV file, see Alternative delimiters and quote characters. (#230)The
table.rows_where(),table.search()andtable.search_sql()methods all now take optionaloffset=andlimit=arguments. (#231)New
--no-headersoption forsqlite-utils insert --csvto handle CSV files that are missing the header row, see CSV files without a header row. (#228)Fixed bug where inserting data with extra columns in subsequent chunks would throw an error. Thanks @nieuwenhoven for the fix. (#234)
Fixed bug importing CSV files with columns containing more than 128KB of data. (#229)
Test suite now runs in CI against Ubuntu, macOS and Windows. Thanks @nieuwenhoven for the Windows test fixes. (#232)
3.4.1 (2021-02-05)¶
Fixed a code import bug that slipped in to 3.4. (#226)
3.4 (2021-02-05)¶
sqlite-utils insert --csvnow accepts optional--delimiterand--quotecharoptions. See Alternative delimiters and quote characters. (#223)
3.3 (2021-01-17)¶
The
table.m2m()method now accepts an optionalalter=Trueargument to specify that any missing columns should be added to the referenced table. See Working with many-to-many relationships. (#222)
3.2.1 (2021-01-12)¶
Fixed a bug where
.add_missing_columns()failed to take case insensitive column names into account. (#221)
3.2 (2021-01-03)¶
This release introduces a new mechanism for speeding up count(*) queries using cached table counts, stored in a _counts table and updated by triggers. This mechanism is described in Cached table counts using triggers, and can be enabled using Python API methods or the new enable-counts CLI command. (#212)
table.enable_counts()method for enabling these triggers on a specific table.db.enable_counts()method for enabling triggers on every table in the database. (#213)New
sqlite-utils enable-counts my.dbcommand for enabling counts on all or specific tables, see Enabling cached counts. (#214)New
sqlite-utils triggerscommand for listing the triggers defined for a database or specific tables, see Listing triggers. (#218)New
db.use_counts_tableproperty which, ifTrue, causestable.countto read from the_countstable. (#215)table.has_counts_triggersproperty revealing if a table has been configured with the new_countsdatabase triggers.db.reset_counts()method andsqlite-utils reset-countscommand for resetting the values in the_countstable. (#219)The previously undocumented
db.escape()method has been renamed todb.quote()and is now covered by the documentation: Quoting strings for use in SQL. (#217)New
table.triggers_dictanddb.triggers_dictintrospection properties. (#211, #216)sqlite-utils insertnow shows a more useful error message for invalid JSON. (#206)
3.1.1 (2021-01-01)¶
Fixed failing test caused by
optimizesometimes creating larger database files. (#209)Documentation now lives on https://sqlite-utils.datasette.io/
README now includes
brew install sqlite-utilsinstallation method.
3.1 (2020-12-12)¶
New command:
sqlite-utils analyze-tables my.dboutputs useful information about the table columns in the database, such as the number of distinct values and how many rows are null. See Analyzing tables for documentation. (#207)New
table.analyze_column(column)Python method used by theanalyze-tablescommand - see Analyzing a column.The
table.update()method now correctly handles values that should be stored as JSON. Thanks, Andreas Madsack. (#204)
3.0 (2020-11-08)¶
This release introduces a new sqlite-utils search command for searching tables, see Executing searches. (#192)
The table.search() method has been redesigned, see Searching with table.search(). (#197)
The release includes minor backwards-incompatible changes, hence the version bump to 3.0. Those changes, which should not affect most users, are:
The
-cshortcut option for outputting CSV is no longer available. The full--csvoption is required instead.The
-fshortcut for--fmthas also been removed - use--fmt.The
table.search()method now defaults to sorting by relevance, not sorting byrowid. (#198)The
table.search()method now returns a generator over a list of Python dictionaries. It previously returned a list of tuples.
Also in this release:
The
query,tables,rowsandsearchCLI commands now accept a new--tsvoption which outputs the results in TSV. (#193)A new
table.virtual_table_usingproperty reveals if a table is a virtual table, and returns the upper case type of virtual table (e.g.FTS4orFTS5) if it is. It returnsNoneif the table is not a virtual table. (#196)The new
table.search_sql()method returns the SQL for searching a table, see Building SQL queries with table.search_sql().sqlite-utils rowsnow accepts multiple optional-cparameters specifying the columns to return. (#200)
Changes since the 3.0a0 alpha release:
The
sqlite-utils searchcommand now defaults to returning every result, unless you add a--limit 20option.The
sqlite-utils search -candtable.search(columns=[])options are now fully respected. (#201)
2.23 (2020-10-28)¶
table.m2m(other_table, records)method now takes any iterable, not just a list or tuple. Thanks, Adam Wolf. (#189)sqlite-utils insertnow displays a progress bar for CSV or TSV imports. (#173)New
@db.register_function(deterministic=True)option for registering deterministic SQLite functions in Python 3.8 or higher. (#191)
2.22 (2020-10-16)¶
New
--encodingoption for processing CSV and TSV files that use a non-utf-8 encoding, for both theinsertandupdatecommands. (#182)The
--load-extensionoption is now available to many more commands. (#137)--load-extension=spatialitecan be used to load SpatiaLite from common installation locations, if it is available. (#136)Tests now also run against Python 3.9. (#184)
Passing
pk=["id"]now has the same effect as passingpk="id". (#181)
2.21 (2020-09-24)¶
table.extract()andsqlite-utils extractnow apply much, much faster - one example operation reduced from twelve minutes to just four seconds! (#172)sqlite-utils extractno longer shows a progress bar, because it’s fast enough not to need one.New
column_order=option fortable.transform()which can be used to alter the order of columns in a table. (#175)sqlite-utils transform --column-order=option (with a-oshortcut) for changing column order. (#176)The
table.transform(drop_foreign_keys=)parameter and thesqlite-utils transform --drop-foreign-keyoption have changed. They now accept just the name of the column rather than requiring all three of the column, other table and other column. This is technically a backwards-incompatible change but I chose not to bump the major version number because the transform feature is so new. (#177)The table
.disable_fts(),.rebuild_fts(),.delete(),.delete_where()and.add_missing_columns()methods all nowreturn self, which means they can be chained together with other table operations.
2.20 (2020-09-22)¶
This release introduces two key new capabilities: transform (#114) and extract (#42).
Transform¶
SQLite’s ALTER TABLE has several documented limitations. The table.transform() Python method and sqlite-utils transform CLI command work around these limitations using a pattern where a new table with the desired structure is created, data is copied over to it and the old table is then dropped and replaced by the new one.
You can use these tools to change column types, rename columns, drop columns, add and remove NOT NULL and defaults, remove foreign key constraints and more. See the transforming tables (CLI) and transforming tables (Python library) documentation for full details of how to use them.
Extract¶
Sometimes a database table - especially one imported from a CSV file - will contain duplicate data. A Trees table may include a Species column with only a few dozen unique values, when the table itself contains thousands of rows.
The table.extract() method and sqlite-utils extract commands can extract a column - or multiple columns - out into a separate lookup table, and set up a foreign key relationship from the original table.
The Python library extract() documentation describes how extraction works in detail, and Extracting columns into a separate table in the CLI documentation includes a detailed example.
Other changes¶
The
@db.register_functiondecorator can be used to quickly register Python functions as custom SQL functions, see Registering custom SQL functions. (#162)The
table.rows_where()method now accepts an optionalselect=argument for specifying which columns should be selected, see Listing rows.
2.19 (2020-09-20)¶
New
sqlite-utils add-foreign-keyscommand for Adding multiple foreign keys at once. (#157)New
table.enable_fts(..., replace=True)argument for replacing an existing FTS table with a new configuration. (#160)New
table.add_foreign_key(..., ignore=True)argument for ignoring a foreign key if it already exists. (#112)
2.18 (2020-09-08)¶
table.rebuild_fts()method for rebuilding a FTS index, see Rebuilding a full-text search table. (#155)sqlite-utils rebuild-fts data.dbcommand for rebuilding FTS indexes across all tables, or just specific tables. (#155)table.optimize()method no longer deletes junk rows from the*_fts_docsizetable. This was added in 2.17 but it turns out runningtable.rebuild_fts()is a better solution to this problem.Fixed a bug where rows with additional columns that are inserted after the first batch of records could cause an error due to breaking SQLite’s maximum number of parameters. Thanks, Simon Wiles. (#145)
2.17 (2020-09-07)¶
This release handles a bug where replacing rows in FTS tables could result in growing numbers of unnecessary rows in the associated *_fts_docsize table. (#149)
PRAGMA recursive_triggers=onby default for all connections. You can turn it off withDatabase(recursive_triggers=False). (#152)table.optimize()method now deletes unnecessary rows from the*_fts_docsizetable. (#153)New tracer method for tracking underlying SQL queries, see Tracing queries. (#150)
Neater indentation for schema SQL. (#148)
Documentation for
sqlite_utils.AlterErrorexception thrown by inadd_foreign_keys().
2.16.1 (2020-08-28)¶
2.16 (2020-08-21)¶
2.15.1 (2020-08-12)¶
Now available as a
sdistpackage on PyPI in addition to a wheel. (#133)
2.15 (2020-08-10)¶
New
db.enable_wal()anddb.disable_wal()methods for enabling and disabling Write-Ahead Logging for a database file - see WAL mode in the Python API documentation.Also
sqlite-utils enable-wal file.dbandsqlite-utils disable-wal file.dbcommands for doing the same thing on the command-line, see WAL mode (CLI). (#132)
2.14.1 (2020-08-05)¶
Documentation improvements.
2.14 (2020-08-01)¶
The insert-files command can now read from standard input:
cat dog.jpg | sqlite-utils insert-files dogs.db pics - --name=dog.jpg. (#127)You can now specify a full-text search tokenizer using the new
tokenize=parameter to enable_fts(). This means you can enable Porter stemming on a table by runningdb["articles"].enable_fts(["headline", "body"], tokenize="porter"). (#130)You can also set a custom tokenizer using the sqlite-utils enable-fts CLI command, via the new
--tokenizeoption.
2.13 (2020-07-29)¶
memoryviewanduuid.UUIDobjects are now supported.memoryviewobjects will be stored usingBLOBanduuid.UUIDobjects will be stored usingTEXT. (#128)
2.12 (2020-07-27)¶
The theme of this release is better tools for working with binary data. The new insert-files command can be used to insert binary files directly into a database table, and other commands have been improved with better support for BLOB columns.
sqlite-utils insert-files my.db gifs *.gifcan now insert the contents of files into a specified table. The columns in the table can be customized to include different pieces of metadata derived from the files. See Inserting data from files. (#122)--rawoption tosqlite-utils query- for outputting just a single raw column value - see Returning raw data, such as binary content. (#123)JSON output now encodes BLOB values as special base64 objects - see Returning JSON. (#125)
The same format of JSON base64 objects can now be used to insert binary data - see Inserting JSON data. (#126)
The
sqlite-utils querycommand can now accept named parameters, e.g.sqlite-utils :memory: "select :num * :num2" -p num 5 -p num2 6- see Returning JSON. (#124)
2.11 (2020-07-08)¶
2.10.1 (2020-06-23)¶
Added documentation for the
table.pksintrospection property. (#116)
2.10 (2020-06-12)¶
The
sqlite-utilscommand now supports UPDATE/INSERT/DELETE in addition to SELECT. (#115)
2.9.1 (2020-05-11)¶
Added custom project links to the PyPI listing.
2.9 (2020-05-10)¶
New
sqlite-utils drop-tablecommand, see Dropping tables. (#111)New
sqlite-utils drop-viewcommand, see Dropping views.Python
decimal.Decimalobjects are now stored asFLOAT. (#110)
2.8 (2020-05-03)¶
New
sqlite-utils create-tablecommand, see Creating tables. (#27)New
sqlite-utils create-viewcommand, see Creating views. (#107)
2.7.2 (2020-05-02)¶
db.create_view(...)now has additional parametersignore=Trueorreplace=True, see Creating views. (#106)
2.7.1 (2020-05-01)¶
New
sqlite-utils views my.dbcommand for listing views in a database, see Listing views. (#105)sqlite-utils tables(andviews) has a new--schemaoption which outputs the table/view schema, see Listing tables. (#104)Nested structures containing invalid JSON values (e.g. Python bytestrings) are now serialized using
repr()instead of throwing an error. (#102)
2.7 (2020-04-17)¶
New
columns=argument for the.insert(),.insert_all(),.upsert()and.upsert_all()methods, for over-riding the auto-detected types for columns and specifying additional columns that should be added when the table is created. See Custom column order and column types. (#100)
2.6 (2020-04-15)¶
New
table.rows_where(..., order_by="age desc")argument, see Listing rows. (#76)
2.5 (2020-04-12)¶
2.4.4 (2020-03-23)¶
Fixed bug where columns with only null values were not correctly created. (#95)
2.4.3 (2020-03-23)¶
Column type suggestion code is no longer confused by null values. (#94)
2.4.2 (2020-03-14)¶
table.column_dictsnow works with all column types - previously it would throw errors on types other thanTEXT,BLOB,INTEGERorFLOAT. (#92)Documentation for
NotFoundErrorthrown bytable.get(pk)- see Retrieving a specific record.
2.4.1 (2020-03-01)¶
table.enable_fts()now works with columns that contain spaces. (#90)
2.4 (2020-02-26)¶
table.disable_fts()can now be used to remove FTS tables and triggers that were created usingtable.enable_fts(...). (#88)The
sqlite-utils disable-ftscommand can be used to remove FTS tables and triggers from the command-line. (#88)Trying to create table columns with square braces ([ or ]) in the name now raises an error. (#86)
Subclasses of
dict,listandtupleare now detected as needing a JSON column. (#87)
2.3.1 (2020-02-10)¶
table.create_index() now works for columns that contain spaces. (#85)
2.3 (2020-02-08)¶
table.exists() is now a method, not a property. This was not a documented part of the API before so I’m considering this a non-breaking change. (#83)
2.2.1 (2020-02-06)¶
Fixed a bug where .upsert(..., hash_id="pk") threw an error (#84).
2.2 (2020-02-01)¶
New feature: sqlite_utils.suggest_column_types([records]) returns the suggested column types for a list of records. See Suggesting column types. (#81).
This replaces the undocumented table.detect_column_types() method.
2.1 (2020-01-30)¶
New feature: conversions={...} can be passed to the .insert() family of functions to specify SQL conversions that should be applied to values that are being inserted or updated. See Converting column values using SQL functions . (#77).
2.0.1 (2020-01-05)¶
The .upsert() and .upsert_all() methods now raise a sqlite_utils.db.PrimaryKeyRequired exception if you call them without specifying the primary key column using pk= (#73).
2.0 (2019-12-29)¶
This release changes the behaviour of upsert. It’s a breaking change, hence 2.0.
The upsert command-line utility and the .upsert() and .upsert_all() Python API methods have had their behaviour altered. They used to completely replace the affected records: now, they update the specified values on existing records but leave other columns unaffected.
See Upserting data using the Python API and Upserting data using the CLI for full details.
If you want the old behaviour - where records were completely replaced - you can use $ sqlite-utils insert ... --replace on the command-line and .insert(..., replace=True) and .insert_all(..., replace=True) in the Python API. See Insert-replacing data using the Python API and Insert-replacing data using the CLI for more.
For full background on this change, see issue #66.
1.12.1 (2019-11-06)¶
Fixed error thrown when
.insert_all()and.upsert_all()were called with empty lists (#52)
1.12 (2019-11-04)¶
Python library utilities for deleting records (#62)
db["tablename"].delete(4)to delete by primary key, see Deleting a specific recorddb["tablename"].delete_where("id > ?", [3])to delete by a where clause, see Deleting multiple records
1.11 (2019-09-02)¶
Option to create triggers to automatically keep FTS tables up-to-date with newly inserted, updated and deleted records. Thanks, Amjith Ramanujam! (#57)
sqlite-utils enable-fts ... --create-triggers- see Configuring full-text search using the CLIdb["tablename"].enable_fts(..., create_triggers=True)- see Configuring full-text search using the Python librarySupport for introspecting triggers for a database or table - see Introspecting tables and views (#59)
1.10 (2019-08-23)¶
Ability to introspect and run queries against views (#54)
db.view_names()method and anddb.viewspropertySeparate
ViewandTableclasses, both subclassing newQueryableclassview.drop()method
See Listing views.
1.9 (2019-08-04)¶
table.m2m(...)method for creating many-to-many relationships: Working with many-to-many relationships (#23)
1.8 (2019-07-28)¶
table.update(pk, values)method: Updating a specific record (#35)
1.7.1 (2019-07-28)¶
Fixed bug where inserting records with 11 columns in a batch of 100 triggered a “too many SQL variables” error (#50)
Documentation and tests for
table.drop()method: Dropping a table or view
1.7 (2019-07-24)¶
Support for lookup tables.
New
table.lookup({...})utility method for building and querying lookup tables - see Working with lookup tables (#44)New
extracts=table configuration option, see Populating lookup tables automatically during insert/upsert (#46)Use pysqlite3 if it is available, otherwise use
sqlite3from the standard libraryTable options can now be passed to the new
db.table(name, **options)factory function in addition to being passed toinsert_all(records, **options)and friends - see Table configuration optionsIn-memory databases can now be created using
db = Database(memory=True)
1.6 (2019-07-18)¶
sqlite-utils insertcan now accept TSV data via the new--tsvoption (#41)
1.5 (2019-07-14)¶
Support for compound primary keys (#36)
Configure these using the CLI tool by passing
--pkmultiple timesIn Python, pass a tuple of columns to the
pk=(..., ...)argument: Compound primary keys
New
table.get()method for retrieving a record by its primary key: Retrieving a specific record (#39)
1.4.1 (2019-07-14)¶
Assorted minor documentation fixes: changes since 1.4
1.4 (2019-06-30)¶
1.3 (2019-06-28)¶
New mechanism for adding multiple foreign key constraints at once: db.add_foreign_keys() documentation (#31)
1.2.2 (2019-06-25)¶
Fixed bug where
datetime.timewas not being handled correctly
1.2.1 (2019-06-20)¶
Check the column exists before attempting to add a foreign key (#29)
1.2 (2019-06-12)¶
Improved foreign key definitions: you no longer need to specify the
column,other_tableANDother_columnto define a foreign key - if you omit theother_tableorother_columnthe script will attempt to guess the correct values by introspecting the database. See Adding foreign key constraints for details. (#25)Ability to set
NOT NULLconstraints andDEFAULTvalues when creating tables (#24). Documentation: Setting defaults and not null constraints (Python API), Setting defaults and not null constraints (CLI)Support for
not_null_default=X/--not-null-defaultfor setting aNOT NULL DEFAULT 'x'when adding a new column. Documentation: Adding columns (Python API), Adding columns (CLI)
1.1 (2019-05-28)¶
Support for
ignore=True/--ignorefor ignoring inserted records if the primary key already exists (#21) - documentation: Inserting data (Python API), Inserting data (CLI)Ability to add a column that is a foreign key reference using
fk=.../--fk(#16) - documentation: Adding columns (Python API), Adding columns (CLI)
1.0.1 (2019-05-27)¶
sqlite-utils rows data.db table --json-cols- fixed bug where--json-colswas not obeyed
1.0 (2019-05-24)¶
- Option to automatically add new columns if you attempt to insert or upsert data with extra fields:
sqlite-utils insert ... --alter- see Adding columns automatically with the sqlite-utils CLIdb["tablename"].insert(record, alter=True)- see Adding columns automatically using the Python API
New
--json-colsoption for outputting nested JSON, see Nested JSON values
0.14 (2019-02-24)¶
Ability to create unique indexes:
db["mytable"].create_index(["name"], unique=True)db["mytable"].create_index(["name"], if_not_exists=True)$ sqlite-utils create-index mydb.db mytable col1 [col2...], see Creating indexestable.add_column(name, type)method, see Adding columns$ sqlite-utils add-column mydb.db mytable nameofcolumn, see Adding columns (CLI)db["books"].add_foreign_key("author_id", "authors", "id"), see Adding foreign key constraints$ sqlite-utils add-foreign-key books.db books author_id authors id, see Adding foreign key constraints (CLI)Improved (but backwards-incompatible)
foreign_keys=argument to various methods, see Specifying foreign keys
0.13 (2019-02-23)¶
New
--tableand--fmtoptions can be used to output query results in a variety of visual table formats, see Table-formatted outputNew
hash_id=argument can now be used for Setting an ID based on the hash of the row contentsCan now derive correct column types for numpy int, uint and float values
table.last_idhas been renamed totable.last_rowidtable.last_pknow contains the last inserted primary key, ifpk=was specifiedPrettier indentation in the
CREATE TABLEgenerated schemas
0.12 (2019-02-22)¶
Added
db[table].rowsiterator - see Listing rowsReplaced
sqlite-utils jsonandsqlite-utils csvwith a new default subcommand calledsqlite-utils querywhich defaults to JSON and takes formatting options--nl,--csvand--no-headers- see Returning JSON and Returning CSV or TSVNew
sqlite-utils rows data.db name-of-tablecommand, see Returning all rows in a tablesqlite-utils tablecommand now takes options--countsand--columnsplus the standard output format options, see Listing tables
0.11 (2019-02-07)¶
New commands for enabling FTS against a table and columns:
sqlite-utils enable-fts db.db mytable col1 col2
0.10 (2019-02-06)¶
Handle datetime.date and datetime.time values.
New option for efficiently inserting rows from a CSV:
sqlite-utils insert db.db foo - --csv
0.9 (2019-01-27)¶
Improved support for newline-delimited JSON.
sqlite-utils insert has two new command-line options:
--nlmeans “expect newline-delimited JSON”. This is an extremely efficient way of loading in large amounts of data, especially if you pipe it into standard input.--batch-size=1000lets you increase the batch size (default is 100). A commit will be issued every X records. This also control how many initial records are considered when detecting the desired SQL table schema for the data.
In the Python API, the table.insert_all(...) method can now accept a generator as well as a list of objects. This will be efficiently used to populate the table no matter how many records are produced by the generator.
The Database() constructor can now accept a pathlib.Path object in addition to a string or an existing SQLite connection object.
0.8 (2019-01-25)¶
Two new commands: sqlite-utils csv and sqlite-utils json
These commands execute a SQL query and return the results as CSV or JSON. See Returning CSV or TSV and Returning JSON for more details.
$ sqlite-utils json --help
Usage: sqlite-utils json [OPTIONS] PATH SQL
Execute SQL query and return the results as JSON
Options:
--nl Output newline-delimited JSON
--arrays Output rows as arrays instead of objects
--help Show this message and exit.
$ sqlite-utils csv --help
Usage: sqlite-utils csv [OPTIONS] PATH SQL
Execute SQL query and return the results as CSV
Options:
--no-headers Exclude headers from CSV output
--help Show this message and exit.
0.7 (2019-01-24)¶
This release implements the sqlite-utils command-line tool with a number of useful subcommands.
sqlite-utils tables demo.dblists the tables in the databasesqlite-utils tables demo.db --fts4shows just the FTS4 tablessqlite-utils tables demo.db --fts5shows just the FTS5 tablessqlite-utils vacuum demo.dbruns VACUUM against the databasesqlite-utils optimize demo.dbruns OPTIMIZE against all FTS tables, then VACUUMsqlite-utils optimize demo.db --no-vacuumruns OPTIMIZE but skips VACUUM
The two most useful subcommands are upsert and insert, which allow you to ingest JSON files with one or more records in them, creating the corresponding table with the correct columns if it does not already exist. See Inserting JSON data for more details.
sqlite-utils insert demo.db dogs dogs.json --pk=idinserts new records fromdogs.jsoninto thedogstablesqlite-utils upsert demo.db dogs dogs.json --pk=idupserts records, replacing any records with duplicate primary keys
One backwards incompatible change: the db["table"].table_names property is now a method:
db["table"].table_names()returns a list of table namesdb["table"].table_names(fts4=True)returns a list of just the FTS4 tablesdb["table"].table_names(fts5=True)returns a list of just the FTS5 tables
A few other changes:
Plenty of updated documentation, including full coverage of the new command-line tool
Allow column names to be reserved words (use correct SQL escaping)
Added automatic column support for bytes and datetime.datetime
0.6 (2018-08-12)¶
.enable_fts()now takes optional argumentfts_version, defaults toFTS5. UseFTS4if the version of SQLite bundled with your Python does not support FTS5New optional
column_order=argument to.insert()and friends for providing a partial or full desired order of the columns when a database table is createdNew documentation for
.insert_all()and.upsert()and.upsert_all()
0.5 (2018-08-05)¶
db.tablesanddb.table_namesintrospection propertiesdb.indexesproperty for introspecting indexestable.create_index(columns, index_name)methoddb.create_view(name, sql)methodTable methods can now be chained, plus added
table.last_idfor accessing the last inserted row ID
0.4 (2018-07-31)¶
enable_fts(),populate_fts()andsearch()table methods
0.3.1 (2018-07-31)¶
Documented related projects
Added badges to the documentation
0.3 (2018-07-31)¶
New
Tableclass representing a table in the SQLite database
0.2 (2018-07-28)¶
Initial release to PyPI