graflo.hq.container_write¶
Write a graph container to a database by identity upsert, without a resource.
For producers that assemble a :class:GraphContainer themselves rather than
casting rows through an ingestion resource. The schema is defined on the
target first, and an existing definition is reused. Edges whose endpoint is
known only by a secondary identity (:class:PendingEdge) are looked up in the
target after the container is written, so an endpoint the container itself
carries is found. Everything is upserted by identity through :class:DBWriter, so writing the same container twice leaves the
database as it was after the first write. The file backend is the exception:
it appends.
Attributes¶
Classes¶
ContainerWriteReport
¶
Bases: ConfigBaseModel
What :func:write_container sent to the database.
Source code in graflo/hq/container_write.py
Attributes¶
edges = Field(description='Edges per edge, keyed ``source-relation-target``.')
class-attribute
instance-attribute
¶
lookups_resolved = Field(default=0, description='Pending edges whose endpoints were found.')
class-attribute
instance-attribute
¶
lookups_unresolved = Field(default=0, description='Pending edges dropped: no match, or an ambiguous one.')
class-attribute
instance-attribute
¶
schema_defined = Field(description='False when an existing definition was reused.')
class-attribute
instance-attribute
¶
target = Field(description='Connection type written to.')
class-attribute
instance-attribute
¶
vertices = Field(description='Documents per vertex type.')
class-attribute
instance-attribute
¶
Functions:¶
define_schema(schema, conn_conf, recreate)
¶
Define schema on the target, or reuse its definition; True when defined.
Source code in graflo/hq/container_write.py
edge_label(edge_id)
¶
write_container(schema, container, conn_conf, *, pending=(), recreate_schema=False, ambiguity='skip', stamp=None, guard=None)
async
¶
Define schema on the target and upsert container by identity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
The schema every document conforms to. Never mutated. |
required |
container
|
GraphContainer
|
Vertices and edges keyed by primary identity. Never mutated. |
required |
conn_conf
|
DBConfig
|
The target database. |
required |
pending
|
Sequence[PendingEdge]
|
Edges with an endpoint known only by a secondary identity; each is looked up in the target once container is written, and written when found. |
()
|
recreate_schema
|
bool
|
Drop and redefine the schema instead of reusing it. |
False
|
ambiguity
|
EndpointAmbiguityPolicy
|
What a secondary identity matching several vertices does.
|
'skip'
|
stamp
|
Mapping[str, Any] | None
|
Values of the schema's reserved fields, set on everything
written, pending edges included ( |
None
|
guard
|
FilterExpression | None
|
A trusted read guard every pending lookup must pass, so an endpoint is never resolved to a vertex the guard hides; refused, before anything is written, by a backend without read guards. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ContainerWriteReport |
ContainerWriteReport
|
counts of what was sent and what was looked up. |
Source code in graflo/hq/container_write.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |