-
-
Notifications
You must be signed in to change notification settings - Fork 273
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
[loader] Integrate generic SQL loader #729
Comments
Hi @amotl, thanks for your comments and suggestion! I've thought about using SQLAlchemy for the reasons you've indicated, but if I remember correctly, it seems you have to describe your schema using it, in order for it to work. This is contrary to the usage of VisiData, which should be able to connect to an arbitrary database and allow you to interact with it without knowing the schema in advance. If there's some way to do this using SQLAlchemy, that could be a very useful integration, I agree. If you know how to use SQLAlchemy to do this, please attach a small working Python script that does it, and that should be a good starting place for us to see how it might integrate into VisiData. |
Hi Saul,
For using the full ORM functionality, working with declarative schemas defined in Python is the way to go, right. However, the ORM layer can also reflect the current schema from the database.
It should work by just using the SQLAlchemy dialect engine under the hood, completely skipping the ORM layer, see https://docs.sqlalchemy.org/en/13/core/engines.html.
Sure. Does With kind regards, |
Basics
-- https://docs.sqlalchemy.org/en/13/core/connections.html List of tables
-- https://docs.sqlalchemy.org/en/13/core/reflection.html#fine-grained-reflection-with-inspector List of columns
List of databasesThis is not quite straight-forward, SQLAlchemy apparently doesn't provide that feature in a database-agnostic manner. So, we should probably only support full qualified connection strings including the database name when invoking VisiData. However, if we want to go the extra mile and even present the user a list of databases, we will probably have to implement it specific to each database, see [3] for getting a rough idea. Everything should work out of the box for all databases listed at [1]. Obviously, the specific database drivers will still have to be installed. Expanding from here, it will also be possible to talk to many additional databases, see [2]. [1] https://docs.sqlalchemy.org/en/13/core/engines.html#supported-databases |
Just to get you an idea. Please adjust to your operating system.
Alternatively, install the pure-Python MySQL driver.
Alternatively, use the MariaDB client.
|
The The plugin currently summarizes all available schemas within the database for presentation and subsequent selection by the user. My assumption is that this should play nicely with anything that is compatible with SQL Alchemy but I haven't tested on anything but Oracle. I have no problem with integrating my code into visidata proper and would definitely appreciate not needing to consider possible friction between the plugin system and having the code held natively within Visidata. |
Oh, and because I just found @Mytherin has also starred this repository (maybe also @hannesmuehleisen?), we might think about also supporting DuckDB through duckdb_engine by @Mause, see also duckdb/duckdb#305. |
Please be aware that it is very very very basic 😅 the python package for duckdb doesn't really expose enough information in results to be able to build a decent implementation |
Thanks for chiming in, @aswan89, and for your work on the genericSQL plugin. I forgot that you used SQLAlchemy (of course!) And I'm sorry @amotl, I missed the main point of your original issue and responded as though it were just another loader or feature request.
The real request here, is for me to take on the maintenance of the SQL plugin. I don't have ready access to test databases and it's a pain to set them up, so it would make ongoing maintenance more work for us. I appreciate that @aswan89 is willing to do this work (and already has at least one test environment that he's using with VisiData on a regular basis). The whole point of the plugin system is to distribute the maintenance effort to people who have a vested interest in the feature working. If genericSQL were incorporated into core VisiData, it would just rot anyway (see how the Postgresql loader is broken right now, even :) That said, I have been thinking about making a more fully featured SQL explorer/editor based on VisiData, but it would be "sold separately", as it's a different internal architecture to work seamlessly with offline data. You and anyone who would be interested in this, put some 👀 on this comment and I'll ping you if it's what I decide to work on. |
Kondo'ed for now. |
Hi @saulpw, just wanted to know if there's been any updates on Visdata based SQL db explorers? |
Hi @dufferzafar, good question. There's a new plugin for Ibis in vdplus. Only a few commands are implemented and it only works with sqlite currently, but in a month or two it should support all the backends that Ibis supports (read-only for the time being). |
Dear @saulpw and @anjakefala,
SQLAlchemy does not only provide the best-in-class ORM for Python, its underlying engine is also a gateway to many different databases on the SQL level. While the list of databases supported by SQLAlchemy enumerates all of the builtin backends, there are more database drivers out there which plug in to that architecture, for example CrateDB.
@aswan89 probably has been aware of that, so I was happy to find his genericSQL plugin for VisiData [1].
So, because I believe SQL support should be made a first citizen for VisiData, I would like to propose to integrate this plugin into VisiData core. It will probably also make ongoing maintenance easier.
Now that VisiData 2.x changed its license to GPL3, I am hereby humbly asking @aswan89 whether you would agree to follow this adjustment.
At the same time, I would like to propose to fold the threefold entrypoints
openurl_oracle
,openurl_mysql
andopenurl_mssql
into a single entrypointopen_sql
, if that would even be possible in some way [2]. This would definitively be cool so VisiData will not have to know about all possible databases supported by SQLAlchemy.With kind regards,
Andreas.
P.S.: These days, as you might know, there are not only SQL databases around. Supporting loading data from other databases like MongoDB or EdgeDB in the long run would also be awesome.
[1] However, I have to admit it was difficult to find without being aware of the plugin subsystem at first. Luckily, I have been able to find it within
plugins.jsonl
by searching for SQLAlchemy.[2] Disclaimer: I don't know enough of the code base in detail yet. Currently, it looks like VisiData will invoke
open_"scheme"
automagically when it obtains an URI on the command line likevd mysql://abc:def@localhost:1234/abc
. Thus, generalizing that interface might not be that easy, but maybe @saulpw and @anjakefala have some ideas how to move into that direction.The text was updated successfully, but these errors were encountered: