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

discovering existing tables across python/matlab #412

Open
mikewehr opened this issue Apr 26, 2022 · 5 comments
Open

discovering existing tables across python/matlab #412

mikewehr opened this issue Apr 26, 2022 · 5 comments
Labels
awaiting-triage Issues awaiting proper priority/milestone assignment. bug

Comments

@mikewehr
Copy link

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

  • Ubuntu 21.10
  • MATLAB Version 2021b
  • MySQL Version - docker image 8.0
  • MySQL Deployment Strategy = local-docker
  • DataJoint Version 3.5.0
@mikewehr mikewehr added awaiting-triage Issues awaiting proper priority/milestone assignment. bug labels Apr 26, 2022
@CBroz1
Copy link
Contributor

CBroz1 commented Apr 26, 2022

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

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

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

CBroz1 commented Apr 27, 2022

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-triage Issues awaiting proper priority/milestone assignment. bug
Projects
None yet
Development

No branches or pull requests

3 participants