cldellow / datasette-parquet

Add DuckDB, Parquet, CSV and JSON lines support to Datasette
Apache License 2.0
44 stars 4 forks source link

Support MySQL as a backend #22

Open larsyencken opened 1 month ago

larsyencken commented 1 month ago

Motivation

Datasette is an amazing frontend UI that only officially supports sqlite. With datasette-parquet, a DuckDB backend works pretty well. But DuckDB is also capable of attaching a live MySQL connection with:

INSTALL mysql;
LOAD mysql;
ATTACH 'host=... user=... passwd=... port=... database=...' AS mysql_db (TYPE MYSQL);
USE mysql_db;

This opens the door to Datasette over live MySQL, which would be very attractive for many people with an existing MySQL database.

Proposal

Add a mysql config option (similar to file and directory) that takes all the config needed to create a MySQL connection string in DuckDB (e.g. db_host, ...), so that datasette works with a live MySQL connection.

larsyencken commented 1 month ago

I got this working as a proof of concept with many hacks, which I could clean up into a PR.

Getting a MySQL connection is not hard, but then it's available at <alias>.<mysql_db_name> instead of being the default db, which means you need to add USE statements in front of every cursor creation/execution to make it run cleanly.

In my current proof-of-concept, Datasette fails on / path, works on /<db> path and all queries, but fails on /<db>/<table> path for browsing.

Incidentally, it's amazing to me to have gotten this far in just an hour or two, and I'm super impressed that you put this plugin together. Nice work 🙌