Documentation ¶
Index ¶
- Variables
- func CamelToSnake(s string) string
- func DerefType(t reflect.Type) reflect.Type
- func DerefValue(v reflect.Value) reflect.Value
- func FieldIndex(obj interface{}, sqlFieldName string) (out int, rete error)
- func FieldValue(obj interface{}, sqlFieldName string) (interface{}, error)
- func Split(src string) (entries []string)
- type Config
- type Connection
- type Connector
- type Session
- func (s *Session) Begin() (*Tx, error)
- func (s *Session) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
- func (s *Session) ObjDelete(obj interface{}, pk ...interface{}) error
- func (s *Session) ObjGet(obj interface{}, pk ...interface{}) error
- func (s *Session) ObjInsert(obj interface{}) error
- func (s *Session) ObjUpdate(obj interface{}) error
- func (s *Session) ObjUpdateDiff(newObj interface{}, oldObj interface{}) error
- func (s *Session) ObjUpsert(obj interface{}, sqlSet string, args ...interface{}) error
- type Sharder
- type TableInfo
- type TableInfoMap
- type Tx
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNoField = fmt.Errorf("field not found")
View Source
var ErrNoTable = fmt.Errorf("table not found for object/type")
View Source
var FieldNameMapper = CamelToSnake
View Source
var TableNameMapper = CamelToSnake
Functions ¶
func CamelToSnake ¶
func FieldIndex ¶
func FieldValue ¶
func Split ¶
Split splits the camelcase word and returns a list of words. It also supports digits. Both lower camel case and upper camel case are supported. For more info please check: http://en.wikipedia.org/wiki/CamelCase
Examples
"" => [""] "lowercase" => ["lowercase"] "Class" => ["Class"] "MyClass" => ["My", "Class"] "MyC" => ["My", "C"] "HTML" => ["HTML"] "PDFLoader" => ["PDF", "Loader"] "AString" => ["A", "String"] "SimpleXMLParser" => ["Simple", "XML", "Parser"] "vimRPCPlugin" => ["vim", "RPC", "Plugin"] "GL11Version" => ["GL", "11", "Version"] "99Bottles" => ["99", "Bottles"] "May5" => ["May", "5"] "BFG9000" => ["BFG", "9000"] "BöseÜberraschung" => ["Böse", "Überraschung"] "Two spaces" => ["Two", " ", "spaces"] "BadUTF8\xe2\xe2\xa1" => ["BadUTF8\xe2\xe2\xa1"]
Splitting rules
- If string is not valid UTF-8, return it without splitting as single item array.
- Assign all unicode characters into one of 4 sets: lower case letters, upper case letters, numbers, and all other characters.
- Iterate through characters of string, introducing splits between adjacent characters that belong to different sets.
- Iterate through array of split strings, and if a given string is upper case: if subsequent string is lower case: move last character of upper case string to beginning of lower case string
Types ¶
type Config ¶
type Config struct {
TableInfoMap
}
func (*Config) NewConnector ¶
func (c *Config) NewConnector(defaultDbrConn *dbr.Connection, sharder Sharder) *Connector
type Connection ¶
type Connection struct { TableInfoMap *dbr.Connection }
func (*Connection) NewSession ¶
func (c *Connection) NewSession(log dbr.EventReceiver) *Session
type Connector ¶
type Connector struct { // embed default Connection, for ease of transitioning existing code *Connection // Sharder provides a means to obtain a sharded connection. Sharder }
func (*Connector) NewShardSession ¶
func (c *Connector) NewShardSession(log dbr.EventReceiver, i interface{}, keys ...interface{}) *Session
func (*Connector) NewShardSessionForType ¶
type Session ¶
type Session struct { TableInfoMap *dbr.Session }
func (*Session) ObjUpdateDiff ¶
func (*Session) ObjUpsert ¶
idea: what if we construct an INSERT ON DUPLICATE KEY UPDATE (db-specific logic) statement (actually, check out MERGE and see how wide the support is) and the sqlSet is in the form of "a = ?, b = ?" and that gets put into the update part of the statement. If sqlSet is empty then it becomes a full replace. This handles both the "counter" case and the "i just want to make sure this is there" case.
type Sharder ¶
type Sharder interface { // can select connection and create session, and also // copy TableInfoMap and make mods as needed for table names Shard(i interface{}, keys ...interface{}) *Connection ShardForType(t reflect.Type, keys ...interface{}) *Connection }
type TableInfo ¶
type TableInfo struct { GoType reflect.Type // underlying Go type (pointer removed) TableName string // SQL table names KeyNames []string // SQL primary key field names KeyAutoIncr bool // true if keys are auto-incremented by the database VersionColName string // name of version col, empty disables optimistic locking }
func (*TableInfo) KeyAndColNames ¶
func (*TableInfo) SetVersionCol ¶
type TableInfoMap ¶
func (TableInfoMap) AddTable ¶
func (m TableInfoMap) AddTable(i interface{}) *TableInfo
func (TableInfoMap) AddTableWithName ¶
func (m TableInfoMap) AddTableWithName(i interface{}, tableName string) *TableInfo
func (TableInfoMap) TableFor ¶
func (m TableInfoMap) TableFor(i interface{}) *TableInfo
func (TableInfoMap) TableForType ¶
func (m TableInfoMap) TableForType(t reflect.Type) *TableInfo
Click to show internal directories.
Click to hide internal directories.