bedrock.db.bedrock_model

This module provides a base class for all your models in the form of BedrockModel. It provides the following fields:

  • uuid - a UUID field that is the primary key of the model
  • created_at - a DateTime field that is set to the current time when the model is created
  • updated_at - a DateTime field that is set to the current time when the model is updated

If your model has different requirements (e.g. the primary key is a UUID field but is named id), create your own base class, like so:

from sqlalchemy.orm import declarative_base

class MyBaseClass(object):
    id = Column(UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"))

Base = declarative_base(cls=MyBaseClass)
 1"""
 2This module provides a base class for all your models in the form of `BedrockModel`. It provides the following fields:
 3* `uuid` - a UUID field that is the primary key of the model
 4* `created_at` - a DateTime field that is set to the current time when the model is created
 5* `updated_at` - a DateTime field that is set to the current time when the model is updated
 6
 7If your model has different requirements (e.g. the primary key is a UUID field but is named `id`), create your own
 8base class, like so:
 9```python
10from sqlalchemy.orm import declarative_base
11
12class MyBaseClass(object):
13    id = Column(UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"))
14
15Base = declarative_base(cls=MyBaseClass)
16```
17"""
18
19from sqlalchemy import Column, DateTime, func, text, UUID
20
21
22class BedrockModel(object):  # pragma: integration
23    """
24    BedrockModel is a class that serves as a base model for all models in Bedrock projects.
25
26    This class is initialised as `Base` in [`model_helper.py`](./db/model_helper.html) and all classes should inherit from that rather than directly
27    from this class.
28    """
29    uuid = Column(UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"))
30    created_at = Column(DateTime(timezone=True), server_default=func.now())
31    updated_at = Column(DateTime(timezone=True), onupdate=func.now())
class BedrockModel:
23class BedrockModel(object):  # pragma: integration
24    """
25    BedrockModel is a class that serves as a base model for all models in Bedrock projects.
26
27    This class is initialised as `Base` in [`model_helper.py`](./db/model_helper.html) and all classes should inherit from that rather than directly
28    from this class.
29    """
30    uuid = Column(UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"))
31    created_at = Column(DateTime(timezone=True), server_default=func.now())
32    updated_at = Column(DateTime(timezone=True), onupdate=func.now())

BedrockModel is a class that serves as a base model for all models in Bedrock projects.

This class is initialised as Base in model_helper.py and all classes should inherit from that rather than directly from this class.

uuid = Column(None, UUID(), table=None, primary_key=True, nullable=False, server_default=DefaultClause(<sqlalchemy.sql.elements.TextClause object>, for_update=False))
created_at = Column(None, DateTime(timezone=True), table=None, server_default=DefaultClause(<sqlalchemy.sql.functions.now at 0x7f3708953e00; now>, for_update=False))
updated_at = Column(None, DateTime(timezone=True), table=None, onupdate=ColumnElementColumnDefault(<sqlalchemy.sql.functions.now at 0x7f370896ac10; now>))