postgresdb

package
v0.9.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 4 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 AddNarInfoReferenceParams added in v0.8.0

type AddNarInfoReferenceParams struct {
	NarInfoID int64
	Reference string
}

type AddNarInfoReferencesParams added in v0.8.0

type AddNarInfoReferencesParams struct {
	NarInfoID int64
	Reference []string
}

type AddNarInfoSignatureParams added in v0.8.0

type AddNarInfoSignatureParams struct {
	NarInfoID int64
	Signature string
}

type AddNarInfoSignaturesParams added in v0.8.0

type AddNarInfoSignaturesParams struct {
	NarInfoID int64
	Signature []string
}

type Chunk added in v0.9.0

type Chunk struct {
	ID        int64
	Hash      string
	Size      uint32
	CreatedAt time.Time
	UpdatedAt sql.NullTime
}

type Config

type Config struct {
	ID        int64
	Key       string
	Value     string
	CreatedAt time.Time
	UpdatedAt sql.NullTime
}

type CreateChunkParams added in v0.9.0

type CreateChunkParams struct {
	Hash string
	Size uint32
}

type CreateConfigParams

type CreateConfigParams struct {
	Key   string
	Value string
}

type CreateNarFileParams

type CreateNarFileParams struct {
	Hash        string
	Compression string
	Query       string
	FileSize    uint64
	TotalChunks int64
}

type CreateNarInfoParams added in v0.8.0

type CreateNarInfoParams struct {
	Hash        string
	StorePath   sql.NullString
	URL         sql.NullString
	Compression sql.NullString
	FileHash    sql.NullString
	FileSize    sql.NullInt64
	NarHash     sql.NullString
	NarSize     sql.NullInt64
	Deriver     sql.NullString
	System      sql.NullString
	Ca          sql.NullString
}

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 DeleteNarFileByHashParams added in v0.8.0

type DeleteNarFileByHashParams struct {
	Hash        string
	Compression string
	Query       string
}

type GetChunkByNarFileIDAndIndexParams added in v0.9.0

type GetChunkByNarFileIDAndIndexParams struct {
	NarFileID  int64
	ChunkIndex int64
}

type GetLeastUsedNarFilesRow

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

type GetMigratedNarInfoHashesPaginatedParams added in v0.8.0

type GetMigratedNarInfoHashesPaginatedParams struct {
	Limit  int32
	Offset int32
}

type GetNarFileByHashAndCompressionAndQueryParams added in v0.8.0

type GetNarFileByHashAndCompressionAndQueryParams struct {
	Hash        string
	Compression string
	Query       string
}

type GetNarFileByNarInfoIDRow

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

type GetNarInfoHashesToChunkRow

type GetNarInfoHashesToChunkRow struct {
	Hash string
	URL  sql.NullString
}

type GetOrphanedNarFilesRow

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

type LinkNarFileToChunkParams added in v0.9.0

type LinkNarFileToChunkParams struct {
	NarFileID  int64
	ChunkID    int64
	ChunkIndex int64
}

type LinkNarFileToChunksParams added in v0.9.0

type LinkNarFileToChunksParams struct {
	NarFileID  int64
	ChunkID    []int64
	ChunkIndex []int64
}

type LinkNarInfoToNarFileParams

type LinkNarInfoToNarFileParams struct {
	NarInfoID int64
	NarFileID int64
}

type NarFile

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

type NarFileChunk added in v0.9.0

type NarFileChunk struct {
	NarFileID  int64
	ChunkID    int64
	ChunkIndex int64
}

type NarInfo

type NarInfo struct {
	ID             int64
	Hash           string
	CreatedAt      time.Time
	UpdatedAt      sql.NullTime
	LastAccessedAt sql.NullTime
	StorePath      sql.NullString
	URL            sql.NullString
	Compression    sql.NullString
	FileHash       sql.NullString
	FileSize       sql.NullInt64
	NarHash        sql.NullString
	NarSize        sql.NullInt64
	Deriver        sql.NullString
	System         sql.NullString
	Ca             sql.NullString
}

type NarinfoNarFile

type NarinfoNarFile struct {
	NarInfoID int64
	NarFileID int64
}

type NarinfoReference added in v0.8.0

type NarinfoReference struct {
	NarInfoID int64
	Reference string
}

type NarinfoSignature added in v0.8.0

type NarinfoSignature struct {
	NarInfoID int64
	Signature string
}

type Querier

type Querier interface {
	//AddNarInfoReference
	//
	//  INSERT INTO narinfo_references (
	//      narinfo_id, reference
	//  ) VALUES (
	//      $1, $2
	//  )
	//  ON CONFLICT (narinfo_id, reference) DO NOTHING
	AddNarInfoReference(ctx context.Context, arg AddNarInfoReferenceParams) error
	// @bulk-for AddNarInfoReference
	//
	//  INSERT INTO narinfo_references (
	//      narinfo_id, reference
	//  )
	//  SELECT $1, unnest($2::text[]) ON CONFLICT (narinfo_id, reference) DO NOTHING
	AddNarInfoReferences(ctx context.Context, arg AddNarInfoReferencesParams) error
	//AddNarInfoSignature
	//
	//  INSERT INTO narinfo_signatures (
	//      narinfo_id, signature
	//  ) VALUES (
	//      $1, $2
	//  )
	//  ON CONFLICT (narinfo_id, signature) DO NOTHING
	AddNarInfoSignature(ctx context.Context, arg AddNarInfoSignatureParams) error
	// @bulk-for AddNarInfoSignature
	//
	//  INSERT INTO narinfo_signatures (
	//      narinfo_id, signature
	//  )
	//  SELECT $1, unnest($2::text[]) ON CONFLICT (narinfo_id, signature) DO NOTHING
	AddNarInfoSignatures(ctx context.Context, arg AddNarInfoSignaturesParams) error
	//CreateChunk
	//
	//  INSERT INTO chunks (
	//      hash, size
	//  ) VALUES (
	//      $1, $2
	//  )
	//  ON CONFLICT(hash) DO UPDATE SET
	//      updated_at = CURRENT_TIMESTAMP
	//  RETURNING id, hash, size, created_at, updated_at
	CreateChunk(ctx context.Context, arg CreateChunkParams) (Chunk, error)
	//CreateConfig
	//
	//  INSERT INTO config (
	//      key, value
	//  ) VALUES (
	//      $1, $2
	//  )
	//  RETURNING id, key, value, created_at, updated_at
	CreateConfig(ctx context.Context, arg CreateConfigParams) (Config, error)
	//CreateNarFile
	//
	//  INSERT INTO nar_files (
	//      hash, compression, query, file_size, total_chunks
	//  ) VALUES (
	//      $1, $2, $3, $4, $5
	//  )
	//  ON CONFLICT (hash, compression, query) DO UPDATE SET
	//      updated_at = EXCLUDED.updated_at
	//  RETURNING id, hash, compression, file_size, query, created_at, updated_at, last_accessed_at, total_chunks
	CreateNarFile(ctx context.Context, arg CreateNarFileParams) (NarFile, error)
	//CreateNarInfo
	//
	//  INSERT INTO narinfos (
	//      hash, store_path, url, compression, file_hash, file_size, nar_hash, nar_size, deriver, system, ca
	//  ) VALUES (
	//      $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11
	//  )
	//  ON CONFLICT (hash) DO UPDATE SET
	//      store_path = EXCLUDED.store_path,
	//      url = EXCLUDED.url,
	//      compression = EXCLUDED.compression,
	//      file_hash = EXCLUDED.file_hash,
	//      file_size = EXCLUDED.file_size,
	//      nar_hash = EXCLUDED.nar_hash,
	//      nar_size = EXCLUDED.nar_size,
	//      deriver = EXCLUDED.deriver,
	//      system = EXCLUDED.system,
	//      ca = EXCLUDED.ca,
	//      updated_at = CURRENT_TIMESTAMP
	//  WHERE narinfos.url IS NULL
	//  RETURNING id, hash, created_at, updated_at, last_accessed_at, store_path, url, compression, file_hash, file_size, nar_hash, nar_size, deriver, system, ca
	CreateNarInfo(ctx context.Context, arg CreateNarInfoParams) (NarInfo, error)
	//DeleteChunkByID
	//
	//  DELETE FROM chunks
	//  WHERE id = $1
	DeleteChunkByID(ctx context.Context, id int64) error
	//DeleteNarFileByHash
	//
	//  DELETE FROM nar_files
	//  WHERE hash = $1 AND compression = $2 AND query = $3
	DeleteNarFileByHash(ctx context.Context, arg DeleteNarFileByHashParams) (int64, error)
	//DeleteNarFileByID
	//
	//  DELETE FROM nar_files
	//  WHERE id = $1
	DeleteNarFileByID(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)
	//DeleteOrphanedNarFiles
	//
	//  DELETE FROM nar_files
	//  WHERE id NOT IN (
	//      SELECT DISTINCT nar_file_id
	//      FROM narinfo_nar_files
	//  )
	DeleteOrphanedNarFiles(ctx context.Context) (int64, error)
	//DeleteOrphanedNarInfos
	//
	//  DELETE FROM narinfos
	//  WHERE id NOT IN (
	//      SELECT DISTINCT narinfo_id
	//      FROM narinfo_nar_files
	//  )
	DeleteOrphanedNarInfos(ctx context.Context) (int64, error)
	//GetChunkByHash
	//
	//  SELECT id, hash, size, created_at, updated_at
	//  FROM chunks
	//  WHERE hash = $1
	GetChunkByHash(ctx context.Context, hash string) (Chunk, error)
	//GetChunkByID
	//
	//  SELECT id, hash, size, created_at, updated_at
	//  FROM chunks
	//  WHERE id = $1
	GetChunkByID(ctx context.Context, id int64) (Chunk, error)
	//GetChunkByNarFileIDAndIndex
	//
	//  SELECT c.id, c.hash, c.size, c.created_at, c.updated_at
	//  FROM chunks c
	//  INNER JOIN nar_file_chunks nfc ON c.id = nfc.chunk_id
	//  WHERE nfc.nar_file_id = $1 AND nfc.chunk_index = $2
	GetChunkByNarFileIDAndIndex(ctx context.Context, arg GetChunkByNarFileIDAndIndexParams) (Chunk, error)
	//GetChunkCount
	//
	//  SELECT CAST(COUNT(*) AS BIGINT) AS count
	//  FROM chunks
	GetChunkCount(ctx context.Context) (int64, error)
	//GetChunksByNarFileID
	//
	//  SELECT c.id, c.hash, c.size, c.created_at, c.updated_at
	//  FROM chunks c
	//  INNER JOIN nar_file_chunks nfc ON c.id = nfc.chunk_id
	//  WHERE nfc.nar_file_id = $1
	//  ORDER BY nfc.chunk_index
	GetChunksByNarFileID(ctx context.Context, narFileID int64) ([]Chunk, error)
	//GetConfigByID
	//
	//  SELECT id, key, value, created_at, updated_at
	//  FROM config
	//  WHERE id = $1
	GetConfigByID(ctx context.Context, id int64) (Config, error)
	//GetConfigByKey
	//
	//  SELECT id, key, value, created_at, updated_at
	//  FROM config
	//  WHERE key = $1
	GetConfigByKey(ctx context.Context, key string) (Config, 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.hash, n1.compression, n1.file_size, n1.query, n1.created_at, n1.updated_at, n1.last_accessed_at
	//  FROM nar_files n1
	//  WHERE (
	//      SELECT SUM(n2.file_size)
	//      FROM nar_files 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
	GetLeastUsedNarFiles(ctx context.Context, fileSize uint64) ([]GetLeastUsedNarFilesRow, 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.
	// Gets the least-used narinfos up to a certain total file size (accounting for their nar_files).
	//
	//  SELECT ni1.id, ni1.hash, ni1.created_at, ni1.updated_at, ni1.last_accessed_at, ni1.store_path, ni1.url, ni1.compression, ni1.file_hash, ni1.file_size, ni1.nar_hash, ni1.nar_size, ni1.deriver, ni1.system, ni1.ca
	//  FROM narinfos ni1
	//  WHERE (
	//      SELECT COALESCE(SUM(nf.file_size), 0)
	//      FROM nar_files nf
	//      WHERE nf.id IN (
	//          SELECT DISTINCT nnf.nar_file_id
	//          FROM narinfo_nar_files nnf
	//          INNER JOIN narinfos ni2 ON nnf.narinfo_id = ni2.id
	//          WHERE ni2.last_accessed_at < ni1.last_accessed_at
	//              OR (ni2.last_accessed_at = ni1.last_accessed_at AND ni2.id <= ni1.id)
	//      )
	//  ) <= $1
	GetLeastUsedNarInfos(ctx context.Context, fileSize uint64) ([]NarInfo, error)
	// Get all narinfo hashes that have a URL (migrated).
	//
	//  SELECT hash
	//  FROM narinfos
	//  WHERE url IS NOT NULL
	GetMigratedNarInfoHashes(ctx context.Context) ([]string, error)
	// Get migrated narinfo hashes with pagination support.
	//
	//  SELECT hash
	//  FROM narinfos
	//  WHERE url IS NOT NULL
	//  ORDER BY hash
	//  LIMIT $1 OFFSET $2
	GetMigratedNarInfoHashesPaginated(ctx context.Context, arg GetMigratedNarInfoHashesPaginatedParams) ([]string, error)
	//GetNarFileByHashAndCompressionAndQuery
	//
	//  SELECT id, hash, compression, file_size, query, created_at, updated_at, last_accessed_at, total_chunks
	//  FROM nar_files
	//  WHERE hash = $1 AND compression = $2 AND query = $3
	GetNarFileByHashAndCompressionAndQuery(ctx context.Context, arg GetNarFileByHashAndCompressionAndQueryParams) (NarFile, error)
	//GetNarFileByID
	//
	//  SELECT id, hash, compression, file_size, query, created_at, updated_at, last_accessed_at, total_chunks
	//  FROM nar_files
	//  WHERE id = $1
	GetNarFileByID(ctx context.Context, id int64) (NarFile, error)
	//GetNarFileByNarInfoID
	//
	//  SELECT nf.id, nf.hash, nf.compression, nf.file_size, nf.query, nf.created_at, nf.updated_at, nf.last_accessed_at
	//  FROM nar_files nf
	//  INNER JOIN narinfo_nar_files nnf ON nf.id = nnf.nar_file_id
	//  WHERE nnf.narinfo_id = $1
	GetNarFileByNarInfoID(ctx context.Context, narinfoID int64) (GetNarFileByNarInfoIDRow, error)
	//GetNarFileCount
	//
	//  SELECT CAST(COUNT(*) AS BIGINT) AS count
	//  FROM nar_files
	GetNarFileCount(ctx context.Context) (int64, error)
	//GetNarInfoByHash
	//
	//  SELECT id, hash, created_at, updated_at, last_accessed_at, store_path, url, compression, file_hash, file_size, nar_hash, nar_size, deriver, system, ca
	//  FROM narinfos
	//  WHERE hash = $1
	GetNarInfoByHash(ctx context.Context, hash string) (NarInfo, error)
	//GetNarInfoByID
	//
	//  SELECT id, hash, created_at, updated_at, last_accessed_at, store_path, url, compression, file_hash, file_size, nar_hash, nar_size, deriver, system, ca
	//  FROM narinfos
	//  WHERE id = $1
	GetNarInfoByID(ctx context.Context, id int64) (NarInfo, error)
	//GetNarInfoCount
	//
	//  SELECT CAST(COUNT(*) AS BIGINT) AS count
	//  FROM narinfos
	GetNarInfoCount(ctx context.Context) (int64, error)
	//GetNarInfoHashesByNarFileID
	//
	//  SELECT ni.hash
	//  FROM narinfos ni
	//  INNER JOIN narinfo_nar_files nnf ON ni.id = nnf.narinfo_id
	//  WHERE nnf.nar_file_id = $1
	GetNarInfoHashesByNarFileID(ctx context.Context, narFileID int64) ([]string, error)
	//GetNarInfoHashesByURL
	//
	//  SELECT hash
	//  FROM narinfos
	//  WHERE url = $1
	GetNarInfoHashesByURL(ctx context.Context, url sql.NullString) ([]string, error)
	// Get all narinfo hashes that have a URL (migrated) but whose NAR is not yet chunked.
	//
	//  SELECT ni.hash, ni.url
	//  FROM narinfos ni
	//  LEFT JOIN narinfo_nar_files nnf ON ni.id = nnf.narinfo_id
	//  LEFT JOIN nar_files nf ON nnf.nar_file_id = nf.id
	//  WHERE ni.url IS NOT NULL
	//    AND (nf.id IS NULL OR nf.total_chunks = 0)
	//  ORDER BY ni.hash
	GetNarInfoHashesToChunk(ctx context.Context) ([]GetNarInfoHashesToChunkRow, error)
	//GetNarInfoReferences
	//
	//  SELECT reference
	//  FROM narinfo_references
	//  WHERE narinfo_id = $1
	GetNarInfoReferences(ctx context.Context, narinfoID int64) ([]string, error)
	//GetNarInfoSignatures
	//
	//  SELECT signature
	//  FROM narinfo_signatures
	//  WHERE narinfo_id = $1
	GetNarInfoSignatures(ctx context.Context, narinfoID int64) ([]string, error)
	//GetNarTotalSize
	//
	//  SELECT CAST(COALESCE(SUM(file_size), 0) AS BIGINT) AS total_size
	//  FROM nar_files
	GetNarTotalSize(ctx context.Context) (int64, error)
	//GetOrphanedChunks
	//
	//  SELECT c.id, c.hash, c.size, c.created_at, c.updated_at
	//  FROM chunks c
	//  LEFT JOIN nar_file_chunks nfc ON c.id = nfc.chunk_id
	//  WHERE nfc.chunk_id IS NULL
	GetOrphanedChunks(ctx context.Context) ([]Chunk, error)
	// Find files that have no relationship to any narinfo
	//
	//  SELECT nf.id, nf.hash, nf.compression, nf.file_size, nf.query, nf.created_at, nf.updated_at, nf.last_accessed_at
	//  FROM nar_files nf
	//  LEFT JOIN narinfo_nar_files ninf ON nf.id = ninf.nar_file_id
	//  WHERE ninf.narinfo_id IS NULL
	GetOrphanedNarFiles(ctx context.Context) ([]GetOrphanedNarFilesRow, error)
	//GetTotalChunkSize
	//
	//  SELECT CAST(COALESCE(SUM(size), 0) AS BIGINT) AS total_size
	//  FROM chunks
	GetTotalChunkSize(ctx context.Context) (int64, error)
	// Get all narinfo hashes that have no URL (unmigrated).
	//
	//  SELECT hash
	//  FROM narinfos
	//  WHERE url IS NULL
	GetUnmigratedNarInfoHashes(ctx context.Context) ([]string, error)
	// Check if a narinfo hash has been migrated (has a URL).
	//
	//  SELECT EXISTS(
	//      SELECT 1
	//      FROM narinfos
	//      WHERE hash = $1 AND url IS NOT NULL
	//  ) AS is_migrated
	IsNarInfoMigrated(ctx context.Context, hash string) (bool, error)
	//LinkNarFileToChunk
	//
	//  INSERT INTO nar_file_chunks (
	//      nar_file_id, chunk_id, chunk_index
	//  ) VALUES (
	//      $1, $2, $3
	//  )
	//  ON CONFLICT (nar_file_id, chunk_index) DO NOTHING
	LinkNarFileToChunk(ctx context.Context, arg LinkNarFileToChunkParams) error
	// @bulk-for LinkNarFileToChunk
	//
	//  INSERT INTO nar_file_chunks (
	//      nar_file_id, chunk_id, chunk_index
	//  )
	//  SELECT $1, unnest($2::bigint[]), unnest($3::bigint[])
	//  ON CONFLICT (nar_file_id, chunk_index) DO NOTHING
	LinkNarFileToChunks(ctx context.Context, arg LinkNarFileToChunksParams) error
	//LinkNarInfoToNarFile
	//
	//  INSERT INTO narinfo_nar_files (
	//      narinfo_id, nar_file_id
	//  ) VALUES (
	//      $1, $2
	//  )
	//  ON CONFLICT (narinfo_id, nar_file_id) DO NOTHING
	LinkNarInfoToNarFile(ctx context.Context, arg LinkNarInfoToNarFileParams) error
	//SetConfig
	//
	//  INSERT INTO config (
	//      key, value
	//  ) VALUES (
	//      $1, $2
	//  )
	//  ON CONFLICT(key)
	//  DO UPDATE SET
	//    value = EXCLUDED.value,
	//    updated_at = CURRENT_TIMESTAMP
	SetConfig(ctx context.Context, arg SetConfigParams) error
	//TouchNarFile
	//
	//  UPDATE nar_files
	//  SET
	//      last_accessed_at = CURRENT_TIMESTAMP,
	//      updated_at = CURRENT_TIMESTAMP
	//  WHERE hash = $1 AND compression = $2 AND query = $3
	TouchNarFile(ctx context.Context, arg TouchNarFileParams) (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)
	//UpdateNarFileTotalChunks
	//
	//  UPDATE nar_files
	//  SET total_chunks = $1, updated_at = CURRENT_TIMESTAMP
	//  WHERE id = $2
	UpdateNarFileTotalChunks(ctx context.Context, arg UpdateNarFileTotalChunksParams) error
	//UpdateNarInfoFileSize
	//
	//  UPDATE narinfos
	//  SET file_size = $2, updated_at = CURRENT_TIMESTAMP
	//  WHERE hash = $1
	UpdateNarInfoFileSize(ctx context.Context, arg UpdateNarInfoFileSizeParams) error
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) AddNarInfoReference added in v0.8.0

func (q *Queries) AddNarInfoReference(ctx context.Context, arg AddNarInfoReferenceParams) error

AddNarInfoReference

INSERT INTO narinfo_references (
    narinfo_id, reference
) VALUES (
    $1, $2
)
ON CONFLICT (narinfo_id, reference) DO NOTHING

func (*Queries) AddNarInfoReferences added in v0.8.0

func (q *Queries) AddNarInfoReferences(ctx context.Context, arg AddNarInfoReferencesParams) error

@bulk-for AddNarInfoReference

INSERT INTO narinfo_references (
    narinfo_id, reference
)
SELECT $1, unnest($2::text[]) ON CONFLICT (narinfo_id, reference) DO NOTHING

func (*Queries) AddNarInfoSignature added in v0.8.0

func (q *Queries) AddNarInfoSignature(ctx context.Context, arg AddNarInfoSignatureParams) error

AddNarInfoSignature

INSERT INTO narinfo_signatures (
    narinfo_id, signature
) VALUES (
    $1, $2
)
ON CONFLICT (narinfo_id, signature) DO NOTHING

func (*Queries) AddNarInfoSignatures added in v0.8.0

func (q *Queries) AddNarInfoSignatures(ctx context.Context, arg AddNarInfoSignaturesParams) error

@bulk-for AddNarInfoSignature

INSERT INTO narinfo_signatures (
    narinfo_id, signature
)
SELECT $1, unnest($2::text[]) ON CONFLICT (narinfo_id, signature) DO NOTHING

func (*Queries) CreateChunk added in v0.9.0

func (q *Queries) CreateChunk(ctx context.Context, arg CreateChunkParams) (Chunk, error)

CreateChunk

INSERT INTO chunks (
    hash, size
) VALUES (
    $1, $2
)
ON CONFLICT(hash) DO UPDATE SET
    updated_at = CURRENT_TIMESTAMP
RETURNING id, hash, size, created_at, updated_at

func (*Queries) CreateConfig

func (q *Queries) CreateConfig(ctx context.Context, arg CreateConfigParams) (Config, error)

CreateConfig

INSERT INTO config (
    key, value
) VALUES (
    $1, $2
)
RETURNING id, key, value, created_at, updated_at

func (*Queries) CreateNarFile

func (q *Queries) CreateNarFile(ctx context.Context, arg CreateNarFileParams) (NarFile, error)

CreateNarFile

INSERT INTO nar_files (
    hash, compression, query, file_size, total_chunks
) VALUES (
    $1, $2, $3, $4, $5
)
ON CONFLICT (hash, compression, query) DO UPDATE SET
    updated_at = EXCLUDED.updated_at
RETURNING id, hash, compression, file_size, query, created_at, updated_at, last_accessed_at, total_chunks

func (*Queries) CreateNarInfo

func (q *Queries) CreateNarInfo(ctx context.Context, arg CreateNarInfoParams) (NarInfo, error)

CreateNarInfo

INSERT INTO narinfos (
    hash, store_path, url, compression, file_hash, file_size, nar_hash, nar_size, deriver, system, ca
) VALUES (
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11
)
ON CONFLICT (hash) DO UPDATE SET
    store_path = EXCLUDED.store_path,
    url = EXCLUDED.url,
    compression = EXCLUDED.compression,
    file_hash = EXCLUDED.file_hash,
    file_size = EXCLUDED.file_size,
    nar_hash = EXCLUDED.nar_hash,
    nar_size = EXCLUDED.nar_size,
    deriver = EXCLUDED.deriver,
    system = EXCLUDED.system,
    ca = EXCLUDED.ca,
    updated_at = CURRENT_TIMESTAMP
WHERE narinfos.url IS NULL
RETURNING id, hash, created_at, updated_at, last_accessed_at, store_path, url, compression, file_hash, file_size, nar_hash, nar_size, deriver, system, ca

func (*Queries) DeleteChunkByID added in v0.9.0

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

DeleteChunkByID

DELETE FROM chunks
WHERE id = $1

func (*Queries) DeleteNarFileByHash

func (q *Queries) DeleteNarFileByHash(ctx context.Context, arg DeleteNarFileByHashParams) (int64, error)

DeleteNarFileByHash

DELETE FROM nar_files
WHERE hash = $1 AND compression = $2 AND query = $3

func (*Queries) DeleteNarFileByID

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

DeleteNarFileByID

DELETE FROM nar_files
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) DeleteOrphanedNarFiles

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

DeleteOrphanedNarFiles

DELETE FROM nar_files
WHERE id NOT IN (
    SELECT DISTINCT nar_file_id
    FROM narinfo_nar_files
)

func (*Queries) DeleteOrphanedNarInfos

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

DeleteOrphanedNarInfos

DELETE FROM narinfos
WHERE id NOT IN (
    SELECT DISTINCT narinfo_id
    FROM narinfo_nar_files
)

func (*Queries) GetChunkByHash added in v0.9.0

func (q *Queries) GetChunkByHash(ctx context.Context, hash string) (Chunk, error)

GetChunkByHash

SELECT id, hash, size, created_at, updated_at
FROM chunks
WHERE hash = $1

func (*Queries) GetChunkByID

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

GetChunkByID

SELECT id, hash, size, created_at, updated_at
FROM chunks
WHERE id = $1

func (*Queries) GetChunkByNarFileIDAndIndex added in v0.9.0

func (q *Queries) GetChunkByNarFileIDAndIndex(ctx context.Context, arg GetChunkByNarFileIDAndIndexParams) (Chunk, error)

GetChunkByNarFileIDAndIndex

SELECT c.id, c.hash, c.size, c.created_at, c.updated_at
FROM chunks c
INNER JOIN nar_file_chunks nfc ON c.id = nfc.chunk_id
WHERE nfc.nar_file_id = $1 AND nfc.chunk_index = $2

func (*Queries) GetChunkCount added in v0.9.0

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

GetChunkCount

SELECT CAST(COUNT(*) AS BIGINT) AS count
FROM chunks

func (*Queries) GetChunksByNarFileID added in v0.9.0

func (q *Queries) GetChunksByNarFileID(ctx context.Context, narFileID int64) ([]Chunk, error)

GetChunksByNarFileID

SELECT c.id, c.hash, c.size, c.created_at, c.updated_at
FROM chunks c
INNER JOIN nar_file_chunks nfc ON c.id = nfc.chunk_id
WHERE nfc.nar_file_id = $1
ORDER BY nfc.chunk_index

func (*Queries) GetConfigByID

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

GetConfigByID

SELECT id, key, value, created_at, updated_at
FROM config
WHERE id = $1

func (*Queries) GetConfigByKey

func (q *Queries) GetConfigByKey(ctx context.Context, key string) (Config, error)

GetConfigByKey

SELECT id, key, value, created_at, updated_at
FROM config
WHERE key = $1

func (*Queries) GetLeastUsedNarFiles

func (q *Queries) GetLeastUsedNarFiles(ctx context.Context, fileSize uint64) ([]GetLeastUsedNarFilesRow, 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.hash, n1.compression, n1.file_size, n1.query, n1.created_at, n1.updated_at, n1.last_accessed_at
FROM nar_files n1
WHERE (
    SELECT SUM(n2.file_size)
    FROM nar_files 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) GetLeastUsedNarInfos

func (q *Queries) GetLeastUsedNarInfos(ctx context.Context, fileSize uint64) ([]NarInfo, 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. Gets the least-used narinfos up to a certain total file size (accounting for their nar_files).

SELECT ni1.id, ni1.hash, ni1.created_at, ni1.updated_at, ni1.last_accessed_at, ni1.store_path, ni1.url, ni1.compression, ni1.file_hash, ni1.file_size, ni1.nar_hash, ni1.nar_size, ni1.deriver, ni1.system, ni1.ca
FROM narinfos ni1
WHERE (
    SELECT COALESCE(SUM(nf.file_size), 0)
    FROM nar_files nf
    WHERE nf.id IN (
        SELECT DISTINCT nnf.nar_file_id
        FROM narinfo_nar_files nnf
        INNER JOIN narinfos ni2 ON nnf.narinfo_id = ni2.id
        WHERE ni2.last_accessed_at < ni1.last_accessed_at
            OR (ni2.last_accessed_at = ni1.last_accessed_at AND ni2.id <= ni1.id)
    )
) <= $1

func (*Queries) GetMigratedNarInfoHashes added in v0.8.0

func (q *Queries) GetMigratedNarInfoHashes(ctx context.Context) ([]string, error)

Get all narinfo hashes that have a URL (migrated).

SELECT hash
FROM narinfos
WHERE url IS NOT NULL

func (*Queries) GetMigratedNarInfoHashesPaginated added in v0.8.0

func (q *Queries) GetMigratedNarInfoHashesPaginated(ctx context.Context, arg GetMigratedNarInfoHashesPaginatedParams) ([]string, error)

Get migrated narinfo hashes with pagination support.

SELECT hash
FROM narinfos
WHERE url IS NOT NULL
ORDER BY hash
LIMIT $1 OFFSET $2

func (*Queries) GetNarFileByHashAndCompressionAndQuery added in v0.8.0

func (q *Queries) GetNarFileByHashAndCompressionAndQuery(ctx context.Context, arg GetNarFileByHashAndCompressionAndQueryParams) (NarFile, error)

GetNarFileByHashAndCompressionAndQuery

SELECT id, hash, compression, file_size, query, created_at, updated_at, last_accessed_at, total_chunks
FROM nar_files
WHERE hash = $1 AND compression = $2 AND query = $3

func (*Queries) GetNarFileByID

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

GetNarFileByID

SELECT id, hash, compression, file_size, query, created_at, updated_at, last_accessed_at, total_chunks
FROM nar_files
WHERE id = $1

func (*Queries) GetNarFileByNarInfoID

func (q *Queries) GetNarFileByNarInfoID(ctx context.Context, narinfoID int64) (GetNarFileByNarInfoIDRow, error)

GetNarFileByNarInfoID

SELECT nf.id, nf.hash, nf.compression, nf.file_size, nf.query, nf.created_at, nf.updated_at, nf.last_accessed_at
FROM nar_files nf
INNER JOIN narinfo_nar_files nnf ON nf.id = nnf.nar_file_id
WHERE nnf.narinfo_id = $1

func (*Queries) GetNarFileCount added in v0.7.1

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

GetNarFileCount

SELECT CAST(COUNT(*) AS BIGINT) AS count
FROM nar_files

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, store_path, url, compression, file_hash, file_size, nar_hash, nar_size, deriver, system, ca
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, store_path, url, compression, file_hash, file_size, nar_hash, nar_size, deriver, system, ca
FROM narinfos
WHERE id = $1

func (*Queries) GetNarInfoCount added in v0.7.1

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

GetNarInfoCount

SELECT CAST(COUNT(*) AS BIGINT) AS count
FROM narinfos

func (*Queries) GetNarInfoHashesByNarFileID

func (q *Queries) GetNarInfoHashesByNarFileID(ctx context.Context, narFileID int64) ([]string, error)

GetNarInfoHashesByNarFileID

SELECT ni.hash
FROM narinfos ni
INNER JOIN narinfo_nar_files nnf ON ni.id = nnf.narinfo_id
WHERE nnf.nar_file_id = $1

func (*Queries) GetNarInfoHashesByURL added in v0.9.0

func (q *Queries) GetNarInfoHashesByURL(ctx context.Context, url sql.NullString) ([]string, error)

GetNarInfoHashesByURL

SELECT hash
FROM narinfos
WHERE url = $1

func (*Queries) GetNarInfoHashesToChunk

func (q *Queries) GetNarInfoHashesToChunk(ctx context.Context) ([]GetNarInfoHashesToChunkRow, error)

Get all narinfo hashes that have a URL (migrated) but whose NAR is not yet chunked.

SELECT ni.hash, ni.url
FROM narinfos ni
LEFT JOIN narinfo_nar_files nnf ON ni.id = nnf.narinfo_id
LEFT JOIN nar_files nf ON nnf.nar_file_id = nf.id
WHERE ni.url IS NOT NULL
  AND (nf.id IS NULL OR nf.total_chunks = 0)
ORDER BY ni.hash

func (*Queries) GetNarInfoReferences added in v0.8.0

func (q *Queries) GetNarInfoReferences(ctx context.Context, narinfoID int64) ([]string, error)

GetNarInfoReferences

SELECT reference
FROM narinfo_references
WHERE narinfo_id = $1

func (*Queries) GetNarInfoSignatures added in v0.8.0

func (q *Queries) GetNarInfoSignatures(ctx context.Context, narinfoID int64) ([]string, error)

GetNarInfoSignatures

SELECT signature
FROM narinfo_signatures
WHERE narinfo_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 nar_files

func (*Queries) GetOrphanedChunks added in v0.9.0

func (q *Queries) GetOrphanedChunks(ctx context.Context) ([]Chunk, error)

GetOrphanedChunks

SELECT c.id, c.hash, c.size, c.created_at, c.updated_at
FROM chunks c
LEFT JOIN nar_file_chunks nfc ON c.id = nfc.chunk_id
WHERE nfc.chunk_id IS NULL

func (*Queries) GetOrphanedNarFiles

func (q *Queries) GetOrphanedNarFiles(ctx context.Context) ([]GetOrphanedNarFilesRow, error)

Find files that have no relationship to any narinfo

SELECT nf.id, nf.hash, nf.compression, nf.file_size, nf.query, nf.created_at, nf.updated_at, nf.last_accessed_at
FROM nar_files nf
LEFT JOIN narinfo_nar_files ninf ON nf.id = ninf.nar_file_id
WHERE ninf.narinfo_id IS NULL

func (*Queries) GetTotalChunkSize

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

GetTotalChunkSize

SELECT CAST(COALESCE(SUM(size), 0) AS BIGINT) AS total_size
FROM chunks

func (*Queries) GetUnmigratedNarInfoHashes added in v0.8.0

func (q *Queries) GetUnmigratedNarInfoHashes(ctx context.Context) ([]string, error)

Get all narinfo hashes that have no URL (unmigrated).

SELECT hash
FROM narinfos
WHERE url IS NULL

func (*Queries) IsNarInfoMigrated added in v0.8.0

func (q *Queries) IsNarInfoMigrated(ctx context.Context, hash string) (bool, error)

Check if a narinfo hash has been migrated (has a URL).

SELECT EXISTS(
    SELECT 1
    FROM narinfos
    WHERE hash = $1 AND url IS NOT NULL
) AS is_migrated

func (*Queries) LinkNarFileToChunk added in v0.9.0

func (q *Queries) LinkNarFileToChunk(ctx context.Context, arg LinkNarFileToChunkParams) error

LinkNarFileToChunk

INSERT INTO nar_file_chunks (
    nar_file_id, chunk_id, chunk_index
) VALUES (
    $1, $2, $3
)
ON CONFLICT (nar_file_id, chunk_index) DO NOTHING

func (*Queries) LinkNarFileToChunks added in v0.9.0

func (q *Queries) LinkNarFileToChunks(ctx context.Context, arg LinkNarFileToChunksParams) error

@bulk-for LinkNarFileToChunk

INSERT INTO nar_file_chunks (
    nar_file_id, chunk_id, chunk_index
)
SELECT $1, unnest($2::bigint[]), unnest($3::bigint[])
ON CONFLICT (nar_file_id, chunk_index) DO NOTHING

func (*Queries) LinkNarInfoToNarFile

func (q *Queries) LinkNarInfoToNarFile(ctx context.Context, arg LinkNarInfoToNarFileParams) error

LinkNarInfoToNarFile

INSERT INTO narinfo_nar_files (
    narinfo_id, nar_file_id
) VALUES (
    $1, $2
)
ON CONFLICT (narinfo_id, nar_file_id) DO NOTHING

func (*Queries) SetConfig

func (q *Queries) SetConfig(ctx context.Context, arg SetConfigParams) error

SetConfig

INSERT INTO config (
    key, value
) VALUES (
    $1, $2
)
ON CONFLICT(key)
DO UPDATE SET
  value = EXCLUDED.value,
  updated_at = CURRENT_TIMESTAMP

func (*Queries) TouchNarFile

func (q *Queries) TouchNarFile(ctx context.Context, arg TouchNarFileParams) (int64, error)

TouchNarFile

UPDATE nar_files
SET
    last_accessed_at = CURRENT_TIMESTAMP,
    updated_at = CURRENT_TIMESTAMP
WHERE hash = $1 AND compression = $2 AND query = $3

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) UpdateNarFileTotalChunks added in v0.9.0

func (q *Queries) UpdateNarFileTotalChunks(ctx context.Context, arg UpdateNarFileTotalChunksParams) error

UpdateNarFileTotalChunks

UPDATE nar_files
SET total_chunks = $1, updated_at = CURRENT_TIMESTAMP
WHERE id = $2

func (*Queries) UpdateNarInfoFileSize added in v0.9.0

func (q *Queries) UpdateNarInfoFileSize(ctx context.Context, arg UpdateNarInfoFileSizeParams) error

UpdateNarInfoFileSize

UPDATE narinfos
SET file_size = $2, updated_at = CURRENT_TIMESTAMP
WHERE hash = $1

func (*Queries) WithTx

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

type SetConfigParams

type SetConfigParams struct {
	Key   string
	Value string
}

type TouchNarFileParams added in v0.8.0

type TouchNarFileParams struct {
	Hash        string
	Compression string
	Query       string
}

type UpdateNarFileTotalChunksParams added in v0.9.0

type UpdateNarFileTotalChunksParams struct {
	TotalChunks int64
	ID          int64
}

type UpdateNarInfoFileSizeParams added in v0.9.0

type UpdateNarInfoFileSizeParams struct {
	Hash     string
	FileSize sql.NullInt64
}

Jump to

Keyboard shortcuts

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