yusufgundogdu commited on
Commit
d31320d
·
verified ·
1 Parent(s): ed2095c

Update database.py

Browse files
Files changed (1) hide show
  1. 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/udids.db'
9
- elif os.path.exists('/home/udid_data'):
10
- return '/home/udid_data/udids.db'
11
- return 'udids.db'
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 udids (
34
  id INTEGER PRIMARY KEY AUTOINCREMENT,
35
- name TEXT NOT NULL
 
36
  )
37
  ''')
38
 
39
- cursor.execute('SELECT COUNT(*) FROM udids')
40
  if cursor.fetchone()[0] == 0:
41
- cursor.executemany('INSERT INTO udids (name) VALUES (?)',
42
- [('111'), ('222')])
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()