about summary refs log blame commit diff
path: root/src/payload-processor/processor/db.go
blob: 220093745a99523f061ac664c4c607322700dda4 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11



                 
 
                                                  




                                                                                   
                                                                            











                              

                                                                                       
                                                                                                                                                                                      

                  
package processor

import (
	"context"

	"github.com/Baitinq/fs-tracer-backend/lib"
	"github.com/jmoiron/sqlx"
)

//go:generate mockgen -source=$GOFILE -package=$GOPACKAGE -destination=mock_$GOFILE
type DB interface {
	InsertFile(ctx context.Context, file lib.File, user_id string) error
}

type DBImpl struct {
	db *sqlx.DB
}

var _ DB = (*DBImpl)(nil)

func NewDB(db *sqlx.DB) DB {
	return &DBImpl{db: db}
}

func (db DBImpl) InsertFile(ctx context.Context, file lib.File, user_id string) error {
	file.User_id = user_id
	_, err := db.db.NamedExecContext(ctx, "INSERT INTO private.file (user_id, absolute_path, contents, timestamp) VALUES (:user_id, :absolute_path, :contents, :timestamp)", file)
	return err
}