postgresdb

package
v0.6.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

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

Adapter wraps postgresdb.Queries and provides the DB() method.

func NewAdapter

func NewAdapter(db *sql.DB) *Adapter

NewAdapter creates a new PostgreSQL adapter.

func (*Adapter) DB

func (a *Adapter) DB() *sql.DB

DB returns the underlying database connection.

func (*Adapter) WithTx

func (a *Adapter) WithTx(tx *sql.Tx) *Adapter

WithTx returns a new Adapter with the queries scoped to the given transaction.

type CreateNarParams

type CreateNarParams struct {
	NarInfoID   int64
	Hash        string
	Compression string
	Query       string
	FileSize    uint64
}

type DBTX

type DBTX interface {
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	PrepareContext(context.Context, string) (*sql.Stmt, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}

type Nar

type Nar struct {
	ID             int64
	NarInfoID      int64
	Hash           string
	Compression    string
	FileSize       uint64
	CreatedAt      time.Time
	UpdatedAt      sql.NullTime
	LastAccessedAt sql.NullTime
	Query          string
}

type NarInfo

type NarInfo struct {
	ID             int64
	Hash           string
	CreatedAt      time.Time
	UpdatedAt      sql.NullTime
	LastAccessedAt sql.NullTime
}

type Querier

type Querier interface {
	//CreateNar
	//
	//  INSERT INTO nars (
	//      narinfo_id, hash, compression, query, file_size
	//  ) VALUES (
	//      $1, $2, $3, $4, $5
	//  )
	//  RETURNING id, narinfo_id, hash, compression, file_size, created_at, updated_at, last_accessed_at, query
	CreateNar(ctx context.Context, arg CreateNarParams) (Nar, error)
	//CreateNarInfo
	//
	//  INSERT INTO narinfos (
	//      hash
	//  ) VALUES (
	//      $1
	//  )
	//  RETURNING id, hash, created_at, updated_at, last_accessed_at
	CreateNarInfo(ctx context.Context, hash string) (NarInfo, error)
	//DeleteNarByHash
	//
	//  DELETE FROM nars
	//  WHERE hash = $1
	DeleteNarByHash(ctx context.Context, hash string) (int64, error)
	//DeleteNarByID
	//
	//  DELETE FROM nars
	//  WHERE id = $1
	DeleteNarByID(ctx context.Context, id int64) (int64, error)
	//DeleteNarInfoByHash
	//
	//  DELETE FROM narinfos
	//  WHERE hash = $1
	DeleteNarInfoByHash(ctx context.Context, hash string) (int64, error)
	//DeleteNarInfoByID
	//
	//  DELETE FROM narinfos
	//  WHERE id = $1
	DeleteNarInfoByID(ctx context.Context, id int64) (int64, error)
	// NOTE: This query uses a correlated subquery which is not optimal for performance.
	// The ideal implementation would use a window function (SUM OVER), but sqlc v1.30.0
	// does not properly support filtering on window function results in subqueries.
	//
	//  SELECT n1.id, n1.narinfo_id, n1.hash, n1.compression, n1.file_size, n1.created_at, n1.updated_at, n1.last_accessed_at, n1.query
	//  FROM nars n1
	//  WHERE (
	//      SELECT SUM(n2.file_size)
	//      FROM nars n2
	//      WHERE n2.last_accessed_at < n1.last_accessed_at
	//         OR (n2.last_accessed_at = n1.last_accessed_at AND n2.id <= n1.id)
	//  ) <= $1
	GetLeastUsedNars(ctx context.Context, fileSize uint64) ([]Nar, error)
	//GetNarByHash
	//
	//  SELECT id, narinfo_id, hash, compression, file_size, created_at, updated_at, last_accessed_at, query
	//  FROM nars
	//  WHERE hash = $1
	GetNarByHash(ctx context.Context, hash string) (Nar, error)
	//GetNarByID
	//
	//  SELECT id, narinfo_id, hash, compression, file_size, created_at, updated_at, last_accessed_at, query
	//  FROM nars
	//  WHERE id = $1
	GetNarByID(ctx context.Context, id int64) (Nar, error)
	//GetNarInfoByHash
	//
	//  SELECT id, hash, created_at, updated_at, last_accessed_at
	//  FROM narinfos
	//  WHERE hash = $1
	GetNarInfoByHash(ctx context.Context, hash string) (NarInfo, error)
	//GetNarInfoByID
	//
	//  SELECT id, hash, created_at, updated_at, last_accessed_at
	//  FROM narinfos
	//  WHERE id = $1
	GetNarInfoByID(ctx context.Context, id int64) (NarInfo, error)
	//GetNarTotalSize
	//
	//  SELECT CAST(COALESCE(SUM(file_size), 0) AS BIGINT) AS total_size
	//  FROM nars
	GetNarTotalSize(ctx context.Context) (int64, error)
	//TouchNar
	//
	//  UPDATE nars
	//  SET
	//      last_accessed_at = CURRENT_TIMESTAMP,
	//      updated_at = CURRENT_TIMESTAMP
	//  WHERE hash = $1
	TouchNar(ctx context.Context, hash string) (int64, error)
	//TouchNarInfo
	//
	//  UPDATE narinfos
	//  SET
	//      last_accessed_at = CURRENT_TIMESTAMP,
	//      updated_at = CURRENT_TIMESTAMP
	//  WHERE hash = $1
	TouchNarInfo(ctx context.Context, hash string) (int64, error)
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) CreateNar

func (q *Queries) CreateNar(ctx context.Context, arg CreateNarParams) (Nar, error)

CreateNar

INSERT INTO nars (
    narinfo_id, hash, compression, query, file_size
) VALUES (
    $1, $2, $3, $4, $5
)
RETURNING id, narinfo_id, hash, compression, file_size, created_at, updated_at, last_accessed_at, query

func (*Queries) CreateNarInfo

func (q *Queries) CreateNarInfo(ctx context.Context, hash string) (NarInfo, error)

CreateNarInfo

INSERT INTO narinfos (
    hash
) VALUES (
    $1
)
RETURNING id, hash, created_at, updated_at, last_accessed_at

func (*Queries) DeleteNarByHash

func (q *Queries) DeleteNarByHash(ctx context.Context, hash string) (int64, error)

DeleteNarByHash

DELETE FROM nars
WHERE hash = $1

func (*Queries) DeleteNarByID

func (q *Queries) DeleteNarByID(ctx context.Context, id int64) (int64, error)

DeleteNarByID

DELETE FROM nars
WHERE id = $1

func (*Queries) DeleteNarInfoByHash

func (q *Queries) DeleteNarInfoByHash(ctx context.Context, hash string) (int64, error)

DeleteNarInfoByHash

DELETE FROM narinfos
WHERE hash = $1

func (*Queries) DeleteNarInfoByID

func (q *Queries) DeleteNarInfoByID(ctx context.Context, id int64) (int64, error)

DeleteNarInfoByID

DELETE FROM narinfos
WHERE id = $1

func (*Queries) GetLeastUsedNars

func (q *Queries) GetLeastUsedNars(ctx context.Context, fileSize uint64) ([]Nar, error)

NOTE: This query uses a correlated subquery which is not optimal for performance. The ideal implementation would use a window function (SUM OVER), but sqlc v1.30.0 does not properly support filtering on window function results in subqueries.

SELECT n1.id, n1.narinfo_id, n1.hash, n1.compression, n1.file_size, n1.created_at, n1.updated_at, n1.last_accessed_at, n1.query
FROM nars n1
WHERE (
    SELECT SUM(n2.file_size)
    FROM nars n2
    WHERE n2.last_accessed_at < n1.last_accessed_at
       OR (n2.last_accessed_at = n1.last_accessed_at AND n2.id <= n1.id)
) <= $1

func (*Queries) GetNarByHash

func (q *Queries) GetNarByHash(ctx context.Context, hash string) (Nar, error)

GetNarByHash

SELECT id, narinfo_id, hash, compression, file_size, created_at, updated_at, last_accessed_at, query
FROM nars
WHERE hash = $1

func (*Queries) GetNarByID

func (q *Queries) GetNarByID(ctx context.Context, id int64) (Nar, error)

GetNarByID

SELECT id, narinfo_id, hash, compression, file_size, created_at, updated_at, last_accessed_at, query
FROM nars
WHERE id = $1

func (*Queries) GetNarInfoByHash

func (q *Queries) GetNarInfoByHash(ctx context.Context, hash string) (NarInfo, error)

GetNarInfoByHash

SELECT id, hash, created_at, updated_at, last_accessed_at
FROM narinfos
WHERE hash = $1

func (*Queries) GetNarInfoByID

func (q *Queries) GetNarInfoByID(ctx context.Context, id int64) (NarInfo, error)

GetNarInfoByID

SELECT id, hash, created_at, updated_at, last_accessed_at
FROM narinfos
WHERE id = $1

func (*Queries) GetNarTotalSize

func (q *Queries) GetNarTotalSize(ctx context.Context) (int64, error)

GetNarTotalSize

SELECT CAST(COALESCE(SUM(file_size), 0) AS BIGINT) AS total_size
FROM nars

func (*Queries) TouchNar

func (q *Queries) TouchNar(ctx context.Context, hash string) (int64, error)

TouchNar

UPDATE nars
SET
    last_accessed_at = CURRENT_TIMESTAMP,
    updated_at = CURRENT_TIMESTAMP
WHERE hash = $1

func (*Queries) TouchNarInfo

func (q *Queries) TouchNarInfo(ctx context.Context, hash string) (int64, error)

TouchNarInfo

UPDATE narinfos
SET
    last_accessed_at = CURRENT_TIMESTAMP,
    updated_at = CURRENT_TIMESTAMP
WHERE hash = $1

func (*Queries) WithTx

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

Jump to

Keyboard shortcuts

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