diff --git a/.ocamlformat b/.ocamlformat new file mode 100644 index 0000000..78e716a --- /dev/null +++ b/.ocamlformat @@ -0,0 +1,10 @@ +profile = janestreet + +margin = 100 +doc-comments-padding = 100 +exp-grouping = preserve +break-string-literals = never + +module-item-spacing = preserve +exp-grouping = preserve +sequence-blank-line = preserve diff --git a/dune-project b/dune-project index eb73cd8..682ca2b 100644 --- a/dune-project +++ b/dune-project @@ -10,10 +10,14 @@ (documentation https://url/to/documentation) (package (name lithos) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml) - (tags - ("add topics" "to describe" your project))) + (synopsis "Embedded key-value database inspired by BoltDB") + (description "Lithos is an embedded, transactional key-value database written in OCaml. It provides MVCC with single-writer/multi-reader semantics and a functional API.") + (depends + (ocaml (>= 4.14)) + dune + (cmdliner (>= 1.2.0)) + (alcotest :with-test) + (odoc :with-doc)) + (tags (database "key-value" embedded transactional MVCC))) ; See https://dune.readthedocs.io/en/stable/reference/dune-project/index.html diff --git a/lib/dune b/lib/dune index f4f6842..ed5cadd 100644 --- a/lib/dune +++ b/lib/dune @@ -1,2 +1,3 @@ (library - (name lithos)) + (name lithos) + (libraries unix)) diff --git a/lib/error.ml b/lib/error.ml new file mode 100644 index 0000000..765e949 --- /dev/null +++ b/lib/error.ml @@ -0,0 +1,16 @@ +(** Error types for Lithos database operations *) + +type t = + | IO_error of string + | Invalid_database of string + | Database_locked + | Not_found + +let to_string = function + | IO_error msg -> Printf.sprintf "I/O error: %s" msg + | Invalid_database msg -> Printf.sprintf "Invalid database: %s" msg + | Database_locked -> "Database is locked" + | Not_found -> "Not found" +;; + +let of_unix_error err path = IO_error (Printf.sprintf "%s: %s" (Unix.error_message err) path) diff --git a/lib/error.mli b/lib/error.mli new file mode 100644 index 0000000..8f530c6 --- /dev/null +++ b/lib/error.mli @@ -0,0 +1,13 @@ +(** Error types for Lithos database operations *) + +type t = + | IO_error of string + | Invalid_database of string + | Database_locked + | Not_found + +(** Convert error to human-readable string *) +val to_string : t -> string + +(** Create an I/O error from a Unix error *) +val of_unix_error : Unix.error -> string -> t diff --git a/lithos.opam b/lithos.opam index e69de29..bb18b42 100644 --- a/lithos.opam +++ b/lithos.opam @@ -0,0 +1,35 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +synopsis: "Embedded key-value database inspired by BoltDB" +description: + "Lithos is an embedded, transactional key-value database written in OCaml. It provides MVCC with single-writer/multi-reader semantics and a functional API." +maintainer: ["Owais J "] +authors: ["Owais J "] +license: "MIT" +tags: ["database" "key-value" "embedded" "transactional" "MVCC"] +homepage: "https://github.com/desertthunder/lithos" +doc: "https://url/to/documentation" +bug-reports: "https://github.com/desertthunder/lithos/issues" +depends: [ + "ocaml" {>= "4.14"} + "dune" {>= "3.18"} + "cmdliner" {>= "1.2.0"} + "alcotest" {with-test} + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/desertthunder/lithos.git" +x-maintenance-intent: ["(latest)"] diff --git a/test/dune b/test/dune index 0c0f20e..208a81a 100644 --- a/test/dune +++ b/test/dune @@ -1,2 +1,3 @@ (test - (name test_lithos)) + (name test_lithos) + (libraries lithos alcotest)) diff --git a/test/test_error.ml b/test/test_error.ml new file mode 100644 index 0000000..3089214 --- /dev/null +++ b/test/test_error.ml @@ -0,0 +1,27 @@ +(** Tests for Error module *) + +let test_to_string () = + let open Lithos.Error in + Alcotest.(check string) + "IO_error message" + "I/O error: file not found" + (to_string (IO_error "file not found")); + Alcotest.(check string) + "Invalid_database message" + "Invalid database: bad header" + (to_string (Invalid_database "bad header")); + Alcotest.(check string) "Database_locked message" "Database is locked" (to_string Database_locked); + Alcotest.(check string) "Not_found message" "Not found" (to_string Not_found) +;; + +let test_of_unix_error () = + let open Lithos.Error in + let err = of_unix_error Unix.ENOENT "/tmp/test.db" in + let msg = to_string err in + Alcotest.(check bool) + "Unix error contains path" + true + (String.length msg > 0 && String.contains msg '/') +;; + +let suite = [ "to_string", `Quick, test_to_string; "of_unix_error", `Quick, test_of_unix_error ] diff --git a/test/test_lithos.ml b/test/test_lithos.ml index e69de29..edbbdb6 100644 --- a/test/test_lithos.ml +++ b/test/test_lithos.ml @@ -0,0 +1,3 @@ +(** Main test suite for Lithos *) + +let () = Alcotest.run "Lithos" [ "Error", Test_error.suite ]