common
Common column types like Text, Integer, and Float.
Column
Bases: ColumnBase
The main parent class for creating columns, generic over the Python type.
Source code in src/embar/column/common.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
__get__(obj, owner)
__get__(obj: None, owner: type) -> Self
__get__(obj: object, owner: type) -> T
This allows this class to be typed as itself in Table definitions
but as T in object instances. The overloads ensure this works for typechecking too.
from embar.table import Table
from embar.column.common import Text
class MyTable(Table):
my_col: Text = Text() # typechecked as `Text`
my_row = MyTable(my_col="foo") # typechecked as `str`
assert isinstance(MyTable.my_col, Text)
assert isinstance(my_row.my_col, str)
Source code in src/embar/column/common.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
__init__(name=None, default=None, primary=False, not_null=False)
Create a new Column instance.
Source code in src/embar/column/common.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
__set__(obj, value)
Allows values of type T (rather than Column[T]) to be assigned to this class when it's a field of an object.
Source code in src/embar/column/common.py
72 73 74 75 76 | |
__set_name__(owner, attr_name)
Called after the class body has executed, when the owning Table is being created.
This is needed so that each Column can be told what the owning table's name is.
Source code in src/embar/column/common.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
fk(ref, on_delete=None)
Create a foreign key reference to another table.
Source code in src/embar/column/common.py
106 107 108 109 110 111 112 113 114 115 | |
many()
Used to nest many values of this column in a model.
from typing import Annotated
from pydantic import BaseModel
from embar.column.common import Text
from embar.table import Table
class MyTable(Table):
my_col: Text = Text()
class MyModel(BaseModel):
values: Annotated[list[str], MyTable.my_col.many()]
Source code in src/embar/column/common.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
Float
Bases: Column[float]
A floating point column type.
Source code in src/embar/column/common.py
153 154 155 156 157 158 159 | |
Integer
Bases: Column[int]
An integer column type.
Source code in src/embar/column/common.py
144 145 146 147 148 149 150 | |
Text
Bases: Column[str]
A text column type.
Source code in src/embar/column/common.py
135 136 137 138 139 140 141 | |