Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
📝 Harmonize with Record docs
Browse files Browse the repository at this point in the history
  • Loading branch information
falexwolf committed Nov 24, 2024
1 parent b454376 commit 5c4f172
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions lnschema_core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
)
from lamin_utils import colors
from lamindb_setup import _check_instance_setup
from lamindb_setup.core._docs import doc_args
from lamindb_setup.core.hashing import HASH_LENGTH

from lnschema_core.fields import (
Expand Down Expand Up @@ -529,19 +530,7 @@ def query_children(self) -> QuerySet:
pass


# this is the metaclass for Record
class Registry(ModelBase):
"""Metaclass for :class:`~lamindb.core.Record`.
Each `Registry` *object* is a `Record` *class* and corresponds to a table in the metadata SQL database.
You work with `Registry` objects whenever you use *class methods* of `Record`.
You call any subclass of `Record` a "registry" and their objects "records". A `Record` object corresponds to a row in the SQL table.
If you want to create a new registry, you sub-class `Record`.
Example::
RECORD_REGISTRY_EXAMPLE = """Example::
from lnschema_core import Record, fields
Expand All @@ -552,11 +541,28 @@ class Experiment(Record):
# instantiating `Experiment` creates a record `experiment`
experiment = Experiment(name="my experiment")
# you can save the record in the database
# you can save the record to the database
experiment.save()
# `Experiment` refers to the registry, which you can query
df = Experiment.filter(name__startswith="my ").df()
"""


# this is the metaclass for Record
@doc_args(RECORD_REGISTRY_EXAMPLE)
class Registry(ModelBase):
"""Metaclass for :class:`~lamindb.core.Record`.
Each `Registry` *object* is a `Record` *class* and corresponds to a table in the metadata SQL database.
You work with `Registry` objects whenever you use *class methods* of `Record`.
You call any subclass of `Record` a "registry" and their objects "records". A `Record` object corresponds to a row in the SQL table.
If you want to create a new registry, you sub-class `Record`.
{}
Note: `Registry` inherits from Django's `ModelBase`.
"""
Expand Down Expand Up @@ -772,22 +778,23 @@ def __get_name_with_schema__(cls) -> str:
return f"{schema_prefix}{cls.__name__}"


@doc_args(RECORD_REGISTRY_EXAMPLE)
class Record(models.Model, metaclass=Registry):
"""Base class for metadata records.
Every `Record` is a data model that comes with a registry in form of a SQL
table in your database.
Sub-classing `Record` defines a new registry while instantiating a `Record`
subclass defines a new record.
Sub-classing `Record` creates a new registry while instantiating a `Record`
creates a new record.
`Record` extends Django's `Model` class. Why does LaminDB call it `Record`
and not `Model`? The term `Record` can't lead to confusion with statistical,
machine learning or biological models.
{}
For an example, see `here
<https://github.com/laminlabs/wetlab/blob/64e1ec74c1edfa3e26bc0b432add358c34db8006/wetlab/models.py#L64-L99>`__.
`Record`'s metaclass is :class:`~lamindb.core.Registry`.
`Record` inherits from Django's `Model` class. Why does LaminDB call it `Record`
and not `Model`? The term `Record` can't lead to confusion with statistical,
machine learning or biological models.
"""

def save(self, *args, **kwargs) -> Record:
Expand Down

0 comments on commit 5c4f172

Please sign in to comment.