Skip to content

Commit

Permalink
Be explicit about table names in queries
Browse files Browse the repository at this point in the history
  • Loading branch information
theandrew168 committed Aug 8, 2024
1 parent 0cf70b0 commit a774e18
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 99 deletions.
28 changes: 14 additions & 14 deletions backend/storage/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ func (s *AccountStorage) Create(account *model.Account) error {
func (s *AccountStorage) Read(id uuid.UUID) (*model.Account, error) {
stmt := `
SELECT
id,
username,
password_hash,
is_admin,
created_at,
updated_at
account.id,
account.username,
account.password_hash,
account.is_admin,
account.created_at,
account.updated_at
FROM account
WHERE id = $1`
WHERE account.id = $1`

ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
defer cancel()
Expand All @@ -119,14 +119,14 @@ func (s *AccountStorage) Read(id uuid.UUID) (*model.Account, error) {
func (s *AccountStorage) ReadByUsername(username string) (*model.Account, error) {
stmt := `
SELECT
id,
username,
password_hash,
is_admin,
created_at,
updated_at
account.id,
account.username,
account.password_hash,
account.is_admin,
account.created_at,
account.updated_at
FROM account
WHERE username = $1`
WHERE account.username = $1`

ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
defer cancel()
Expand Down
83 changes: 42 additions & 41 deletions backend/storage/blog.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ func (s *BlogStorage) Create(blog *model.Blog) error {
func (s *BlogStorage) Read(id uuid.UUID) (*model.Blog, error) {
stmt := `
SELECT
id,
feed_url,
site_url,
title,
etag,
last_modified,
synced_at,
created_at,
updated_at
blog.id,
blog.feed_url,
blog.site_url,
blog.title,
blog.etag,
blog.last_modified,
blog.synced_at,
blog.created_at,
blog.updated_at
FROM blog
WHERE id = $1`

Expand All @@ -134,17 +134,17 @@ func (s *BlogStorage) Read(id uuid.UUID) (*model.Blog, error) {
func (s *BlogStorage) ReadByFeedURL(feedURL string) (*model.Blog, error) {
stmt := `
SELECT
id,
feed_url,
site_url,
title,
etag,
last_modified,
synced_at,
created_at,
updated_at
blog.id,
blog.feed_url,
blog.site_url,
blog.title,
blog.etag,
blog.last_modified,
blog.synced_at,
blog.created_at,
blog.updated_at
FROM blog
WHERE feed_url = $1`
WHERE blog.feed_url = $1`

ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
defer cancel()
Expand All @@ -165,17 +165,17 @@ func (s *BlogStorage) ReadByFeedURL(feedURL string) (*model.Blog, error) {
func (s *BlogStorage) List(limit, offset int) ([]*model.Blog, error) {
stmt := `
SELECT
id,
feed_url,
site_url,
title,
etag,
last_modified,
synced_at,
created_at,
updated_at
blog.id,
blog.feed_url,
blog.site_url,
blog.title,
blog.etag,
blog.last_modified,
blog.synced_at,
blog.created_at,
blog.updated_at
FROM blog
ORDER BY created_at DESC
ORDER BY blog.created_at DESC
LIMIT $1 OFFSET $2`

ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
Expand Down Expand Up @@ -220,7 +220,7 @@ func (s *BlogStorage) ListByAccount(account *model.Account, limit, offset int) (
INNER JOIN account_blog
ON account_blog.blog_id = blog.id
WHERE account_blog.account_id = $1
ORDER BY created_at DESC
ORDER BY blog.created_at DESC
LIMIT $2 OFFSET $3`

ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
Expand Down Expand Up @@ -249,20 +249,21 @@ func (s *BlogStorage) ListByAccount(account *model.Account, limit, offset int) (
return blogs, nil
}

// DEPRECATED
func (s *BlogStorage) ListAll() ([]*model.Blog, error) {
stmt := `
SELECT
id,
feed_url,
site_url,
title,
etag,
last_modified,
synced_at,
created_at,
updated_at
blog.id,
blog.feed_url,
blog.site_url,
blog.title,
blog.etag,
blog.last_modified,
blog.synced_at,
blog.created_at,
blog.updated_at
FROM blog
ORDER BY created_at DESC`
ORDER BY blog.created_at DESC`

ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
defer cancel()
Expand Down Expand Up @@ -324,7 +325,7 @@ func (s *BlogStorage) Update(blog *model.Blog) error {
synced_at = $6,
updated_at = $7
WHERE id = $8
AND updated_at = $9
AND updated_at = $9
RETURNING updated_at`

row, err := marshalBlog(blog)
Expand Down
54 changes: 27 additions & 27 deletions backend/storage/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@ func (s *PostStorage) Create(post *model.Post) error {
func (s *PostStorage) Read(id uuid.UUID) (*model.Post, error) {
stmt := `
SELECT
id,
blog_id,
url,
title,
content,
published_at,
created_at,
updated_at
post.id,
post.blog_id,
post.url,
post.title,
post.content,
post.published_at,
post.created_at,
post.updated_at
FROM post
WHERE id = $1`
WHERE post.id = $1`

ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
defer cancel()
Expand All @@ -129,16 +129,16 @@ func (s *PostStorage) Read(id uuid.UUID) (*model.Post, error) {
func (s *PostStorage) ReadByURL(url string) (*model.Post, error) {
stmt := `
SELECT
id,
blog_id,
url,
title,
content,
published_at,
created_at,
updated_at
post.id,
post.blog_id,
post.url,
post.title,
post.content,
post.published_at,
post.created_at,
post.updated_at
FROM post
WHERE url = $1`
WHERE post.url = $1`

ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
defer cancel()
Expand All @@ -159,17 +159,17 @@ func (s *PostStorage) ReadByURL(url string) (*model.Post, error) {
func (s *PostStorage) List(blog *model.Blog, limit, offset int) ([]*model.Post, error) {
stmt := `
SELECT
id,
blog_id,
url,
title,
content,
published_at,
created_at,
updated_at
post.id,
post.blog_id,
post.url,
post.title,
post.content,
post.published_at,
post.created_at,
post.updated_at
FROM post
WHERE post.blog_id = $1
ORDER BY published_at DESC
ORDER BY post.published_at DESC
LIMIT $2 OFFSET $3`

ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
Expand Down
20 changes: 10 additions & 10 deletions backend/storage/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ func (s *TagStorage) Create(tag *model.Tag) error {
func (s *TagStorage) Read(id uuid.UUID) (*model.Tag, error) {
stmt := `
SELECT
id,
name,
created_at,
updated_at
tag.id,
tag.name,
tag.created_at,
tag.updated_at
FROM tag
WHERE id = $1`
WHERE tag.id = $1`

ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
defer cancel()
Expand All @@ -108,12 +108,12 @@ func (s *TagStorage) Read(id uuid.UUID) (*model.Tag, error) {
func (s *TagStorage) List(limit, offset int) ([]*model.Tag, error) {
stmt := `
SELECT
id,
name,
created_at,
updated_at
tag.id,
tag.name,
tag.created_at,
tag.updated_at
FROM tag
ORDER BY created_at DESC
ORDER BY tag.created_at DESC
LIMIT $1 OFFSET $2`

ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
Expand Down
14 changes: 7 additions & 7 deletions backend/storage/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ func (s *TokenStorage) Create(token *model.Token) error {
func (s *TokenStorage) Read(id uuid.UUID) (*model.Token, error) {
stmt := `
SELECT
id,
account_id,
hash,
expires_at,
created_at,
updated_at
token.id,
token.account_id,
token.hash,
token.expires_at,
token.created_at,
token.updated_at
FROM token
WHERE id = $1`
WHERE token.id = $1`

ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
defer cancel()
Expand Down

0 comments on commit a774e18

Please sign in to comment.