update method now written should build fine
This commit is contained in:
parent
d08ae63f50
commit
5e48fa1ab9
@ -6,7 +6,7 @@ use async_trait::async_trait;
|
|||||||
|
|
||||||
use crate::{VarChar, UBigInt, Integer};
|
use crate::{VarChar, UBigInt, Integer};
|
||||||
use crate::common::FromDB;
|
use crate::common::FromDB;
|
||||||
use crate::{no_conn, Response};
|
use crate::{sql_err, no_conn, Response};
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub struct Channel {
|
pub struct Channel {
|
||||||
@ -23,7 +23,7 @@ impl FromDB<Channel> for Channel {
|
|||||||
|
|
||||||
async fn get(p: &Pool, id: UBigInt) -> Response<Channel> {
|
async fn get(p: &Pool, id: UBigInt) -> Response<Channel> {
|
||||||
if let Ok(conn) = p.get_conn().await {
|
if let Ok(conn) = p.get_conn().await {
|
||||||
let q = "SELECT id, name, description, kind WHERE id = :id";
|
let q = "SELECT id, name, description, kind FROM channels WHERE id = :id";
|
||||||
let result: Result<(Conn, Self::Row), SqlError> =
|
let result: Result<(Conn, Self::Row), SqlError> =
|
||||||
conn.first_exec(q, params!{"id" => id}).await;
|
conn.first_exec(q, params!{"id" => id}).await;
|
||||||
if let Ok((_, row)) = result {
|
if let Ok((_, row)) = result {
|
||||||
@ -44,7 +44,23 @@ impl FromDB<Channel> for Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn update(p: &Pool, row: Self) -> Response<Channel> {
|
async fn update(p: &Pool, row: Self) -> Response<Channel> {
|
||||||
unimplemented!()
|
if let Ok(conn) = p.get_conn().await {
|
||||||
|
let q = "UPDATE channels
|
||||||
|
SET name = :name, description = :desc, kind = :kind
|
||||||
|
WHERE id = :id";
|
||||||
|
let result: Result<Conn, SqlError> =
|
||||||
|
conn.drop_exec(q, params!{
|
||||||
|
"id" => row.id,
|
||||||
|
"name" => row.name,
|
||||||
|
"desc" => row.description,
|
||||||
|
"kind" => row.kind
|
||||||
|
}).await;
|
||||||
|
return match result {
|
||||||
|
Ok(_) => Response::Success,
|
||||||
|
Err(_) => Response::Other(sql_err!("Invite::FromDB::update Update failed"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Response::Other(no_conn!("Invite::FromDB::get connection failed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete(p: &Pool, id: UBigInt) -> Response<Channel> {
|
async fn delete(p: &Pool, id: UBigInt) -> Response<Channel> {
|
||||||
|
Loading…
Reference in New Issue
Block a user