aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/disk.ml20
-rw-r--r--lib/protocol.ml2
-rw-r--r--lib/server.ml13
3 files changed, 28 insertions, 7 deletions
diff --git a/lib/disk.ml b/lib/disk.ml
index 8d9d062..6996b2d 100644
--- a/lib/disk.ml
+++ b/lib/disk.ml
@@ -129,6 +129,8 @@ module Executor = struct
(tup2 (list string) string)
end
+ open Sexplib0.Sexp_conv
+
type relational_type =
| Text
| Integer32
@@ -137,7 +139,7 @@ module Executor = struct
(* | DiscriminatedUnion of (string * relational_type option) list * string *)
(* [("MemberA", None); ("MemberB", Some Integer32)], "NameOfDU" *)
| Relation of string
- [@@deriving show]
+ [@@deriving show, sexp]
type relational_literal =
| LText of string
@@ -443,7 +445,13 @@ module Command = struct
type': Executor.relational_type;
}
- type t = SequentialRead of { relation_name : string }
+ open Sexplib0.Sexp_conv
+
+ type t =
+ | SequentialRead of { relation_name : string }
+ | SpecifyRelation of { relation_name: string;
+ attributes: (string*Executor.relational_type) list }
+ [@@deriving sexp]
let command_encoding =
conv
@@ -526,9 +534,13 @@ module Command = struct
| Some _, None -> Error "Cannot write an entity without its referential."
| None, _ -> Ok ((commit, locations), Nothing)
- let perform (commit : Executor.commit) (locations : Executor.locations)
- (command : t) =
+ let perform (commit : Executor.commit) (locations : Executor.locations) (command : t) =
match command with
+ | SpecifyRelation {relation_name; attributes} ->
+ (* If it already exists under the relation name key, it will be replaced *)
+ Ok (({ commit with
+ schema = commit.schema
+ |> Executor.StringMap.add relation_name attributes}, locations), Nothing)
| SequentialRead { relation_name } ->
let relation_name = List.hd @@ String.split_on_char '/' relation_name in
let entities : (string * Executor.relational_type * string) list Executor.IntMap.t =
diff --git a/lib/protocol.ml b/lib/protocol.ml
index 79ed8d0..5fe29d1 100644
--- a/lib/protocol.ml
+++ b/lib/protocol.ml
@@ -3,6 +3,8 @@ open Sexplib0.Sexp_conv
type tuple = string list [@@deriving sexp, protocol ~driver:(module Xml_light)]
+type command = Disk.Command.t [@@deriving sexp]
+
type relation = {
attribute_name : string;
attribute_type : string;
diff --git a/lib/server.ml b/lib/server.ml
index 4a99b29..4af94fb 100644
--- a/lib/server.ml
+++ b/lib/server.ml
@@ -25,9 +25,16 @@ let client_read sock maxlen =
let acc = acc ^ Bytes.to_string (Bytes.sub str 0 recvlen) in
if recvlen <= maxlen then Lwt.return acc else _read sock acc
in
- _read sock String.empty >>= fun _ ->
- match Relation.write_and_retrieve () with
- | Ok (last_commit, locations) ->
+ _read sock String.empty >>= fun x ->
+ print_string "RECEIVED: ";
+ print_endline x;
+ let command = Protocol.command_of_sexp (Sexplib0.Sexp_conv.sexp_of_string x) in
+ match
+ (* Relation.write_and_retrieve () *)
+ command
+ with
+ | Disk.Command.SequentialRead {relation}
+ (* | Ok (last_commit, locations) -> *)
(* let (first_names, last_names) = (Planner.Scan.execute last_commit locations "user/first-name", Planner.Scan.execute last_commit locations "user/last-name") in *)
(* let tuples = Planner.Join.execute first_names last_names locations in *)
let fname, lname = List.split [] in