account

package module
v0.0.0-...-229629d Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: MIT Imports: 10 Imported by: 0

README

Account model for MySQL in Go

In Progress..

Features

Installation

Importing this module.

import "github.com/k4k3ru-hub/go/db/mysql/account"

Usage

Support me

I am a Japanese developer, and your support is a great encouragement for my work! In addition to support, feel free to reach out with comments, feature requests, or development inquiries!

Thank you for your support😊

Support on Ko-fi Support on Buy Me a Coffee

License

This repository is open-source and distributed under the MIT License.

Documentation

Overview

accounts.go

Index

Constants

View Source
const (
	ColCreatedAt    = "created_at"
	ColEmail        = "email"
	ColId           = "id"
	ColLastLoggedIn = "last_logged_in"
	ColPassword     = "password"
	ColPublicToken  = "public_token"
	ColRole         = "role"
	ColSecretToken  = "secret_token"
	ColStatus       = "status"
	ColUpdatedAt    = "updated_at"
	ColName         = "name"

	TableName = "accounts"
)

Variables

This section is empty.

Functions

func GenerateId

func GenerateId() uint64

Generate an ID.

func ValidateEmail

func ValidateEmail(value string) bool

Validate email

func ValidateName

func ValidateName(value string) bool

Validate name

func ValidatePassword

func ValidatePassword(value string) bool

Validate password

Types

type Account

type Account struct {
	Id           uint64
	Status       Status
	Role         Role
	Name         string
	Email        *string
	Password     *string
	PublicToken  *string
	SecretToken  *string
	LastLoggedIn *time.Time
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

type Client

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

func NewClient

func NewClient(db *sql.DB, tableName string) *Client

New Client

func (*Client) Count

func (c *Client) Count(option *SelectOption) (int64, error)

Count

func (*Client) CreateTable

func (c *Client) CreateTable() error

Create table

func (*Client) Delete

func (c *Client) Delete(options []*DeleteOption) error

Delete.

func (*Client) DeleteByPrimaryKey

func (c *Client) DeleteByPrimaryKey(id uint64) error

Delete by primary key

func (*Client) HasDuplicateForUpdate

func (c *Client) HasDuplicateForUpdate(option *UpdateOption) (bool, error)

Has duplicate for update.

func (*Client) Insert

func (c *Client) Insert(option *InsertOption) error

Insert

func (*Client) Select

func (c *Client) Select(option *SelectOption) ([]*Account, error)

Select

func (*Client) SelectByPrimaryKey

func (c *Client) SelectByPrimaryKey(id uint64) (*Account, error)

Select by primary key

func (*Client) SelectByUniqueKey

func (c *Client) SelectByUniqueKey(name string) (*Account, error)

Select by unique key.

func (*Client) Update

func (c *Client) Update(id uint64, option *UpdateOption) error

Update

func (*Client) UpdateLastLoggedIn

func (c *Client) UpdateLastLoggedIn(id uint64) error

Update last logged In

type DeleteOption

type DeleteOption struct {
	Id uint64 `json:"id,string"`
}

type InsertOption

type InsertOption struct {
	Id           uint64     `json:"id"`
	Status       Status     `json:"status"`
	Role         Role       `json:"role"`
	Name         *string    `json:"name,omitempty"`
	Email        *string    `json:"email,omitempty"`
	Password     *string    `json:"password,omitempty"`
	PublicToken  *string    `json:"publicToken,omitempty"`
	SecretToken  *string    `json:"secretToken,omitempty"`
	LastLoggedIn *time.Time `json:"lastLoggedIn,omitempty"`
	CreatedAt    *time.Time `json:"createdAt,omitempty"`
	UpdatedAt    *time.Time `json:"updatedAt,omitempty"`
}

func NewInsertOption

func NewInsertOption() *InsertOption

New InsertOption

type Role

type Role uint8
const (
	RoleNone Role = iota
	RoleViewer
	RoleEditor
	RoleAdmin
)

func (Role) IsValid

func (r Role) IsValid() bool

func (*Role) Scan

func (r *Role) Scan(src any) error

func (Role) Value

func (r Role) Value() (driver.Value, error)

type SelectOption

type SelectOption struct {
	Status          *Status `json:"status,omitempty"`
	Role            *Role   `json:"role,omitempty"`
	NameLike        *string `json:"nameLike,omitempty"`
	Email           *string `json:"email,omitempty"`
	EmailLike       *string `json:"emailLike,omitempty"`
	LastIdOrLater   *uint64 `json:"lastIdOrLater,omitempty"`
	LastIdOrEarlier *uint64 `json:"lastIdOrEarlier,omitempty"`
	OrderBy         string  `json:"orderBy"`
	OrderByDesc     bool    `json:"orderByDesc"`
	Limit           int     `json:"limit"`
	Offset          int     `json:"offset"`
}

func NewSelectOption

func NewSelectOption() *SelectOption

New SelectOption

type Status

type Status uint8
const (
	StatusNew Status = iota
	StatusActived
	StatusInactived
	StatusPending
	StatusSuspended
	StatusDeleted
)

func (Status) IsValid

func (s Status) IsValid() bool

func (*Status) Scan

func (s *Status) Scan(src any) error

func (Status) Value

func (s Status) Value() (driver.Value, error)

type UpdateFilter

type UpdateFilter struct {
	Primary *UpdateFilterPrimary `json:"primary,omitempty"`
	Unique  *UpdateFilterUnique  `json:"unique,omitempty"`
}

type UpdateFilterPrimary

type UpdateFilterPrimary struct {
	Id uint64 `json:"id,string"`
}

type UpdateFilterUnique

type UpdateFilterUnique struct {
	Name string `json:"name"`
}

type UpdateOption

type UpdateOption struct {
	Status       *myHelper.UpdateField[Status]    `json:"status,omitempty"`
	Role         *myHelper.UpdateField[Role]      `json:"role,omitempty"`
	Name         *myHelper.UpdateField[string]    `json:"name,omitempty"`
	Email        *myHelper.UpdateField[string]    `json:"email,omitempty"`
	Password     *myHelper.UpdateField[string]    `json:"password,omitempty"`
	PublicToken  *myHelper.UpdateField[string]    `json:",omitempty"`
	SecretToken  *myHelper.UpdateField[string]    `json:",omitempty"`
	LastLoggedIn *myHelper.UpdateField[time.Time] `json:"lastLoggedIn,omitempty"`
	Filter       *UpdateFilter                    `json:"filter,omitempty"`
}

func NewUpdateOption

func NewUpdateOption() *UpdateOption

New UpdateOption

Jump to

Keyboard shortcuts

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