db

package
v0.0.0-...-27103db Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Tx

func Tx(ctx context.Context, db *Db, statements func(ctx context.Context, tx *Db) error) error

func TxR

func TxR[T any](ctx context.Context, db *Db, statements func(ctx context.Context, tx *Db) (*T, error)) (*T, error)

Types

type Author

type Author struct {
	ID        int64
	Email     string
	CreatedAt SqliteDateTime
	UpdatedAt SqliteDateTime
}

type ChangeAuthorEmailParams

type ChangeAuthorEmailParams struct {
	Email string
	ID    int64
}

type ChangeCommentBodyParams

type ChangeCommentBodyParams struct {
	Body sql.NullString
	ID   int64
}

type ChangeEntryBodyParams

type ChangeEntryBodyParams struct {
	Body sql.NullString
	ID   int64
}

type ChangeEntryTitleParams

type ChangeEntryTitleParams struct {
	Title string
	ID    int64
}

type Comment

type Comment struct {
	ID        int64
	Body      string
	EntryID   int64
	AuthorID  int64
	CreatedAt SqliteDateTime
	UpdatedAt SqliteDateTime
}

type CreateCommentParams

type CreateCommentParams struct {
	Body     string
	AuthorID int64
	EntryID  int64
}

type CreateEntryParams

type CreateEntryParams struct {
	Title    string
	Body     sql.NullString
	AuthorID int64
}

type DBTX

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

type Db

type Db struct {
	Queries

	Tx *sql.Tx
	// contains filtered or unexported fields
}

func NewDb

func NewDb(c *sql.DB) *Db

func (*Db) Connection

func (db *Db) Connection() *sql.DB

type Entry

type Entry struct {
	ID        int64
	Title     string
	Body      sql.NullString
	CreatedAt SqliteDateTime
	UpdatedAt SqliteDateTime
	AuthorID  int64
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) ChangeAuthorEmail

func (q *Queries) ChangeAuthorEmail(ctx context.Context, arg ChangeAuthorEmailParams) error

func (*Queries) ChangeCommentBody

func (q *Queries) ChangeCommentBody(ctx context.Context, arg ChangeCommentBodyParams) error

func (*Queries) ChangeEntryBody

func (q *Queries) ChangeEntryBody(ctx context.Context, arg ChangeEntryBodyParams) error

func (*Queries) ChangeEntryTitle

func (q *Queries) ChangeEntryTitle(ctx context.Context, arg ChangeEntryTitleParams) error

func (*Queries) CreateAuthor

func (q *Queries) CreateAuthor(ctx context.Context, email string) (Author, error)

func (*Queries) CreateComment

func (q *Queries) CreateComment(ctx context.Context, arg CreateCommentParams) (Comment, error)

func (*Queries) CreateEntry

func (q *Queries) CreateEntry(ctx context.Context, arg CreateEntryParams) (Entry, error)

func (*Queries) DeleteAuthor

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

func (*Queries) DeleteComment

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

func (*Queries) DeleteEntry

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

func (*Queries) GetCommentsByEntry

func (q *Queries) GetCommentsByEntry(ctx context.Context, entryID int64) ([]Comment, error)

func (*Queries) GetEntryByAuthor

func (q *Queries) GetEntryByAuthor(ctx context.Context, authorID int64) ([]Entry, error)

func (*Queries) UpdateTS

func (q *Queries) UpdateTS(ctx context.Context, arg UpdateTSParams) error

func (*Queries) WithTx

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

type SqliteDateTime

type SqliteDateTime struct {
	time.Time
}

func (*SqliteDateTime) Scan

func (ts *SqliteDateTime) Scan(src any) error

func (SqliteDateTime) Value

func (ts SqliteDateTime) Value() (driver.Value, error)

type UpdateTSParams

type UpdateTSParams struct {
	UpdatedAt SqliteDateTime
	ID        int64
}

Jump to

Keyboard shortcuts

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