Documentation
¶
Index ¶
- Constants
- Variables
- func ErrorCode(err error) string
- type CreatVerifyEmailParams
- type CreateSessionParams
- type CreateUserParams
- type CreateUserTxParams
- type CreateUserTxResult
- type DBTX
- type Querier
- type Queries
- func (q *Queries) CreatVerifyEmail(ctx context.Context, arg CreatVerifyEmailParams) (VerifyEmail, error)
- func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) (Session, error)
- func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error)
- func (q *Queries) GetSession(ctx context.Context, id uuid.UUID) (Session, error)
- func (q *Queries) GetUser(ctx context.Context, username string) (User, error)
- func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (User, error)
- func (q *Queries) UpdateVerifyEmail(ctx context.Context, arg UpdateVerifyEmailParams) (VerifyEmail, error)
- func (q *Queries) WithTx(tx pgx.Tx) *Queries
- type SQLStore
- type Session
- type Store
- type UpdateUserParams
- type UpdateVerifyEmailParams
- type User
- type VerifyEmail
- type VerifyEmailTxParams
- type VerifyEmailTxResult
Constants ¶
const ( UniqueViolation = "23505" ForeignKeyViolation = "23503" )
Variables ¶
var ErrRecordNotFound = pgx.ErrNoRows // doing this because sql.ErrNoWRows returns a different string message than pgx does, so we made this for our unit tests
var ErrUniqueViolation = &pgconn.PgError{ Code: UniqueViolation, }
Functions ¶
Types ¶
type CreatVerifyEmailParams ¶
type CreateSessionParams ¶
type CreateUserParams ¶
type CreateUserTxParams ¶
type CreateUserTxParams struct {
CreateUserParams
//This is a callback function that will only be called after the user is created
AfterCreate func(user User) error // output will determine weather to complete or rollback db tx
}
type CreateUserTxResult ¶
type CreateUserTxResult struct {
User User
}
CreateUserTxResult is the result of the transfer transaction
type Querier ¶
type Querier interface {
CreatVerifyEmail(ctx context.Context, arg CreatVerifyEmailParams) (VerifyEmail, error)
CreateSession(ctx context.Context, arg CreateSessionParams) (Session, error)
CreateUser(ctx context.Context, arg CreateUserParams) (User, error)
GetSession(ctx context.Context, id uuid.UUID) (Session, error)
GetUser(ctx context.Context, username string) (User, error)
UpdateUser(ctx context.Context, arg UpdateUserParams) (User, error)
UpdateVerifyEmail(ctx context.Context, arg UpdateVerifyEmailParams) (VerifyEmail, error)
}
type Queries ¶
type Queries struct {
// contains filtered or unexported fields
}
func (*Queries) CreatVerifyEmail ¶
func (q *Queries) CreatVerifyEmail(ctx context.Context, arg CreatVerifyEmailParams) (VerifyEmail, error)
func (*Queries) CreateSession ¶
func (*Queries) CreateUser ¶
func (*Queries) GetSession ¶
func (*Queries) UpdateUser ¶
func (*Queries) UpdateVerifyEmail ¶
func (q *Queries) UpdateVerifyEmail(ctx context.Context, arg UpdateVerifyEmailParams) (VerifyEmail, error)
type SQLStore ¶
type SQLStore struct {
*Queries // all individual Query functions provided by `Queries` is available to Store struct
// contains filtered or unexported fields
}
SQLStore provides all functions to execute db queries and transactions For individual queries, we already have the Queries struct in db.go (generated by sqlc) each query does 1 operation per table so it doesnt support transactions (COMMIT/ROLLBACK) This file will extend its functionality to support Transactions by embedding it in the store struct (This is called composition) It is the preferred way to extend struct functionality in goLang instead of inheritance
func (*SQLStore) CreateUserTx ¶
func (store *SQLStore) CreateUserTx(ctx context.Context, arg CreateUserTxParams) (CreateUserTxResult, error)
func (*SQLStore) VerifyEmailTx ¶
func (store *SQLStore) VerifyEmailTx(ctx context.Context, arg VerifyEmailTxParams) (VerifyEmailTxResult, error)
type Store ¶
type Store interface {
Querier
CreateUserTx(ctx context.Context, arg CreateUserTxParams) (CreateUserTxResult, error)
VerifyEmailTx(ctx context.Context, arg VerifyEmailTxParams) (VerifyEmailTxResult, error)
}
Store was created to be able to mock the DB for our tests. note : we updated sqlc.yaml with `emit_interface: true`, then we ran `make sqlc` so we won't have to copy everything that Queries implements into store interface (Check querier.go)
type UpdateUserParams ¶
type UpdateUserParams struct {
HashedPassword pgtype.Text `json:"hashed_password"`
PasswordChangeAt pgtype.Timestamptz `json:"password_change_at"`
FullName pgtype.Text `json:"full_name"`
Email pgtype.Text `json:"email"`
IsEmailVerified pgtype.Bool `json:"is_email_verified"`
Username string `json:"username"`
}
type UpdateVerifyEmailParams ¶
type User ¶
type User struct {
Username string `json:"username"`
HashedPassword string `json:"hashed_password"`
FullName string `json:"full_name"`
Email string `json:"email"`
IsEmailVerified bool `json:"is_email_verified"`
PasswordChangeAt time.Time `json:"password_change_at"`
CreatedAt time.Time `json:"created_at"`
Role string `json:"role"`
}
type VerifyEmail ¶
type VerifyEmailTxParams ¶
type VerifyEmailTxResult ¶
type VerifyEmailTxResult struct {
User User
VerifyEmail VerifyEmail
}