refactor: simplify random ID generation in history initialization

This commit is contained in:
pandadev 2025-01-29 17:39:04 +01:00
parent 6016fbb494
commit 66df55017f
No known key found for this signature in database
GPG key ID: C39629DACB8E762F

View file

@ -1,16 +1,19 @@
use crate::utils::types::{ ContentType, HistoryItem };
use base64::{ engine::general_purpose::STANDARD, Engine };
use rand::distributions::Alphanumeric;
use rand::{ thread_rng, Rng };
use rand::{ rng, Rng };
use rand::distr::Alphanumeric;
use sqlx::{ Row, SqlitePool };
use std::fs;
use tauri_plugin_aptabase::EventTracker;
pub async fn initialize_history(pool: &SqlitePool) -> Result<(), Box<dyn std::error::Error>> {
let id: String = thread_rng().sample_iter(&Alphanumeric).take(16).map(char::from).collect();
let id: String = rng()
.sample_iter(&Alphanumeric)
.take(16)
.map(char::from)
.collect();
sqlx
::query(
sqlx::query(
"INSERT INTO history (id, source, content_type, content, timestamp) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP)"
)
.bind(id)