


The final step (and for me, the trickiest) is to build pysqlite against the new static library. If not, cruise the console output and hopefully the error is easy to spot. There should now be a file named lib/libsqlite3.a in the SQLite3 source checkout. configure -prefix=$JQLITE -enable-static -disable-shared make sqlite3.c cat ext/misc/json1.c > sqlite3.c make lib_install I put mine in ~/bin/jqlite for fun, but you can change the path to whatever you like.Įxport CFLAGS="-fPIC -DSQLITE_ENABLE_FTS3=1 \ -DSQLITE_ENABLE_COLUMN_METADATA=1 \ -DSQLITE_ENABLE_UNLOCK_NOTIFY \ -DSQLITE_SECURE_DELETE \ -DSQLITE_ENABLE_LOAD_EXTENSION=1". To get started, we need a nice clean home for the new libraries.

There were a couple steps involved, so I'll try and break it down into sub-steps. SQLite also requires tcl and awk to create the source amalgamation, so before starting in, you'll need to install:
#JSON TO SQLITE PYTHON CODE#
We'll be grabbing the latest SQLite source code - to do this you can use fossil, the source-code management system used by SQLite, or alternatively you can pull down a compressed image. I've done this now on arch and ubuntu, but I'm not sure about fapple or windoze. In this post, we'll build SQLite with the new JSON extension, then build pysqlite against the json-ready SQLite. Hipp posted to the sqlite-users mailing list requesting feedback for a draft of the json1 module APIs, so I thought the Python community might be able to help out.
#JSON TO SQLITE PYTHON HOW TO#
The post includes instructions for compiling pysqlite and apsw, as well as example code showing how to use these new extensions in your Python projects.Ī couple weeks ago, word started getting around trendy programming circles about a new file that had appeared in the SQLite fossil repo named json1.c. I've written a new version of this post with updated instructions for compiling SQLite with JSON1 and FTS5.
#JSON TO SQLITE PYTHON UPDATE#
ON CONFLICT DO UPDATE SET Name=excluded.Name WHERE Name!=excluded.With the release of SQLite 3.9.0, the instructions for compiling SQLite and building pysqlite have been greatly simplified. WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x>'appid', Value->'name' I generated a sample database file like this. Note that the performance on the query I was working to optimize, which isĪn production query for a clients, is about twice as fast.

We are still a month away from feature-freeze You'll notice that the JSON parser is quite a bit faster. Here (temporarily - the link will be taken down at some point): I concur that there is about a 16% performance reduction in the particular Seems unfortunate, but I'm guessing it's because the caching doesn't get used much so it just slows the parsing down in this case?Īdmittedly I'm going to get around to moving the JSON parsing out of SQL, so it's not like it'll eventually matter either way, but I decided it was worth mentioning my findings here. Testing it (with an in-memory DB and empty table, and an on-disk DB with the real table) shows about a 20% increase in time required for the query. The upsert was INSERT INTO app_names SELECT Value->'appid', Value->'name' FROM json_each(?) WHERE 1 ON CONFLICT DO UPDATE SET Name=excluded.Name WHERE Name!=excluded.Name The JSON being parsed is essentially and the table is defined as CREATE TABLE app_names (AppID INTEGER PRIMARY KEY, Name TEXT). I saw the new JSON changes got merged into the trunk and was hoping it might improve a big upsert I do, so I updated and gave it some tests.
