db

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IntConvert

func IntConvert[From, To ~int | ~int8 | ~int16 | ~int32 | ~int64 |
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
	~float32 | ~float64](src From) To

func IntPtrConvert

func IntPtrConvert[From, To ~int | ~int32 | ~int64 | ~float32 | ~float64](src *From) *To

example: IntPtrConvert[int64, int32](dbRow.Age)

func NullBoolToPtr

func NullBoolToPtr(n sql.NullBool) *bool

func NullBytesToPtr

func NullBytesToPtr(b []byte) *[]byte

--- Bytes Converters ---

func NullFloat64ToPtr

func NullFloat64ToPtr(n sql.NullFloat64) *float64

func NullInt32ToPtr

func NullInt32ToPtr(n sql.NullInt32) *int32

--- Nullable SQL Type Converters ---

func NullInt64ToPtr

func NullInt64ToPtr(n sql.NullInt64) *int64

func NullStringToPtr

func NullStringToPtr(n sql.NullString) *string

func NullTimeToProto

func NullTimeToProto(n sql.NullTime) *timestamppb.Timestamp

--- Time Converters ---

func OptionalWithFallback

func OptionalWithFallback[T any](val *T, fallback T) T

OptionalWithFallback chooses fallback if optional value is nil

func ProtoToNullTime

func ProtoToNullTime(t *timestamppb.Timestamp) sql.NullTime

func ProtoToTime

func ProtoToTime(t *timestamppb.Timestamp) time.Time

A nil pointer returns a zero time.Time{}

func PtrBytesToNullString

func PtrBytesToNullString(p *[]byte) sql.NullString

PtrBytesToNullString converts *[]byte to sql.NullString for MySQL compatibility

func PtrToNullBool

func PtrToNullBool(p *bool) sql.NullBool

func PtrToNullBytes

func PtrToNullBytes(b *[]byte) []byte

func PtrToNullFloat64

func PtrToNullFloat64(p *float64) sql.NullFloat64

func PtrToNullInt32

func PtrToNullInt32(p *int32) sql.NullInt32

func PtrToNullInt64

func PtrToNullInt64(p *int64) sql.NullInt64

func PtrToNullString

func PtrToNullString(p *string) sql.NullString

func SQLiteBoolPtrToInt64Ptr

func SQLiteBoolPtrToInt64Ptr(b *bool) *int64

SQLiteBoolPtrToInt64Ptr converts *bool to *int64 for nullable columns via sqlc.narg

func SQLiteBoolToInt

func SQLiteBoolToInt(b bool) int64

func SQLiteInt64PtrToBoolPtr

func SQLiteInt64PtrToBoolPtr(i *int64) *bool

SQLiteInt64PtrToBoolPtr is the inverse of SQLiteBoolPtrToInt64Ptr.

func SQLiteIntToBool

func SQLiteIntToBool(i int64) bool

--- SQLite bool converters ---

func TimeToProto

func TimeToProto(t time.Time) *timestamppb.Timestamp

TimeToProto converts time.Time to timestamppb.Timestamp pointer

Types

type Article

type Article struct {
	ID             string     `json:"id"`
	Slug           string     `json:"slug"`
	Title          string     `json:"title"`
	Author         string     `json:"author"`
	Subtitle       *string    `json:"subtitle"`
	ReadingMinutes *int32     `json:"reading_minutes"`
	LastViewedMs   *int64     `json:"last_viewed_ms"`
	Rating         *float64   `json:"rating"`
	CoverImage     *[]byte    `json:"cover_image"`
	PublishedAt    *time.Time `json:"published_at"`
	Metadata       *string    `json:"metadata"`
	IsFeatured     bool       `json:"is_featured"`
	CreatedAt      time.Time  `json:"created_at"`
	UpdatedAt      time.Time  `json:"updated_at"`
}

func ArticleFromSQL

func ArticleFromSQL(db *internal.Article) *Article

func (*Article) ArticleToSQL

func (m *Article) ArticleToSQL() *internal.Article

func (*Article) ToProto

func (m *Article) ToProto() *pb.Article

ToProto converts Article to proto format

type CreateArticleParams

type CreateArticleParams struct {
	Slug           string     `json:"slug"`
	Title          string     `json:"title"`
	Author         string     `json:"author"`
	Subtitle       *string    `json:"subtitle"`
	ReadingMinutes *int32     `json:"reading_minutes"`
	LastViewedMs   *int64     `json:"last_viewed_ms"`
	Rating         *float64   `json:"rating"`
	CoverImage     *[]byte    `json:"cover_image"`
	PublishedAt    *time.Time `json:"published_at"`
	Metadata       *string    `json:"metadata"`
	IsFeatured     *bool      `json:"is_featured"`
}

type DBTX

type DBTX = internal.DBTX

type ListArticleByAuthorParams added in v0.0.4

type ListArticleByAuthorParams struct {
	Author string `json:"author"`
	Offset int32  `json:"offset"`
	Limit  int32  `json:"limit"`
}

type ListArticleFilterByAuthorIsFeaturedPublishedAtTitleParams

type ListArticleFilterByAuthorIsFeaturedPublishedAtTitleParams struct {
	Author         string     `json:"author"`
	IsFeatured     bool       `json:"is_featured"`
	MinPublishedAt *time.Time `json:"min_published_at"`
	MaxPublishedAt *time.Time `json:"max_published_at"`
	Title          string     `json:"title"`
	Offset         int32      `json:"offset"`
	Limit          int32      `json:"limit"`
}

type ListArticleFilterByAuthorIsFeaturedPublishedAtTitleRow added in v0.0.5

type ListArticleFilterByAuthorIsFeaturedPublishedAtTitleRow = internal.ListArticleFilterByAuthorIsFeaturedPublishedAtTitleRow

type Queries

type Queries internal.Queries

func New

func New(db DBTX) *Queries

func (*Queries) CreateArticle

func (q *Queries) CreateArticle(ctx context.Context, arg CreateArticleParams) (string, error)

func (*Queries) DeleteArticle

func (q *Queries) DeleteArticle(ctx context.Context, id string) error

func (*Queries) GetArticleById added in v0.0.6

func (q *Queries) GetArticleById(ctx context.Context, id string) (*Article, error)

func (*Queries) GetArticleBySlug

func (q *Queries) GetArticleBySlug(ctx context.Context, slug string) (*Article, error)

func (*Queries) ListAllArticle

func (q *Queries) ListAllArticle(ctx context.Context) ([]*Article, error)

func (*Queries) ListArticleByAuthor

func (q *Queries) ListArticleByAuthor(ctx context.Context, arg ListArticleByAuthorParams) ([]*Article, error)

func (*Queries) ListArticleFilterByAuthorIsFeaturedPublishedAtTitle

func (q *Queries) ListArticleFilterByAuthorIsFeaturedPublishedAtTitle(ctx context.Context, arg ListArticleFilterByAuthorIsFeaturedPublishedAtTitleParams) ([]*Article, int64, error)

func (*Queries) UpdateArticle

func (q *Queries) UpdateArticle(ctx context.Context, arg UpdateArticleParams) (*Article, error)

func (*Queries) WithTx

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

type UpdateArticleParams

type UpdateArticleParams struct {
	Slug           string     `json:"slug"`
	Title          string     `json:"title"`
	Author         string     `json:"author"`
	Subtitle       *string    `json:"subtitle"`
	ReadingMinutes *int32     `json:"reading_minutes"`
	LastViewedMs   *int64     `json:"last_viewed_ms"`
	Rating         *float64   `json:"rating"`
	CoverImage     *[]byte    `json:"cover_image"`
	PublishedAt    *time.Time `json:"published_at"`
	Metadata       *string    `json:"metadata"`
	IsFeatured     *bool      `json:"is_featured"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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