database

package
v0.0.0-...-5a29284 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2020 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBAccess

type DBAccess interface {
	AccessDB() *DBClient
}

DBAccess implement this to show that the struct has access to database

type DBClient

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

DBClient is a handle to database

func CreateClient

func CreateClient() *DBClient

CreateClient creates DBClient struct

func (*DBClient) BulkInsert

func (client *DBClient) BulkInsert(allowDuplicate bool, o ...interface{}) (bool, error)

BulkInsert inserts data by bulk, i.e. in a one query. It may fail if any one of the data has a problem, i.e. all or none.

func (*DBClient) BulkUpsert

func (client *DBClient) BulkUpsert(o ...interface{}) (bool, error)

BulkUpsert upserts data by bulk, i.e. in a one query. It may fail if any one of the data has a problem, i.e. all or none.

func (*DBClient) Close

func (client *DBClient) Close()

Close closes connection to database only if there are no more needs for connection.

func (*DBClient) Delete

func (client *DBClient) Delete(typeIndicator interface{}, query string, args ...interface{}) (bool, error)

Delete deletes by appending a query starting with 'where'

func (*DBClient) DropTable

func (client *DBClient) DropTable(forms []DBRegisterForm)

DropTable drops table of struct if exists

func (*DBClient) Init

func (client *DBClient) Init(credential DBCredential)

Init prepares for opening database

func (*DBClient) Insert

func (client *DBClient) Insert(o ...interface{}) (bool, error)

Insert inserts struct to database Returns (false, nonnil error) if something wrong has happened

func (*DBClient) IsOpen

func (client *DBClient) IsOpen() bool

IsOpen returns true if database connection is open

func (*DBClient) Open

func (client *DBClient) Open()

Open may start a connection to database if there are no active connections. Calling this method many times does not have any effect to overconnection.

func (*DBClient) RegisterStruct

func (client *DBClient) RegisterStruct(forms []DBRegisterForm)

RegisterStruct registers struct types to gorp.DbMap Use this method as such:

 	register := make([]DBRegisterForm{}, 2)
		register[0] = Stock{}
     register[1] = User{}
		RegisterStruct(register)

func (*DBClient) RegisterStructFromRegisterables

func (client *DBClient) RegisterStructFromRegisterables(registerables []DBRegisterable)

RegisterStructFromRegisterables registers structs from slice of DBRegisterable

func (*DBClient) Select

func (client *DBClient) Select(bucket interface{}, query string, args ...interface{}) (bool, error)

Select returns the list matching the query through argument bucket. Only slice is allowed to the argument `bucket`

func (*DBClient) Update

func (client *DBClient) Update(o ...interface{}) (bool, error)

Update updates value to the database

func (*DBClient) Upsert

func (client *DBClient) Upsert(o ...interface{}) (bool, error)

Upsert performs update if the data is already inserted.

type DBCredential

type DBCredential struct {
	InstanceConnectionName string `json:"instanceConnectionName"`
	DatabaseUser           string `json:"databaseUser"`
	Password               string `json:"password"`
	DBName                 string `json:"dbName"`
}

DBCredential contains info needed to connect to DB

func LoadCredential

func LoadCredential(filePath string) DBCredential

LoadCredential load DB credential from json file

type DBRegisterForm

type DBRegisterForm struct {
	BaseStruct    interface{}
	Name          string
	AutoIncrement bool
	KeyColumns    []string
	UniqueColumns []string
}

DBRegisterForm is a struct for registering struct type as a DB table

type DBRegisterable

type DBRegisterable interface {
	// GetDBRegisterForm returns a DBRegisterForm struct
	GetDBRegisterForm() DBRegisterForm
}

DBRegisterable is an interface every struct which should be recorded in database should implement

Jump to

Keyboard shortcuts

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