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

ENH: Add convenience wrappers for Integer indices

parent 0be053a7
No related branches found
No related tags found
1 merge request!7ENH: Implement queries and entity retrieval
......@@ -305,7 +305,7 @@ function create_property(;
set_id(property, id)
end
if value
if value != ""
set_value(property, value)
end
......@@ -805,7 +805,7 @@ function get_error(entity::Ref{_Entity}, index::Cint)
Cint,
(Ref{_Entity}, Cint),
entity,
index - 1,
index - Cint(1),
)
CaosDB.Exceptions.evaluate_return_code(err_code)
......@@ -817,6 +817,19 @@ function get_error(entity::Ref{_Entity}, index::Cint)
return CaosDB.Exceptions.CaosDBMessage(message_text, code)
end
"""
function get_error(entity::Ref{_Entity}, index::Integer)
Convenience wrapper for `get_error(::Ref{_Entity}, ::Cint)`. Convert
`index` to Int32 and return the error at position `index` of the given
`entity`.
"""
function get_error(entity::Ref{_Entity}, index::Integer)
return get_error(entity, Cint(index))
end
"""
function get_warning(entity::Ref{_Entity}, index::Cint)
......@@ -832,7 +845,7 @@ function get_warning(entity::Ref{_Entity}, index::Cint)
Cint,
(Ref{_Entity}, Cint),
entity,
index - 1,
index - Cint(1),
)
CaosDB.Exceptions.evaluate_return_code(err_code)
......@@ -844,6 +857,18 @@ function get_warning(entity::Ref{_Entity}, index::Cint)
return CaosDB.Exceptions.CaosDBMessage(message_text, code)
end
"""
function get_warning(entity::Ref{_Entity}, index::Integer)
Convenience wrapper for `get_warning(::Ref{_Entity}, ::Cint)`. Convert
`index` to Int32 and return the warning at position `index` of the given
`entity`.
"""
function get_warning(entity::Ref{_Entity}, index::Integer)
return get_warning(entity, Cint(index))
end
"""
function get_info(entity::Ref{_Entity}, index::Cint)
......@@ -860,7 +885,7 @@ function get_info(entity::Ref{_Entity}, index::Cint)
Cint,
(Ref{_Entity}, Cint),
entity,
index - 1,
index - Cint(1),
)
CaosDB.Exceptions.evaluate_return_code(err_code)
......@@ -872,6 +897,20 @@ function get_info(entity::Ref{_Entity}, index::Cint)
return CaosDB.Exceptions.CaosDBMessage(message_text, code)
end
"""
function get_info(entity::Ref{_Entity}, index::Integer)
Convenience wrapper for `get_info(::Ref{_Entity}, ::Cint)`. Convert
`index` to Int32 and return the info at position `index` of the given
`entity`.
"""
function get_info(entity::Ref{_Entity}, index::Integer)
return get_info(entity, Cint(index))
end
"""
function get_errors(entity::Ref{_Entity})
......@@ -954,12 +993,16 @@ function get_parent(entity::Ref{_Entity}, index::Cint)
parent = Ref{_Parent}(_Parent())
println(index - Cint(1))
println(typeof(index - Cint(1)))
err_code = ccall(
(:caosdb_entity_entity_get_parent, CaosDB.library_name),
Cint,
(Ref{_Entity}, Ref{Cint}),
(Ref{_Entity}, Ref{_Parent}, Ref{Cint}),
entity,
index - 1,
parent,
index - Cint(1),
)
CaosDB.Exceptions.evaluate_return_code(err_code)
......@@ -967,6 +1010,20 @@ function get_parent(entity::Ref{_Entity}, index::Cint)
return parent
end
"""
function get_parent(entity::Ref{_Entity}, index::Integer)
Convenience wrapper for `get_parent(::Ref{_Entity}, ::Cint)`. Convert
`index` to Int32 and return the parent at position `index` of the given
`entity`.
"""
function get_parent(entity::Ref{_Entity}, index::Integer)
return get_parent(entity, Cint(index))
end
"""
function get_parents(entity::Ref{_Entity})
......@@ -1003,9 +1060,10 @@ function get_property(entity::Ref{_Entity}, index::Cint)
err_code = ccall(
(:caosdb_entity_entity_get_property, CaosDB.library_name),
Cint,
(Ref{_Entity}, Ref{Cint}),
(Ref{_Entity}, Ref{_Property}, Ref{Cint}),
entity,
index - 1,
property,
index - Cint(1),
)
CaosDB.Exceptions.evaluate_return_code(err_code)
......@@ -1013,6 +1071,21 @@ function get_property(entity::Ref{_Entity}, index::Cint)
return property
end
"""
function get_property(entity::Ref{_Entity}, index::Integer)
Convenience wrapper for `get_property(::Ref{_Entity}, ::Cint)`. Convert
`index` to Int32 and return the property at position `index` of the given
`entity`.
"""
function get_property(entity::Ref{_Entity}, index::Integer)
return get_property(entity, Cint(index))
end
"""
function get_properties(entity::Ref{_Entity})
......@@ -1339,7 +1412,7 @@ function remove_parent(entity::Ref{_Entity}, index::Cint)
Cint,
(Ref{_Entity}, Cint),
entity,
index - 1,
index - Cint(1),
)
CaosDB.Exceptions.evaluate_return_code(err_code)
......@@ -1391,7 +1464,7 @@ function remove_property(entity::Ref{_Entity}, index::Cint)
Cint,
(Ref{_Entity}, Cint),
entity,
index - 1,
index - Cint(1),
)
CaosDB.Exceptions.evaluate_return_code(err_code)
......
......@@ -116,11 +116,12 @@ using CaosDB
par2 = CaosDB.Entity.create_parent(name = "Parent2", id = "id_of_parent_2")
CaosDB.Entity.append_parents(rec_with_parent_and_props, [par1, par2])
@test length(CaosDB.Entity.get_parents(rec_with_parent_and_props)) == 2
# Getting has to work with all Integers that can be cast to Cint
@test CaosDB.Entity.get_name(
CaosDB.Entity.get_parent(rec_with_parent_and_props, Cint(1)),
) == "Parent1"
@test CaosDB.Entity.get_name(
CaosDB.Entity.get_parent(rec_with_parent_and_props, Cint(2)),
CaosDB.Entity.get_parent(rec_with_parent_and_props, 2),
) == "Parent2"
@test CaosDB.Entity.get_id(
CaosDB.Entity.get_parent(rec_with_parent_and_props, Cint(2)),
......
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