db

package
v0.0.0-...-d1aa883 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRecordNotFound = pgx.ErrNoRows

Functions

func DbMigrationsUrl

func DbMigrationsUrl() string

func RunDBMigrationUp

func RunDBMigrationUp(dbSource string) error

Types

type Config

type Config struct {
	Name     string `env:"DB_DATABASE"`
	User     string `env:"DB_USERNAME"`
	Password string `env:"DB_PASSWORD"`
	Host     string `env:"DB_HOST"`
	Port     string `env:"DB_PORT"`
}

func (Config) DSN

func (cfg Config) DSN() string

type CreateSleepLogParams

type CreateSleepLogParams struct {
	ID        uuid.UUID `json:"id"`
	UserID    uuid.UUID `json:"user_id"`
	StartTime time.Time `json:"start_time"`
	EndTime   time.Time `json:"end_time"`
	Quality   string    `json:"quality"`
}

type CreateUserParams

type CreateUserParams struct {
	ID           uuid.UUID `json:"id"`
	Username     string    `json:"username"`
	PasswordHash string    `json:"password_hash"`
}

type DBTX

type DBTX interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
}

type DeleteSleepLogByIDParams

type DeleteSleepLogByIDParams struct {
	ID     uuid.UUID `json:"id"`
	UserID uuid.UUID `json:"user_id"`
}

type GetSleepLogsByUserIDParams

type GetSleepLogsByUserIDParams struct {
	UserID uuid.UUID `json:"user_id"`
	Limit  int32     `json:"limit"`
	Offset int32     `json:"offset"`
}

type Querier

type Querier interface {
	CreateSleepLog(ctx context.Context, arg CreateSleepLogParams) (SleepLog, error)
	CreateUser(ctx context.Context, arg CreateUserParams) (User, error)
	DeleteSleepLogByID(ctx context.Context, arg DeleteSleepLogByIDParams) error
	GetSleepLogCountByUserID(ctx context.Context, userID uuid.UUID) (int64, error)
	GetSleepLogsByUserID(ctx context.Context, arg GetSleepLogsByUserIDParams) ([]SleepLog, error)
	GetUserByUsername(ctx context.Context, username string) (User, error)
	UpdateSleepLogById(ctx context.Context, arg UpdateSleepLogByIdParams) error
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) CreateSleepLog

func (q *Queries) CreateSleepLog(ctx context.Context, arg CreateSleepLogParams) (SleepLog, error)

func (*Queries) CreateUser

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

func (*Queries) DeleteSleepLogByID

func (q *Queries) DeleteSleepLogByID(ctx context.Context, arg DeleteSleepLogByIDParams) error

func (*Queries) GetSleepLogCountByUserID

func (q *Queries) GetSleepLogCountByUserID(ctx context.Context, userID uuid.UUID) (int64, error)

func (*Queries) GetSleepLogsByUserID

func (q *Queries) GetSleepLogsByUserID(ctx context.Context, arg GetSleepLogsByUserIDParams) ([]SleepLog, error)

func (*Queries) GetUserByUsername

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

func (*Queries) UpdateSleepLogById

func (q *Queries) UpdateSleepLogById(ctx context.Context, arg UpdateSleepLogByIdParams) error

func (*Queries) WithTx

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

type SleepLog

type SleepLog struct {
	ID        uuid.UUID `json:"id"`
	UserID    uuid.UUID `json:"user_id"`
	StartTime time.Time `json:"start_time"`
	EndTime   time.Time `json:"end_time"`
	Quality   string    `json:"quality"`
	CreatedAt time.Time `json:"created_at"`
}

type SqlStore

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

func (*SqlStore) Close

func (store *SqlStore) Close()

type Store

type Store interface {
	Querier
	Close()
}

func NewStore

func NewStore(ctx context.Context, cfg Config) Store

type TestDatabase

type TestDatabase struct {
	Config Config
	// contains filtered or unexported fields
}

func NewTestDatabase

func NewTestDatabase() *TestDatabase

func (*TestDatabase) Close

func (td *TestDatabase) Close()

type UpdateSleepLogByIdParams

type UpdateSleepLogByIdParams struct {
	ID        uuid.UUID `json:"id"`
	UserID    uuid.UUID `json:"user_id"`
	StartTime time.Time `json:"start_time"`
	EndTime   time.Time `json:"end_time"`
	Quality   string    `json:"quality"`
}

type User

type User struct {
	ID           uuid.UUID `json:"id"`
	Username     string    `json:"username"`
	PasswordHash string    `json:"password_hash"`
	CreatedAt    time.Time `json:"created_at"`
}

Jump to

Keyboard shortcuts

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