userstore

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

README

UserStore Open in Gitpod

Tests Status Go Report Card PkgGoDev

UserStore is a robust user management package.

Supports multiple database storages (SQLite, MySQL, or PostgreSQL)

License

This project is licensed under the GNU General Public License version 3 (GPL-3.0). You can find a copy of the license at https://www.gnu.org/licenses/gpl-3.0.en.html

For commercial use, please use my contact page to obtain a commercial license.

Installation

go get github.com/gouniverse/userstore

Setup

userStore, err = userstore.NewStore(userstore.NewStoreOptions{
	DB:                 databaseInstance,
    UserTableName:      "user",
	AutomigrateEnabled: true,
	DebugEnabled:       false,
})

if err != nil {
	return errors.Join(errors.New("userstore.NewStore"), err)
}

Examples

user := userstore.NewUser().
    SetStatus(userstore.USER_STATUS_ACTIVE).
    SetFirstName("John").
    SetLastName("Doe").
    SetEmail("test@test.com")

err := userStore.UserCreate(user)

if err != nil {
	return errors.New("user failed to create")
}

Documentation

Index

Constants

View Source
const COLUMN_BUSINESS_NAME = "business_name"
View Source
const COLUMN_COUNTRY = "country"
View Source
const COLUMN_CREATED_AT = "created_at"
View Source
const COLUMN_EMAIL = "email"
View Source
const COLUMN_FIRST_NAME = "first_name"
View Source
const COLUMN_HANDLE = "handle"
View Source
const COLUMN_ID = "id"
View Source
const COLUMN_LAST_NAME = "last_name"
View Source
const COLUMN_MEMO = "memo"
View Source
const COLUMN_METAS = "metas"
View Source
const COLUMN_MIDDLE_NAMES = "middle_names"
View Source
const COLUMN_NAME = "name"
View Source
const COLUMN_PASSWORD = "password"
View Source
const COLUMN_PHONE = "phone"
View Source
const COLUMN_PROFILE_IMAGE_URL = "profile_image_url"
View Source
const COLUMN_ROLE = "role"
View Source
const COLUMN_SOFT_DELETED_AT = "soft_deleted_at"
View Source
const COLUMN_STATUS = "status"
View Source
const COLUMN_TIMEZONE = "timezone"
View Source
const COLUMN_UPDATED_AT = "updated_at"
View Source
const ERROR_EMPTY_ARRAY = "array cannot be empty"
View Source
const ERROR_EMPTY_STRING = "string cannot be empty"
View Source
const ERROR_NEGATIVE_NUMBER = "number cannot be negative"
View Source
const ROLE_STATUS_ACTIVE = "active"
View Source
const ROLE_STATUS_DELETED = "deleted"
View Source
const ROLE_STATUS_INACTIVE = "inactive"
View Source
const USER_ROLE_ADMINISTRATOR = "administrator"
View Source
const USER_ROLE_MANAGER = "manager"
View Source
const USER_ROLE_SUPERUSER = "superuser"
View Source
const USER_ROLE_USER = "user"
View Source
const USER_STATUS_ACTIVE = "active"
View Source
const USER_STATUS_DELETED = "deleted"
View Source
const USER_STATUS_INACTIVE = "inactive"
View Source
const USER_STATUS_UNVERIFIED = "unverified"

Variables

This section is empty.

Functions

func RoleNoImageUrl added in v0.8.1

func RoleNoImageUrl() string

func UserNoImageUrl

func UserNoImageUrl() string

Types

type NewStoreOptions

type NewStoreOptions struct {
	UserTableName      string
	DB                 *sql.DB
	DbDriverName       string
	AutomigrateEnabled bool
	DebugEnabled       bool
}

NewStoreOptions define the options for creating a new block store

type RoleInterface added in v0.8.1

type RoleInterface interface {
	Data() map[string]string
	DataChanged() map[string]string
	MarkAsNotDirty()

	CreatedAt() string
	CreatedAtCarbon() carbon.Carbon
	SetCreatedAt(createdAt string) RoleInterface

	Handle() string
	SetHandle(handle string) RoleInterface

	ID() string
	SetID(id string) RoleInterface

	Name() string
	SetName(name string) RoleInterface

	Memo() string
	SetMemo(memo string) RoleInterface

	Meta(name string) string
	SetMeta(name string, value string) error
	Metas() (map[string]string, error)
	SetMetas(metas map[string]string) error

	Status() string
	SetStatus(status string) RoleInterface

	SoftDeletedAt() string
	SoftDeletedAtCarbon() carbon.Carbon
	SetSoftDeletedAt(softDeletedAt string) RoleInterface

	UpdatedAt() string
	UpdatedAtCarbon() carbon.Carbon
	SetUpdatedAt(updatedAt string) RoleInterface
}

func NewRole added in v0.8.1

func NewRole() RoleInterface

func NewRoleFromExistingData added in v0.8.1

func NewRoleFromExistingData(data map[string]string) RoleInterface

type RoleQueryInterface added in v0.8.1

type RoleQueryInterface interface {
	Validate() error

	Columns() []string
	SetColumns(columns []string) RoleQueryInterface

	HasCountOnly() bool
	IsCountOnly() bool
	SetCountOnly(countOnly bool) RoleQueryInterface

	HasHandle() bool
	Handle() string
	SetHandle(handle string) RoleQueryInterface

	HasID() bool
	ID() string
	SetID(id string) RoleQueryInterface

	HasLimit() bool
	Limit() int
	SetLimit(limit int) RoleQueryInterface

	HasOffset() bool
	Offset() int
	SetOffset(offset int) RoleQueryInterface

	HasOrderBy() bool
	OrderBy() string
	SetOrderBy(orderBy string) RoleQueryInterface

	HasSortDirection() bool
	SortDirection() string
	SetSortDirection(sortDirection string) RoleQueryInterface

	HasSoftDeletedIncluded() bool
	SoftDeletedIncluded() bool
	SetSoftDeletedIncluded(softDeletedIncluded bool) RoleQueryInterface

	HasStatus() bool
	Status() string
	SetStatus(status string) RoleQueryInterface

	HasTitleLike() bool
	TitleLike() string
	SetTitleLike(titleLike string) RoleQueryInterface
	// contains filtered or unexported methods
}

func NewRoleQuery added in v0.8.1

func NewRoleQuery() RoleQueryInterface

type StoreInterface

type StoreInterface interface {
	AutoMigrate() error
	EnableDebug(debug bool)
	DB() *sql.DB

	UserCreate(ctx context.Context, user UserInterface) error
	UserCount(ctx context.Context, options UserQueryInterface) (int64, error)
	UserDelete(ctx context.Context, user UserInterface) error
	UserDeleteByID(ctx context.Context, id string) error
	UserFindByEmail(ctx context.Context, email string) (UserInterface, error)
	UserFindByID(ctx context.Context, userID string) (UserInterface, error)
	UserList(ctx context.Context, query UserQueryInterface) ([]UserInterface, error)
	UserSoftDelete(ctx context.Context, user UserInterface) error
	UserSoftDeleteByID(ctx context.Context, id string) error
	UserUpdate(ctx context.Context, user UserInterface) error
}

func NewStore

func NewStore(opts NewStoreOptions) (StoreInterface, error)

NewStore creates a new block store

type UserInterface

type UserInterface interface {
	Data() map[string]string
	DataChanged() map[string]string
	MarkAsNotDirty()
	Get(columnName string) string
	Set(columnName string, value string)

	IsActive() bool
	IsInactive() bool
	IsSoftDeleted() bool
	IsUnverified() bool

	IsAdministrator() bool
	IsManager() bool
	IsSuperuser() bool

	IsRegistrationCompleted() bool

	BusinessName() string
	SetBusinessName(businessName string) UserInterface

	Country() string
	SetCountry(country string) UserInterface

	CreatedAt() string
	CreatedAtCarbon() carbon.Carbon
	SetCreatedAt(createdAt string) UserInterface

	Email() string
	SetEmail(email string) UserInterface

	ID() string
	SetID(id string) UserInterface

	FirstName() string
	SetFirstName(firstName string) UserInterface

	LastName() string
	SetLastName(lastName string) UserInterface

	Memo() string
	SetMemo(memo string) UserInterface

	Meta(name string) string
	SetMeta(name string, value string) error
	Metas() (map[string]string, error)
	SetMetas(metas map[string]string) error
	UpsertMetas(metas map[string]string) error

	MiddleNames() string
	SetMiddleNames(middleNames string) UserInterface

	Password() string
	SetPassword(password string) UserInterface

	Phone() string
	SetPhone(phone string) UserInterface

	ProfileImageUrl() string
	SetProfileImageUrl(profileImageUrl string) UserInterface

	Role() string
	SetRole(role string) UserInterface

	SoftDeletedAt() string
	SoftDeletedAtCarbon() carbon.Carbon
	SetSoftDeletedAt(deletedAt string) UserInterface

	Timezone() string
	SetTimezone(timezone string) UserInterface

	Status() string
	SetStatus(status string) UserInterface

	PasswordCompare(password string) bool

	UpdatedAt() string
	UpdatedAtCarbon() carbon.Carbon
	SetUpdatedAt(updatedAt string) UserInterface
}

func NewUser

func NewUser() UserInterface

func NewUserFromExistingData

func NewUserFromExistingData(data map[string]string) UserInterface

type UserQueryInterface added in v0.3.0

type UserQueryInterface interface {
	Validate() error

	Columns() []string
	SetColumns(columns []string) UserQueryInterface

	HasCountOnly() bool
	IsCountOnly() bool
	SetCountOnly(countOnly bool) UserQueryInterface

	HasCreatedAtGte() bool
	CreatedAtGte() string
	SetCreatedAtGte(createdAtGte string) UserQueryInterface

	HasCreatedAtLte() bool
	CreatedAtLte() string
	SetCreatedAtLte(createdAtLte string) UserQueryInterface

	HasEmail() bool
	Email() string
	SetEmail(email string) UserQueryInterface

	HasID() bool
	ID() string
	SetID(id string) UserQueryInterface

	HasIDIn() bool
	IDIn() []string
	SetIDIn(idIn []string) UserQueryInterface

	HasLimit() bool
	Limit() int
	SetLimit(limit int) UserQueryInterface

	HasOffset() bool
	Offset() int
	SetOffset(offset int) UserQueryInterface

	HasOrderBy() bool
	OrderBy() string
	SetOrderBy(orderBy string) UserQueryInterface

	HasSortDirection() bool
	SortDirection() string
	SetSortDirection(sortDirection string) UserQueryInterface

	HasSoftDeletedIncluded() bool
	SoftDeletedIncluded() bool
	SetSoftDeletedIncluded(softDeletedIncluded bool) UserQueryInterface

	HasStatus() bool
	Status() string
	SetStatus(status string) UserQueryInterface

	HasStatusIn() bool
	StatusIn() []string
	SetStatusIn(statusIn []string) UserQueryInterface
	// contains filtered or unexported methods
}

func NewUserQuery added in v0.3.0

func NewUserQuery() UserQueryInterface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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