MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / ConfigData

Class ConfigData

examples/versioned_rows/versioned_map.py:67–150  ·  view source on GitHub ↗

Represent a series of key/value pairs. ConfigData will generate a new version of itself upon change. The "data" dictionary provides access via string name mapped to a string/int value.

Source from the content-addressed store, hash-verified

65
66
67class ConfigData(Base):
68 """Represent a series of key/value pairs.
69
70 ConfigData will generate a new version of itself
71 upon change.
72
73 The "data" dictionary provides access via
74 string name mapped to a string/int value.
75
76 """
77
78 __tablename__ = "config"
79
80 id = Column(Integer, primary_key=True)
81 """Primary key column of this ConfigData."""
82
83 elements = relationship(
84 "ConfigValueAssociation",
85 collection_class=attribute_keyed_dict("name"),
86 backref=backref("config_data"),
87 lazy="subquery",
88 )
89 """Dictionary-backed collection of ConfigValueAssociation objects,
90 keyed to the name of the associated ConfigValue.
91
92 Note there's no "cascade" here. ConfigValueAssociation objects
93 are never deleted or changed.
94 """
95
96 def _new_value(name, value):
97 """Create a new entry for usage in the 'elements' dictionary."""
98 return ConfigValueAssociation(ConfigValue(name, value))
99
100 data = association_proxy("elements", "value", creator=_new_value)
101 """Proxy to the 'value' elements of each related ConfigValue,
102 via the 'elements' dictionary.
103 """
104
105 def __init__(self, data):
106 self.data = data
107
108 @validates("elements")
109 def _associate_with_element(self, key, element):
110 """Associate incoming ConfigValues with this
111 ConfigData, if not already associated.
112
113 This is an optional feature which allows
114 more comprehensive history tracking.
115
116 """
117 if element.config_value.originating_config is None:
118 element.config_value.originating_config = self
119 return element
120
121 def new_version(self, session):
122 # convert to an INSERT
123 make_transient(self)
124 self.id = None

Callers 1

versioned_map.pyFile · 0.85

Calls 5

ColumnClass · 0.90
relationshipFunction · 0.90
backrefFunction · 0.90
association_proxyFunction · 0.90
attribute_keyed_dictFunction · 0.85

Tested by

no test coverage detected