mirror of
https://github.com/yanislav-igonin/micrach
synced 2024-12-22 14:22:33 +03:00
feat: add files creation in repo
This commit is contained in:
parent
0e46965130
commit
54a201d0a8
29
repositories/files_repository.go
Normal file
29
repositories/files_repository.go
Normal file
@ -0,0 +1,29 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"context"
|
||||
Db "micrach/db"
|
||||
)
|
||||
|
||||
type FilesRepository struct{}
|
||||
|
||||
var Files FilesRepository
|
||||
|
||||
func (r *FilesRepository) Create(f File) error {
|
||||
conn, err := Db.Pool.Acquire(context.TODO())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Release()
|
||||
|
||||
sql := `
|
||||
INSERT INTO files (post_id, name, ext, size)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
`
|
||||
|
||||
conn.QueryRow(
|
||||
context.TODO(), sql, f.PostID, f.Name, f.Ext, f.Size,
|
||||
)
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user