database

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Code generated by gen-db-wrappers. DO NOT EDIT.

Code generated by gen-db-wrappers. DO NOT EDIT.

Code generated by gen-db-wrappers. DO NOT EDIT.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when a query returns no rows.
	ErrNotFound = errors.New("not found")

	// ErrUnsupportedDriver is returned when the database driver is not recognized.
	ErrUnsupportedDriver = errors.New("unsupported database driver")
)

Functions

func IsDuplicateKeyError added in v0.6.0

func IsDuplicateKeyError(err error) bool

IsDuplicateKeyError checks if the error is a unique constraint violation Works across SQLite, PostgreSQL, and MySQL.

func IsNotFoundError added in v0.6.0

func IsNotFoundError(err error) bool

IsNotFoundError checks if the error indicates a row was not found.

Types

type Config added in v0.6.0

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

type CreateConfigParams added in v0.6.0

type CreateConfigParams struct {
	Key   string
	Value string
}

type CreateNarFileParams added in v0.6.0

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

CreateNarFileParams holds parameters for creating a NAR file entry.

type LinkNarInfoToNarFileParams added in v0.6.0

type LinkNarInfoToNarFileParams struct {
	NarInfoID int64
	NarFileID int64
}

LinkNarInfoToNarFileParams holds parameters for linking a NarInfo to a NarFile.

type NarFile added in v0.6.0

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

NarFile represents a cached NAR file.

type NarInfo added in v0.0.13

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

NarInfo represents metadata about a Nix store path.

type PoolConfig added in v0.6.0

type PoolConfig struct {
	// MaxOpenConns is the maximum number of open connections to the database.
	// If <= 0, defaults are used based on database type.
	MaxOpenConns int
	// MaxIdleConns is the maximum number of connections in the idle connection pool.
	// If <= 0, defaults are used based on database type.
	MaxIdleConns int
}

PoolConfig holds database connection pool settings.

type Querier added in v0.6.0

type Querier interface {
	CreateConfig(ctx context.Context, arg CreateConfigParams) (Config, error)
	CreateNarFile(ctx context.Context, arg CreateNarFileParams) (NarFile, error)
	CreateNarInfo(ctx context.Context, hash string) (NarInfo, error)
	DeleteNarFileByHash(ctx context.Context, hash string) (int64, error)
	DeleteNarFileByID(ctx context.Context, id int64) (int64, error)
	DeleteNarInfoByHash(ctx context.Context, hash string) (int64, error)
	DeleteNarInfoByID(ctx context.Context, id int64) (int64, error)
	DeleteOrphanedNarFiles(ctx context.Context) (int64, error)
	DeleteOrphanedNarInfos(ctx context.Context) (int64, error)
	GetConfigByID(ctx context.Context, id int64) (Config, error)
	GetConfigByKey(ctx context.Context, key string) (Config, error)
	GetLeastUsedNarFiles(ctx context.Context, fileSize uint64) ([]NarFile, error)
	GetLeastUsedNarInfos(ctx context.Context, fileSize uint64) ([]NarInfo, error)
	GetNarFileByHash(ctx context.Context, hash string) (NarFile, error)
	GetNarFileByID(ctx context.Context, id int64) (NarFile, error)
	GetNarFileByNarInfoID(ctx context.Context, narinfoID int64) (NarFile, error)
	GetNarInfoByHash(ctx context.Context, hash string) (NarInfo, error)
	GetNarInfoByID(ctx context.Context, id int64) (NarInfo, error)
	GetNarInfoHashesByNarFileID(ctx context.Context, narFileID int64) ([]string, error)
	GetNarTotalSize(ctx context.Context) (int64, error)
	GetOrphanedNarFiles(ctx context.Context) ([]NarFile, error)
	LinkNarInfoToNarFile(ctx context.Context, arg LinkNarInfoToNarFileParams) error
	SetConfig(ctx context.Context, arg SetConfigParams) error
	TouchNarFile(ctx context.Context, hash string) (int64, error)
	TouchNarInfo(ctx context.Context, hash string) (int64, error)

	WithTx(tx *sql.Tx) Querier
	DB() *sql.DB
}

Querier is the common interface satisfied by SQLite, PostgreSQL, and MySQL implementations. This interface is automatically generated by sqlc for all database engines.

func Open

func Open(dbURL string, poolCfg *PoolConfig) (Querier, error)

Open opens a database connection and returns a Querier implementation. The database type is determined from the URL scheme:

  • sqlite:// or sqlite3:// for SQLite
  • postgres:// or postgresql:// for PostgreSQL
  • mysql:// for MySQL/MariaDB

The poolCfg parameter is optional. If nil, sensible defaults are used based on the database type. SQLite uses MaxOpenConns=1, PostgreSQL and MySQL use higher values.

type SetConfigParams added in v0.6.0

type SetConfigParams struct {
	Key   string
	Value string
}

type Type added in v0.6.0

type Type uint8
const (
	TypeUnknown Type = iota
	TypeMySQL
	TypePostgreSQL
	TypeSQLite
)

func DetectFromDatabaseURL added in v0.6.0

func DetectFromDatabaseURL(dbURL string) (Type, error)

DetectFromDatabaseURL detects the database type given a database url.

func (Type) String added in v0.6.0

func (t Type) String() string

String returns the string representation of a Type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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