aliases
alias_for(relation_path)
cached
Returns the table alias for a relation path.
The path is the dunder separated chain of relation names from the root model of a single sql statement. The alias is a short hash of the path, stable between queries and processes. Two paths with the same hash would share an alias in one statement, so each alias is owned by the first path that gets it and a colliding path gets a salted hash (an alias that is unique in the process, but depends on which path came first). Through tables of many to many relations use the relation path followed by the through model name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
relation_path
|
str
|
dunder separated relation path, empty for the root model |
required |
Returns:
| Type | Description |
|---|---|
str
|
alias of the table joined under that path, empty for the root model |
Source code in ormar/relations/aliases.py
| Python | |
|---|---|
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 | |
build_prefixed_columns(*, alias, table, fields)
cached
Builds labelled columns of a table, cached as labels are immutable and the same model/alias/fields combination is selected over and over.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alias
|
str
|
alias of given table |
required |
table
|
Table
|
table from which fields should be aliased |
required |
fields
|
Optional[frozenset[str]]
|
column names (ormar aliases) to include, None for all |
required |
Returns:
| Type | Description |
|---|---|
tuple[Label[Any], ...]
|
tuple of labelled columns |
Source code in ormar/relations/aliases.py
| Python | |
|---|---|
10 11 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 | |
path_hash(relation_path, attempt)
Returns a candidate alias of a relation path, the plain hash of the path on the first attempt and a hash salted with the attempt number afterwards.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
relation_path
|
str
|
dunder separated relation path |
required |
attempt
|
int
|
number of the candidate, 0 for the plain hash |
required |
Returns:
| Type | Description |
|---|---|
str
|
candidate alias |
Source code in ormar/relations/aliases.py
| Python | |
|---|---|
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
prefixed_columns(alias, table, fields=None)
Creates a list of labelled columns of a table prefixed with the table alias.
Optional list of fields to include can be passed to extract only those columns. List has to have sqlalchemy names of columns (ormar aliases) not the ormar ones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alias
|
str
|
alias of given table |
required |
table
|
Table
|
table from which fields should be aliased |
required |
fields
|
Optional[list]
|
fields to include |
None
|
Returns:
| Type | Description |
|---|---|
list[Label[Any]]
|
list of labelled columns |
Source code in ormar/relations/aliases.py
| Python | |
|---|---|
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
prefixed_table(*, alias, table)
cached
Returns the table aliased under its table alias.
Cached without a size limit, as filters and joins of one statement have to reference the same aliased table object, and the number of aliases is bounded by the relation paths of the defined models. The parameters are keyword-only, as the cache keys keyword and positional calls differently, and two aliased objects of one table break the query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alias
|
str
|
alias of given table |
required |
table
|
Table
|
table to alias |
required |
Returns:
| Type | Description |
|---|---|
NamedFromClause
|
aliased table |
Source code in ormar/relations/aliases.py
| Python | |
|---|---|
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |