From 54a201d0a833482d807faef03b8aa032857a9bfc Mon Sep 17 00:00:00 2001 From: Yanislav Igonin Date: Wed, 1 Sep 2021 18:40:13 +0300 Subject: [PATCH] feat: add files creation in repo --- repositories/files_repository.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 repositories/files_repository.go diff --git a/repositories/files_repository.go b/repositories/files_repository.go new file mode 100644 index 0000000..5884f53 --- /dev/null +++ b/repositories/files_repository.go @@ -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 +}