Update database.py
Browse files- database.py +10 -9
database.py
CHANGED
|
@@ -5,10 +5,10 @@ from flask import g
|
|
| 5 |
def get_db_path():
|
| 6 |
# Hugging Face Spaces için özel yol kontrolü
|
| 7 |
if os.path.exists('/data'):
|
| 8 |
-
return '/data/
|
| 9 |
-
elif os.path.exists('/home/
|
| 10 |
-
return '/home/
|
| 11 |
-
return '
|
| 12 |
|
| 13 |
def get_db():
|
| 14 |
if 'db' not in g:
|
|
@@ -30,15 +30,16 @@ def init_db(app):
|
|
| 30 |
cursor = db.cursor()
|
| 31 |
|
| 32 |
cursor.execute('''
|
| 33 |
-
CREATE TABLE IF NOT EXISTS
|
| 34 |
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 35 |
-
name TEXT NOT NULL
|
|
|
|
| 36 |
)
|
| 37 |
''')
|
| 38 |
|
| 39 |
-
cursor.execute('SELECT COUNT(*) FROM
|
| 40 |
if cursor.fetchone()[0] == 0:
|
| 41 |
-
cursor.executemany('INSERT INTO
|
| 42 |
-
[('
|
| 43 |
|
| 44 |
db.commit()
|
|
|
|
| 5 |
def get_db_path():
|
| 6 |
# Hugging Face Spaces için özel yol kontrolü
|
| 7 |
if os.path.exists('/data'):
|
| 8 |
+
return '/data/users.db'
|
| 9 |
+
elif os.path.exists('/home/user_data'):
|
| 10 |
+
return '/home/user_data/users.db'
|
| 11 |
+
return 'users.db'
|
| 12 |
|
| 13 |
def get_db():
|
| 14 |
if 'db' not in g:
|
|
|
|
| 30 |
cursor = db.cursor()
|
| 31 |
|
| 32 |
cursor.execute('''
|
| 33 |
+
CREATE TABLE IF NOT EXISTS users (
|
| 34 |
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 35 |
+
name TEXT NOT NULL,
|
| 36 |
+
score INTEGER DEFAULT 0
|
| 37 |
)
|
| 38 |
''')
|
| 39 |
|
| 40 |
+
cursor.execute('SELECT COUNT(*) FROM users')
|
| 41 |
if cursor.fetchone()[0] == 0:
|
| 42 |
+
cursor.executemany('INSERT INTO users (name, score) VALUES (?, ?)',
|
| 43 |
+
[('Ahmet', 85), ('Mehmet', 92)])
|
| 44 |
|
| 45 |
db.commit()
|