mirror of
https://github.com/yanislav-igonin/micrach
synced 2024-12-22 14:22:33 +03:00
feat: remove conn aquire in file create
This commit is contained in:
parent
2a21b5b4b0
commit
545a131801
@ -13,22 +13,16 @@ type FilesRepository struct{}
|
|||||||
var Files FilesRepository
|
var Files FilesRepository
|
||||||
|
|
||||||
func (r *FilesRepository) Create(f File) error {
|
func (r *FilesRepository) Create(f File) error {
|
||||||
conn, err := Db.Pool.Acquire(context.TODO())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer conn.Release()
|
|
||||||
|
|
||||||
sql := `
|
sql := `
|
||||||
INSERT INTO files (post_id, name, ext, size)
|
INSERT INTO files (post_id, name, ext, size)
|
||||||
VALUES ($1, $2, $3, $4)
|
VALUES ($1, $2, $3, $4)
|
||||||
`
|
`
|
||||||
|
|
||||||
row := conn.QueryRow(
|
row := Db.Pool.QueryRow(
|
||||||
context.TODO(), sql, f.PostID, f.Name, f.Ext, f.Size,
|
context.TODO(), sql, f.PostID, f.Name, f.Ext, f.Size,
|
||||||
)
|
)
|
||||||
|
|
||||||
err = row.Scan()
|
err := row.Scan()
|
||||||
if err != nil && err != pgx.ErrNoRows {
|
if err != nil && err != pgx.ErrNoRows {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user