users

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package users demonstrates how to extend sqlcredo with custom SQL queries. It provides a complete example of a user repository that includes standard CRUD operations and a custom query method for counting users based on whether they have a last name.

Index

Constants

View Source
const (
	TableName = "users"
	IDColumn  = "id"
)
View Source
const CountByLastNameExistsQuery = `` /* 191-byte string literal not displayed */

Variables

This section is empty.

Functions

This section is empty.

Types

type Article added in v0.9.0

type Article struct {
	ID        Identity  `db:"id"`
	Title     string    `db:"title"`
	CreatedAt time.Time `db:"created_at"`
	UserID    Identity  `db:"user_id"`
}

type ArticlesRepo added in v0.9.0

type ArticlesRepo struct {
	sc.SQLCredo[Article, Identity]
}

func NewArticlesRepo added in v0.9.0

func NewArticlesRepo(db *sql.DB, driver string, debugFunc sc.DebugFunc) *ArticlesRepo

func (*ArticlesRepo) DeleteByUserID added in v0.9.0

func (r *ArticlesRepo) DeleteByUserID(ctx context.Context, userID Identity) (sql.Result, error)

func (*ArticlesRepo) GetByUserID added in v0.9.0

func (r *ArticlesRepo) GetByUserID(ctx context.Context, userID Identity) ([]Article, error)

func (*ArticlesRepo) WithTxx added in v0.9.0

func (r *ArticlesRepo) WithTxx(txExec sc.SQLExecutor) *ArticlesRepo

type CountByLastNameExistsCategory

type CountByLastNameExistsCategory struct {
	Name  string `db:"category"`
	Count int    `db:"cnt"`
}

type Identity

type Identity string

type Repo

type Repo struct {
	sc.SQLCredo[User, Identity]
	// contains filtered or unexported fields
}

func NewRepo

func NewRepo(db *sql.DB, driver string, debugFunc sc.DebugFunc) *Repo

func (*Repo) Articles added in v0.9.0

func (r *Repo) Articles() *ArticlesRepo

func (*Repo) CountByLastNameExists

func (r *Repo) CountByLastNameExists(ctx context.Context) (map[string]int, error)

func (*Repo) CreateWithArticle added in v0.9.0

func (r *Repo) CreateWithArticle(ctx context.Context, user *User, article *Article) error

func (*Repo) DeleteWithArticles added in v0.9.0

func (r *Repo) DeleteWithArticles(ctx context.Context, id Identity) error

func (*Repo) GetWithArticles added in v0.9.0

func (r *Repo) GetWithArticles(ctx context.Context, dest *User, id Identity) error

func (*Repo) WithTxx added in v0.9.0

func (r *Repo) WithTxx(txExec sc.SQLExecutor) *Repo

type User added in v0.9.0

type User struct {
	ID        Identity  `db:"id"`
	FirstName string    `db:"first_name"`
	LastName  *string   `db:"last_name"`
	BirthDate time.Time `db:"birth_date"`
	Articles  []Article `db:"-"`
}

func (*User) String added in v0.9.0

func (u *User) String() string

Jump to

Keyboard shortcuts

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