Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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
IsDuplicateKeyError checks if the error is a unique constraint violation Works across SQLite, PostgreSQL, and MySQL.
func IsNotFoundError ¶ added in v0.6.0
IsNotFoundError checks if the error indicates a row was not found.
Types ¶
type CreateNarParams ¶ added in v0.0.13
type CreateNarParams struct {
NarInfoID int64
Hash string
Compression string
Query string
FileSize uint64
}
CreateNarParams holds parameters for creating a NAR entry.
type Nar ¶ added in v0.0.13
type Nar struct {
ID int64
NarInfoID int64
Hash string
Compression string
FileSize uint64
CreatedAt time.Time
UpdatedAt sql.NullTime
LastAccessedAt sql.NullTime
Query string
}
Nar 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 {
CreateNar(ctx context.Context, arg CreateNarParams) (Nar, error)
CreateNarInfo(ctx context.Context, hash string) (NarInfo, error)
DeleteNarByHash(ctx context.Context, hash string) (int64, error)
DeleteNarByID(ctx context.Context, id int64) (int64, error)
DeleteNarInfoByHash(ctx context.Context, hash string) (int64, error)
DeleteNarInfoByID(ctx context.Context, id int64) (int64, error)
GetLeastUsedNars(ctx context.Context, fileSize uint64) ([]Nar, error)
GetNarByHash(ctx context.Context, hash string) (Nar, error)
GetNarByID(ctx context.Context, id int64) (Nar, error)
GetNarInfoByHash(ctx context.Context, hash string) (NarInfo, error)
GetNarInfoByID(ctx context.Context, id int64) (NarInfo, error)
GetNarTotalSize(ctx context.Context) (int64, error)
TouchNar(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 both SQLite and PostgreSQL implementations. This interface is automatically generated by sqlc for both 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.