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.
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 ¶
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") // ErrInvalidPostgresUnixURL is returned when a postgres+unix URL is invalid. ErrInvalidPostgresUnixURL = errors.New("invalid postgres+unix URL") // ErrInvalidMySQLUnixURL is returned when a mysql+unix URL is invalid. ErrInvalidMySQLUnixURL = errors.New("invalid mysql+unix URL") )
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
type LinkNarInfoToNarFileParams ¶ added in v0.6.0
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
//
// 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
// ) VALUES (
// $1, $2, $3, $4
// )
// RETURNING id, hash, compression, file_size, query, created_at, updated_at, last_accessed_at
CreateNarFile(ctx context.Context, arg CreateNarFileParams) (NarFile, 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)
//DeleteNarFileByHash
//
// DELETE FROM nar_files
// WHERE hash = $1
DeleteNarFileByHash(ctx context.Context, hash string) (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)
//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) ([]NarFile, 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
// 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)
//GetNarFileByHash
//
// SELECT id, hash, compression, file_size, query, created_at, updated_at, last_accessed_at
// FROM nar_files
// WHERE hash = $1
GetNarFileByHash(ctx context.Context, hash string) (NarFile, error)
//GetNarFileByID
//
// SELECT id, hash, compression, file_size, query, created_at, updated_at, last_accessed_at
// 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) (NarFile, 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
// 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)
//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)
//GetNarTotalSize
//
// SELECT CAST(COALESCE(SUM(file_size), 0) AS BIGINT) AS total_size
// FROM nar_files
GetNarTotalSize(ctx context.Context) (int64, 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) ([]NarFile, error)
//LinkNarInfoToNarFile
//
// INSERT INTO narinfo_nar_files (
// narinfo_id, nar_file_id
// ) VALUES (
// $1, $2
// )
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
TouchNarFile(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)
WithTx(tx *sql.Tx) Querier
DB() *sql.DB
}
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.