Creating Tables

Classes represent tables

To make it easy to work with tables in MATLAB and Python, DataJoint programs create a separate class for each table. Computer programmers refer to this concept as object-relational mapping. For example, the class experiment.Subject in the DataJoint client language may correspond to the table called subject on the database server. Users never need to see the database directly; they only interact with data in the database by creating and interacting with DataJoint classes.

Data tiers

The table class must inherit from one of the following superclasses to indicate its data tier: dj.Lookup, dj.Manual, dj.Imported, dj.Computed, or dj.Part. See Data Tiers and Master-Part Relationship.

Defining a table

DataJoint provides the interactive script dj.new for creating a new table. It will prompt to enter the new table’s class name in the form package.ClassName. This will create the file +package/ClassName.m.

For example, define the table experiment.Person

>> dj.new
Enter <package>.<ClassName>: experiment.Person

Choose table tier:
  L=lookup
  M=manual
  I=imported
  C=computed
  P=part
 (L/M/I/C/P) > M

This will create the file +experiment/Person.m with the following contents:

%{
# my newest table
# add primary key here
-----
# add additional attributes
%}

classdef Person < dj.Manual
end

While dj.new adds a little bit of convenience, some users may create the classes from scratch manually.

Each newly created class must inherit from the DataJoint class corresponding to the correct data tier: dj.Lookup, dj.Manual, dj.Imported or dj.Computed.

The most important part of the table definition is the comment preceding the classdef. DataJoint will parse this comment to define the table.

The class will become usable after you edit this comment as described in Table Definition.

Valid class names

Note that in both MATLAB and Python, the class names must follow the CamelCase compound word notation:

  • start with a capital letter and

  • contain only alphanumerical characters (no underscores).

Examples of valid class names:

TwoPhotonScan, Scan2P, Ephys, MembraneVoltage

Invalid class names:

Two_photon_Scan, twoPhotonScan, 2PhotonScan, membranePotential, membrane_potential

Talk to the Community