Help us shape the future of Go! Take the 2026 Go Developer Survey

db

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package db provides type-safe database queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateUserParams

type CreateUserParams struct {
	OrgID    int64  `json:"org_id"`
	Email    string `json:"email"`
	FullName string `json:"full_name"`
}

CreateUserParams contains parameters for creating a new user.

type DB

type DB interface {
	ExecContext(context.Context, string, ...any) (sql.Result, error)
	PrepareContext(context.Context, string) (*sql.Stmt, error)
	QueryContext(context.Context, string, ...any) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...any) *sql.Row
}

DB represents a database connection or transaction.

type Organization

type Organization struct {
	ID        int64     `json:"id"`
	Name      string    `json:"name"`
	CreatedAt time.Time `json:"created_at"`
}

Organization represents an organization record.

type Queries

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

Queries provides query execution methods.

func New

func New(db DB) *Queries

New returns a new Queries instance bound to db.

func (*Queries) CreateOrganization

func (q *Queries) CreateOrganization(ctx context.Context, name string) (Organization, error)

CreateOrganization inserts a new organization and returns the created record.

func (*Queries) CreateUser

func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error)

CreateUser inserts a new user and returns the created record.

func (*Queries) GetUserByEmail

func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error)

GetUserByEmail fetches a user matching the provided email address.

func (*Queries) ListUsersByOrg

func (q *Queries) ListUsersByOrg(ctx context.Context, orgID int64) ([]User, error)

ListUsersByOrg returns all users belonging to an organization.

func (*Queries) WithTx

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

WithTx returns a new Queries instance scoped to a transaction.

type User

type User struct {
	ID        int64     `json:"id"`
	OrgID     int64     `json:"org_id"`
	Email     string    `json:"email"`
	FullName  string    `json:"full_name"`
	CreatedAt time.Time `json:"created_at"`
}

User represents a user record.

Jump to

Keyboard shortcuts

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