db

package
v0.0.0-...-57b3fe1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateUserParams

type CreateUserParams struct {
	SocialID string `json:"social_id"`
	Username string `json:"username"`
	Email    string `json:"email"`
	Picture  string `json:"picture"`
	Provider string `json:"provider"`
}

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 GenerateSessionParams

type GenerateSessionParams struct {
	UserIDSession int64  `json:"user_id_session"`
	Valid         bool   `json:"valid"`
	UserAgent     string `json:"user_agent"`
}

type Querier

type Querier interface {
	CreateUser(ctx context.Context, arg CreateUserParams) (User, error)
	GenerateSession(ctx context.Context, arg GenerateSessionParams) (Session, error)
	GetSession(ctx context.Context, userIDSession int64) (Session, error)
	GetUserById(ctx context.Context, userID int64) (User, error)
	GetUserBySocialId(ctx context.Context, socialID string) (User, error)
	UpdateUser(ctx context.Context, arg UpdateUserParams) (User, error)
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) CreateUser

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

func (*Queries) GenerateSession

func (q *Queries) GenerateSession(ctx context.Context, arg GenerateSessionParams) (Session, error)

func (*Queries) GetSession

func (q *Queries) GetSession(ctx context.Context, userIDSession int64) (Session, error)

func (*Queries) GetUserById

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

func (*Queries) GetUserBySocialId

func (q *Queries) GetUserBySocialId(ctx context.Context, socialID string) (User, error)

func (*Queries) UpdateUser

func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (User, error)

func (*Queries) WithTx

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

type SQLCStore

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

SQLCStore provides all functions to execute db queries and transactions ----> IMPORTANT : we implement store to re-use neccesary code for transactions

func NewStore

func NewStore(db *sql.DB) *SQLCStore

create new SQLCStore with db reference

func (*SQLCStore) TransferTx

func (store *SQLCStore) TransferTx(ctx context.Context, arg any) (any, error)

TransferTx

type Session

type Session struct {
	UserIDSession int64     `json:"user_id_session"`
	Valid         bool      `json:"valid"`
	UserAgent     string    `json:"user_agent"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`
}

type UpdateUserParams

type UpdateUserParams struct {
	Username    string `json:"username"`
	Email       string `json:"email"`
	Pictue      string `json:"pictue"`
	UserID      int64  `json:"user_id"`
	OldUsername string `json:"old_username"`
	OldEmail    string `json:"old_email"`
	OldPicture  string `json:"old_picture"`
}

type User

type User struct {
	UserID int64 `json:"user_id"`
	// this field is for the unique id provided by google, or facebook, or tik tok etc etc.. to identify a user
	SocialID     string    `json:"social_id"`
	Username     string    `json:"username"`
	Email        string    `json:"email"`
	Picture      string    `json:"picture"`
	Provider     string    `json:"provider"`
	RegisteredAt time.Time `json:"registered_at"`
}

primary key is composed by user_id and social_id, both of those properties are unique

Jump to

Keyboard shortcuts

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