From 998cf183c45e604430b4a80425bd2332fb30cfe1 Mon Sep 17 00:00:00 2001 From: Marcos Magueta Date: Sun, 29 Jun 2025 01:33:13 -0300 Subject: base serialization and command reorganization --- .envrc | 1 + README.org | 3 +++ client.el | 2 +- lib/disk.ml | 20 ++++++++++++++++---- lib/protocol.ml | 2 ++ lib/server.ml | 13 ++++++++++--- sources/Geometry64x64.png | Bin 0 -> 1017 bytes 7 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 .envrc create mode 100644 sources/Geometry64x64.png diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/README.org b/README.org index dcd2b7c..737ae19 100644 --- a/README.org +++ b/README.org @@ -4,6 +4,9 @@ This is a relational engine. * Roadmap +- [ ] State + - [ ] Add the schema modifications to the commit state hash + - [ ] Save a history of the schema - [ ] Filesystem [0/6] - [ ] Durability - [ ] Immutable storage diff --git a/client.el b/client.el index bb8eaa7..8656306 100644 --- a/client.el +++ b/client.el @@ -8,7 +8,7 @@ (message "Received: %s" response) (delete-process process))) -(setq relational-engine-address "localhost") +(setq relational-engine-address "/tmp/relational_engine.socket") (setq relational-engine-port 7524) (defun relational-client (content) 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 diff --git a/sources/Geometry64x64.png b/sources/Geometry64x64.png new file mode 100644 index 0000000..d256e49 Binary files /dev/null and b/sources/Geometry64x64.png differ -- cgit v1.2.3