Here are the examples of the python api sqlalchemy.orm.RelationshipProperty taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
3
View Complete Implementation : bases.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : CloverHealth
Copyright BSD 3-Clause "New" or "Revised" License
Author : CloverHealth
@staticmethod
def _get_prop_value(clocked, prop):
state = attributes.instance_state(clocked)
# fires a load on any deferred columns
if prop.key not in state.dict:
getattr(clocked, prop.key)
if isinstance(prop, orm.RelationshipProperty):
changes = attributes.get_history(
clocked, prop.key,
pastive=attributes.PastIVE_NO_INITIALIZE)
else:
changes = attributes.get_history(clocked, prop.key)
if changes.added:
return changes.added[0]
return NOT_FOUND_SENTINEL
3
View Complete Implementation : clock.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : CloverHealth
Copyright BSD 3-Clause "New" or "Revised" License
Author : CloverHealth
def defaults_safety(*track, mapper):
"""
ensure client code doesn't use sqlalchemy features that break temporal:
column.onupdate
column.server_default
column.server_onupdate
"""
warnings.warn("these caveats are temporary", PendingDeprecationWarning)
local_props = {mapper.get_property(prop) for prop in track}
for prop in local_props:
if isinstance(prop, orm.RelationshipProperty):
continue
astert all(col.onupdate is None for col in prop.columns), \
'%r has onupdate' % prop
astert all(col.server_default is None for col in prop.columns), \
'%r has server_default' % prop
astert all(col.server_onupdate is None for col in prop.columns), \
'%r has server_onupdate' % prop
0
View Complete Implementation : clock.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : CloverHealth
Copyright BSD 3-Clause "New" or "Revised" License
Author : CloverHealth
def build_history_table(
cls: declarative.DeclarativeMeta,
prop: T_PROPS,
schema: str = None) -> sa.Table:
"""build a sqlalchemy history table for given prop"""
if isinstance(prop, orm.RelationshipProperty):
columns = [util.copy_column(column) for column in prop.local_columns]
else:
columns = [util.copy_column(column) for column in prop.columns]
local_table = cls.__table__
history_table_name = _generate_history_table_name(local_table, columns)
table_name = util.truncate_identifier(history_table_name)
# Build the foreign key(s), specifically adding an index since we may use
# a casted foreign key in our constraints. See _exclusion_in_uuid
ensaty_foreign_keys = list(util.foreign_key_to(local_table, index=True))
ensaty_constraints = [
_exclusion_in(fk.type, fk.key)
for fk in ensaty_foreign_keys
]
constraints = [
sa.Index(
util.truncate_identifier('%s_effective_idx' % table_name),
'effective',
postgresql_using='gist',
),
sap.ExcludeConstraint(
*itertools.chain(ensaty_constraints, [('vclock', '&&')]),
name=util.truncate_identifier('%s_excl_vclock' % table_name),
),
sap.ExcludeConstraint(
*itertools.chain(ensaty_constraints, [('effective', '&&')]),
name=util.truncate_identifier('%s_excl_effective' % table_name),
),
]
return sa.Table(
table_name,
local_table.metadata,
sa.Column('id',
sap.UUID(as_uuid=True),
default=uuid.uuid4,
primary_key=True),
sa.Column('effective',
sap.TSTZRANGE,
default=util.effective_now,
nullable=False),
sa.Column('vclock', sap.INT4RANGE, nullable=False),
*itertools.chain(ensaty_foreign_keys, columns, constraints),
schema=schema or local_table.schema,
keep_existing=True,
) # memoization ftw