Documentation ¶
Index ¶
- type DBAccess
- type DBClient
- func (client *DBClient) BulkInsert(allowDuplicate bool, o ...interface{}) (bool, error)
- func (client *DBClient) BulkUpsert(o ...interface{}) (bool, error)
- func (client *DBClient) Close()
- func (client *DBClient) Delete(typeIndicator interface{}, query string, args ...interface{}) (bool, error)
- func (client *DBClient) DropTable(forms []DBRegisterForm)
- func (client *DBClient) Init(credential DBCredential)
- func (client *DBClient) Insert(o ...interface{}) (bool, error)
- func (client *DBClient) IsOpen() bool
- func (client *DBClient) Open()
- func (client *DBClient) RegisterStruct(forms []DBRegisterForm)
- func (client *DBClient) RegisterStructFromRegisterables(registerables []DBRegisterable)
- func (client *DBClient) Select(bucket interface{}, query string, args ...interface{}) (bool, error)
- func (client *DBClient) Update(o ...interface{}) (bool, error)
- func (client *DBClient) Upsert(o ...interface{}) (bool, error)
- type DBCredential
- type DBRegisterForm
- type DBRegisterable
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 (*DBClient) BulkInsert ¶
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 ¶
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 ¶
Insert inserts struct to database Returns (false, nonnil error) if something wrong has happened
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 ¶
Select returns the list matching the query through argument bucket. Only slice is allowed to the argument `bucket`
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