-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bind params on queries #189
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,7 @@ use crate::config::Config; | |
use crate::connect; | ||
use crate::errors::ExtensionRegistryError; | ||
use actix_web::{get, web, HttpResponse, Responder}; | ||
use sqlx::Row; | ||
|
||
use log::info; | ||
#[get("/")] | ||
pub async fn running() -> impl Responder { | ||
HttpResponse::Ok().body("API is up and running!") | ||
|
@@ -19,10 +18,9 @@ pub async fn get_all_extensions( | |
// Create a transaction on the database, if there are no errors, | ||
// commit the transactions to record a new or updated extension. | ||
let mut tx = conn.begin().await?; | ||
let query = format!("SELECT * FROM extensions",); | ||
let rows = sqlx::query(&query).fetch_all(&mut tx).await?; | ||
let rows = sqlx::query!("SELECT * FROM extensions").fetch_all(&mut tx).await?; | ||
for row in rows.iter() { | ||
extensions.push(row.get(1)); | ||
extensions.push(row.name.as_ref().unwrap().to_owned()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is going to change very soon right? This should probably return json formatted instead of just the name as a string. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, in the |
||
} | ||
// Return results in response | ||
Ok(HttpResponse::Ok().body(format!("{:?}", extensions))) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use
(now() at time zone 'utc')
here (updating version record) and below when we update the extension'supdated_at
timestamp, will we have slightly different values?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, if we assign
time
above we ensure the timestamps are the same when an extension version is updated. Similar forcreated_at
timestamps:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now()
will stay the same within the transaction.https://database.guide/how-now-works-in-postgresql/#:~:text=In%20PostgreSQL%2C%20the%20now(),when%20called%20without%20an%20argument).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense! That's exactly what we want.