Download database.py from anime-backend/stablediffusionapi: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/anime-backend/stablediffusionapi/resolve/bb6afb40ddbf4a32442e802f8fe26e66b3cb5fa0/database.py
- Command line
-
hf download hf://spaces/anime-backend/stablediffusionapi@bb6afb40ddbf4a32442e802f8fe26e66b3cb5fa0/database.py
-
curl -L -o database.py https://huggingface.co/spaces/anime-backend/stablediffusionapi/resolve/bb6afb40ddbf4a32442e802f8fe26e66b3cb5fa0/database.py
1.1 kB
| import sqlite3 | |
| import os | |
| from flask import g | |
| def get_db_path(): | |
| if os.path.exists('/data'): | |
| return '/data/udids.db' | |
| elif os.path.exists('/home/user_data'): | |
| return '/home/user_data/udids.db' | |
| return 'udids.db' | |
| def get_db(): | |
| if 'db' not in g: | |
| db_path = get_db_path() | |
| os.makedirs(os.path.dirname(db_path), exist_ok=True) | |
| g.db = sqlite3.connect(db_path) | |
| g.db.row_factory = sqlite3.Row | |
| return g.db | |
| def close_db(e=None): | |
| db = g.pop('db', None) | |
| if db is not None: | |
| db.close() | |
| def init_db(app): | |
| with app.app_context(): | |
| db = get_db() | |
| cursor = db.cursor() | |
| cursor.execute(''' | |
| CREATE TABLE IF NOT EXISTS udids ( | |
| id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| udid TEXT NOT NULL UNIQUE | |
| ) | |
| ''') | |
| # Örnek veri ekleme | |
| cursor.execute('SELECT COUNT(*) FROM udids') | |
| if cursor.fetchone()[0] == 0: | |
| cursor.execute('INSERT INTO udids (udid) VALUES (?)', ('deneme-udid',)) | |
| db.commit() |