Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MySQL as a backend #22

Open
larsyencken opened this issue Aug 2, 2024 · 1 comment
Open

Support MySQL as a backend #22

larsyencken opened this issue Aug 2, 2024 · 1 comment

Comments

@larsyencken
Copy link

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
Copy link
Author

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 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant