aces / Loris-MRI

The set of scripts that preprocess and insert MRI data into the database.
10 stars 50 forks source link

Python library proposal: SQLAlchemy #1142

Open MaximeMulder opened 2 days ago

MaximeMulder commented 2 days ago

Proposal

I propose to add a Python SQL ORM library, SQLAlchemy, to our LORIS-MRI Python technology stack. The old code can continue using handwritten SQL, but new PRs such as #1117 could benefit from it.

Why a library ?

See some discussion on established libraries in #1141.

Why an ORM ?

I think using a typed ORM (which SQLAlchemy 2.0+ is) is better than using handwritten SQL for three reasons:

Is SQLAlchemy established ?

Both me and @driusan agree that SQLAlchemy is established and the main Python SQL ORM. I can bring more arguments on this point if needed.

Potential conflict with PyBIDS

It seems that PyBIDS depends on a 1.x version of SQLAlchemy, which may not be compatible with SQLAlchemy 2.0+. The problem is obviously with PyBIDS, as it is the library that is not up-to-date, but we still need to work around that if we are to use SQLAlchemy. Here are the potential solutions I see:

Example

I did some tests a month ago by using this library in #1117, I was very satisfied with the result, which is available this branch. You can especially look at the directory python/lib/db and the file python/lib/dicom/dicom_database.py.