Skip to content
Snippets Groups Projects
Commit 50cf9d24 authored by florian's avatar florian
Browse files

ENH: Add `is_list` and `is_reference` to property creators

parent eb57ac6c
No related branches found
No related tags found
1 merge request!7ENH: Implement queries and entity retrieval
This commit is part of merge request !7. Comments created here will be created in the context of that merge request.
...@@ -80,10 +80,10 @@ using CaosDB ...@@ -80,10 +80,10 @@ using CaosDB
# and C++ only understand all-capital strings for datatypes, # and C++ only understand all-capital strings for datatypes,
# importances, roles. What about user input like "record_type", # importances, roles. What about user input like "record_type",
# "RecordType", "recordtype"? # "RecordType", "recordtype"?
""" """
Struct containing a pointer to the wrapped cpp entity Struct containing a pointer to the wrapped cpp entity
object. Meant for internal use; use `CaosDB.Entity.create_entity` to object. Meant for internal use; use `CaosDB.Entity.create_entity` to
create an entity. create an entity.
""" """
mutable struct _Entity mutable struct _Entity
wrapped_entity::Ptr{Cvoid} wrapped_entity::Ptr{Cvoid}
...@@ -111,10 +111,10 @@ mutable struct _Entity ...@@ -111,10 +111,10 @@ mutable struct _Entity
end end
""" """
Struct containing a pointer to the wrapped cpp parent Struct containing a pointer to the wrapped cpp parent
object. Meant for internal use; use `CaosDB.Entity.create_parent` to object. Meant for internal use; use `CaosDB.Entity.create_parent` to
create an parent. create an parent.
""" """
mutable struct _Parent mutable struct _Parent
wrapped_parent::Ptr{Cvoid} wrapped_parent::Ptr{Cvoid}
...@@ -142,10 +142,10 @@ mutable struct _Parent ...@@ -142,10 +142,10 @@ mutable struct _Parent
end end
""" """
Struct containing a pointer to the wrapped cpp property Struct containing a pointer to the wrapped cpp property
object. Meant for internal use; use `CaosDB.Entity.create_property` to object. Meant for internal use; use `CaosDB.Entity.create_property` to
create an property. create an property.
""" """
mutable struct _Property mutable struct _Property
wrapped_property::Ptr{Cvoid} wrapped_property::Ptr{Cvoid}
...@@ -254,12 +254,15 @@ end ...@@ -254,12 +254,15 @@ end
) )
Return a new entity object with role Record. If `name`, `datatype`, or Return a new entity object with role Record. If `name`, `datatype`, or
`unit` were provided, its name, datatype, or unit are set accordingly. `unit` were provided, its name, datatype (including whether it is a
reference or a list), or unit are set accordingly.
""" """
function create_property_entity(; function create_property_entity(;
name::AbstractString = "", name::AbstractString = "",
datatype::AbstractString = "", datatype::AbstractString = "",
unit::AbstractString = "", unit::AbstractString = "",
is_reference::Bool = false,
is_list::Bool = false,
) )
property = create_entity(name) property = create_entity(name)
...@@ -267,7 +270,7 @@ function create_property_entity(; ...@@ -267,7 +270,7 @@ function create_property_entity(;
set_role(property, "PROPERTY") set_role(property, "PROPERTY")
if datatype != "" if datatype != ""
set_datatype(property, datatype) set_datatype(property, datatype, is_list = is_list, is_reference = is_reference)
end end
if unit != "" if unit != ""
...@@ -297,6 +300,9 @@ function create_property(; ...@@ -297,6 +300,9 @@ function create_property(;
name::AbstractString = "", name::AbstractString = "",
id::AbstractString = "", id::AbstractString = "",
value::AbstractString = "", value::AbstractString = "",
datatype::AbstractString = "",
is_reference::Bool = false,
is_list::Bool = false,
) )
property = Ref{_Property}(_Property(true)) property = Ref{_Property}(_Property(true))
...@@ -317,6 +323,10 @@ function create_property(; ...@@ -317,6 +323,10 @@ function create_property(;
set_id(property, id) set_id(property, id)
end end
if datatype != ""
set_datatype(property, datatype, is_reference = is_reference, is_list = is_list)
end
if value != "" if value != ""
set_value(property, value) set_value(property, value)
end end
...@@ -609,7 +619,7 @@ end ...@@ -609,7 +619,7 @@ end
function get_datatype(entity::Ref{_Entity}) function get_datatype(entity::Ref{_Entity})
Return a tuple that contains the name of the datatype of the given Return a tuple that contains the name of the datatype of the given
`entity`, whether it is a reference, and whether it is a list. `entity`, whether it is a reference, and whether it is a list.
""" """
function get_datatype(entity::Ref{_Entity}) function get_datatype(entity::Ref{_Entity})
...@@ -1264,7 +1274,7 @@ to set the id of entities. ...@@ -1264,7 +1274,7 @@ to set the id of entities.
function set_id(entity::Ref{_Entity}, id::AbstractString) function set_id(entity::Ref{_Entity}, id::AbstractString)
throw( throw(
CaosDB.Exceptions.ClientException( CaosDB.Exceptions.ClientException(
"You cannot set the id of an entity object. "You cannot set the id of an entity object.
If you want to update an entity with this id, you have to retrieve it first.", If you want to update an entity with this id, you have to retrieve it first.",
), ),
) )
...@@ -1396,7 +1406,7 @@ end ...@@ -1396,7 +1406,7 @@ end
# too? # too?
""" """
function set_datatype( function set_datatype(
entity::Ref{_Entity}, entity::Ref{_Entity},
datatype::AbstractString; datatype::AbstractString;
is_list::Bool = false, is_list::Bool = false,
is_reference::Bool = false, is_reference::Bool = false,
...@@ -1440,7 +1450,7 @@ end ...@@ -1440,7 +1450,7 @@ end
""" """
function set_datatype( function set_datatype(
property::Ref{_Property}, property::Ref{_Property},
datatype::AbstractString; datatype::AbstractString;
is_list::Bool = false, is_list::Bool = false,
is_reference::Bool = false, is_reference::Bool = false,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment