File: stdlib_jsonb.py

package info (click to toggle)
py-postgresql 1.2.1%2Bgit20180803.ef7b9a9-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,620 kB
  • sloc: python: 18,317; ansic: 2,024; sql: 282; sh: 26; makefile: 22
file content (24 lines) | stat: -rw-r--r-- 459 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from ...types import JSONBOID


def jsonb_pack(x, typeio):
	jsonb = typeio.encode(x)
	return b'\x01' + jsonb


def jsonb_unpack(x, typeio):
	if x[0] != 1:
		raise ValueError('unexpected JSONB format version: {!r}'.format(x[0]))
	return typeio.decode(x[1:])


def _jsonb_io_factory(oid, typeio):
	_pack = lambda x: jsonb_pack(x, typeio)
	_unpack = lambda x: jsonb_unpack(x, typeio)

	return (_pack, _unpack, str)


oid_to_io = {
	JSONBOID: _jsonb_io_factory
}