def spec_to_json(spec: spec.Spec): dct = {} for setting in spec.values(): if issubclass(setting.type, str): typeid = s_obj.get_known_type_id('std::str') elif issubclass(setting.type, bool): typeid = s_obj.get_known_type_id('std::bool') elif issubclass(setting.type, int): typeid = s_obj.get_known_type_id('std::int64') elif issubclass(setting.type, types.ConfigType): typeid = setting.type.get_edgeql_typeid() elif issubclass(setting.type, statypes.Duration): typeid = s_obj.get_known_type_id('std::duration') elif issubclass(setting.type, statypes.ConfigMemory): typeid = s_obj.get_known_type_id('cfg::memory') else: raise RuntimeError( f'cannot serialize type for config setting {setting.name}') typemod = qltypes.TypeModifier.SingletonType if setting.set_of: typemod = qltypes.TypeModifier.SetOfType dct[setting.name] = { 'default': value_to_json_value(setting, setting.default), 'internal': setting.internal, 'system': setting.system, 'typeid': str(typeid), 'typemod': str(typemod), 'backend_setting': setting.backend_setting, 'report': setting.report, } return json.dumps(dct)
def spec_to_json(spec: spec.Spec): dct = {} for setting in spec.values(): if issubclass(setting.type, str): typeid = s_obj.get_known_type_id('std::str') elif issubclass(setting.type, bool): typeid = s_obj.get_known_type_id('std::bool') elif issubclass(setting.type, int): typeid = s_obj.get_known_type_id('std::int64') elif issubclass(setting.type, types.ConfigType): typeid = setting.type.get_edgeql_typeid() else: raise RuntimeError( f'cannot serialize type for config setting {setting.name}') typemod = qltypes.TypeModifier.SINGLETON if setting.set_of: typemod = qltypes.TypeModifier.SET_OF dct[setting.name] = { 'default': value_to_json_value(setting, setting.default), 'internal': setting.internal, 'system': setting.system, 'typeid': str(typeid), 'typemod': str(typemod), } return json.dumps(dct)
def _get_id(cls, data): if data['collection'] == 'tuple' and not data['subtypes']: return s_obj.get_known_type_id('empty-tuple') if data['name'] == 'anytype': return s_obj.get_known_type_id('anytype') # A type desc node is uniquely identified by it's type, # and the name and position within a parent type. id_str = f"{data['maintype']!r}::{data['name']!r}::{data['position']}" return uuid.uuid5(s_types.TYPE_ID_NAMESPACE, id_str)
def _describe_json(cls) -> bytes: json_id = s_obj.get_known_type_id('std::str') buf = [] buf.append(b'\x02') buf.append(json_id.bytes) return b''.join(buf), json_id
def _describe_json(cls) -> typing.Tuple[bytes, uuid.UUID]: json_id = s_obj.get_known_type_id('std::str') buf = [] buf.append(b'\x02') buf.append(json_id.bytes) return b''.join(buf), json_id
def _get_collection_type_id(self, coll_type, subtypes, element_names=None): if coll_type == 'tuple' and not subtypes: return s_obj.get_known_type_id('empty-tuple') subtypes = (f"{st}" for st in subtypes) string_id = f'{coll_type}\x00{":".join(subtypes)}' if element_names: string_id += f'\x00{":".join(element_names)}' return uuidgen.uuid5(s_types.TYPE_ID_NAMESPACE, string_id)
def _unpack_typedesc_node(self, typemap, id, schema): t = typemap[id] if t['collection'] is not None: coll_type = s_types.Collection.get_class(t['collection']) subtypes = [] for stid in t['subtypes']: schema, *s = self._unpack_typedesc_node(typemap, stid, schema) subtypes.append(s) if t['dimensions']: typemods = (t['dimensions'],) else: typemods = None named = all(s[0] is not None for s in subtypes) if issubclass(coll_type, s_abc.Tuple) and named: st = dict(subtypes) typemods = {'named': named} else: st = [st[1] for st in subtypes] schema, scls = coll_type.from_subtypes( schema, st, typemods=typemods, is_persistent=True, ) elif t['maintype'] == 'anytype': scls = s_pseudo.Any.get(schema) elif t['maintype'] == 'anytuple': scls = s_pseudo.AnyTuple.get(schema) else: type_id = t['maintype'] if type_id == s_obj.get_known_type_id('anytype'): scls = s_pseudo.Any.get(schema) elif type_id == s_obj.get_known_type_id('anytuple'): scls = s_pseudo.AnyTuple.get(schema) else: scls = schema.get_by_id(t['maintype']) return schema, t['name'], scls
def test_server_config_05(self): j = ops.spec_to_json(testspec1) self.assertEqual( json.loads(j)['bool'], { 'default': True, 'internal': False, 'system': False, 'typemod': 'SINGLETON', 'typeid': str(s_obj.get_known_type_id('std::bool')), })
def test_server_config_05(self): j = ops.spec_to_json(testspec1) self.assertEqual( json.loads(j)['bool'], { 'backend_setting': None, 'default': True, 'internal': False, 'system': False, 'report': False, 'typemod': 'SingletonType', 'typeid': str(s_obj.get_known_type_id('std::bool')), })
from edb import errors from edb.common import binwrapper from edb.common import uuidgen from edb.schema import links as s_links from edb.schema import objects as s_obj from edb.schema import types as s_types _int32_packer = struct.Struct('!l').pack _uint32_packer = struct.Struct('!L').pack _uint16_packer = struct.Struct('!H').pack _uint8_packer = struct.Struct('!B').pack EMPTY_TUPLE_ID = s_obj.get_known_type_id('empty-tuple').bytes EMPTY_TUPLE_DESC = b'\x04' + EMPTY_TUPLE_ID + b'\x00\x00' UUID_TYPE_ID = s_obj.get_known_type_id('std::uuid') NULL_TYPE_ID = b'\x00' * 16 NULL_TYPE_DESC = b'' CTYPE_SET = b'\x00' CTYPE_SHAPE = b'\x01' CTYPE_BASE_SCALAR = b'\x02' CTYPE_SCALAR = b'\x03' CTYPE_TUPLE = b'\x04' CTYPE_NAMEDTUPLE = b'\x05' CTYPE_ARRAY = b'\x06' CTYPE_ENUM = b'\x07'
from typing import * from edb.ir import ast as irast from edb.ir import typeutils as irtyputils from edb.schema import abc as s_abc from edb.schema import scalars as s_scalars from edb.schema import objtypes as s_objtypes from edb.schema import name as sn from edb.schema import objects as s_obj from edb.schema import schema as s_schema from . import common base_type_name_map = { s_obj.get_known_type_id('std::str'): ('text', ), s_obj.get_known_type_id('std::int64'): ('int8', ), s_obj.get_known_type_id('std::int32'): ('int4', ), s_obj.get_known_type_id('std::int16'): ('int2', ), s_obj.get_known_type_id('std::decimal'): ('numeric', ), s_obj.get_known_type_id('std::bigint'): ('edgedb', 'bigint_t'), s_obj.get_known_type_id('std::bool'): ('bool', ), s_obj.get_known_type_id('std::float64'): ('float8', ), s_obj.get_known_type_id('std::float32'): ('float4', ), s_obj.get_known_type_id('std::uuid'): ('uuid', ), s_obj.get_known_type_id('std::datetime'): ('edgedb', 'timestamptz_t'), s_obj.get_known_type_id('std::duration'): ( 'edgedb', 'duration_t', ), s_obj.get_known_type_id('std::bytes'): ('bytea', ),
from edb.ir import ast as irast from edb.ir import typeutils as irtyputils from edb.schema import abc as s_abc from edb.schema import scalars as s_scalars from edb.schema import objtypes as s_objtypes from edb.schema import name as sn from edb.schema import objects as s_obj from edb.schema import schema as s_schema from edb.schema import types as s_types from . import common from .common import quote_literal as ql base_type_name_map = { s_obj.get_known_type_id('std::str'): 'text', s_obj.get_known_type_id('std::int64'): 'bigint', s_obj.get_known_type_id('std::int32'): 'integer', s_obj.get_known_type_id('std::int16'): 'smallint', s_obj.get_known_type_id('std::decimal'): 'numeric', s_obj.get_known_type_id('std::bool'): 'boolean', s_obj.get_known_type_id('std::float64'): 'float8', s_obj.get_known_type_id('std::float32'): 'float4', s_obj.get_known_type_id('std::uuid'): 'uuid', s_obj.get_known_type_id('std::datetime'): 'timestamptz', s_obj.get_known_type_id('std::local_datetime'): 'timestamp', s_obj.get_known_type_id('std::local_date'): 'date', s_obj.get_known_type_id('std::local_time'): 'time', s_obj.get_known_type_id('std::duration'): 'interval', s_obj.get_known_type_id('std::bytes'): 'bytea', s_obj.get_known_type_id('std::json'): 'jsonb',
from edb.schema import links as s_links from edb.schema import objects as s_obj from edb.schema import objtypes as s_objtypes from edb.schema import scalars as s_scalars from edb.schema import schema as s_schema from edb.schema import types as s_types from . import enums _int32_packer = struct.Struct('!l').pack _uint32_packer = struct.Struct('!L').pack _uint16_packer = struct.Struct('!H').pack _uint8_packer = struct.Struct('!B').pack EMPTY_TUPLE_ID = s_obj.get_known_type_id('empty-tuple') EMPTY_TUPLE_DESC = b'\x04' + EMPTY_TUPLE_ID.bytes + b'\x00\x00' UUID_TYPE_ID = s_obj.get_known_type_id('std::uuid') STR_TYPE_ID = s_obj.get_known_type_id('std::str') NULL_TYPE_ID = uuidgen.UUID(b'\x00' * 16) NULL_TYPE_DESC = b'' CTYPE_SET = b'\x00' CTYPE_SHAPE = b'\x01' CTYPE_BASE_SCALAR = b'\x02' CTYPE_SCALAR = b'\x03' CTYPE_TUPLE = b'\x04' CTYPE_NAMEDTUPLE = b'\x05' CTYPE_ARRAY = b'\x06'
def get_edgeql_typeid(cls): return s_obj.get_known_type_id('std::json')
def is_bytes(typeref: irast.TypeRef) -> bool: """Return True if *typeref* describes the bytes type.""" return typeref.real_base_type.id == s_obj.get_known_type_id('std::bytes')