Update database.py
Browse files- database.py +9 -12
database.py
CHANGED
|
@@ -1,19 +1,17 @@
|
|
| 1 |
import sqlite3
|
| 2 |
-
import os
|
| 3 |
from flask import g
|
| 4 |
|
| 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/user_data'):
|
| 10 |
-
return '/home/user_data/
|
| 11 |
-
return '
|
| 12 |
|
| 13 |
def get_db():
|
| 14 |
if 'db' not in g:
|
| 15 |
db_path = get_db_path()
|
| 16 |
-
# Dizin yoksa oluştur
|
| 17 |
os.makedirs(os.path.dirname(db_path), exist_ok=True)
|
| 18 |
g.db = sqlite3.connect(db_path)
|
| 19 |
g.db.row_factory = sqlite3.Row
|
|
@@ -30,16 +28,15 @@ 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 |
-
|
| 36 |
-
score INTEGER DEFAULT 0
|
| 37 |
)
|
| 38 |
''')
|
| 39 |
|
| 40 |
-
|
|
|
|
| 41 |
if cursor.fetchone()[0] == 0:
|
| 42 |
-
cursor.
|
| 43 |
-
[('Ahmet', 85), ('Mehmet', 92)])
|
| 44 |
|
| 45 |
db.commit()
|
|
|
|
| 1 |
import sqlite3
|
| 2 |
+
import os
|
| 3 |
from flask import g
|
| 4 |
|
| 5 |
def get_db_path():
|
|
|
|
| 6 |
if os.path.exists('/data'):
|
| 7 |
+
return '/data/udids.db'
|
| 8 |
elif os.path.exists('/home/user_data'):
|
| 9 |
+
return '/home/user_data/udids.db'
|
| 10 |
+
return 'udids.db'
|
| 11 |
|
| 12 |
def get_db():
|
| 13 |
if 'db' not in g:
|
| 14 |
db_path = get_db_path()
|
|
|
|
| 15 |
os.makedirs(os.path.dirname(db_path), exist_ok=True)
|
| 16 |
g.db = sqlite3.connect(db_path)
|
| 17 |
g.db.row_factory = sqlite3.Row
|
|
|
|
| 28 |
cursor = db.cursor()
|
| 29 |
|
| 30 |
cursor.execute('''
|
| 31 |
+
CREATE TABLE IF NOT EXISTS udids (
|
| 32 |
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 33 |
+
udid TEXT NOT NULL UNIQUE
|
|
|
|
| 34 |
)
|
| 35 |
''')
|
| 36 |
|
| 37 |
+
# Örnek veri ekleme
|
| 38 |
+
cursor.execute('SELECT COUNT(*) FROM udids')
|
| 39 |
if cursor.fetchone()[0] == 0:
|
| 40 |
+
cursor.execute('INSERT INTO udids (udid) VALUES (?)', ('deneme-udid',))
|
|
|
|
| 41 |
|
| 42 |
db.commit()
|