db_access

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 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 ConnectClientParams added in v0.0.3

type ConnectClientParams struct {
	IpAddress string      `json:"ip_address"`
	PeerID    pgtype.UUID `json:"peer_id"`
}

type CreateClientParams added in v0.0.2

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

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 DownloadFilesRow added in v0.0.3

type DownloadFilesRow struct {
	FileHash         *string          `json:"file_hash"`
	FileName         string           `json:"file_name"`
	FileData         []byte           `json:"file_data"`
	ModificationDate pgtype.Timestamp `json:"modification_date"`
}

type FileLog added in v0.0.3

type FileLog struct {
	ID                int32              `json:"id"`
	PeerID            uuid.UUID          `json:"peer_id"`
	FileHash          string             `json:"file_hash"`
	CurrentFileStatus NullFileStatusType `json:"current_file_status"`
	OldFileStatus     NullFileStatusType `json:"old_file_status"`
	DeltaTime         pgtype.Timestamptz `json:"delta_time"`
}

type FileStatusType

type FileStatusType string
const (
	FileStatusTypeNew     FileStatusType = "new"
	FileStatusTypeDeleted FileStatusType = "deleted"
	FileStatusTypeUpdated FileStatusType = "updated"
	FileStatusTypeStored  FileStatusType = "stored"
)

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 FileTrackerStatus added in v0.0.3

type FileTrackerStatus string
const (
	FileTrackerStatusRequested FileTrackerStatus = "requested"
	FileTrackerStatusUploaded  FileTrackerStatus = "uploaded"
	FileTrackerStatusStored    FileTrackerStatus = "stored"
	FileTrackerStatusDeleted   FileTrackerStatus = "deleted"
)

func (*FileTrackerStatus) Scan added in v0.0.3

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

type GetFileDataRow added in v0.0.3

type GetFileDataRow struct {
	PeerID    uuid.UUID          `json:"peer_id"`
	FileState NullFileStatusType `json:"file_state"`
	FileData  []byte             `json:"file_data"`
}

type GetFilesRow added in v0.0.3

type GetFilesRow struct {
	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"`
	FileHash         *string            `json:"file_hash"`
	PrevFileHash     *string            `json:"prev_file_hash"`
}

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 InsertFileRow added in v0.0.3

type InsertFileRow struct {
	ID       int32   `json:"id"`
	FileHash *string `json:"file_hash"`
}

type MarkFileDeletedParams added in v0.0.3

type MarkFileDeletedParams struct {
	PeerID   uuid.UUID `json:"peer_id"`
	FileHash *string   `json:"file_hash"`
}

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 NullFileTrackerStatus added in v0.0.3

type NullFileTrackerStatus struct {
	FileTrackerStatus FileTrackerStatus `json:"file_tracker_status"`
	Valid             bool              `json:"valid"` // Valid is true if FileTrackerStatus is not NULL
}

func (*NullFileTrackerStatus) Scan added in v0.0.3

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

Scan implements the Scanner interface.

func (NullFileTrackerStatus) Value added in v0.0.3

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

Value implements the driver Valuer interface.

type NullPeerRoleType added in v0.0.3

type NullPeerRoleType struct {
	PeerRoleType PeerRoleType `json:"peer_role_type"`
	Valid        bool         `json:"valid"` // Valid is true if PeerRoleType is not NULL
}

func (*NullPeerRoleType) Scan added in v0.0.3

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

Scan implements the Scanner interface.

func (NullPeerRoleType) Value added in v0.0.3

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

Value implements the driver Valuer interface.

type PeerRoleType added in v0.0.3

type PeerRoleType string
const (
	PeerRoleTypeClient  PeerRoleType = "client"
	PeerRoleTypeStorage PeerRoleType = "storage"
	PeerRoleTypeServer  PeerRoleType = "server"
)

func (*PeerRoleType) Scan added in v0.0.3

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

type PeersTable

type PeersTable struct {
	ID        int32            `json:"id"`
	PeerID    pgtype.UUID      `json:"peer_id"`
	IpAddress string           `json:"ip_address"`
	PeerRole  NullPeerRoleType `json:"peer_role"`
	PeerName  *string          `json:"peer_name"`
	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, arg *ConnectClientParams) ([]*PeersTable, error)

ConnectClient

SELECT id, peer_id, ip_address, peer_role, peer_name, pem FROM peers_table
WHERE (
     ip_address = $1
     AND
     peer_id = $2
)
LIMIT 1

func (*Queries) CountIfStored added in v0.0.3

func (q *Queries) CountIfStored(ctx context.Context, db DBTX, fileHash *string) (int64, error)

CountIfStored

SELECT COUNT(*) FROM file_storage
WHERE
    (
        file_hash = $1
        OR
        prev_file_hash = $1
    )
AND
    file_state = 'stored'

func (*Queries) CreateClient added in v0.0.2

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

CreateClient

INSERT INTO peers_table(peer_id,ip_address, PEM,peer_role)
VALUES  (default,$1, $2,$3)
RETURNING id, peer_id, ip_address, peer_role, peer_name, pem

func (*Queries) DownloadFiles added in v0.0.3

func (q *Queries) DownloadFiles(ctx context.Context, db DBTX, peerID uuid.UUID) ([]*DownloadFilesRow, error)

DownloadFiles

SELECT
    file_hash,
    file_name,
    file_data,
    modification_date
FROM file_storage
WHERE
    peer_id = $1
    AND
    file_state != 'deleted'
    AND
    file_data IS NOT NULL

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) GetCountOfStoragePeers added in v0.0.3

func (q *Queries) GetCountOfStoragePeers(ctx context.Context, db DBTX) (int64, error)

GetCountOfStoragePeers

SELECT COUNT(*) FROM peers_table
WHERE peer_role = 'storage'

func (*Queries) GetFileData

func (q *Queries) GetFileData(ctx context.Context, db DBTX, fileHash *string) ([]*GetFileDataRow, 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) ([]*GetFilesRow, 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
ORDER BY modification_date DESC

func (*Queries) InsertFile

func (q *Queries) InsertFile(ctx context.Context, db DBTX, arg *InsertFileParams) (*InsertFileRow, 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) MarkFileDeleted added in v0.0.3

func (q *Queries) MarkFileDeleted(ctx context.Context, db DBTX, arg *MarkFileDeletedParams) error

MarkFileDeleted

UPDATE file_storage
SET
    file_state = 'deleted'
WHERE
    peer_id = $1
    AND
    file_hash = $2
    AND
    file_state != 'deleted'

func (*Queries) UpdateFileLog added in v0.0.3

func (q *Queries) UpdateFileLog(ctx context.Context, db DBTX, arg *UpdateFileLogParams) error

UpdateFileLog

INSERT  INTO file_log (
    peer_id,
    file_hash,
    current_file_status,
    old_file_status
) VALUES
    ($1, $2, $3, $4)

func (*Queries) UpdatePeerRole added in v0.0.3

func (q *Queries) UpdatePeerRole(ctx context.Context, db DBTX, arg *UpdatePeerRoleParams) error

UpdatePeerRole

UPDATE peers_table
SET
    peer_role = $2
WHERE
    peer_id = $1

type UpdateFileLogParams added in v0.0.3

type UpdateFileLogParams struct {
	PeerID            uuid.UUID          `json:"peer_id"`
	FileHash          string             `json:"file_hash"`
	CurrentFileStatus NullFileStatusType `json:"current_file_status"`
	OldFileStatus     NullFileStatusType `json:"old_file_status"`
}

type UpdatePeerRoleParams added in v0.0.3

type UpdatePeerRoleParams struct {
	PeerID   pgtype.UUID      `json:"peer_id"`
	PeerRole NullPeerRoleType `json:"peer_role"`
}

Jump to

Keyboard shortcuts

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