yusufgundogdu commited on
Commit
b087d51
·
verified ·
1 Parent(s): 06759fe

Delete database.py

Browse files
Files changed (1) hide show
  1. database.py +0 -47
database.py DELETED
@@ -1,47 +0,0 @@
1
- import sqlite3
2
- import os
3
- from flask import g
4
-
5
- def get_db_path():
6
- """Veritabanı dosya yolunu belirler"""
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
- """Veritabanı bağlantısını getirir veya oluşturur"""
15
- if 'db' not in g:
16
- db_path = get_db_path()
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
20
- return g.db
21
-
22
- def close_db(e=None):
23
- """Veritabanı bağlantısını kapatır"""
24
- db = g.pop('db', None)
25
- if db is not None:
26
- db.close()
27
-
28
-
29
- def create_user(udid, platform):
30
- """Yeni kullanıcı oluşturur"""
31
- try:
32
- if platform not in ['AND', 'IOS']:
33
- raise ValueError("Platform must be either 'AND' or 'IOS'")
34
-
35
- db = get_db()
36
- cursor = db.cursor()
37
- cursor.execute('INSERT INTO users (udid, platform) VALUES (?, ?)', (udid, platform))
38
- db.commit()
39
- cursor.execute('SELECT * FROM users WHERE udid = ?', (udid,))
40
- new_user = cursor.fetchone()
41
- return dict(new_user) if new_user else None
42
-
43
- except sqlite3.IntegrityError:
44
- raise ValueError("User with this UDID already exists")
45
- except Exception as e:
46
- db.rollback()
47
- raise e