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

DRAFT: Begin implementation of entities

parent 475a378f
No related branches found
No related tags found
1 merge request!7ENH: Implement queries and entity retrieval
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment