db_access

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2024 License: GPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBatchAlreadyClosed = errors.New("batch already closed")
)

Functions

This section is empty.

Types

type AddDirForPeerBatchResults

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

func (*AddDirForPeerBatchResults) Close

func (b *AddDirForPeerBatchResults) Close() error

func (*AddDirForPeerBatchResults) QueryRow

func (b *AddDirForPeerBatchResults) QueryRow(f func(int, *PeerDir, error))

type AddDirForPeerParams

type AddDirForPeerParams struct {
	PeerID  pgtype.UUID `json:"peer_id"`
	DirPath string      `json:"dir_path"`
}

type ConnectClientParams

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

type CreateClientParams

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

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
	SendBatch(context.Context, *pgx.Batch) pgx.BatchResults
}

type DownloadFileDataBatchResults

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

func (*DownloadFileDataBatchResults) Close

func (*DownloadFileDataBatchResults) Query

type DownloadFileDataParams

type DownloadFileDataParams struct {
	PeerID           pgtype.UUID      `json:"peer_id"`
	ModificationDate pgtype.Timestamp `json:"modification_date"`
}

type DownloadFileDataRow

type DownloadFileDataRow struct {
	FileDataID       int32              `json:"file_data_id"`
	FileHash         *string            `json:"file_hash"`
	PrevFileHash     *int32             `json:"prev_file_hash"`
	FileStatus       NullFileStatusType `json:"file_status"`
	ModificationDate pgtype.Timestamp   `json:"modification_date"`
	CreationTime     pgtype.Timestamptz `json:"creation_time"`
	FileData         []byte             `json:"file_data"`
	ID               int32              `json:"id"`
	PeerID           pgtype.UUID        `json:"peer_id"`
	DirID            *int32             `json:"dir_id"`
	FileDataID_2     *int32             `json:"file_data_id_2"`
	FileName         string             `json:"file_name"`
	FilePath         string             `json:"file_path"`
	FileType         string             `json:"file_type"`
	CreationDay      pgtype.Date        `json:"creation_day"`
	CreationTime_2   pgtype.Timestamptz `json:"creation_time_2"`
}

type DownloadFilesRow

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 FileChangeLog

type FileChangeLog struct {
	ID            int32              `json:"id"`
	PeerID        pgtype.UUID        `json:"peer_id"`
	PrevFileState NullFileStatusType `json:"prev_file_state"`
	CurrFileState NullFileStatusType `json:"curr_file_state"`
	FileHashID    *int32             `json:"file_hash_id"`
	Messagef      string             `json:"messagef"`
	JsonLog       []byte             `json:"json_log"`
}

type FileDatum

type FileDatum struct {
	FileDataID       int32              `json:"file_data_id"`
	FileHash         *string            `json:"file_hash"`
	PrevFileHash     *int32             `json:"prev_file_hash"`
	FileStatus       NullFileStatusType `json:"file_status"`
	ModificationDate pgtype.Timestamp   `json:"modification_date"`
	CreationTime     pgtype.Timestamptz `json:"creation_time"`
	FileData         []byte             `json:"file_data"`
}

type FileMetadatum

type FileMetadatum struct {
	ID           int32              `json:"id"`
	PeerID       pgtype.UUID        `json:"peer_id"`
	DirID        *int32             `json:"dir_id"`
	FileDataID   *int32             `json:"file_data_id"`
	FileName     string             `json:"file_name"`
	FilePath     string             `json:"file_path"`
	FileType     string             `json:"file_type"`
	CreationDay  pgtype.Date        `json:"creation_day"`
	CreationTime pgtype.Timestamptz `json:"creation_time"`
}

type FileStatusType

type FileStatusType string
const (
	FileStatusTypeCreated  FileStatusType = "created"
	FileStatusTypeModified FileStatusType = "modified"
	FileStatusTypeDeleted  FileStatusType = "deleted"
)

func (*FileStatusType) Scan

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

type FileTransfMsgTable

type FileTransfMsgTable struct {
	ID             int32              `json:"id"`
	PeerReqing     uuid.UUID          `json:"peer_reqing"`
	FileHash       int32              `json:"file_hash"`
	ReqTime        pgtype.Timestamptz `json:"req_time"`
	PeerResponding pgtype.UUID        `json:"peer_responding"`
	ResTime        pgtype.Timestamptz `json:"res_time"`
}

type GetFileDataRow

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

type GetFilesRow

type GetFilesRow struct {
	FilePath         string             `json:"file_path"`
	FileName         string             `json:"file_name"`
	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

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

type MarkFileDeletedParams

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 NullPeerRoleType

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

func (*NullPeerRoleType) Scan

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

Scan implements the Scanner interface.

func (NullPeerRoleType) Value

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

Value implements the driver Valuer interface.

type PeerDir

type PeerDir struct {
	ID           int32              `json:"id"`
	PeerID       pgtype.UUID        `json:"peer_id"`
	CreationTime pgtype.Timestamptz `json:"creation_time"`
	DirPath      string             `json:"dir_path"`
}

type PeerRoleType

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

func (*PeerRoleType) Scan

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"`
	CreationTime pgtype.Timestamptz `json:"creation_time"`
	Pem          []byte             `json:"pem"`
	PeerConfig   []byte             `json:"peer_config"`
}

type Queries

type Queries struct {
}

func New

func New() *Queries

func (*Queries) AddDirForPeer

func (q *Queries) AddDirForPeer(ctx context.Context, db DBTX, arg []*AddDirForPeerParams) *AddDirForPeerBatchResults

AddDirForPeer

INSERT INTO peer_dirs(
    peer_id,
    dir_path
) VALUES ($1, $2)
RETURNING id, peer_id, creation_time, dir_path

func (*Queries) ConnectClient

func (q *Queries) ConnectClient(ctx context.Context, db DBTX, peerID pgtype.UUID) (*PeersTable, error)

ConnectClient

SELECT id, peer_id, ip_address, peer_role, peer_name, creation_time, pem, peer_config
FROM peers_table
WHERE peer_id = $1

func (*Queries) CountIfStored

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

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

CreateClient

INSERT INTO peers_table(peer_id,peer_role,peer_name,pem, peer_config,ip_address)
VALUES (default, $1, $2, $3, $4, $5)
RETURNING id, peer_id, ip_address, peer_role, peer_name, creation_time, pem, peer_config

func (*Queries) DownloadFileData

func (q *Queries) DownloadFileData(ctx context.Context, db DBTX, arg []*DownloadFileDataParams) *DownloadFileDataBatchResults

DownloadFileData

SELECT
    file_data.file_data_id, file_hash, prev_file_hash, file_status, modification_date, file_data.creation_time, file_data, id, peer_id, dir_id, file_metadata.file_data_id, file_name, file_path, file_type, creation_day, file_metadata.creation_time
FROM
    file_data
    INNER JOIN file_metadata USING (file_data_id)
WHERE
    file_metadata.peer_id = $1
    AND file_data.file_data IS NOT NULL
    AND file_data.modification_date >= $2
ORDER BY
    modification_date DESC

func (*Queries) DownloadFiles

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

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

GetAllPem

SELECT pem FROM peers_table

func (*Queries) GetCountOfStoragePeers

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
    DISTINCT file_path,
    file_name,
    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

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

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

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

UpdatePeerRole

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

func (*Queries) UploadFile

func (q *Queries) UploadFile(ctx context.Context, db DBTX, arg []*UploadFileParams) *UploadFileBatchResults

UploadFile

INSERT INTO file_data(
    file_status,
    file_data,
    modification_date
) VALUES ($1, $2,$3)
ON CONFLICT (file_hash)
DO UPDATE
    SET
        file_data = $2
RETURNING
    file_data_id, file_hash

func (*Queries) UploadMetadata

func (q *Queries) UploadMetadata(ctx context.Context, db DBTX, arg []*UploadMetadataParams) *UploadMetadataBatchResults

UploadMetadata

INSERT INTO file_metadata(
    peer_id,
    dir_id,
    file_data_id,
    file_name,
    file_path,
    file_type
) VALUES($1, $2, $3, $4, $5, $6)
RETURNING id

type UpdateFileLogParams

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

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

type UploadFileBatchResults

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

func (*UploadFileBatchResults) Close

func (b *UploadFileBatchResults) Close() error

func (*UploadFileBatchResults) QueryRow

func (b *UploadFileBatchResults) QueryRow(f func(int, *UploadFileRow, error))

type UploadFileParams

type UploadFileParams struct {
	FileStatus       NullFileStatusType `json:"file_status"`
	FileData         []byte             `json:"file_data"`
	ModificationDate pgtype.Timestamp   `json:"modification_date"`
}

type UploadFileRow

type UploadFileRow struct {
	FileDataID int32   `json:"file_data_id"`
	FileHash   *string `json:"file_hash"`
}

type UploadMetadataBatchResults

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

func (*UploadMetadataBatchResults) Close

func (b *UploadMetadataBatchResults) Close() error

func (*UploadMetadataBatchResults) QueryRow

func (b *UploadMetadataBatchResults) QueryRow(f func(int, int32, error))

type UploadMetadataParams

type UploadMetadataParams struct {
	PeerID     pgtype.UUID `json:"peer_id"`
	DirID      *int32      `json:"dir_id"`
	FileDataID *int32      `json:"file_data_id"`
	FileName   string      `json:"file_name"`
	FilePath   string      `json:"file_path"`
	FileType   string      `json:"file_type"`
}

Jump to

Keyboard shortcuts

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