Update database.py
Browse files26 unmodified lines272829303132333434353637373839404142434445464748494344455051525354475556575859606162636465666768697071727374757677787980818283848526 unmodified lines db = get_db() cursor = db.cursor() # Güncellenmiş tablo yapısı cursor.execute(''' CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY AUTOINCREMENT, udid TEXT NOT NULL UNIQUE, platform TEXT DEFAULT '', platform TEXT NOT NULL CHECK (platform IN ('AND', 'IOS')), premium_account BOOLEAN DEFAULT FALSE, usage_limit INTEGER DEFAULT 10, invoice TEXT DEFAULT '' invoice TEXT DEFAULT '', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) ''') # Örnek veri eklerken platform alanını da dolduruyoruz cursor.execute('SELECT COUNT(*) FROM users') if cursor.fetchone()[0] == 0: cursor.executemany(''' INSERT INTO users (udid, platform, premium_account, usage_limit, invoice) VALUES (?, ?, ?, ?, ?) cursor.executemany('INSERT INTO users (udid, platform, premium_account, usage_limit, invoice) VALUES (?, ?, ?, ?, ?)', [('test_udid_1', 'AND', True, 4, 'test_invoice_1'), ('test_udid_2', 'IOS', False, 4, 'test_invoice_2')]) ''', [ ('test_udid_1', 'AND', True, 4, 'test_invoice_1'), ('test_udid_2', 'IOS', False, 4, 'test_invoice_2') ]) db.commit() db.commit()
def create_user(udid, platform): """Yeni kullanıcı oluşturma fonksiyonu""" try: # Platform kontrolü if platform not in ['AND', 'IOS']: raise ValueError("Platform must be either 'AND' or 'IOS'") db = get_db() cursor = db.cursor() # Yeni kullanıcıyı platform bilgisiyle birlikte ekle cursor.execute(''' INSERT INTO users (udid, platform) VALUES (?, ?) ''', (udid, platform)) db.commit() # Oluşturulan kullanıcıyı döndür cursor.execute('SELECT * FROM users WHERE udid = ?', (udid,)) new_user = cursor.fetchone() return dict(new_user) if new_user else None except sqlite3.IntegrityError: raise ValueError("User with this UDID already exists") except Exception as e: db.rollback() raise edatabase.py+44-6