Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-julialib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-julialib
Commits
c748cdf0
Commit
c748cdf0
authored
3 years ago
by
Alexander Kreft
Committed by
Henrik tom Wörden
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ENH: add convenience functions for files, insert, update etc
parent
513cb88d
No related branches found
No related tags found
1 merge request
!10
f conveniencence
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/CaosDB.jl
+11
-2
11 additions, 2 deletions
src/CaosDB.jl
src/Entity.jl
+35
-1
35 additions, 1 deletion
src/Entity.jl
src/Transaction.jl
+56
-1
56 additions, 1 deletion
src/Transaction.jl
test/runtests.jl
+17
-0
17 additions, 0 deletions
test/runtests.jl
with
119 additions
and
4 deletions
src/CaosDB.jl
+
11
−
2
View file @
c748cdf0
...
...
@@ -37,7 +37,12 @@ export connect, connect_manually
# Exports from module Entity
# Creators
export
create_entity
,
create_parent
,
create_property
,
create_property_entity
,
create_record
,
create_recordtype
create_parent
,
create_property
,
create_property_entity
,
create_record
,
create_recordtype
,
create_file_entity
# getters
export
get_id
,
...
...
@@ -96,7 +101,11 @@ export create_transaction,
get_result_at
,
get_results
,
execute_query
,
retrieve
retrieve
,
insert_entity
,
update_entity
,
delete_by_id
,
retrieve_and_download_file_by_id
using
Libdl
...
...
This diff is collapsed.
Click to expand it.
src/Entity.jl
+
35
−
1
View file @
c748cdf0
...
...
@@ -24,7 +24,12 @@ module Entity
# Creators
export
create_entity
,
create_parent
,
create_property
,
create_property_entity
,
create_record
,
create_recordtype
create_parent
,
create_property
,
create_property_entity
,
create_record
,
create_recordtype
,
create_file_entity
# getters
export
get_id
,
...
...
@@ -343,7 +348,36 @@ function create_property(;
return
property
end
"""
function create_file_entity(;
local_path::AbstractString,
remote_path::AbstractString,
name::AbstractString = "",
)
Return a new entity object with role File.
`local_path` is the path of the file on the local file system. An exception is
thrown if this file is not existent. `remote_path` is the path of the file on
the remote caosdb server.
"""
function
create_file_entity
(;
local_path
::
AbstractString
,
remote_path
::
AbstractString
,
name
::
AbstractString
=
""
,
)
if
isfile
(
local_path
)
==
false
throw
(
CaosDB
.
Exceptions
.
ClientException
(
"Cannot find the local file '
$
local_path'."
),
)
end
file_entity
=
create_entity
(
name
)
set_role
(
file_entity
,
"FILE"
)
set_local_path
(
file_entity
,
local_path
)
set_remote_path
(
file_entity
,
remote_path
)
return
file_entity
end
"""
function create_parent(; name::AbstractString = "", id::AbstractString = "")
...
...
This diff is collapsed.
Click to expand it.
src/Transaction.jl
+
56
−
1
View file @
c748cdf0
...
...
@@ -36,7 +36,11 @@ export create_transaction,
get_result_at
,
get_results
,
execute_query
,
retrieve
retrieve
,
insert_entity
,
update_entity
,
delete_by_id
,
retrieve_and_download_file_by_id
using
CaosDB
...
...
@@ -606,5 +610,56 @@ function retrieve(
return
get_results
(
transaction
)
end
"""
function insert_entity(entity::Ref{CaosDB.Entity._Entity})
Insert a single Entity.
"""
function
insert_entity
(
entity
::
Ref
{
CaosDB
.
Entity
.
_Entity
})
transaction
=
create_transaction
()
add_insert_entity
(
transaction
,
entity
)
execute
(
transaction
)
return
get_results
(
transaction
)
end
"""
function update_entity(entity::Ref{CaosDB.Entity._Entity})
Update a single Entity.
"""
function
update_entity
(
entity
::
Ref
{
CaosDB
.
Entity
.
_Entity
})
transaction
=
create_transaction
()
add_update_entity
(
transaction
,
entity
)
execute
(
transaction
)
return
get_results
(
transaction
)
end
"""
function delete_by_id(id::AbstractString)
Delete a single Entity identified by its `id`.
"""
function
delete_by_id
(
id
::
AbstractString
)
transaction
=
create_transaction
()
add_delete_by_id
(
transaction
,
id
)
execute
(
transaction
)
return
get_results
(
transaction
)
end
"""
function retrieve_and_download_file_by_id(
id::AbstractString,
download_path::AbstractString)
Retrieve and download a single File-Entity identified by its `id`.
`download_path` is the path where the file will be downloaded.
"""
function
retrieve_and_download_file_by_id
(
id
::
AbstractString
,
download_path
::
AbstractString
)
transaction
=
create_transaction
()
add_retrieve_and_download_file_by_id
(
transaction
,
id
,
download_path
)
execute
(
transaction
)
return
get_results
(
transaction
)
end
end
# Transaction
This diff is collapsed.
Click to expand it.
test/runtests.jl
+
17
−
0
View file @
c748cdf0
...
...
@@ -164,6 +164,23 @@ using CaosDB
@test
CaosDB
.
Entity
.
get_name
(
CaosDB
.
Entity
.
get_properties
(
rec_with_parent_and_props
)[
2
],
)
==
"Property3"
f
=
touch
(
"caosdbfilefortests.txt"
)
write
(
f
,
"Content"
)
file_ent
=
CaosDB
.
Entity
.
create_file_entity
(
name
=
"TestFile"
,
local_path
=
string
(
pwd
(),
"/"
,
"caosdbfilefortests.txt"
),
remote_path
=
"/remote_path/file.txt"
,
)
@test
CaosDB
.
Entity
.
get_role
(
file_ent
)
==
"FILE"
@test
CaosDB
.
Entity
.
get_name
(
file_ent
)
==
"TestFile"
# local file not found
rm
(
string
(
pwd
(),
"/"
,
"caosdbfilefortests.txt"
))
@test_throws
CaosDB
.
Exceptions
.
ClientException
CaosDB
.
Entity
.
create_file_entity
(
name
=
"TestFile"
,
local_path
=
string
(
pwd
(),
"/"
,
"caosdbfilefortests.txt"
),
remote_path
=
"/remote_path/file.txt"
,
)
end
@testset
"Datatype and values"
begin
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment