db_access

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2024 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBTX

type DBTX interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
}

type FileStatusType

type FileStatusType string
const (
	FileStatusTypeNew     FileStatusType = "new"
	FileStatusTypeShared  FileStatusType = "shared"
	FileStatusTypeDeleted FileStatusType = "deleted"
	FileStatusTypeUpdated FileStatusType = "updated"
)

func (*FileStatusType) Scan

func (e *FileStatusType) Scan(src interface{}) error

type FileStorage

type FileStorage struct {
	ID               int32              `json:"id"`
	PeerID           uuid.UUID          `json:"peer_id"`
	FileName         string             `json:"file_name"`
	FilePath         string             `json:"file_path"`
	FileType         string             `json:"file_type"`
	FileHash         *string            `json:"file_hash"`
	PrevFileHash     *string            `json:"prev_file_hash"`
	Creation         pgtype.Timestamptz `json:"creation"`
	ModificationDate pgtype.Timestamp   `json:"modification_date"`
	FileState        NullFileStatusType `json:"file_state"`
	FileData         []byte             `json:"file_data"`
}

type InsertFileParams

type InsertFileParams struct {
	PeerID           uuid.UUID          `json:"peer_id"`
	FileName         string             `json:"file_name"`
	FilePath         string             `json:"file_path"`
	FileType         string             `json:"file_type"`
	ModificationDate pgtype.Timestamp   `json:"modification_date"`
	FileState        NullFileStatusType `json:"file_state"`
	FileData         []byte             `json:"file_data"`
}

type NullFileStatusType

type NullFileStatusType struct {
	FileStatusType FileStatusType `json:"file_status_type"`
	Valid          bool           `json:"valid"` // Valid is true if FileStatusType is not NULL
}

func (*NullFileStatusType) Scan

func (ns *NullFileStatusType) Scan(value interface{}) error

Scan implements the Scanner interface.

func (NullFileStatusType) Value

func (ns NullFileStatusType) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type PeersTable

type PeersTable struct {
	ID        int32       `json:"id"`
	PeerID    pgtype.UUID `json:"peer_id"`
	IpAddress string      `json:"ip_address"`
	Pem       []byte      `json:"pem"`
}

type Queries

type Queries struct {
	// contains filtered or unexported fields
}

func New

func New(db DBTX) *Queries

func (*Queries) GetFileData

func (q *Queries) GetFileData(ctx context.Context, fileHash *string) (interface{}, error)

GetFileData

SELECT (
    peer_id,
    file_state,
    file_data
) FROM file_storage
WHERE file_hash = $1

func (*Queries) GetFiles

func (q *Queries) GetFiles(ctx context.Context, peerID uuid.UUID) ([]interface{}, error)

GetFiles

SELECT (
    file_name,
    file_path,
    file_type,
    modification_date,
    file_state,
    file_hash,
    prev_file_hash
) FROM file_storage
WHERE peer_id = $1

func (*Queries) InsertFile

func (q *Queries) InsertFile(ctx context.Context, arg *InsertFileParams) (interface{}, error)

InsertFile

INSERT INTO file_storage (
    peer_id,
    file_name,
    file_path,
    file_type,
    modification_date,
    file_state,
    file_data
) VALUES (
    $1,
    $2,
    $3,
    $4,
    $5,
    $6,
    $7
) RETURNING (
    id,
    file_hash
)

func (*Queries) WithTx

func (q *Queries) WithTx(tx pgx.Tx) *Queries

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL