sqlc

package
v1.3.28 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package sqlc is a scaffold for integrating SQLC-generated query code with the go-core database infrastructure.

SCAFFOLD STATUS: The Querier interface and Queries struct below are intentionally empty placeholders. To activate this package:

  1. Define your SQL queries in database/queries/*.sql
  2. Run `sqlc generate` from the repository root (see sqlc.yaml)
  3. Replace the empty Querier interface with the generated sqlc.Querier
  4. Replace the Queries stub with the generated sqlc.Queries struct

Until those steps are complete, NewFromTx returns an empty Querier that cannot execute any real queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithQuerier

func WithQuerier(ctx context.Context, q Querier) context.Context

WithQuerier returns a copy of ctx that carries the provided Querier.

Types

type Querier

type Querier interface {
}

Querier is the minimal interface that generated *Queries structs implement.

func NewFromTx

func NewFromTx(tx *sql.Tx) Querier

NewFromTx returns a Querier backed by the given SQL transaction. NOTE: scaffold implementation — returns an empty Queries struct. Replace with the sqlc-generated version after running `sqlc generate`.

func QuerierFromContext

func QuerierFromContext(ctx context.Context) (Querier, bool)

QuerierFromContext retrieves a Querier from the context if present. If a Querier is not directly present, this will attempt to retrieve a *sql.Tx from the context (stored by database.Transactor) and construct a Querier using NewFromTx.

type Queries

type Queries struct{}

Queries is a placeholder. Replace with the sqlc-generated Queries struct after running `sqlc generate`. See package doc in sqlc.go.

type SQLCRepository

type SQLCRepository struct {
	Queries    Querier
	Transactor database.Transactor
}

SQLCRepository is a minimal base repository for sqlc-generated Querier implementations. It holds a Querier and an optional Transactor used to run operations inside transactions.

func NewSQLCRepository

func NewSQLCRepository(q Querier, t database.Transactor) *SQLCRepository

NewSQLCRepository constructs a new SQLCRepository.

func (*SQLCRepository) WithinTransaction

func (r *SQLCRepository) WithinTransaction(ctx context.Context, fn func(ctx context.Context, q Querier) error) error

WithinTransaction executes fn within a transaction if a Transactor is provided. If the Transactor stored a Querier in the context (via sqlc.WithQuerier), prefer that Querier; otherwise fall back to the repository's Queries instance.

Jump to

Keyboard shortcuts

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