Open gaojulong opened 3 weeks ago
Hi there! Currently, the database is in JSON format, containing links to photos. However, I am working on a more user-friendly database solution with detailed instructions that will be available soon
Brief Instruction on Using the Database:
Loading and Saving Data: You can use the load_db()
function to load data from images.json
To save data back to images.json, use the save_db(data)
function
Additionally, you can easily modify the file to implement your own database solution. Here is an example of how might look if you want to make adjustments:
import sqlite3
def init_db():
conn = sqlite3.connect('images.db')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS images (
id INTEGER PRIMARY KEY AUTOINCREMENT,
image_hash TEXT NOT NULL,
file_path TEXT NOT NULL
)
''')
conn.commit()
conn.close()
def add_image_to_db(file_path, image_hash):
conn = sqlite3.connect('images.db')
cursor = conn.cursor()
cursor.execute('INSERT INTO images (image_hash, file_path) VALUES (?, ?)', (image_hash, file_path))
conn.commit()
conn.close()
def load_db():
conn = sqlite3.connect('images.db')
cursor = conn.cursor()
cursor.execute('SELECT image_hash, file_path FROM images')
db_data = [{"hash": row[0], "path": row[1]} for row in cursor.fetchall()]
conn.close()
return db_data
def save_db(data):
conn = sqlite3.connect('images.db')
cursor = conn.cursor()
cursor.executemany('INSERT INTO images (image_hash, file_path) VALUES (?, ?)', [(entry["hash"], entry["path"]) for entry in data])
conn.commit()
conn.close()
I hope this helps! If you have any questions or need further assistance, feel free to ask
Hi there!
I hope you're doing well. I just wanted to inform you that I have switched from using a JSON format for the database to using S3 storage for handling image uploads and retrievals. This new solution improves efficiency and scalability.
Brief Instruction on Using the New S3 Database:
I hope this helps clarify the new storage solution!
How to create a database?