You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to make command that executes query and output this in format:
col1=val1 col2=val2 ...
(this is Serenity Discord bot command):
#[command]#[description("Fetch single row from DB table.")]#[owners_only]asyncfnrow(ctx:&Context,msg:&Message,args:Args) -> CommandResult{// First we have to get PostgreSQL pool.let data = ctx.data.read().await;let pool = data.get::<PostgresPool>().expect("Unable to get PostgreSQL pool.");// After this, we can execute query.let raw_result: sqlx::postgres::PgRow = sqlx::query(args.rest()).fetch_one(pool).await?;letmut result = String::new();for column in raw_result.columns().iter(){let value:&str = raw_result.get(column.name());
result.push_str(format!("{}={:?} ", column.name(), value).as_str());}
msg.channel_id.send_message(ctx, |m| {
m.embed(|e| {
e.title("Query result");
e.description(format!("```{}```", result));
e
});
m
}).await?;Ok(())}
Biggest problem of this is that I don't know to what type to convert it value. I want that this convert value to that type what is equal with column's PostgreSQL type. How to do this?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I want to make command that executes query and output this in format:
(this is Serenity Discord bot command):
Biggest problem of this is that I don't know to what type to convert it value. I want that this convert value to that type what is equal with column's PostgreSQL type. How to do this?
Beta Was this translation helpful? Give feedback.
All reactions