datajoint / datajoint-matlab

Relational data pipelines for the science lab
MIT License
42 stars 37 forks source link

discovering existing tables across python/matlab #412

Open mikewehr opened 2 years ago

mikewehr commented 2 years ago

Hi, we're just getting started implementing datajoint in our lab, using a local docker server. Jonny, a python user, started by adding subject schemas with basic biographical info. I, a matlab user, can connect to the database but do not know in advance what schemas have been created in python. How do I discover which schemas/tables already exist in the database and connect matlab schemas to them? Is this documented somewhere? This docs page https://docs.datajoint.org/matlab/existing/5-Loading-Classes.html didn't seem to help me, unless I'm missing something. Thank you!

Reproducibility

CBroz1 commented 2 years ago

The datajoint python function list_schemas has the SQL syntax for querying the available schemas. Within MATLAB, that SQL syntax could be embedded in a query().

There's probably a more native way to do the same, but this is the first thing that comes to mind

dimitri-yatsenko commented 2 years ago

To connect to an existing schema from matlab, you need to know its name. You can list the schema names using SQL commands:

conn = dj.conn()
conn.query('SHOW SCHEMAS')

Once you know the schema name, you you can connect to it using the dj.createSchema function. This will match the corresponding database schema to a MATLAB package (a +package folder) with the getSchema function inside it.

Then you can plot the diagram of that schema using the erd command

erd <package>

You can access the schema using the schema object, which you can instantiate by calling the getSchema function in the package

schema = package.getSchema()

With this schema object, you can use its dynamic property .v to access any table as if it was a table class.

schema.v.Scan

Alternatively, you can use the dj.new function to create a full-blow class for the given table. If the table already exists, it will create the matlab classdef file with the full definition reverse-engineered from the database definition.

mikewehr commented 2 years ago

Thank you, this was super helpful. Did I miss this in the documentation, or is this a topic that could be more completely documented? Do you encourage users to contribute to docs with PRs?

CBroz1 commented 2 years ago

Our documentation is lagging behind a bit, especially with matlab. I would be very happy to see a user-contributed PR to our docs repository.

dimitri-yatsenko commented 2 years ago

@mikewehr Your contributions in both functionality and documentation are welcome! We will be refactoring the documentation to make contributions easier.