post

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 CreateParams

type CreateParams struct {
	UserID      int64          `json:"userId"`
	Title       string         `json:"title"`
	Short       string         `json:"short"`
	Body        string         `json:"body"`
	Tags        sql.NullString `json:"tags"`
	IsPublished bool           `json:"isPublished"`
}

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 EditParams

type EditParams struct {
	Title       string         `json:"title"`
	Short       string         `json:"short"`
	Body        string         `json:"body"`
	Tags        sql.NullString `json:"tags"`
	IsPublished bool           `json:"isPublished"`
	ID          int64          `json:"id"`
	UserID      int64          `json:"userId"`
}

type GetByIDParams

type GetByIDParams struct {
	ID     int64         `json:"id"`
	UserID sql.NullInt64 `json:"userId"`
}

type ListParams

type ListParams struct {
	DisplayOnlyPublished bool   `json:"displayOnlyPublished"`
	Query                string `json:"query"`
	RelatedToUser        int64  `json:"relatedToUser"`
	Offset               int64  `json:"offset"`
	Limit                int64  `json:"limit"`
}

type ListRow

type ListRow struct {
	Post  Post  `json:"post"`
	Count int64 `json:"count"`
}

type Post

type Post struct {
	ID          int64          `json:"id"`
	UserID      int64          `json:"userId"`
	Title       string         `json:"title"`
	Short       string         `json:"short"`
	Body        string         `json:"body"`
	Tags        sql.NullString `json:"tags"`
	IsPublished bool           `json:"isPublished"`
	CreatedAt   time.Time      `json:"createdAt"`
	UpdatedAt   time.Time      `json:"updatedAt"`
	DeletedAt   sql.NullTime   `json:"deletedAt"`
}

type Querier

type Querier interface {
	//Create
	//
	//  INSERT INTO posts (user_id, title, short, body, tags, is_published)
	//  VALUES (?, ?, ?, ?, ?, ?)
	//  RETURNING id, user_id, title, short, body, tags, is_published, created_at, updated_at, deleted_at
	Create(ctx context.Context, arg CreateParams) (*Post, error)
	//Edit
	//
	//  UPDATE posts
	//  SET title = ?, short = ?, body = ?, tags = ?, is_published = ?, updated_at = datetime('now')
	//  WHERE id = ?
	//    AND deleted_at IS NULL
	//    AND user_id = ?
	//  RETURNING id, user_id, title, short, body, tags, is_published, created_at, updated_at, deleted_at
	Edit(ctx context.Context, arg EditParams) (*Post, error)
	//GetByID
	//
	//  SELECT id, user_id, title, short, body, tags, is_published, created_at, updated_at, deleted_at
	//  FROM posts
	//  WHERE deleted_at IS NULL
	//    AND id = ?
	//    AND CASE WHEN CAST(?2 AS int) IS NULL THEN is_published IS TRUE ELSE user_id = ?2 END
	GetByID(ctx context.Context, arg GetByIDParams) (*Post, error)
	//List
	//
	//  SELECT posts.id, posts.user_id, posts.title, posts.short, posts.body, posts.tags, posts.is_published, posts.created_at, posts.updated_at, posts.deleted_at, count(*) over()
	//  FROM posts
	//  WHERE deleted_at IS NULL
	//    AND CASE WHEN CAST(?1 AS boolean) IS TRUE THEN is_published IS true ELSE true END
	//    AND CASE WHEN CAST(?2 AS text) <> ” THEN lower(title) LIKE ?2 ELSE true END
	//    AND CASE WHEN CAST(?3 AS int) > 0 THEN user_id = ?3 ELSE true END
	//  ORDER BY id DESC
	//  LIMIT CASE WHEN CAST(?5 AS int) > 0 THEN ?5 ELSE 10 END
	//  OFFSET ?4
	List(ctx context.Context, arg ListParams) ([]*ListRow, 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) Create

func (q *Queries) Create(ctx context.Context, arg CreateParams) (*Post, error)

Create

INSERT INTO posts (user_id, title, short, body, tags, is_published)
VALUES (?, ?, ?, ?, ?, ?)
RETURNING id, user_id, title, short, body, tags, is_published, created_at, updated_at, deleted_at

func (*Queries) Edit

func (q *Queries) Edit(ctx context.Context, arg EditParams) (*Post, error)

Edit

UPDATE posts
SET title = ?, short = ?, body = ?, tags = ?, is_published = ?, updated_at = datetime('now')
WHERE id = ?
  AND deleted_at IS NULL
  AND user_id = ?
RETURNING id, user_id, title, short, body, tags, is_published, created_at, updated_at, deleted_at

func (*Queries) GetByID

func (q *Queries) GetByID(ctx context.Context, arg GetByIDParams) (*Post, error)

GetByID

SELECT id, user_id, title, short, body, tags, is_published, created_at, updated_at, deleted_at
FROM posts
WHERE deleted_at IS NULL
  AND id = ?
  AND CASE WHEN CAST(?2 AS int) IS NULL THEN is_published IS TRUE ELSE user_id = ?2 END

func (*Queries) List

func (q *Queries) List(ctx context.Context, arg ListParams) ([]*ListRow, error)

List

SELECT posts.id, posts.user_id, posts.title, posts.short, posts.body, posts.tags, posts.is_published, posts.created_at, posts.updated_at, posts.deleted_at, count(*) over()
FROM posts
WHERE deleted_at IS NULL
  AND CASE WHEN CAST(?1 AS boolean) IS TRUE THEN is_published IS true ELSE true END
  AND CASE WHEN CAST(?2 AS text) <> '' THEN lower(title) LIKE ?2 ELSE true END
  AND CASE WHEN CAST(?3 AS int) > 0 THEN user_id = ?3 ELSE true END
ORDER BY id DESC
LIMIT CASE WHEN CAST(?5 AS int) > 0 THEN ?5 ELSE 10 END
OFFSET ?4

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