Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
U
url_shorter_docker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Jonas Leder
url_shorter_docker
Commits
79a2b8cd
Commit
79a2b8cd
authored
5 years ago
by
Jonas Leder
Browse files
Options
Downloads
Patches
Plain Diff
added clonedb script to test db performance
parent
44db46a2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
clonedb.py
+32
-0
32 additions, 0 deletions
clonedb.py
with
33 additions
and
0 deletions
.gitignore
+
1
−
0
View file @
79a2b8cd
...
...
@@ -8,3 +8,4 @@ import.csv
__pycache__/
builddate.txt
db/urls.db-journal
This diff is collapsed.
Click to expand it.
clonedb.py
0 → 100644
+
32
−
0
View file @
79a2b8cd
#!/usr/bin/env python3
# This script will clone all entries from the database. I ised this to show what happens with extreme database sizes.
#The output will be in excel-style CSV (";" instead of "," as column seperator.)
import
sqlite3
from
tqdm
import
tqdm
create_table
=
"""
CREATE TABLE WEB_URL(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
LONG_URL TEXT NOT NULL, SHORT_URL TEXT NOT NULL
);
"""
with
sqlite3
.
connect
(
'
db/urls.db
'
)
as
conn
:
cursor
=
conn
.
cursor
()
try
:
#Try making the database structure, if succeeded, exit, because there can't be any data.
cursor
.
execute
(
create_table
)
raise
Exception
(
'
No database Found
'
,
"
Can
'
t find the database ==> No data to export
"
)
except
sqlite3
.
OperationalError
:
pass
conn
=
sqlite3
.
connect
(
'
db/urls.db
'
)
cursor
=
conn
.
cursor
()
res
=
cursor
.
execute
(
'
SELECT LONG_URL, SHORT_URL FROM WEB_URL WHERE 1
'
)
#read all data from database
with
sqlite3
.
connect
(
'
db/urls.db
'
)
as
conn2
:
cursor2
=
conn2
.
cursor
()
for
entries
in
tqdm
(
res
.
fetchall
()):
cursor2
.
execute
(
#Insert the data in the SQL table
'
INSERT INTO WEB_URL (LONG_URL, SHORT_URL) VALUES (?, ?)
'
,
[
entries
[
0
],
entries
[
1
]]
)
print
(
"
Database duplicated
"
)
\ No newline at end of file
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