Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Jannik Hellenkamp
website
Commits
2468d5a6
Commit
2468d5a6
authored
8 years ago
by
Julian Rother
Browse files
Options
Downloads
Patches
Plain Diff
Implement database initialisation
parent
bbef90c0
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
config.py
+2
-0
2 additions, 0 deletions
config.py
server.py
+16
-0
16 additions, 0 deletions
server.py
with
19 additions
and
0 deletions
.gitignore
+
1
−
0
View file @
2468d5a6
*.swp
config.py
__pycache__
*.sqlite
This diff is collapsed.
Click to expand it.
config.py
+
2
−
0
View file @
2468d5a6
...
...
@@ -9,3 +9,5 @@ DEBUG = True
SQLITE_DB
=
'
db.sqlite
'
DB_ENGINE
=
'
sqlite
'
SQLITE_INIT_SCHEMA
=
True
SQLITE_INIT_DATA
=
True
This diff is collapsed.
Click to expand it.
server.py
+
16
−
0
View file @
2468d5a6
...
...
@@ -2,11 +2,27 @@
from
flask
import
Flask
,
render_template
,
g
import
mysql.connector
import
sqlite3
import
os
app
=
Flask
(
__name__
)
config
=
app
.
config
config
[
'
DB_SCHEMA
'
]
=
'
db_schema.sql
'
config
[
'
DB_DATA
'
]
=
'
db_example.sql
'
config
[
'
SQLITE_INIT_SCHEMA
'
]
=
False
config
[
'
SQLITE_INIT_DATA
'
]
=
False
config
.
from_pyfile
(
'
config.py
'
)
if
config
[
'
DB_ENGINE
'
]
==
'
sqlite
'
:
created
=
not
os
.
path
.
exists
(
config
[
'
SQLITE_DB
'
])
db
=
sqlite3
.
connect
(
config
[
'
SQLITE_DB
'
])
cur
=
db
.
cursor
()
if
config
[
'
SQLITE_INIT_SCHEMA
'
]:
cur
.
executescript
(
open
(
config
[
'
DB_SCHEMA
'
]).
read
())
if
config
[
'
SQLITE_INIT_DATA
'
]
and
created
:
cur
.
executescript
(
open
(
config
[
'
DB_DATA
'
]).
read
())
db
.
commit
()
db
.
close
()
# Row wrapper for sqlite
def
dict_factory
(
cursor
,
row
):
d
=
{}
...
...
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