Skip to content
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

Merged
merged 2 commits into from
Mar 30, 2023
Merged

bind params on queries #189

merged 2 commits into from
Mar 30, 2023

Conversation

ChuckHend
Copy link
Collaborator

@ChuckHend ChuckHend commented Mar 30, 2023

  • Using sqlx query! marcro, which uses bind parameters, and has compile time checks on the statements.
  • use now() at time zone 'utc' from the database in the queries instead of computing time in the webserver
  • dropped "IS TRUE" from the sql statements.

@ChuckHend ChuckHend added the pgtrunk.io Created by Linear-GitHub Sync label Mar 30, 2023
for row in rows.iter() {
extensions.push(row.get(1));
extensions.push(row.name.as_ref().unwrap().to_owned());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in the cor-526 branch

@ChuckHend ChuckHend marked this pull request as ready for review March 30, 2023 18:09
Copy link
Member

@ianstanton ianstanton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question about the timestamps. Everything else seems good. Thanks for the updates!

time, extension_id, new_extension.vers
);
sqlx::query(&query).execute(&mut tx).await?;
SET updated_at = (now() at time zone 'utc')
Copy link
Member

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's updated_at timestamp, will we have slightly different values?

Copy link
Member

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 for created_at timestamps:
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

postgres=# begin;
BEGIN
postgres=*# select now();
              now              
-------------------------------
 2023-03-30 19:32:06.570287+00
(1 row)

postgres=*# select now();
              now              
-------------------------------
 2023-03-30 19:32:06.570287+00
(1 row)

postgres=*# commit;
COMMIT
postgres=# select now();
              now              
-------------------------------
 2023-03-30 19:32:23.667648+00

Copy link
Member

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.

@ChuckHend ChuckHend merged commit 974df79 into main Mar 30, 2023
@ChuckHend ChuckHend deleted the sqlx-query branch March 30, 2023 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pgtrunk.io Created by Linear-GitHub Sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants