cachedb

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(ctx context.Context, key string) (any, bool)
	Set(ctx context.Context, key string, value any, ttl time.Duration)
	Delete(ctx context.Context, key string)
	Invalidate(ctx context.Context, pattern string)
}

type CreateUserParams

type CreateUserParams struct {
	Name  string
	Name2 string
}

type DBTX

type DBTX interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}

type GetPopularPostsRow

type GetPopularPostsRow struct {
	Id        int64
	UserId    int64
	Title     string
	Content   sql.NullString
	Likes     int64
	CreatedAt int64
}

type GetUserByEmailRow

type GetUserByEmailRow struct {
	Id        int64
	Name      string
	Email     string
	Active    bool
	CreatedAt int64
}

type GetUserPostsRow

type GetUserPostsRow struct {
	Id        int64
	UserId    int64
	Title     string
	Content   sql.NullString
	Likes     int64
	CreatedAt int64
}

type GetUserRow

type GetUserRow struct {
	Id        int64
	Name      string
	Email     string
	Active    bool
	CreatedAt int64
}

type ListActiveUsersRow

type ListActiveUsersRow struct {
	Id        int64
	Name      string
	Email     string
	Active    bool
	CreatedAt int64
}

type Posts

type Posts struct {
	Id        int64
	UserId    int64
	Title     string
	Content   sql.NullString
	Likes     int64
	CreatedAt int64
}

type Querier

type Querier interface {
	CreateUser(ctx context.Context, arg CreateUserParams) error
	GetPopularPosts(ctx context.Context, limit any) ([]GetPopularPostsRow, error)
	GetUser(ctx context.Context, id int64) (GetUserRow, error)
	GetUserByEmail(ctx context.Context, email string) (GetUserByEmailRow, error)
	GetUserPosts(ctx context.Context, userId int64) ([]GetUserPostsRow, error)
	ListActiveUsers(ctx context.Context) ([]ListActiveUsersRow, error)
	UpdateUser(ctx context.Context, arg UpdateUserParams) error
	WithTx(tx DBTX) *Queries
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) CreateUser

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

CreateUser inserts a new user (no caching, but invalidates users list). This is a write operation so we don't cache it, but we invalidate the cached list of users.

func (*Queries) GetPopularPosts

func (q *Queries) GetPopularPosts(ctx context.Context, limit any) ([]GetPopularPostsRow, error)

GetPopularPosts retrieves popular posts with longer cache TTL.

func (*Queries) GetUser

func (q *Queries) GetUser(ctx context.Context, id int64) (GetUserRow, error)

GetUser retrieves a user by ID with 5-minute cache. The cache key includes the user ID.

func (*Queries) GetUserByEmail

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

GetUserByEmail retrieves a user by email with caching.

func (*Queries) GetUserPosts

func (q *Queries) GetUserPosts(ctx context.Context, userId int64) ([]GetUserPostsRow, error)

GetUserPosts retrieves posts for a specific user.

func (*Queries) ListActiveUsers

func (q *Queries) ListActiveUsers(ctx context.Context) ([]ListActiveUsersRow, error)

ListActiveUsers retrieves all active users with 1-hour cache. No custom key pattern, so cache key is auto-generated.

func (*Queries) UpdateUser

func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) error

UpdateUser updates a user and invalidates related caches.

func (*Queries) WithTx

func (q *Queries) WithTx(tx DBTX) *Queries

type QueryResult

type QueryResult struct {
	LastInsertID int64
	RowsAffected int64
}

type UpdateUserParams

type UpdateUserParams struct {
	Name  string
	Email string
	Id    int64
}

type Users

type Users struct {
	Id        int64
	Name      string
	Email     string
	Active    bool
	CreatedAt int64
}

Jump to

Keyboard shortcuts

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