Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Base Worker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
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
Workers
Base Worker
Merge requests
!67
Store created elements in a local SQLite database
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Store created elements in a local SQLite database
sqlite-database
into
master
Overview
17
Commits
12
Pipelines
1
Changes
2
All threads resolved!
Hide all comments
Merged
Eva Bardou
requested to merge
sqlite-database
into
master
4 years ago
Overview
17
Commits
12
Pipelines
1
Changes
2
All threads resolved!
Hide all comments
Expand
Closes
#41 (closed)
Edited
4 years ago
by
Eva Bardou
0
0
Merge request reports
Viewing commit
462bf308
Prev
Next
Show latest version
2 files
+
48
−
33
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
462bf308
Fix some review related code snippets
· 462bf308
Eva Bardou
authored
4 years ago
arkindex_worker/cache.py
+
23
−
19
Options
# -*- coding: utf-8 -*-
import
os
import
sqlite3
from
arkindex_worker
import
logger
SQL_ELEMENTS_TABLE_CREATION
=
"""
CREATE TABLE IF NOT EXISTS elements (
id VARCHAR(32) PRIMARY KEY,
parent_id VARCHAR(32),
name TEXT NOT NULL,
type TEXT NOT NULL,
polygon TEXT,
worker_version_id VARCHAR(32)
)
"""
class
LocalDB
(
object
):
def
__init__
(
self
,
path
):
if
not
os
.
path
.
exists
(
path
):
open
(
path
,
"
x
"
).
close
()
self
.
db
=
sqlite3
.
connect
(
path
)
self
.
db
.
row_factory
=
sqlite3
.
Row
self
.
cursor
=
self
.
db
.
cursor
()
logger
.
info
(
f
"
Connection to local cache
{
path
}
established.
"
)
def
create_elements_table
(
self
):
try
:
self
.
cursor
.
execute
(
"""
CREATE TABLE elements (
id TEXT PRIMARY KEY,
parent_id TEXT,
name TEXT NOT NULL,
type TEXT NOT NULL,
polygon TEXT,
worker_version_id TEXT
)
"""
)
except
sqlite3
.
OperationalError
:
print
(
"
Table
'
elements
'
already exists
"
)
def
create_tables
(
self
):
self
.
cursor
.
execute
(
SQL_ELEMENTS_TABLE_CREATION
)
def
insert
(
self
,
table
,
lines
):
self
.
cursor
.
executemany
(
f
"
INSERT INTO
{
table
}
VALUES (?,?,?,?,?,?)
"
,
lines
)
if
not
lines
:
return
columns
=
"
,
"
.
join
(
lines
[
0
].
keys
())
placeholders
=
"
,
"
.
join
(
"
?
"
*
len
(
lines
[
0
]))
values
=
[
tuple
(
line
.
values
())
for
line
in
lines
]
self
.
cursor
.
executemany
(
f
"
INSERT INTO
{
table
}
(
{
columns
}
) VALUES (
{
placeholders
}
)
"
,
values
)
self
.
db
.
commit
()
Loading