Skip to content

Class tigrbl.column._column.Column

tigrbl.column._column.Column

Column(
    *,
    spec=None,
    storage=None,
    field=None,
    io=None,
    default_factory=None,
    read_producer=None,
    **kw,
)

Bases: ColumnSpec, MappedColumn

SQLAlchemy column implementing a :class:ColumnSpec.

Source code in tigrbl/column/_column.py
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
def __init__(
    self,
    *,
    spec: ColumnSpec | None = None,
    storage: S | None = None,
    field: F | None = None,
    io: IO | None = None,
    default_factory: Optional[Callable[[dict], Any]] = None,
    read_producer: Optional[Callable[[object, dict], Any]] = None,
    **kw: Any,
) -> None:
    if spec is not None and any(
        x is not None for x in (storage, field, io, default_factory, read_producer)
    ):
        raise ValueError("Provide either spec or individual components, not both.")
    if spec is None:
        spec = ColumnSpec(
            storage=storage,
            field=field,
            io=io,
            default_factory=default_factory,
            read_producer=read_producer,
        )
    else:
        storage = spec.storage
        field = spec.field
        io = spec.io
        default_factory = spec.default_factory
        read_producer = spec.read_producer

    s = storage
    if s is not None:
        args: list[Any] = [s.type_]
        fk = getattr(s, "fk", None)
        if fk is not None:
            args.append(
                ForeignKey(
                    fk.target,
                    ondelete=fk.on_delete,
                    onupdate=fk.on_update,
                    deferrable=fk.deferrable,
                    initially="DEFERRED" if fk.initially_deferred else "IMMEDIATE",
                    match=fk.match,
                )
            )
        MappedColumn.__init__(
            self,
            *args,
            primary_key=s.primary_key,
            nullable=s.nullable,
            unique=s.unique,
            index=s.index,
            default=s.default,
            autoincrement=s.autoincrement,
            server_default=s.server_default,
            onupdate=s.onupdate,
            comment=s.comment,
            **kw,
        )
    else:
        MappedColumn.__init__(self, **kw)

    self.storage = s
    self.field = field if field is not None else F()
    self.io = io if io is not None else IO()
    self.default_factory = default_factory
    self.read_producer = read_producer

storage instance-attribute

storage = s

field instance-attribute

field = field if field is not None else FieldSpec()

io instance-attribute

io = io if io is not None else IOSpec()

default_factory instance-attribute

default_factory = default_factory

read_producer instance-attribute

read_producer = read_producer