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 CreateConfigParams ¶ added in v0.6.0
type CreateNarFileParams ¶ added in v0.6.0
CreateNarFileParams holds parameters for creating a NAR file entry.
type LinkNarInfoToNarFileParams ¶ added in v0.6.0
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 Type ¶ added in v0.6.0
type Type uint8
func DetectFromDatabaseURL ¶ added in v0.6.0
DetectFromDatabaseURL detects the database type given a database url.