Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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-pylib
Commits
8a836a2c
Commit
8a836a2c
authored
10 months ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
ENH: allow to provide the role when using get_entity
parent
51190b6b
No related branches found
No related tags found
2 merge requests
!143
Release 0.15.0
,
!140
Opt-in linkahead package to mypy type checking
Pipeline
#51109
failed
10 months ago
Stage: code_style
Stage: linting
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/linkahead/utils/get_entity.py
+8
-4
8 additions, 4 deletions
src/linkahead/utils/get_entity.py
with
8 additions
and
4 deletions
src/linkahead/utils/get_entity.py
+
8
−
4
View file @
8a836a2c
...
...
@@ -27,23 +27,27 @@ from ..common.models import Entity, execute_query
from
.escape
import
escape_squoted_text
def
get_entity_by_name
(
name
:
str
)
->
Entity
:
def
get_entity_by_name
(
name
:
str
,
role
:
Optional
[
str
]
=
None
)
->
Entity
:
"""
Return the result of a unique query that uses the name to find the correct entity.
Submits the query
"
FIND ENTITY WITH name=
'
{name}
'"
.
"""
name
=
escape_squoted_text
(
name
)
if
role
is
None
:
role
=
"
ENTITY
"
# type hint can be ignored, it's a unique query, so never Container or int
return
execute_query
(
f
"
FIND
ENTITY
WITH name=
'
{
name
}
'"
,
unique
=
True
)
# type: ignore
return
execute_query
(
f
"
FIND
{
role
}
WITH name=
'
{
name
}
'"
,
unique
=
True
)
# type: ignore
def
get_entity_by_id
(
eid
:
Union
[
str
,
int
])
->
Entity
:
def
get_entity_by_id
(
eid
:
Union
[
str
,
int
]
,
role
:
Optional
[
str
]
=
None
)
->
Entity
:
"""
Return the result of a unique query that uses the id to find the correct entity.
Submits the query
"
FIND ENTITY WITH id=
'
{eid}
'"
.
"""
if
role
is
None
:
role
=
"
ENTITY
"
# type hint can be ignored, it's a unique query
return
execute_query
(
f
"
FIND
ENTITY
WITH id=
'
{
eid
}
'"
,
unique
=
True
)
# type: ignore
return
execute_query
(
f
"
FIND
{
role
}
WITH id=
'
{
eid
}
'"
,
unique
=
True
)
# type: ignore
def
get_entity_by_path
(
path
:
str
)
->
Entity
:
...
...
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