db

package
v0.0.0-...-ae5e3d9 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package db provides database access for gitgres: repos, refs, and Git objects stored in PostgreSQL. Schema and queries are in sql/; Go code is generated by sqlc (see Queries, ListRefs, ObjectRead, etc.) plus hand-written connection and helpers.

Library usage: open a pool with OpenPool, then create Queries with New(pool). Use GetOrCreateRepo or GetRepo to resolve a repo name to an ID. For a storage.Storer implementation that uses this package, see internal/storer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenPool

func OpenPool(ctx context.Context, connString string) (*pgxpool.Pool, error)

OpenPool opens a connection pool from connString. If empty, uses PG connection env (e.g. PGDATABASE=gitgres_test or PGCONN).

Types

type DBTX

type DBTX interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
}

type ListRefsRow

type ListRefsRow struct {
	Name     string      `json:"name"`
	Oid      []byte      `json:"oid"`
	Symbolic pgtype.Text `json:"symbolic"`
}

type Object

type Object struct {
	RepoID  int32  `json:"repo_id"`
	Oid     []byte `json:"oid"`
	Type    int16  `json:"type"`
	Size    int32  `json:"size"`
	Content []byte `json:"content"`
}

type ObjectReadParams

type ObjectReadParams struct {
	RepoID int32  `json:"repo_id"`
	Oid    []byte `json:"oid"`
}

type ObjectReadRow

type ObjectReadRow struct {
	Type    int16  `json:"type"`
	Size    int32  `json:"size"`
	Content []byte `json:"content"`
}

type ObjectWriteParams

type ObjectWriteParams struct {
	RepoID  int32       `json:"repo_id"`
	ObjType int16       `json:"obj_type"`
	Content interface{} `json:"content"`
}

type Queries

type Queries struct {
	// contains filtered or unexported fields
}

func New

func New(db DBTX) *Queries

func (*Queries) GetOrCreateRepo

func (q *Queries) GetOrCreateRepo(ctx context.Context, name string) (int32, error)

func (*Queries) GetRepo

func (q *Queries) GetRepo(ctx context.Context, name string) (int32, error)

func (*Queries) ListObjectOids

func (q *Queries) ListObjectOids(ctx context.Context, repoID int32) ([][]byte, error)

func (*Queries) ListObjectOidsCount

func (q *Queries) ListObjectOidsCount(ctx context.Context, repoID int32) (int32, error)

func (*Queries) ListObjectOidsPrealloc

func (q *Queries) ListObjectOidsPrealloc(ctx context.Context, repoID int32) ([][]byte, error)

ListObjectOidsPrealloc returns object OIDs for the repo. Semantically equivalent to ListObjectOids.

func (*Queries) ListRefs

func (q *Queries) ListRefs(ctx context.Context, repoID int32) ([]ListRefsRow, error)

func (*Queries) ListRefsCount

func (q *Queries) ListRefsCount(ctx context.Context, repoID int32) (int32, error)

func (*Queries) ListRefsPrealloc

func (q *Queries) ListRefsPrealloc(ctx context.Context, repoID int32) ([]ListRefsRow, error)

ListRefsPrealloc returns refs for the repo. Semantically equivalent to ListRefs.

func (*Queries) ObjectRead

func (q *Queries) ObjectRead(ctx context.Context, arg ObjectReadParams) (ObjectReadRow, error)

func (*Queries) ObjectWrite

func (q *Queries) ObjectWrite(ctx context.Context, arg ObjectWriteParams) (interface{}, error)

func (*Queries) RefDelete

func (q *Queries) RefDelete(ctx context.Context, arg RefDeleteParams) error

func (*Queries) RefInsert

func (q *Queries) RefInsert(ctx context.Context, arg RefInsertParams) error

Remote-helper push: direct ref write/delete (no reflog, no CAS)

func (*Queries) RefInsertSymbolic

func (q *Queries) RefInsertSymbolic(ctx context.Context, arg RefInsertSymbolicParams) error

func (*Queries) RefSetSymbolic

func (q *Queries) RefSetSymbolic(ctx context.Context, arg RefSetSymbolicParams) error

func (*Queries) RefUpdate

func (q *Queries) RefUpdate(ctx context.Context, arg RefUpdateParams) (interface{}, error)

func (*Queries) RefsHasHEAD

func (q *Queries) RefsHasHEAD(ctx context.Context, repoID int32) (int32, error)

func (*Queries) WithTx

func (q *Queries) WithTx(tx pgx.Tx) *Queries

type Ref

type Ref struct {
	RepoID   int32       `json:"repo_id"`
	Name     string      `json:"name"`
	Oid      []byte      `json:"oid"`
	Symbolic pgtype.Text `json:"symbolic"`
}

type RefDeleteParams

type RefDeleteParams struct {
	RepoID int32  `json:"repo_id"`
	Name   string `json:"name"`
}

type RefInsertParams

type RefInsertParams struct {
	RepoID int32  `json:"repo_id"`
	Name   string `json:"name"`
	Oid    []byte `json:"oid"`
}

type RefInsertSymbolicParams

type RefInsertSymbolicParams struct {
	RepoID   int32       `json:"repo_id"`
	Name     string      `json:"name"`
	Symbolic pgtype.Text `json:"symbolic"`
}

type RefSetSymbolicParams

type RefSetSymbolicParams struct {
	RepoID int32  `json:"repo_id"`
	Name   string `json:"name"`
	Target string `json:"target"`
}

type RefUpdateParams

type RefUpdateParams struct {
	RepoID int32       `json:"repo_id"`
	Name   string      `json:"name"`
	NewOid interface{} `json:"new_oid"`
	OldOid interface{} `json:"old_oid"`
	Force  bool        `json:"force"`
}

type Repository

type Repository struct {
	ID        int32              `json:"id"`
	Name      string             `json:"name"`
	CreatedAt pgtype.Timestamptz `json:"created_at"`
}

Jump to

Keyboard shortcuts

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