Delete shared_data.py
Browse files- shared_data.py +0 -28
shared_data.py
DELETED
|
@@ -1,28 +0,0 @@
|
|
| 1 |
-
import sqlite3
|
| 2 |
-
from flask import g
|
| 3 |
-
|
| 4 |
-
DATABASE = 'users.db'
|
| 5 |
-
|
| 6 |
-
def get_db():
|
| 7 |
-
db = getattr(g, '_database', None)
|
| 8 |
-
if db is None:
|
| 9 |
-
db = g._database = sqlite3.connect(DATABASE)
|
| 10 |
-
return db
|
| 11 |
-
|
| 12 |
-
def init_db():
|
| 13 |
-
with app.app_context():
|
| 14 |
-
db = get_db()
|
| 15 |
-
cursor = db.cursor()
|
| 16 |
-
cursor.execute('''
|
| 17 |
-
CREATE TABLE IF NOT EXISTS users (
|
| 18 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 19 |
-
name TEXT NOT NULL,
|
| 20 |
-
score INTEGER DEFAULT 0
|
| 21 |
-
)
|
| 22 |
-
''')
|
| 23 |
-
# Insert initial data if empty
|
| 24 |
-
cursor.execute('SELECT COUNT(*) FROM users')
|
| 25 |
-
if cursor.fetchone()[0] == 0:
|
| 26 |
-
cursor.executemany('INSERT INTO users (name, score) VALUES (?, ?)',
|
| 27 |
-
[('Ahmet', 85), ('Mehmet', 92)])
|
| 28 |
-
db.commit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|