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

DRAFT: Check for correct role when setting a value

parent 50cf9d24
No related branches found
No related tags found
1 merge request!7ENH: Implement queries and entity retrieval
......@@ -251,6 +251,8 @@ end
name::AbstractString = "",
datatype::AbstractString = "",
unit::AbstractString = "",
is_reference::Bool = false,
is_list::Bool = false,
)
Return a new entity object with role Record. If `name`, `datatype`, or
......@@ -284,12 +286,17 @@ end
function create_property(;
name::AbstractString = "",
id::AbstractString = "",
value::AbstractString = "",
value::Union{AbstractString, Number, Bool} = "",
datatype::AbstractString = "",
is_reference::Bool = false,
is_list::Bool = false,
)
Create a property object that can be appended to another `_Entity`. If
`name`, `id`, or `value` are given, the property's name, id, or value
are set accordingly.
are set accordingly. The datatype and whether it is a list or a
reference can be specified with `datatype`, `is_reference`, and
`is_list`, respectively.
!!! info
......@@ -299,7 +306,7 @@ are set accordingly.
function create_property(;
name::AbstractString = "",
id::AbstractString = "",
value::AbstractString = "",
value::Union{AbstractString,Number,Bool} = "",
datatype::AbstractString = "",
is_reference::Bool = false,
is_list::Bool = false,
......@@ -1518,13 +1525,23 @@ function set_unit(property::Ref{_Property}, unit::AbstractString)
end
# TODO(henrik, daniel) overload to choose the correct set
# function. Should throw an error for entities with role != PROPERTY.
# function.
"""
function set_value(entity::Ref{_Entity}, value::AbstractString)
Set the value of the given `entity` object.
Set the value of the given `entity` object. Throw an error if it
doesn't have the correct role.
"""
function set_value(entity::Ref{_Entity}, value::AbstractString)
if get_role(entity) != "PROPERTY"
throw(
CaosDB.Exceptions.ClientException(
"Only entites with role PROPERTY may be assigned a value.",
),
)
end
err_code = ccall(
(:caosdb_entity_entity_set_value, CaosDB.library_name),
Cint,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment