func (u User) Delete(db orm.DB, user gorsk.User) error {
	return db.Delete(&user)
}
Delete sets deleted_at for a user
package pgsql
import (
	"net/http"
	"strings"
	"github.com/go-pg/pg/v9"
	"github.com/go-pg/pg/v9/orm"
	"github.com/labstack/echo"
	"github.com/ribice/gorsk"
)
type User struct{}
var (
	ErrAlreadyExists = echo.NewHTTPError(http.StatusInternalServerError, "Username or email already exists.")
)
func (u User) Create(db orm.DB, usr gorsk.User) (gorsk.User, error) {
	var user = new(gorsk.User)
	err := db.Model(user).Where("lower(username) = ? or lower(email) = ? and deleted_at is null",
		strings.ToLower(usr.Username), strings.ToLower(usr.Email)).Select()
	if err == nil || err != pg.ErrNoRows {
		return gorsk.User{}, ErrAlreadyExists
	}
	err = db.Insert(&usr)
	return usr, err
}
func (u User) View(db orm.DB, id int) (gorsk.User, error) {
	var user gorsk.User
	sql := `SELECT "user".*, "role"."id" AS "role__id", "role"."access_level" AS "role__access_level", "role"."name" AS "role__name" 
	FROM "users" AS "user" LEFT JOIN "roles" AS "role" ON "role"."id" = "user"."role_id" 
	WHERE ("user"."id" = ? and deleted_at is null)`
	_, err := db.QueryOne(&user, sql, id)
	return user, err
}
func (u User) Update(db orm.DB, user gorsk.User) error {
	_, err := db.Model(&user).WherePK().UpdateNotZero()
	return err
}
func (u User) List(db orm.DB, qp *gorsk.ListQuery, p gorsk.Pagination) ([]gorsk.User, error) {
	var users []gorsk.User
	q := db.Model(&users).Relation("Role").Limit(p.Limit).Offset(p.Offset).Where("deleted_at is null").Order("user.id desc")
	if qp != nil {
		q.Where(qp.Query, qp.ID)
	}
	err := q.Select()
	return users, err
}