data

package
v0.0.0-...-bc47717 Latest Latest
Warning

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

Go to latest
Published: May 17, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTimeUTCPointer

func GetTimeUTCPointer() *time.Time

GetTimeUTCPointer gets utc time pointer

func IsUnixZero

func IsUnixZero(t time.Time) bool

func RandString

func RandString(n int) string

RandString generates random sting from characters in letters

func TimeToPointer

func TimeToPointer(t time.Time) *time.Time

func UnixToTimePointer

func UnixToTimePointer(v int64) *time.Time

Types

type DBConf

type DBConf struct {
	Database        string   `toml:"database"`
	Hosts           []string `toml:"hosts"`
	Username        string   `toml:"username"`
	Password        string   `toml:"password"`
	DebugQueries    bool     `toml:"debug_queries"`
	ApplicationName string   `toml:"application_name"`
	MaxConnection   int      `toml:"max_connection"`
	SSLMode         string   `toml:"ssl_mode"`
	DatabaseURL     string   `env:"DATABASE_URL"`
}

DBConf database configuration

func (*DBConf) String

func (cf *DBConf) String() string

String converts database config to a connection url

type Database

type Database struct {
	db.Session

	User     *UsersStore
	TodoList *TodoListStore
	TodoItem *TodoItemStore
}

Database holds database postgres table structure

var DB *Database

DB is a pointer to the database interface

func NewDB

func NewDB(conf DBConf) (*Database, error)

NewDB initializes / opens a new database connection

type Item

type Item struct {
	ID         int64      `db:"id"           json:"id"`
	TodoListID int64      `db:"todo_list_id" json:"todo_list_id"`
	Title      string     `db:"title"        json:"title"`
	Todo       string     `db:"todo"         json:"todo"`
	Comment    string     `db:"comment"      json:"comment"`
	ListStatus ListStatus `db:"list_status"  json:"list_status"`
	ItemStatus TodoStatus `db:"todo_status"  json:"todo_status"`
}

type ListStatus

type ListStatus string

ListStatus is list status

const (
	// ListStatusActive is todo_list status active
	ListStatusActive ListStatus = "active"
	// ListStatusCompleted is todo_list status completed
	ListStatusCompleted ListStatus = "completed"
	// ListStatusCancelled is todo_list status cancelled
	ListStatusCancelled ListStatus = "cancelled"
)

type TodoItem

type TodoItem struct {
	ID         int64      `db:"id,omitempty" json:"id"`
	TodoListID int64      `db:"todo_list_id,omitempty" json:"todo_list_id"`
	Status     TodoStatus `db:"status" json:"status"`
	Todo       string     `db:"todo,omitempty" json:"todo"`
	Comment    string     `db:"comment,omitempty" json:"comment"`
	CreatedAt  *time.Time `db:"created_at,omitempty" json:"createdAt"`
	UpdatedAt  *time.Time `db:"updated_at,omitempty" json:"updatedAt"`
}

TodoItem holds postgres data structure for todo_item

func (*TodoItem) BeforeCreate

func (tl *TodoItem) BeforeCreate(sess db.Session) error

BeforeCreate retrives and sets GetTimeUTCPointer before creating a new todoitem

func (*TodoItem) BeforeUpdate

func (tl *TodoItem) BeforeUpdate(sess db.Session) error

BeforeUpdate retrives and sets GetTimeUTCPointer before updating a todoitem

func (*TodoItem) Bind

func (u *TodoItem) Bind(r *http.Request) error

func (*TodoItem) Store

func (tl *TodoItem) Store(sess db.Session) db.Store

Store initializes a session interface that defines methods for database adapters.

type TodoItemStore

type TodoItemStore struct {
	db.Collection
}

TodoItemStore holds thread todoitem database collection

func TodoItems

func TodoItems(sess db.Session) *TodoItemStore

TodoItems retrieves all todoitems

func (TodoItemStore) FindAll

func (store TodoItemStore) FindAll(cond ...interface{}) ([]*TodoItem, error)

FindAll retrieves todoitems by certain conditions from TodoItemStore

func (TodoItemStore) FindByID

func (store TodoItemStore) FindByID(ID int64) (*TodoItem, error)

FindByID retrieves a particular todoitem by id

func (TodoItemStore) FindOne

func (store TodoItemStore) FindOne(cond ...interface{}) (*TodoItem, error)

FindOne retrieves todoitem by certain conditions from TodoItemStore

func (TodoItemStore) UpdateByID

func (store TodoItemStore) UpdateByID(ID int64, todoitem *TodoItem) (*TodoItem, error)

UpdateByID retrieves and updates todoitem by id

type TodoList

type TodoList struct {
	ID        int64      `db:"id,omitempty" json:"id"`
	Status    ListStatus `db:"status,omitempty" json:"status"`
	Title     string     `db:"title,omitempty" json:"title"`
	CreatedAt *time.Time `db:"created_at,omitempty" json:"createdAt"`
	UpdatedAt *time.Time `db:"updated_at,omitempty" json:"updatedAt"`
}

TodoList holds postgres data structure for todo_list

func (*TodoList) BeforeCreate

func (tl *TodoList) BeforeCreate(sess db.Session) error

BeforeCreate retrives and sets GetTimeUTCPointer before creating a new todolist

func (*TodoList) BeforeUpdate

func (tl *TodoList) BeforeUpdate(sess db.Session) error

BeforeUpdate retrives and sets GetTimeUTCPointer before updating a todolist

func (*TodoList) Store

func (tl *TodoList) Store(sess db.Session) db.Store

Store initializes a session interface that defines methods for database adapters.

type TodoListItems

type TodoListItems []Item

func (*TodoListItems) Render

type TodoListStore

type TodoListStore struct {
	db.Collection
}

TodoListStore holds thread todolist database collection

func TodoLists

func TodoLists(sess db.Session) *TodoListStore

TodoLists retrieves all todolists

func (TodoListStore) FindAll

func (store TodoListStore) FindAll(cond ...interface{}) ([]*TodoList, error)

FindAll retrieves todolists by certain conditions from TodoListStore

func (TodoListStore) FindByID

func (store TodoListStore) FindByID(ID int64) (*TodoListItems, error)

FindByID retrieves a particular todolist by id

func (TodoListStore) FindOne

func (store TodoListStore) FindOne(cond ...interface{}) (*TodoList, error)

FindOne retrieves todolist by certain conditions from TodoListStore

type TodoStatus

type TodoStatus string

TodoStatus is todo status

const (
	// TodoStatusActive is todo_item status active
	TodoStatusActive TodoStatus = "active"
	// TodoStatusCompleted is todo_item status completed
	TodoStatusCompleted TodoStatus = "completed"
	// TodoStatusCancelled is todo_item status cancelled
	TodoStatusCancelled TodoStatus = "cancelled"
)

type User

type User struct {
	ID           int64      `db:"id,omitempty" json:"id"`
	Email        string     `db:"email,omitempty" json:"email"`
	PasswordHash string     `db:"password_hash,omitempty" json:"-"`
	Role         UserRole   `db:"role" json:"role"`
	FirstName    string     `db:"first_name,omitempty" json:"firstName"`
	LastName     string     `db:"last_name,omitempty" json:"lastName"`
	Location     string     `db:"location,omitempty" json:"location"`
	Etc          UserEtc    `db:"etc,omitempty" json:"etc"`
	CreatedAt    *time.Time `db:"created_at,omitempty" json:"createdAt"`
	UpdatedAt    *time.Time `db:"updated_at,omitempty" json:"updatedAt"`

	// Display Only
	Biography string `json:"biography"`
	Name      string `json:"name"`
}

User holds postgres data structure for user

func (*User) BeforeCreate

func (u *User) BeforeCreate(sess db.Session) error

BeforeCreate retrives and sets GetTimeUTCPointer before creating a new user

func (*User) BeforeUpdate

func (u *User) BeforeUpdate(sess db.Session) error

BeforeUpdate retrives and sets GetTimeUTCPointer before updating a user

func (*User) Store

func (u *User) Store(sess db.Session) db.Store

Store initializes a session interface that defines methods for database adapters.

type UserEtc

type UserEtc struct {
	HasProfile bool

	*postgresql.JSONBConverter
}

UserEtc is a collection of auxillary key/values around a user

type UserRole

type UserRole string

UserRole is users role

const (
	// UserRoleMember is user role member
	UserRoleMember UserRole = "member"
	// UserRoleAdmin is user role admin
	UserRoleAdmin UserRole = "admin"
	// UserRoleBlocked is user role blocked
	UserRoleBlocked UserRole = "blocked"
)

type UsersStore

type UsersStore struct {
	db.Collection
}

UsersStore holds thread users database collection

func Users

func Users(sess db.Session) *UsersStore

Users retrieves a list of all users

func (UsersStore) FindAll

func (store UsersStore) FindAll(cond ...interface{}) ([]*User, error)

FindAll retrieves users by certain conditions from UsersStore

func (UsersStore) FindByAlias

func (store UsersStore) FindByAlias(alias string) (*User, error)

FindByAlias retrieves a particular user by alias

func (UsersStore) FindByEmail

func (store UsersStore) FindByEmail(email string) (*User, error)

FindByEmail retrieves a particular user by email

func (UsersStore) FindByID

func (store UsersStore) FindByID(ID int64) (*User, error)

FindByID retrieves a particular user by id

func (UsersStore) FindOne

func (store UsersStore) FindOne(cond ...interface{}) (*User, error)

FindOne retrieves user by certain conditions from UsersStore

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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