diff --git a/src/Transaction.jl b/src/Transaction.jl index 00ceabc15ccb8eaaefacd7d1051f40c6ade590bd..a3a1549d25cb47c0e5aa355fd6ebb3219aef0739 100644 --- a/src/Transaction.jl +++ b/src/Transaction.jl @@ -23,6 +23,8 @@ module Transaction +export create_transaction + using CaosDB """ @@ -50,4 +52,38 @@ mutable struct _Transaction end end +""" + create_transaction(name::AbstractString = "default") + +Return a transaction created with the connection of the given name. If +none is given, the defult connection is used. +""" +function create_transaction(name::AbstractString = "default") + connection = CaosDB.Connection.get_connection(name) + + return create_transaction(connection) +end + +""" + function create_transaction(connection::Ref{CaosDB.Connection._Connection}) + +Return a transactioncreated with the given connection object. +""" +function create_transaction(connection::Ref{CaosDB.Connection._Connection}) + + transaction = Ref{_Transaction}(_Transaction(true)) + + err_code = ccall( + (:caosdb_connection_connection_create_transaction, CaosDB.library_name), + Cint, + (Ref{CaosDB.Connection._Connection}, Ref{_Transaction}), + connection, + transaction, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return transaction +end + end # Transaction