Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CCS
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marko Mecina
CCS
Commits
dbccfea2
Commit
dbccfea2
authored
4 years ago
by
Marko Mecina
Browse files
Options
Downloads
Patches
Plain Diff
get rid of class-owned SQL session instance
parent
5541f35d
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Tst/codeblockreusefeature/codeblockreuse.py
+5
-5
5 additions, 5 deletions
Tst/codeblockreusefeature/codeblockreuse.py
Tst/codeblockreusefeature/db_interaction.py
+13
-8
13 additions, 8 deletions
Tst/codeblockreusefeature/db_interaction.py
with
18 additions
and
13 deletions
Tst/codeblockreusefeature/codeblockreuse.py
+
5
−
5
View file @
dbccfea2
...
@@ -257,8 +257,9 @@ class CBRSearch(Gtk.Box):
...
@@ -257,8 +257,9 @@ class CBRSearch(Gtk.Box):
super
().
__init__
(
*
args
,
**
kwargs
)
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
app_win
=
app_win
self
.
app_win
=
app_win
self
.
logger
=
logger
self
.
logger
=
logger
with
db_schema
.
session_scope
()
as
session
:
self
.
session
=
session
# with db_schema.session_scope() as session:
# self.session = session
self
.
_filter_searchstring
=
''
self
.
_filter_searchstring
=
''
self
.
_filter_type_snippet
=
None
self
.
_filter_type_snippet
=
None
...
@@ -769,11 +770,10 @@ class CBRSearch(Gtk.Box):
...
@@ -769,11 +770,10 @@ class CBRSearch(Gtk.Box):
Loads the data from the database. The filter properties are used to build the SQL query.
Loads the data from the database. The filter properties are used to build the SQL query.
"""
"""
self
.
logger
.
debug
(
'
Loading data from the database
'
)
self
.
logger
.
debug
(
'
Loading data from the database
'
)
self
.
session
.
commit
()
# this updates the session instantiated in the class init
if
self
.
filter_searchstring
!=
''
:
if
self
.
filter_searchstring
!=
''
:
self
.
data
=
db_interaction
.
query_using_textsearch
(
session
=
self
.
session
,
expressions
=
self
.
filter_searchstring
)
self
.
data
=
db_interaction
.
query_using_textsearch
(
expressions
=
self
.
filter_searchstring
)
else
:
else
:
self
.
data
=
db_interaction
.
query_get_all_entries
(
self
.
session
)
self
.
data
=
db_interaction
.
query_get_all_entries
()
self
.
load_data_into_liststore
(
self
.
data
)
self
.
load_data_into_liststore
(
self
.
data
)
def
reload_data
(
self
):
def
reload_data
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Tst/codeblockreusefeature/db_interaction.py
+
13
−
8
View file @
dbccfea2
...
@@ -2,8 +2,10 @@ import db_schema
...
@@ -2,8 +2,10 @@ import db_schema
from
db_schema
import
CodeBlock
from
db_schema
import
CodeBlock
def
query_get_all_entries
(
session
):
def
query_get_all_entries
():
with
db_schema
.
session_scope
()
as
session
:
data
=
session
.
query
(
CodeBlock
).
all
()
data
=
session
.
query
(
CodeBlock
).
all
()
session
.
expunge_all
()
return
data
return
data
...
@@ -27,16 +29,19 @@ def delete_db_row(id):
...
@@ -27,16 +29,19 @@ def delete_db_row(id):
return
return
def
query_using_textsearch
(
session
,
expressions
):
def
query_using_textsearch
(
expressions
):
with
db_schema
.
session_scope
()
as
session
:
data
=
session
.
query
(
CodeBlock
).
filter
(
CodeBlock
.
description
.
contains
(
expressions
)).
all
()
data
=
session
.
query
(
CodeBlock
).
filter
(
CodeBlock
.
description
.
contains
(
expressions
)).
all
()
session
.
expunge_all
()
return
data
return
data
def
query_code_types
(
session
):
def
query_code_types
():
with
db_schema
.
session_scope
()
as
session
:
data
=
session
.
query
(
CodeBlock
.
code_type
).
group_by
(
CodeBlock
.
code_type
).
all
()
data
=
session
.
query
(
CodeBlock
.
code_type
).
group_by
(
CodeBlock
.
code_type
).
all
()
session
.
expunge_all
()
return
data
return
data
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
with
db_schema
.
session_scope
()
as
session
:
query_code_types
()
query_code_types
(
session
)
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