Example #1
0
class Chart(ormar.Model):
    class Meta(ormar.ModelMeta):
        tablename = "charts"
        database = database
        metadata = metadata

    chart_id = ormar.Integer(primary_key=True, autoincrement=True)
    name = ormar.String(max_length=200, unique=True, index=True)
    query_text = ormar.Text()
    datasets = ormar.JSON()
    layout = ormar.JSON()
    data_config = ormar.JSON()
    created_date = ormar.DateTime(server_default=func.now())
    library = ormar.String(max_length=200, default="plotly")
    used_filters = ormar.JSON()
class Thing(ormar.Model):
    class Meta(BaseMeta):
        tablename = "things"

    id: uuid.UUID = ormar.UUID(primary_key=True, default=uuid.uuid4)
    name: str = ormar.Text(default="")
    js: pydantic.Json = ormar.JSON()
class Organisation(ormar.Model):
    class Meta:
        tablename = "org"
        metadata = metadata
        database = database

    id: int = ormar.Integer(primary_key=True)
    ident: str = ormar.String(max_length=100,
                              choices=["ACME Ltd", "Other ltd"])
    priority: int = ormar.Integer(choices=[1, 2, 3, 4, 5])
    priority2: int = ormar.BigInteger(choices=[1, 2, 3, 4, 5])
    expire_date: datetime.date = ormar.Date(
        choices=[datetime.date(2021, 1, 1),
                 datetime.date(2022, 5, 1)])
    expire_time: datetime.time = ormar.Time(
        choices=[datetime.time(10, 0, 0),
                 datetime.time(12, 30)])

    expire_datetime: datetime.datetime = ormar.DateTime(choices=[
        datetime.datetime(2021, 1, 1, 10, 0, 0),
        datetime.datetime(2022, 5, 1, 12, 30),
    ])
    random_val: float = ormar.Float(choices=[2.0, 3.5])
    random_decimal: decimal.Decimal = ormar.Decimal(
        scale=2,
        precision=4,
        choices=[decimal.Decimal(12.4),
                 decimal.Decimal(58.2)])
    random_json: pydantic.Json = ormar.JSON(choices=["aa", '{"aa":"bb"}'])
    random_uuid: uuid.UUID = ormar.UUID(choices=[uuid1, uuid2])
    enum_string: str = ormar.String(max_length=100, choices=list(EnumTest))
class Author(ormar.Model):
    class Meta(BaseMeta):
        tablename = "authors"

    id: int = ormar.Integer(primary_key=True)
    name: str = ormar.String(max_length=100, **default_fernet)
    uuid_test = ormar.UUID(default=uuid.uuid4, uuid_format="string")
    uuid_test2 = ormar.UUID(nullable=True, uuid_format="string")
    password: str = ormar.String(
        max_length=128,
        encrypt_secret="udxc32",
        encrypt_backend=ormar.EncryptBackends.HASH,
    )
    birth_year: int = ormar.Integer(
        nullable=True,
        encrypt_secret="secure89key%^&psdijfipew",
        encrypt_backend=ormar.EncryptBackends.FERNET,
    )
    test_text: str = ormar.Text(default="", **default_fernet)
    test_bool: bool = ormar.Boolean(nullable=False, **default_fernet)
    test_float: float = ormar.Float(**default_fernet)
    test_float2: float = ormar.Float(nullable=True, **default_fernet)
    test_datetime = ormar.DateTime(default=datetime.datetime.now, **default_fernet)
    test_date = ormar.Date(default=datetime.date.today, **default_fernet)
    test_time = ormar.Time(default=datetime.time, **default_fernet)
    test_json = ormar.JSON(default={}, **default_fernet)
    test_bigint: int = ormar.BigInteger(default=0, **default_fernet)
    test_decimal = ormar.Decimal(scale=2, precision=10, **default_fernet)
    test_decimal2 = ormar.Decimal(max_digits=10, decimal_places=2, **default_fernet)
    custom_backend: str = ormar.String(
        max_length=200,
        encrypt_secret="asda8",
        encrypt_backend=ormar.EncryptBackends.CUSTOM,
        encrypt_custom_backend=DummyBackend,
    )
Example #5
0
        class JsonSample2(ormar.Model):
            class Meta:
                tablename = "jsons2"
                database = database

            id: int = ormar.Integer(primary_key=True)
            test_json = ormar.JSON(nullable=True)
Example #6
0
class Thing(ormar.Model):
    class Meta(BaseMeta):
        tablename = "things"

    id: UUID = ormar.UUID(primary_key=True, default=uuid4)
    name: str = ormar.Text(default="")
    js: pydantic.Json = ormar.JSON(nullable=True)
    other_thing: Optional[OtherThing] = ormar.ForeignKey(OtherThing,
                                                         nullable=True)
Example #7
0
class AuditLog(ormar.Model):
    class Meta:
        tablename = "audits"
        metadata = metadata
        database = database

    id: int = ormar.Integer(primary_key=True)
    event_type: str = ormar.String(max_length=100)
    event_log: pydantic.Json = ormar.JSON()
Example #8
0
class Example(ormar.Model):
    class Meta:
        tablename = "example"
        metadata = metadata
        database = database

    id: int = ormar.Integer(primary_key=True)
    name: str = ormar.String(max_length=200, default="aaa")
    created: datetime.datetime = ormar.DateTime(default=datetime.datetime.now)
    created_day: datetime.date = ormar.Date(default=datetime.date.today)
    created_time: datetime.time = ormar.Time(default=time)
    description: str = ormar.Text(nullable=True)
    value: float = ormar.Float(nullable=True)
    data: pydantic.Json = ormar.JSON(default={})
Example #9
0
class ExampleModel(Model):
    class Meta:
        tablename = "example"
        metadata = metadata

    test: int = ormar.Integer(primary_key=True)
    test_string: str = ormar.String(max_length=250)
    test_text: str = ormar.Text(default="")
    test_bool: bool = ormar.Boolean(nullable=False)
    test_float: ormar.Float() = None  # type: ignore
    test_datetime = ormar.DateTime(default=datetime.datetime.now)
    test_date = ormar.Date(default=datetime.date.today)
    test_time = ormar.Time(default=datetime.time)
    test_json = ormar.JSON(default={})
    test_bigint: int = ormar.BigInteger(default=0)
    test_decimal = ormar.Decimal(scale=2, precision=10)
    test_decimal2 = ormar.Decimal(max_digits=10, decimal_places=2)
Example #10
0
class Chart(ormar.Model):
    class Meta(BaseMeta):
        tablename = "authors"

    id: int = ormar.Integer(primary_key=True)
    datasets = ormar.JSON()