MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _serialize_hstore

Function _serialize_hstore

lib/sqlalchemy/dialects/postgresql/hstore.py:404–422  ·  view source on GitHub ↗

Serialize a dictionary into an hstore literal. Keys and values must both be strings (except None for values).

(val: _HSTORE_VAL)

Source from the content-addressed store, hash-verified

402
403
404def _serialize_hstore(val: _HSTORE_VAL) -> str:
405 """Serialize a dictionary into an hstore literal. Keys and values must
406 both be strings (except None for values).
407
408 """
409
410 def esc(s: Optional[str], position: str) -> str:
411 if position == "value" and s is None:
412 return "NULL"
413 elif isinstance(s, str):
414 return '"%s"' % s.replace("\\", "\\\\").replace('"', r"\"")
415 else:
416 raise ValueError(
417 "%r in %s position is not a string." % (s, position)
418 )
419
420 return ", ".join(
421 "%s=>%s" % (esc(k, "key"), esc(v, "value")) for k, v in val.items()
422 )

Callers 2

deleteMethod · 0.85
processMethod · 0.85

Calls 3

escFunction · 0.85
joinMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected