From 13b092969026b251ab16e6dddd224f4fed83d54d Mon Sep 17 00:00:00 2001
From: florian <f.spreckelsen@inidscale.com>
Date: Mon, 20 Sep 2021 14:22:52 +0200
Subject: [PATCH] ENH: ADD enums for datatype, importance, role, and collection

---
 src/CaosDB.jl    |  2 +-
 src/Constants.jl | 42 +++++++++++++++++++++++++++++++++++++++++-
 src/Entity.jl    | 12 +++++++-----
 3 files changed, 49 insertions(+), 7 deletions(-)

diff --git a/src/CaosDB.jl b/src/CaosDB.jl
index e15b46d..cbcd567 100644
--- a/src/CaosDB.jl
+++ b/src/CaosDB.jl
@@ -29,7 +29,7 @@ export evaluate_return_code,
     CaosDBException, ClientException, GenericCaosDBException, CaosDBMessage
 
 # Exports from module Constants
-export MIN_CCAOSDB_VERSION
+export COLLECTION, DATATYPE, IMPORTANCE, MIN_CCAOSDB_VERSION, ROLE
 
 # Exports from module Utility
 export get_ccaosdb_version, get_env_fallback
diff --git a/src/Constants.jl b/src/Constants.jl
index 70b244e..4d3972e 100644
--- a/src/Constants.jl
+++ b/src/Constants.jl
@@ -23,7 +23,7 @@
 
 module Constants
 
-export MIN_CCAOSDB_VERSION
+export COLLECTION, DATATYPE, IMPORTANCE, MIN_CCAOSDB_VERSION, ROLE
 
 """
 The minimum version of CaosDB's cpplib and C interface that is
@@ -31,4 +31,44 @@ supported by this version of CaosDB.jl.
 """
 const MIN_CCAOSDB_VERSION = v"0.0.17"
 
+# enums have to be encapsulated in modules to prevent namespce conflicts, see
+# https://bleepcoder.com/julia/413856244/feature-request-getproperty-on-enum-type-to-access-instances
+module DATATYPE
+@enum _DATATYPE begin
+    UNSPECIFIED
+    BOOLEAN
+    INTEGER
+    DOUBLE
+    DATETIME
+    TEXT
+end
+end
+
+module COLLECTION
+@enum _COLLECTION begin
+    SCALAR
+    LIST
+end
+end
+
+module ROLE
+@enum _ROLE begin
+    UNSPECIFIED
+    RECORD
+    RECORD_TYPE
+    PROPERTY
+    FILE
+end
+end
+
+module IMPORTANCE
+@enum _IMPORTANCE begin
+    UNSPECIFIED
+    OBLIGATORY
+    RECOMMENDED
+    SUGGESTED
+    FIX
+end
+end
+
 end
diff --git a/src/Entity.jl b/src/Entity.jl
index ee18834..ae7fbb0 100644
--- a/src/Entity.jl
+++ b/src/Entity.jl
@@ -200,7 +200,7 @@ Struct containing a pointer to the wrapped cpp DataType object. Meant for
 internal use only; use `CaosDB.Entity.create_<type>_datatype` to create a
 valid _DataType object or use the `set/get_datatype` functions.
 """
-mutable struct _DatatType
+mutable struct _DataType
     wrapped_datatype::Ptr{Cvoid}
     _deletable::Bool
 
@@ -214,7 +214,7 @@ mutable struct _DatatType
                 ccall(
                     (:caosdb_entity_delete_datatype, CaosDB.library_name),
                     Cint,
-                    (Ref{_DatatType},),
+                    (Ref{_DataType},),
                     Ref{_DataType}(t),
                 )
             end
@@ -568,7 +568,7 @@ function create_list_of_reference_datatype(name::AbstractString)
 end
 
 function create_value(
-    value::Union{AbstractString,Number,Bool,Vactor{T}},
+    value::Union{AbstractString,Number,Bool,Vector{T}},
 ) where {T<:Union{AbstractString,Number,Bool}}
 
     in_type = typeof(value)
@@ -643,8 +643,10 @@ function create_value(
         )
     else
         # Should never enter here but treat it just in case
-        @throw ArgumentError(
-            "The argument of type $in_type couldn't be converted into a valid CaosDB value object.",
+        throw(
+            ArgumentError(
+                "The argument of type $in_type couldn't be converted into a valid CaosDB value object.",
+            ),
         )
     end
 
-- 
GitLab