db_access

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 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 CreateClientParams added in v0.0.2

type CreateClientParams struct {
	IpAddress string `json:"ip_address"`
	Pem       []byte `json:"pem"`
}

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"
	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 {
}

func New

func New() *Queries

func (*Queries) ConnectClient added in v0.0.2

func (q *Queries) ConnectClient(ctx context.Context, db DBTX, ipAddress string) ([]*PeersTable, error)

ConnectClient

SELECT id, peer_id, ip_address, pem FROM peers_table
WHERE ip_address = $1
LIMIT 1

func (*Queries) CreateClient added in v0.0.2

func (q *Queries) CreateClient(ctx context.Context, db DBTX, arg *CreateClientParams) ([]pgtype.UUID, error)

CreateClient

INSERT INTO peers_table(peer_id,ip_address, PEM )
VALUES  (default,$1, $2)
RETURNING (peer_id)

func (*Queries) GetAllPem added in v0.0.2

func (q *Queries) GetAllPem(ctx context.Context, db DBTX) ([][]byte, error)

GetAllPem

SELECT (pem) FROM peers_table

func (*Queries) GetFileData

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

GetFileData

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

func (*Queries) GetFiles

func (q *Queries) GetFiles(ctx context.Context, db DBTX, 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, db DBTX, 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
)

Jump to

Keyboard shortcuts

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