Esempio n. 1
0
class User(Entity, schema="execution", registry=REGISTRY):
    id: Serial
    uuid: UUID
    name: String = Field(size=100)
    bio: String
    fixed_char: String = Field(size=[5, 5])
    secret: Bytes

    address_id: Auto = ForeignKey(Address.id)
    address: One[Address]

    salary: Numeric = Field(size=[15, 2])
    distance_mm: Float
    distance_km: Float = Field(size=8)

    point: Point

    is_active: Bool = True
    birth_date: Date
    naive_date: DateTime = datetime(2019, 1, 1, 12, 34, 55)
    created_time: DateTimeTz = func.now()
    updated_time: DateTimeTz
    time: Time
    time_tz: TimeTz

    @virtual
    def virtual_prop(self):
        return f"VIRTUAL:{self.id}"
Esempio n. 2
0
def test_field_size():
    f = Field()
    assert f.min_size == -1
    assert f.max_size == -1

    f = Field(size=1)
    assert f.min_size == 0
    assert f.max_size == 1

    f = Field(size=[10, 12])
    assert f.min_size == 10
    assert f.max_size == 12

    with pytest.raises(ValueError):
        Field(size=[13, 12])
Esempio n. 3
0
class Node(Entity, schema="circular_deps", registry=REGISTRY,
           polymorph="type"):
    id: Serial
    type: String = Field(nullable=False)
    parent_id: Auto = ForeignKey("Node.id")
    author_id: Auto = ForeignKey("circular_deps.User.id")
    author: One["circular_deps.User"]
Esempio n. 4
0
    class User(Entity, schema="execution", registry=new_reg):
        id: Serial
        uuid: UUID
        name_x: String = Field(size=100)
        bio: String = Field(size=200)
        fixed_char: Bytes
        secret: Bytes

        address_id: Auto = ForeignKey(Address.id)
        address: One[Address]

        salary: Numeric = Field(size=[15, 3])
        distance_mm: Float
        distance_km: Float = Field(size=4)

        point: Point

        is_active: Bool = True
        birth_date: String
        naive_date: DateTimeTz = func.now()
        created_time: DateTimeTz = func.CURRENT_TIMESTAMP
        updated_time: DateTimeTz
        time: Time
        time_tz: TimeTz
Esempio n. 5
0
def test_field_default():
    assert Field(default="DEFAULT_VALUE").default == "DEFAULT_VALUE"
    assert Field().default is None
Esempio n. 6
0
 class Pk_large(BaseEntity):
     id: Int = Field(size=8) // PrimaryKey(auto_increment=True)
     id2: Serial = Field(size=8)
Esempio n. 7
0
 class Pk_medium(BaseEntity):
     id: Int = Field(size=4) // PrimaryKey(auto_increment=True)
     id2: Serial = Field(size=4)
Esempio n. 8
0
 class Pk_small(BaseEntity):
     id: Int = Field(size=2) // PrimaryKey(auto_increment=True)
     id2: Serial = Field(size=2)
Esempio n. 9
0
 class Ints(BaseEntity):
     int_small: Int = Field(size=2)
     int_medium: Int = Field(size=4)
     int_large: Int = Field(size=8)
Esempio n. 10
0
 class A(BaseEntity):
     id: String = Field(size=[10, 10]) // PrimaryKey()
     name: String = Field(size=50)
     email: String = Field(size=50)
     description: String
Esempio n. 11
0
class Tag(Entity):
    id: Serial
    value: String = Field(size=50)
Esempio n. 12
0
class Document(Entity, schema="circular_deps", registry=REGISTRY):
    id: Serial
    group_id: Auto = Field(nullable=False) // ForeignKey("DocumentGroup.id")
    group: One["DocumentGroup"]
    author_id: Auto = ForeignKey("circular_deps.User.id")
    author: One["circular_deps.User"]
Esempio n. 13
0
 class CallableDefault(Entity, registry=reg, schema="execution"):
     id: Serial
     creator_id: Int = Field(size=4, nullable=False, default=lambda: 1)
Esempio n. 14
0
 class Defaults(Entity, registry=reg, schema="execution"):
     int_w_def: Int = 0
     int2_w_def: Int = Field(size=2, default=1)
     string_w_def: String = "Hello"
     bool_w_def: Bool = True
     interval: Int = Field(nullable=False)
Esempio n. 15
0
 class CompositePk(Entity, registry=R2, schema="execution"):
     id1: Int = Field(nullable=False) // PrimaryKey()
     later_id: Int = Field(nullable=False) // PrimaryKey()
     id2: Int = Field(nullable=False)
Esempio n. 16
0
 class OnUpdate(Entity, registry=R, schema="execution"):
     id: Serial
     value: String
     updater_id: Int = Field(on_update=lambda entity: 1)
     updater_id2: Int = Field(on_update=get_user_id)