db

package
v0.0.0-...-6f8a6f0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 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 Account

type Account struct {
	ID         int64     `json:"id"`
	Username   string    `json:"username"`
	Role       string    `json:"role"`
	CreatedAt  time.Time `json:"created_at"`
	Reputation int32     `json:"reputation"`
	UserID     int32     `json:"user_id"`
}

type CreateAccountParams

type CreateAccountParams struct {
	Username string `json:"username"`
	Role     string `json:"role"`
	UserID   int32  `json:"user_id"`
}

type CreatePostParams

type CreatePostParams struct {
	Title  string `json:"title"`
	Body   string `json:"body"`
	UserID int32  `json:"user_id"`
	Status string `json:"status"`
}

type CreateUserParams

type CreateUserParams struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Email    string `json:"email"`
}

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 Follow

type Follow struct {
	FollowingUserID int32     `json:"following_user_id"`
	FollowedUserID  int32     `json:"followed_user_id"`
	CreatedAt       time.Time `json:"created_at"`
}

type LikePostParams

type LikePostParams struct {
	UserID int32 `json:"user_id"`
	PostID int32 `json:"post_id"`
}

type ListAccountsParams

type ListAccountsParams struct {
	Limit  int32 `json:"limit"`
	Offset int32 `json:"offset"`
}

type ListPostsParams

type ListPostsParams struct {
	Limit  int32 `json:"limit"`
	Offset int32 `json:"offset"`
}

type ListUsersParams

type ListUsersParams struct {
	Limit  int32 `json:"limit"`
	Offset int32 `json:"offset"`
}

type Post

type Post struct {
	ID    int64  `json:"id"`
	Title string `json:"title"`
	// Content of the post
	Body      string    `json:"body"`
	UserID    int32     `json:"user_id"`
	Status    string    `json:"status"`
	CreatedAt time.Time `json:"created_at"`
	Likes     int32     `json:"likes"`
}

type Querier

type Querier interface {
	CreateAccount(ctx context.Context, arg CreateAccountParams) (Account, error)
	CreatePost(ctx context.Context, arg CreatePostParams) (Post, error)
	CreateUser(ctx context.Context, arg CreateUserParams) (User, error)
	DeleteAccount(ctx context.Context, userID int32) error
	DeleteUser(ctx context.Context, id int64) error
	GetAccount(ctx context.Context, userID int32) (Account, error)
	GetPost(ctx context.Context, id int64) (Post, error)
	GetUserById(ctx context.Context, id int64) (User, error)
	GetUserByUsername(ctx context.Context, username string) (User, error)
	LikePost(ctx context.Context, id int64) error
	ListAccounts(ctx context.Context, arg ListAccountsParams) ([]Account, error)
	ListPosts(ctx context.Context, arg ListPostsParams) ([]Post, error)
	ListUsers(ctx context.Context, arg ListUsersParams) ([]User, error)
	UpdateEmail(ctx context.Context, arg UpdateEmailParams) error
	UpdatePassword(ctx context.Context, arg UpdatePasswordParams) error
	UpdateReputation(ctx context.Context, arg UpdateReputationParams) error
}

type Queries

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

func New

func New(db DBTX) *Queries

func Prepare

func Prepare(ctx context.Context, db DBTX) (*Queries, error)

func (*Queries) Close

func (q *Queries) Close() error

func (*Queries) CreateAccount

func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (Account, error)

func (*Queries) CreatePost

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

func (*Queries) CreateUser

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

func (*Queries) DeleteAccount

func (q *Queries) DeleteAccount(ctx context.Context, userID int32) error

func (*Queries) DeleteUser

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

func (*Queries) GetAccount

func (q *Queries) GetAccount(ctx context.Context, userID int32) (Account, error)

func (*Queries) GetPost

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

func (*Queries) GetUserById

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

func (*Queries) GetUserByUsername

func (q *Queries) GetUserByUsername(ctx context.Context, username string) (User, error)

func (*Queries) LikePost

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

func (*Queries) ListAccounts

func (q *Queries) ListAccounts(ctx context.Context, arg ListAccountsParams) ([]Account, error)

func (*Queries) ListPosts

func (q *Queries) ListPosts(ctx context.Context, arg ListPostsParams) ([]Post, error)

func (*Queries) ListUsers

func (q *Queries) ListUsers(ctx context.Context, arg ListUsersParams) ([]User, error)

func (*Queries) UpdateEmail

func (q *Queries) UpdateEmail(ctx context.Context, arg UpdateEmailParams) error

func (*Queries) UpdatePassword

func (q *Queries) UpdatePassword(ctx context.Context, arg UpdatePasswordParams) error

func (*Queries) UpdateReputation

func (q *Queries) UpdateReputation(ctx context.Context, arg UpdateReputationParams) error

func (*Queries) WithTx

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

type SQLStore

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

has db and set of queries to interact with the database

func (*SQLStore) LikeTx

func (store *SQLStore) LikeTx(ctx context.Context, arg LikePostParams) error

like a post and update the reputation of the author

type Store

type Store interface {
	Querier //genrated by sqlc
	LikeTx(ctx context.Context, arg LikePostParams) error
}

generic interface for all the queries anyone who wants to be a store must implement this interface

func NewStore

func NewStore(db *sql.DB) Store

constructor

type UpdateEmailParams

type UpdateEmailParams struct {
	Email string `json:"email"`
	ID    int64  `json:"id"`
}

type UpdatePasswordParams

type UpdatePasswordParams struct {
	Password string `json:"password"`
	ID       int64  `json:"id"`
}

type UpdateReputationParams

type UpdateReputationParams struct {
	Reputation int32 `json:"reputation"`
	UserID     int32 `json:"user_id"`
}

type User

type User struct {
	ID       int64  `json:"id"`
	Username string `json:"username"`
	Password string `json:"password"`
	Email    string `json:"email"`
}

Jump to

Keyboard shortcuts

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