database

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	Model
	UserID      uint   `gorm:"not null;unique_index:idx_userid_type"`
	Address     string `gorm:"not null" json:"address"`
	AddressType int    `gorm:"not null;unique_index:idx_userid_type" json:"address_type"`
}

Address represents a crypto address and it's address type

type Database

type Database interface {
	Close() error
	CreateTables(bool) error
	HasTables() bool
	CreateUser(*User) error
	UpdateUser(User) error
	CreateOrUpdateAddress(*User, Address) error
	DeleteUser(user User) error
	DeleteAddress(address Address) error
	GetUser(id uint) (User, error)
	GetUserByDomainUsername(domain, username string) (User, error)
	GetAddress(id uint) (Address, error)
	GetAddressByAddressType(user User, addressType int) (Address, error)
	GetAddresses(user User) ([]Address, error)
}

Database represents the functionality that any peristance layer for this server must satisfy

type Gorm

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

Gorm represents a connection to GORM

func GetGormConnection

func GetGormConnection(dbURL, dbType string) (Gorm, error)

GetGormConnection connects to the gorm database

func (Gorm) Close

func (g Gorm) Close() error

func (Gorm) CreateOrUpdateAddress

func (g Gorm) CreateOrUpdateAddress(user *User, address Address) error

CreateOrUpdateAddress creates an address if it doesn't exist If it does already exist it is updated

func (Gorm) CreateTables

func (g Gorm) CreateTables(recreate bool) error

CreateTables creates the necessary tables

func (Gorm) CreateUser

func (g Gorm) CreateUser(user *User) error

CreateUser creates a user in the database

func (Gorm) DeleteAddress

func (g Gorm) DeleteAddress(address Address) error

DeleteAddress deletes an address

func (Gorm) DeleteUser

func (g Gorm) DeleteUser(user User) error

DeleteUser deletes a user

func (Gorm) GetAddress

func (g Gorm) GetAddress(id uint) (Address, error)

GetAddress returns an address given the proper id

func (Gorm) GetAddressByAddressType

func (g Gorm) GetAddressByAddressType(user User, addressType int) (Address, error)

GetAddressByAddressType returns an address given the proper id

func (Gorm) GetAddresses

func (g Gorm) GetAddresses(user User) ([]Address, error)

GetAddresses gets all not-deleted addresses associated with a user (user id must be provided)

func (Gorm) GetUser

func (g Gorm) GetUser(id uint) (User, error)

GetUser returns a user given the proper id

func (Gorm) GetUserByDomainUsername

func (g Gorm) GetUserByDomainUsername(domain, username string) (User, error)

GetUserByDomainUsername returns a user given the proper username

func (Gorm) HasTables

func (g Gorm) HasTables() bool

HasTables alerts us if the tables haven't been setup yet

func (Gorm) UpdateUser

func (g Gorm) UpdateUser(user User) error

UpdateUser updates user fields Does not update associated addresses

type Model

type Model struct {
	ID        uint `gorm:"primary_key"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

Model overrides gorm.Model

type User

type User struct {
	Model
	Username  string    `gorm:"type:varchar(30);unique_index:idx_domain_username;not null" json:"username"`
	Password  string    `gorm:"not null" json:"password"`
	Domain    string    `gorm:"not null;unique_index:idx_domain_username" json:"domain"`
	Addresses []Address `json:"addresses"`
}

User of the api

Jump to

Keyboard shortcuts

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