db

package
v0.0.0-...-9410915 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(c config.DB) (*sql.DB, error)

Types

type Comment

type Comment struct {
	ID        uuid.UUID
	UserID    uuid.UUID
	PostID    uuid.UUID
	Content   string
	CreatedAt time.Time
	UpdatedAt time.Time
}

type CreateCommentParams

type CreateCommentParams struct {
	UserID  uuid.UUID
	PostID  uuid.UUID
	Content string
}

type CreatePostParams

type CreatePostParams struct {
	UserID  uuid.UUID
	Title   string
	Content string
}

type CreateUserParams

type CreateUserParams struct {
	Email          string
	HashedPassword []byte
	Salt           []byte
}

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 Post

type Post struct {
	ID        uuid.UUID
	UserID    uuid.UUID
	Title     string
	Content   string
	CreatedAt time.Time
	UpdatedAt time.Time
}

type Querier

type Querier interface {
	// Inserts a new comment into the comments table
	CreateComment(ctx context.Context, arg CreateCommentParams) (Comment, error)
	// Inserts a new post into the posts table
	CreatePost(ctx context.Context, arg CreatePostParams) (Post, error)
	// Inserts a new user into the users table
	CreateUser(ctx context.Context, arg CreateUserParams) (User, error)
	// Deletes a specific comment from the comments table by ID
	DeleteComment(ctx context.Context, id uuid.UUID) error
	// Deletes a specific post from the posts table by ID
	DeletePost(ctx context.Context, id uuid.UUID) error
	// Retrieves all comments for a specific post from the comments table
	GetAllCommentsForPost(ctx context.Context, postID uuid.UUID) ([]Comment, error)
	// Retrieves all posts from the posts table
	GetAllPosts(ctx context.Context) ([]Post, error)
	// Retrieves a specific post from the posts table by ID
	GetPostByID(ctx context.Context, id uuid.UUID) (Post, error)
	// Retrieves user by email (used for login)
	GetUserByEmail(ctx context.Context, email string) (User, error)
	// Updates a specific comment in the comments table by ID
	UpdateComment(ctx context.Context, arg UpdateCommentParams) (Comment, error)
	// Updates a specific post in the posts table by ID
	UpdatePost(ctx context.Context, arg UpdatePostParams) (Post, error)
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) CreateComment

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

Inserts a new comment into the comments table

func (*Queries) CreatePost

func (q *Queries) CreatePost(ctx context.Context, arg CreatePostParams) (Post, error)

Inserts a new post into the posts table

func (*Queries) CreateUser

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

Inserts a new user into the users table

func (*Queries) DeleteComment

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

Deletes a specific comment from the comments table by ID

func (*Queries) DeletePost

func (q *Queries) DeletePost(ctx context.Context, id uuid.UUID) error

Deletes a specific post from the posts table by ID

func (*Queries) GetAllCommentsForPost

func (q *Queries) GetAllCommentsForPost(ctx context.Context, postID uuid.UUID) ([]Comment, error)

Retrieves all comments for a specific post from the comments table

func (*Queries) GetAllPosts

func (q *Queries) GetAllPosts(ctx context.Context) ([]Post, error)

Retrieves all posts from the posts table

func (*Queries) GetPostByID

func (q *Queries) GetPostByID(ctx context.Context, id uuid.UUID) (Post, error)

Retrieves a specific post from the posts table by ID

func (*Queries) GetUserByEmail

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

Retrieves user by email (used for login)

func (*Queries) UpdateComment

func (q *Queries) UpdateComment(ctx context.Context, arg UpdateCommentParams) (Comment, error)

Updates a specific comment in the comments table by ID

func (*Queries) UpdatePost

func (q *Queries) UpdatePost(ctx context.Context, arg UpdatePostParams) (Post, error)

Updates a specific post in the posts table by ID

func (*Queries) WithTx

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

type SchemaMigration

type SchemaMigration struct {
	Version string
}

type Session

type Session struct {
	Token  string
	Data   []byte
	Expiry time.Time
}

type UpdateCommentParams

type UpdateCommentParams struct {
	ID      uuid.UUID
	Content string
}

type UpdatePostParams

type UpdatePostParams struct {
	ID      uuid.UUID
	Title   string
	Content string
}

type User

type User struct {
	ID             uuid.UUID
	Username       string
	Email          string
	HashedPassword []byte
	Salt           []byte
	CreatedAt      time.Time
	UpdatedAt      time.Time
}

Jump to

Keyboard shortcuts

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