diff --git a/src/Entity.jl b/src/Entity.jl index 8e059a614c2ad36482b16b5ccf6b99e4b8788282..8c9d44313e0af44c799e200024fa243d630d18a3 100644 --- a/src/Entity.jl +++ b/src/Entity.jl @@ -144,4 +144,150 @@ function create_entity(name::AbstractString = "") end +""" + function create_recordtype(name::AbstractString = "") + +Return a new entity object with role RecordType. If a `name` was +provided, its name is set accordingly. +""" +function create_recordtype(name::AbstractString = "") + + record_type = create_entity(name) + + set_role(record_type, "RecordType") + + return record_type + +end + +""" + function create_record(name::AbstractString = "") + +Return a new entity object with role Record. If a `name` was provided, +its name is set accordingly. +""" +function create_record(name::AbstractString = "") + + record = create_entity(name) + + set_role(record, "Record") + + return record + +end + +""" + function create_property_entity(; + name::AbstractString = "", + datatype::AbstractString = "", + unit::AbstractString = "", + ) + +Return a new entity object with role Record. If `name`, `datatype`, or +`unit` were provided, its name, datatype, or unit are set accordingly. +""" +function create_property_entity(; + name::AbstractString = "", + datatype::AbstractString = "", + unit::AbstractString = "", +) + + property = create_entity(name) + + set_role(property, "Property") + + if datatype != "" + set_datatype(property, datatype) + end + + if unit != "" + set_unit(property, unit) + end + + return property +end + +""" + function create_property(; + name::AbstractString = "", + id::AbstractString = "", + value::AbstractString = "", + ) + +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. + +!!! info + + This is not an `_Entity` that could be inserted or updated by its + own but a `_Property` that is to be appended to another `_Entity`. +""" +function create_property(; + name::AbstractString = "", + id::AbstractString = "", + value::AbstractString = "", +) + property = Ref{_Property}(_Property(true)) + + err_code = ccall( + (:caosdb_entity_create_property, CaosDB.library_name), + Cint, + (Ref{_Property},), + property, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + if name != "" + set_name(property, name) + end + + if id != "" + set_id(property, id) + end + + if value + set_value(property, value) + end + + return property + +end + +""" + function create_parent(; name::AbstractString = "", id::AbstractString = "") + +Create a parent object that can be appended to another `_Entity`. If +`name`, `id`, or `value` are given, the parent's name, id, or value +are set accordingly. + +!!! info + + This is not an `_Entity` that could be inserted or updated by its + own but a `_Parent` that is to be appended to another `_Entity`. +""" +function create_parent(; name::AbstractString = "", id::AbstractString = "") + + parent = Ref{_Parent}(_Parent(true)) + + err_code = ccall( + (:caosdb_entity_create_parent, CaosDB.library_name), + Cint, + (Ref{_Parent},)parent, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + if name != "" + set_name(parent, name) + end + + if id != "" + set_id(parent, id) + end + + return parent +end + end