yusufgundogdu commited on
Commit
6761847
·
verified ·
1 Parent(s): ddba67b

Update database.py

Browse files
Files changed (1) hide show
  1. database.py +9 -12
database.py CHANGED
@@ -1,19 +1,17 @@
1
  import sqlite3
2
- import os # Eksik olan import eklendi
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/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:
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 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()
 
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()