SQL add_meme returns meme ID
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
abc4345fc1
commit
467c00410c
2 changed files with 10 additions and 4 deletions
|
@ -149,7 +149,7 @@ async fn upload(
|
|||
for f in files {
|
||||
let res = cat.add_meme(&user, &f, &ip, &db_pool).await?;
|
||||
|
||||
if res != 1 {
|
||||
if res == 0 {
|
||||
return Err(APIError::Internal("Database insertion error".to_string()));
|
||||
}
|
||||
|
||||
|
|
|
@ -116,14 +116,20 @@ impl Category {
|
|||
ip: &String,
|
||||
pool: &MySqlPool,
|
||||
) -> Result<u64> {
|
||||
let q = sqlx::query("INSERT INTO memes (filename, user, category, timestamp, ip, cid) VALUES (?, ?, ?, NOW(), ?, ?)")
|
||||
let mut tx = pool.begin().await?;
|
||||
sqlx::query("INSERT INTO memes (filename, user, category, timestamp, ip, cid) VALUES (?, ?, ?, NOW(), ?, ?)")
|
||||
.bind(&file.name)
|
||||
.bind(&user.id)
|
||||
.bind(&self.id)
|
||||
.bind(ip)
|
||||
.bind(&file.hash)
|
||||
.execute(pool).await?;
|
||||
Ok(q)
|
||||
.execute(&mut tx).await?;
|
||||
let id: u64 = sqlx::query("SELECT LAST_INSERT_ID() as id")
|
||||
.map(|row: MySqlRow| row.get("id"))
|
||||
.fetch_one(&mut tx)
|
||||
.await?;
|
||||
tx.commit().await?;
|
||||
Ok(id)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue