Skip to content

Commit

Permalink
Some correction repo. It didn't write in BD when SendMessage and Delete
Browse files Browse the repository at this point in the history
  • Loading branch information
mchekalov committed Mar 20, 2024
1 parent 229fd02 commit 5247f04
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions internal/client/db/pg/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ type pg struct {
}

// NewDB creates a new PostgreSQL database client.
func NewDB(dbc *pgxpool.Pool) db.DB {
return &pg{
dbc: dbc,
}
}
//func NewDB(dbc *pgxpool.Pool) db.DB {
// return &pg{
// dbc: dbc,
// }
//}

func (p *pg) ScanOneContext(ctx context.Context, dest interface{}, q db.Query, args ...interface{}) error {
logQuery(ctx, q, args...)
Expand Down
8 changes: 4 additions & 4 deletions internal/repository/chat/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

const (
tableName = "chats"
chatnameColumn = "chat_name"
chatNameColumn = "chat_name"
chatIDColumn = "chat_id"
)

Expand All @@ -41,7 +41,7 @@ func (r *repo) Create(ctx context.Context, chat *model.Chat) (int64, error) {
chatRepo := converter.FromChatToRepo(chat)

builder := r.sq.Insert(tableName).
Columns(chatnameColumn).
Columns(chatNameColumn).
Values(chatRepo.ChatName).
Suffix(fmt.Sprintf("RETURNING %v", chatIDColumn))

Expand All @@ -66,7 +66,7 @@ func (r *repo) Create(ctx context.Context, chat *model.Chat) (int64, error) {

func (r *repo) Delete(ctx context.Context, id *model.ChatDelete) error {
builder := r.sq.Delete(tableName).
Where(squirrel.Eq{chatIDColumn: id})
Where(squirrel.Eq{chatIDColumn: id.ChatID})

query, args, err := builder.ToSql()
if err != nil {
Expand Down Expand Up @@ -98,7 +98,7 @@ func (r *repo) SaveMessage(ctx context.Context, message *model.Message) error {
QueryRaw: query,
}

r.db.DB().QueryRowContext(ctx, q, args)
r.db.DB().QueryRowContext(ctx, q, args...)

return nil
}

0 comments on commit 5247f04

Please sign in to comment.