Add the abliity to send a schema write request
This commit is contained in:
parent
aadc8520bb
commit
3b4667d9c8
4 changed files with 42 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
|||
import enum
|
||||
import logging
|
||||
import socket
|
||||
from typing import Tuple
|
||||
from typing import Mapping, Tuple, Type
|
||||
import urllib.parse
|
||||
|
||||
from proto import control_pb2
|
||||
|
@ -21,6 +21,11 @@ DATA_FORMATS = ",".join([
|
|||
"json",
|
||||
])
|
||||
|
||||
PYTHON_TYPE_TO_SCHEMA_TYPE = {
|
||||
str: control_pb2.SchemaEntry.STRING,
|
||||
int: control_pb2.SchemaEntry.INT,
|
||||
}
|
||||
|
||||
# The types of access that are allowed with this connection
|
||||
class Permissions(enum.Enum):
|
||||
pass
|
||||
|
@ -62,6 +67,18 @@ class Connection:
|
|||
def send(self, data):
|
||||
self.socket.send(data)
|
||||
|
||||
def write_schema(self, table_name: str, schema: Mapping[str, Type]) -> None:
|
||||
"Send a command to write the given schema."
|
||||
command = control_pb2.Command(
|
||||
type=control_pb2.Command.Type.SCHEMA_WRITE,
|
||||
table_name=table_name,
|
||||
)
|
||||
for k, v in schema.items():
|
||||
entry = command.schema_entry.add()
|
||||
entry.name = k
|
||||
entry.type = PYTHON_TYPE_TO_SCHEMA_TYPE[v]
|
||||
self.socket.send(command.SerializeToString())
|
||||
|
||||
def _handshake(self):
|
||||
"Handshake with the server, ensure we have all the data we need."
|
||||
fields = [MAGIC, DATA_FORMATS, self.namespace, self.app_name, self.app_version, self.public_key,]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue