invite

package
v0.0.0-...-9305a47 Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateOrUpdateParams

type CreateOrUpdateParams struct {
	UserID     int64  `json:"userId"`
	InviteHash string `json:"inviteHash"`
}

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 Invite

type Invite struct {
	ID          int64        `json:"id"`
	UserID      int64        `json:"userId"`
	InviteHash  string       `json:"inviteHash"`
	IsActivated bool         `json:"isActivated"`
	CreatedAt   time.Time    `json:"createdAt"`
	UpdatedAt   time.Time    `json:"updatedAt"`
	DeletedAt   sql.NullTime `json:"deletedAt"`
}

type Querier

type Querier interface {
	//Activate
	//
	//  UPDATE invites
	//  SET is_activated = true
	//  WHERE id = ?
	//    AND is_activated IS FALSE
	//    AND deleted_at IS NULL
	//  RETURNING id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
	Activate(ctx context.Context, id int64) (*Invite, error)
	//CreateOrUpdate
	//
	//  INSERT INTO invites (user_id, invite_hash, is_activated)
	//  VALUES (?, ?, false)
	//  ON CONFLICT (user_id, is_activated) WHERE is_activated IS FALSE DO UPDATE
	//  SET invite_hash = excluded.invite_hash, updated_at = datetime('now')
	//  RETURNING id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
	CreateOrUpdate(ctx context.Context, arg CreateOrUpdateParams) (*Invite, error)
	//Delete
	//
	//  UPDATE invites
	//  SET deleted_at = datetime('now'), is_activated = true
	//  WHERE id = ?
	//    AND deleted_at IS NULL
	Delete(ctx context.Context, id int64) error
	//GetActiveByUserID
	//
	//  SELECT id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
	//  FROM invites
	//  WHERE id = ?
	//    AND is_activated IS FALSE
	//    AND deleted_at IS NULL
	GetActiveByUserID(ctx context.Context, id int64) (*Invite, error)
	//GetAllByUserID
	//
	//  SELECT id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
	//  FROM invites
	//  WHERE user_id = ?
	//    AND deleted_at IS NULL
	GetAllByUserID(ctx context.Context, userID int64) ([]*Invite, error)
	//GetByID
	//
	//  SELECT id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
	//  FROM invites
	//  WHERE id = ?
	//    AND deleted_at IS NULL
	GetByID(ctx context.Context, id int64) (*Invite, error)
	//GetByInviteHash
	//
	//  SELECT id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
	//  FROM invites
	//  WHERE invite_hash = ?
	//    AND is_activated IS FALSE
	//    AND deleted_at IS NULL
	GetByInviteHash(ctx context.Context, inviteHash string) (*Invite, 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) Activate

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

Activate

UPDATE invites
SET is_activated = true
WHERE id = ?
  AND is_activated IS FALSE
  AND deleted_at IS NULL
RETURNING id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at

func (*Queries) Close

func (q *Queries) Close() error

func (*Queries) CreateOrUpdate

func (q *Queries) CreateOrUpdate(ctx context.Context, arg CreateOrUpdateParams) (*Invite, error)

CreateOrUpdate

INSERT INTO invites (user_id, invite_hash, is_activated)
VALUES (?, ?, false)
ON CONFLICT (user_id, is_activated) WHERE is_activated IS FALSE DO UPDATE
SET invite_hash = excluded.invite_hash, updated_at = datetime('now')
RETURNING id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at

func (*Queries) Delete

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

Delete

UPDATE invites
SET deleted_at = datetime('now'), is_activated = true
WHERE id = ?
  AND deleted_at IS NULL

func (*Queries) GetActiveByUserID

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

GetActiveByUserID

SELECT id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
FROM invites
WHERE id = ?
  AND is_activated IS FALSE
  AND deleted_at IS NULL

func (*Queries) GetAllByUserID

func (q *Queries) GetAllByUserID(ctx context.Context, userID int64) ([]*Invite, error)

GetAllByUserID

SELECT id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
FROM invites
WHERE user_id = ?
  AND deleted_at IS NULL

func (*Queries) GetByID

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

GetByID

SELECT id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
FROM invites
WHERE id = ?
  AND deleted_at IS NULL

func (*Queries) GetByInviteHash

func (q *Queries) GetByInviteHash(ctx context.Context, inviteHash string) (*Invite, error)

GetByInviteHash

SELECT id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
FROM invites
WHERE invite_hash = ?
  AND is_activated IS FALSE
  AND deleted_at IS NULL

func (*Queries) WithTx

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

Jump to

Keyboard shortcuts

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