From b3e203dd1b802033a189d5e0baeeb2dc3451a5a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Thu, 26 Aug 2021 15:02:30 +0000 Subject: [PATCH] ENH: add insert, update, delete and file handling --- src/CaosDB.jl | 8 +++- src/Entity.jl | 37 +++++++++++++++- src/Transaction.jl | 108 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+), 2 deletions(-) diff --git a/src/CaosDB.jl b/src/CaosDB.jl index b81fd46..a3812ea 100644 --- a/src/CaosDB.jl +++ b/src/CaosDB.jl @@ -75,7 +75,9 @@ export append_parent, set_datatype, set_unit, set_value, - set_importance + set_importance, + set_local_path, + set_remote_path # helper functions export has_errors, has_warnings @@ -83,6 +85,10 @@ export has_errors, has_warnings # Exports from module Transaction export create_transaction, add_retrieve_by_id, + add_insert_entity, + add_update_entity, + add_delete_by_id, + add_retrieve_and_download_file_by_id, add_query, execute, get_result_set, diff --git a/src/Entity.jl b/src/Entity.jl index 119729b..6fa2c7e 100644 --- a/src/Entity.jl +++ b/src/Entity.jl @@ -62,7 +62,9 @@ export append_parent, set_datatype, set_unit, set_value, - set_importance + set_importance, + set_local_path, + set_remote_path # helper functions export has_errors, has_warnings @@ -1733,6 +1735,39 @@ function set_importance(property::Ref{_Property}, importance::AbstractString) CaosDB.Exceptions.evaluate_return_code(err_code) end +""" + function set_local_path(entity::Ref{_Entity}, path::AbstractString) + +Set the local path of the given `entity` object. +""" +function set_local_path(entity::Ref{_Entity}, path::AbstractString) + err_code = ccall( + (:caosdb_entity_entity_set_local_path, CaosDB.library_name), + Cint, + (Ref{_Entity}, Cstring), + entity, + path, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + +""" + function set_remote_path(entity::Ref{_Entity}, path::AbstractString) + +Set the remote file path of the given `entity` object. +""" +function set_remote_path(entity::Ref{_Entity}, path::AbstractString) + err_code = ccall( + (:caosdb_entity_entity_set_file_path, CaosDB.library_name), + Cint, + (Ref{_Entity}, Cstring), + entity, + path, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end """ function append_parent(entity::Ref{_Entity}, parent::Ref{_Parent}) diff --git a/src/Transaction.jl b/src/Transaction.jl index 2308048..a84588c 100644 --- a/src/Transaction.jl +++ b/src/Transaction.jl @@ -26,6 +26,10 @@ module Transaction export create_transaction, add_retrieve_by_id, add_query, + add_insert_entity, + add_update_entity, + add_delete_by_id, + add_retrieve_and_download_file_by_id, execute, get_result_set, get_count_result, @@ -137,6 +141,76 @@ function add_retrieve_by_id(transaction::Ref{_Transaction}, id::AbstractString) CaosDB.Exceptions.evaluate_return_code(err_code) end +""" + function add_insert_entity(transaction::Ref{_Transaction}, entity::Ref{_CaosDB.Entity.Entity}) + +Add a sub-request to insert a single entity to the given `transaction`. + +!!! info + + This does not execute the transaction. +""" +function add_insert_entity( + transaction::Ref{_Transaction}, + entity::Ref{CaosDB.Entity._Entity}, +) + + err_code = ccall( + (:caosdb_transaction_transaction_insert_entity, CaosDB.library_name), + Cint, + (Ref{_Transaction}, Ref{CaosDB.Entity._Entity}), + transaction, + entity, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end +""" + function add_update_entity(transaction::Ref{_Transaction}, entity::Ref{_CaosDB.Entity.Entity}) + +Add a sub-request to update a single entity to the given `transaction`. + +!!! info + + This does not execute the transaction. +""" +function add_update_entity( + transaction::Ref{_Transaction}, + entity::Ref{CaosDB.Entity._Entity}, +) + + err_code = ccall( + (:caosdb_transaction_transaction_update_entity, CaosDB.library_name), + Cint, + (Ref{_Transaction}, Ref{CaosDB.Entity._Entity}), + transaction, + entity, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end +""" + function add_delete_by_id(transaction::Ref{_Transaction}, id::AbstractString) + +Add a sub-request to delete a single entity to the given `transaction`. + +!!! info + + This does not execute the transaction. +""" +function add_delete_by_id(transaction::Ref{_Transaction}, id::AbstractString) + + err_code = ccall( + (:caosdb_transaction_transaction_delete_by_id, CaosDB.library_name), + Cint, + (Ref{_Transaction}, Cstring), + transaction, + id, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + """ function add_retrieve_by_id( transaction::Ref{_Transaction}, @@ -168,6 +242,40 @@ function add_retrieve_by_id( CaosDB.Exceptions.evaluate_return_code(err_code) end +""" + function add_retrieve_and_download_file_by_id( + transaction::Ref{_Transaction}, + id::AbstractString, + path::AbstractString, + ) + +Add a sub-request to retrieve and download a single entity (File) to the given `transaction`. + +!!! info + + This does not execute the transaction. +""" +function add_retrieve_and_download_file_by_id( + transaction::Ref{_Transaction}, + id::AbstractString, + path::AbstractString, +) + + err_code = ccall( + ( + :caosdb_transaction_transaction_retrieve_and_download_file_by_id, + CaosDB.library_name, + ), + Cint, + (Ref{_Transaction}, Cstring, Cstring), + transaction, + id, + path, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + """ function add_query(transaction::Ref{_Transaction}, query::AbstractString) -- GitLab