model

package
v0.0.0-...-96c97c1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2017 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserStatusActive   = "active"
	UserStatusInactive = "inactive"
)

User status

Variables

This section is empty.

Functions

func Healthcheck

func Healthcheck(tx Queryer) (string, error)

Healthcheck health check

func TestCreateSchema

func TestCreateSchema(cfg DBConfig, schema, user string) error

TestCreateSchema set up test schema

func TestCreateTables

func TestCreateTables(cfg DBConfig, path string) error

TestCreateTables create test tables

func TestDropSchema

func TestDropSchema(cfg DBConfig, schema string) error

TestDropSchema set up test schema

func UpdateUser

func UpdateUser(tx Queryer, user *TodoUser) error

UpdateUser update user

Types

type AccessToken

type AccessToken struct {
	Token       string    // token
	UserID      string    // user_id
	GeneratedAt time.Time // generated_at
	IsActive    bool      // is_active
}

AccessToken represents gotodoit_api.access_token

func GetAccessTokenByPk

func GetAccessTokenByPk(db Queryer, pk0 string) (*AccessToken, error)

GetAccessTokenByPk select the AccessToken from the database.

func TestCreateAccessTokenData

func TestCreateAccessTokenData(t *testing.T, tx Queryer, u *TodoUser) *AccessToken

TestCreateAccessTokenData create test data

func (*AccessToken) Create

func (r *AccessToken) Create(db Queryer) error

Create inserts the AccessToken to the database.

type DB

type DB struct {
	*sql.DB
}

DB database

type DBConfig

type DBConfig struct {
	Host     string
	User     string
	UserPass string
	Port     string
	DBName   string
	SSLMode  string
}

DBConfig config

type DBer

type DBer interface {
	Queryer
	Begin() (*sql.Tx, error)
	Close() error
	Ping() error
}

DBer database/sql

func TestSetupDB

func TestSetupDB(t *testing.T) (DBer, func())

TestSetupDB create db and cleanup func for test

type Queryer

type Queryer interface {
	Exec(string, ...interface{}) (sql.Result, error)
	Query(string, ...interface{}) (*sql.Rows, error)
	QueryRow(string, ...interface{}) *sql.Row
}

Queryer database/sql compatible query interface

type Todo

type Todo struct {
	UUID        string    // uuid
	UserID      string    // user_id
	Name        string    // name
	Duration    int64     // duration
	StartedAt   time.Time // started_at
	IsCompleted bool      // is_completed
}

Todo represents gotodoit_api.todo

func GetTodoByPk

func GetTodoByPk(db Queryer, pk0 string) (*Todo, error)

GetTodoByPk select the Todo from the database.

func GetTodosByUserID

func GetTodosByUserID(tx Queryer, userID string, completed bool) ([]Todo, error)

GetTodosByUserID get todos by user id

func GetUserTodoByID

func GetUserTodoByID(tx Queryer, userID, todoID string) (*Todo, bool, error)

GetUserTodoByID get todos by user id

func TestCreateTodoData

func TestCreateTodoData(t *testing.T, tx Queryer, u *TodoUser, td *Todo) *Todo

TestCreateTodoData create todo test data

func (*Todo) Create

func (r *Todo) Create(db Queryer) error

Create inserts the Todo to the database.

type TodoUser

type TodoUser struct {
	UUID     string // uuid
	Username string // username
	Email    string // email
	Password string // password
	Status   string // status
}

TodoUser represents gotodoit_api.todo_user

func CreateUser

func CreateUser(tx Queryer, u *TodoUser) (*TodoUser, error)

CreateUser creates user

func GetTodoUserByPk

func GetTodoUserByPk(db Queryer, pk0 string) (*TodoUser, error)

GetTodoUserByPk select the TodoUser from the database.

func GetUserByAccessToken

func GetUserByAccessToken(tx Queryer, token string) (*TodoUser, bool, error)

GetUserByAccessToken get user by access token

func TestCreateUserData

func TestCreateUserData(t *testing.T, tx Queryer, u *TodoUser) *TodoUser

TestCreateUserData create user test data

func (*TodoUser) Create

func (r *TodoUser) Create(db Queryer) error

Create inserts the TodoUser to the database.

type Txer

type Txer interface {
	Queryer
	Commit() error
	Rollback() error
}

Txer database/sql transaction interface

func TestSetupTx

func TestSetupTx(t *testing.T) (Txer, func())

TestSetupTx create tx and cleanup func for test

Jump to

Keyboard shortcuts

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