本文整理汇总了Golang中github.com/vattle/sqlboiler/strmangle.UpdateColumnSet函数的典型用法代码示例。如果您正苦于以下问题:Golang UpdateColumnSet函数的具体用法?Golang UpdateColumnSet怎么用?Golang UpdateColumnSet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UpdateColumnSet函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Update
// Update uses an executor to update the AuthRolePermission.
// Whitelist behavior: If a whitelist is provided, only the columns given are updated.
// No whitelist behavior: Without a whitelist, columns are inferred by the following rules:
// - All columns are inferred to start with
// - All primary keys are subtracted from this set
// Update does not automatically update the record in case of default values. Use .Reload()
// to refresh the records.
func (o *AuthRolePermission) Update(exec boil.Executor, whitelist ...string) error {
currTime := time.Now().In(boil.GetLocation())
o.UpdatedAt.Time = currTime
o.UpdatedAt.Valid = true
var err error
if err = o.doBeforeUpdateHooks(exec); err != nil {
return err
}
key := makeCacheKey(whitelist, nil)
authRolePermissionUpdateCacheMut.RLock()
cache, cached := authRolePermissionUpdateCache[key]
authRolePermissionUpdateCacheMut.RUnlock()
if !cached {
wl := strmangle.UpdateColumnSet(authRolePermissionColumns, authRolePermissionPrimaryKeyColumns, whitelist)
if len(wl) == 0 {
return errors.New("chado: unable to update auth_role_permission, could not build whitelist")
}
cache.query = fmt.Sprintf("UPDATE \"auth_role_permission\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 1, wl),
strmangle.WhereClause("\"", "\"", len(wl)+1, authRolePermissionPrimaryKeyColumns),
)
cache.valueMapping, err = queries.BindMapping(authRolePermissionType, authRolePermissionMapping, append(wl, authRolePermissionPrimaryKeyColumns...))
if err != nil {
return err
}
}
values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, cache.query)
fmt.Fprintln(boil.DebugWriter, values)
}
_, err = exec.Exec(cache.query, values...)
if err != nil {
return errors.Wrap(err, "chado: unable to update auth_role_permission row")
}
if !cached {
authRolePermissionUpdateCacheMut.Lock()
authRolePermissionUpdateCache[key] = cache
authRolePermissionUpdateCacheMut.Unlock()
}
return o.doAfterUpdateHooks(exec)
}
开发者ID:dictyBase,项目名称:Modware,代码行数:58,代码来源:auth_role_permission.go
示例2: Update
// Update uses an executor to update the FeaturepropPub.
// Whitelist behavior: If a whitelist is provided, only the columns given are updated.
// No whitelist behavior: Without a whitelist, columns are inferred by the following rules:
// - All columns are inferred to start with
// - All primary keys are subtracted from this set
// Update does not automatically update the record in case of default values. Use .Reload()
// to refresh the records.
func (o *FeaturepropPub) Update(exec boil.Executor, whitelist ...string) error {
var err error
if err = o.doBeforeUpdateHooks(exec); err != nil {
return err
}
key := makeCacheKey(whitelist, nil)
featurepropPubUpdateCacheMut.RLock()
cache, cached := featurepropPubUpdateCache[key]
featurepropPubUpdateCacheMut.RUnlock()
if !cached {
wl := strmangle.UpdateColumnSet(featurepropPubColumns, featurepropPubPrimaryKeyColumns, whitelist)
if len(wl) == 0 {
return errors.New("chado: unable to update featureprop_pub, could not build whitelist")
}
cache.query = fmt.Sprintf("UPDATE \"featureprop_pub\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 1, wl),
strmangle.WhereClause("\"", "\"", len(wl)+1, featurepropPubPrimaryKeyColumns),
)
cache.valueMapping, err = queries.BindMapping(featurepropPubType, featurepropPubMapping, append(wl, featurepropPubPrimaryKeyColumns...))
if err != nil {
return err
}
}
values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, cache.query)
fmt.Fprintln(boil.DebugWriter, values)
}
_, err = exec.Exec(cache.query, values...)
if err != nil {
return errors.Wrap(err, "chado: unable to update featureprop_pub row")
}
if !cached {
featurepropPubUpdateCacheMut.Lock()
featurepropPubUpdateCache[key] = cache
featurepropPubUpdateCacheMut.Unlock()
}
return o.doAfterUpdateHooks(exec)
}
开发者ID:dictyBase,项目名称:Modware,代码行数:53,代码来源:featureprop_pub.go
示例3: Upsert
// Upsert attempts an insert using an executor, and does an update or ignore on conflict.
func (o *FeaturepropPub) Upsert(exec boil.Executor, updateOnConflict bool, conflictColumns []string, updateColumns []string, whitelist ...string) error {
if o == nil {
return errors.New("chado: no featureprop_pub provided for upsert")
}
if err := o.doBeforeUpsertHooks(exec); err != nil {
return err
}
nzDefaults := queries.NonZeroDefaultSet(featurepropPubColumnsWithDefault, o)
// Build cache key in-line uglily - mysql vs postgres problems
buf := strmangle.GetBuffer()
if updateOnConflict {
buf.WriteByte('t')
} else {
buf.WriteByte('f')
}
buf.WriteByte('.')
for _, c := range conflictColumns {
buf.WriteString(c)
}
buf.WriteByte('.')
for _, c := range updateColumns {
buf.WriteString(c)
}
buf.WriteByte('.')
for _, c := range whitelist {
buf.WriteString(c)
}
buf.WriteByte('.')
for _, c := range nzDefaults {
buf.WriteString(c)
}
key := buf.String()
strmangle.PutBuffer(buf)
featurepropPubUpsertCacheMut.RLock()
cache, cached := featurepropPubUpsertCache[key]
featurepropPubUpsertCacheMut.RUnlock()
var err error
if !cached {
var ret []string
whitelist, ret = strmangle.InsertColumnSet(
featurepropPubColumns,
featurepropPubColumnsWithDefault,
featurepropPubColumnsWithoutDefault,
nzDefaults,
whitelist,
)
update := strmangle.UpdateColumnSet(
featurepropPubColumns,
featurepropPubPrimaryKeyColumns,
updateColumns,
)
if len(update) == 0 {
return errors.New("chado: unable to upsert featureprop_pub, could not build update column list")
}
conflict := conflictColumns
if len(conflict) == 0 {
conflict = make([]string, len(featurepropPubPrimaryKeyColumns))
copy(conflict, featurepropPubPrimaryKeyColumns)
}
cache.query = queries.BuildUpsertQueryPostgres(dialect, "\"featureprop_pub\"", updateOnConflict, ret, update, conflict, whitelist)
cache.valueMapping, err = queries.BindMapping(featurepropPubType, featurepropPubMapping, whitelist)
if err != nil {
return err
}
if len(ret) != 0 {
cache.retMapping, err = queries.BindMapping(featurepropPubType, featurepropPubMapping, ret)
if err != nil {
return err
}
}
}
value := reflect.Indirect(reflect.ValueOf(o))
vals := queries.ValuesFromMapping(value, cache.valueMapping)
var returns []interface{}
if len(cache.retMapping) != 0 {
returns = queries.PtrsFromMapping(value, cache.retMapping)
}
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, cache.query)
fmt.Fprintln(boil.DebugWriter, vals)
}
if len(cache.retMapping) != 0 {
err = exec.QueryRow(cache.query, vals...).Scan(returns...)
} else {
_, err = exec.Exec(cache.query, vals...)
}
if err != nil {
return errors.Wrap(err, "chado: unable to upsert for featureprop_pub")
//.........这里部分代码省略.........
开发者ID:dictyBase,项目名称:Modware,代码行数:101,代码来源:featureprop_pub.go
示例4: Upsert
// Upsert attempts an insert using an executor, and does an update or ignore on conflict.
func (o *AuthRolePermission) Upsert(exec boil.Executor, updateOnConflict bool, conflictColumns []string, updateColumns []string, whitelist ...string) error {
if o == nil {
return errors.New("chado: no auth_role_permission provided for upsert")
}
currTime := time.Now().In(boil.GetLocation())
if o.CreatedAt.Time.IsZero() {
o.CreatedAt.Time = currTime
o.CreatedAt.Valid = true
}
o.UpdatedAt.Time = currTime
o.UpdatedAt.Valid = true
if err := o.doBeforeUpsertHooks(exec); err != nil {
return err
}
nzDefaults := queries.NonZeroDefaultSet(authRolePermissionColumnsWithDefault, o)
// Build cache key in-line uglily - mysql vs postgres problems
buf := strmangle.GetBuffer()
if updateOnConflict {
buf.WriteByte('t')
} else {
buf.WriteByte('f')
}
buf.WriteByte('.')
for _, c := range conflictColumns {
buf.WriteString(c)
}
buf.WriteByte('.')
for _, c := range updateColumns {
buf.WriteString(c)
}
buf.WriteByte('.')
for _, c := range whitelist {
buf.WriteString(c)
}
buf.WriteByte('.')
for _, c := range nzDefaults {
buf.WriteString(c)
}
key := buf.String()
strmangle.PutBuffer(buf)
authRolePermissionUpsertCacheMut.RLock()
cache, cached := authRolePermissionUpsertCache[key]
authRolePermissionUpsertCacheMut.RUnlock()
var err error
if !cached {
var ret []string
whitelist, ret = strmangle.InsertColumnSet(
authRolePermissionColumns,
authRolePermissionColumnsWithDefault,
authRolePermissionColumnsWithoutDefault,
nzDefaults,
whitelist,
)
update := strmangle.UpdateColumnSet(
authRolePermissionColumns,
authRolePermissionPrimaryKeyColumns,
updateColumns,
)
if len(update) == 0 {
return errors.New("chado: unable to upsert auth_role_permission, could not build update column list")
}
conflict := conflictColumns
if len(conflict) == 0 {
conflict = make([]string, len(authRolePermissionPrimaryKeyColumns))
copy(conflict, authRolePermissionPrimaryKeyColumns)
}
cache.query = queries.BuildUpsertQueryPostgres(dialect, "\"auth_role_permission\"", updateOnConflict, ret, update, conflict, whitelist)
cache.valueMapping, err = queries.BindMapping(authRolePermissionType, authRolePermissionMapping, whitelist)
if err != nil {
return err
}
if len(ret) != 0 {
cache.retMapping, err = queries.BindMapping(authRolePermissionType, authRolePermissionMapping, ret)
if err != nil {
return err
}
}
}
value := reflect.Indirect(reflect.ValueOf(o))
vals := queries.ValuesFromMapping(value, cache.valueMapping)
var returns []interface{}
if len(cache.retMapping) != 0 {
returns = queries.PtrsFromMapping(value, cache.retMapping)
}
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, cache.query)
fmt.Fprintln(boil.DebugWriter, vals)
}
//.........这里部分代码省略.........
开发者ID:dictyBase,项目名称:Modware,代码行数:101,代码来源:auth_role_permission.go
注:本文中的github.com/vattle/sqlboiler/strmangle.UpdateColumnSet函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论