2016-08-02 11:56:55 +02:00
|
|
|
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
|
|
|
|
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
2016-08-08 15:30:29 +02:00
|
|
|
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
|
2016-09-24 09:52:18 +02:00
|
|
|
{{- $schemaTable := .Table.Name | .SchemaTable}}
|
2016-08-02 11:56:55 +02:00
|
|
|
// ReloadGP refetches the object from the database and panics on error.
|
|
|
|
func (o *{{$tableNameSingular}}) ReloadGP() {
|
2016-09-14 10:08:30 +02:00
|
|
|
if err := o.ReloadG(); err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
2016-08-02 11:56:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReloadP refetches the object from the database with an executor. Panics on error.
|
|
|
|
func (o *{{$tableNameSingular}}) ReloadP(exec boil.Executor) {
|
2016-09-14 10:08:30 +02:00
|
|
|
if err := o.Reload(exec); err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
2016-08-02 11:56:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReloadG refetches the object from the database using the primary keys.
|
|
|
|
func (o *{{$tableNameSingular}}) ReloadG() error {
|
2016-09-14 10:08:30 +02:00
|
|
|
if o == nil {
|
|
|
|
return errors.New("{{.PkgName}}: no {{$tableNameSingular}} provided for reload")
|
|
|
|
}
|
2016-08-02 11:56:55 +02:00
|
|
|
|
2016-09-14 10:08:30 +02:00
|
|
|
return o.Reload(boil.GetDB())
|
2016-08-02 11:56:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reload refetches the object from the database
|
|
|
|
// using the primary keys with an executor.
|
|
|
|
func (o *{{$tableNameSingular}}) Reload(exec boil.Executor) error {
|
2016-09-14 10:08:30 +02:00
|
|
|
ret, err := Find{{$tableNameSingular}}(exec, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-08-02 11:56:55 +02:00
|
|
|
|
2016-09-14 10:08:30 +02:00
|
|
|
*o = *ret
|
|
|
|
return nil
|
2016-08-02 11:56:55 +02:00
|
|
|
}
|
2016-08-08 15:30:29 +02:00
|
|
|
|
2016-09-15 06:20:35 +02:00
|
|
|
// ReloadAllGP refetches every row with matching primary key column values
|
|
|
|
// and overwrites the original object slice with the newly updated slice.
|
|
|
|
// Panics on error.
|
2016-08-08 15:30:29 +02:00
|
|
|
func (o *{{$tableNameSingular}}Slice) ReloadAllGP() {
|
2016-09-14 10:08:30 +02:00
|
|
|
if err := o.ReloadAllG(); err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
2016-08-08 15:30:29 +02:00
|
|
|
}
|
|
|
|
|
2016-09-15 06:20:35 +02:00
|
|
|
// ReloadAllP refetches every row with matching primary key column values
|
|
|
|
// and overwrites the original object slice with the newly updated slice.
|
|
|
|
// Panics on error.
|
2016-08-08 15:30:29 +02:00
|
|
|
func (o *{{$tableNameSingular}}Slice) ReloadAllP(exec boil.Executor) {
|
2016-09-14 10:08:30 +02:00
|
|
|
if err := o.ReloadAll(exec); err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
2016-08-08 15:30:29 +02:00
|
|
|
}
|
|
|
|
|
2016-09-15 06:20:35 +02:00
|
|
|
// ReloadAllG refetches every row with matching primary key column values
|
|
|
|
// and overwrites the original object slice with the newly updated slice.
|
2016-08-08 15:30:29 +02:00
|
|
|
func (o *{{$tableNameSingular}}Slice) ReloadAllG() error {
|
2016-09-14 10:08:30 +02:00
|
|
|
if o == nil {
|
|
|
|
return errors.New("{{.PkgName}}: empty {{$tableNameSingular}}Slice provided for reload all")
|
|
|
|
}
|
2016-08-08 15:30:29 +02:00
|
|
|
|
2016-09-14 10:08:30 +02:00
|
|
|
return o.ReloadAll(boil.GetDB())
|
2016-08-08 15:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReloadAll refetches every row with matching primary key column values
|
|
|
|
// and overwrites the original object slice with the newly updated slice.
|
|
|
|
func (o *{{$tableNameSingular}}Slice) ReloadAll(exec boil.Executor) error {
|
2016-09-14 10:08:30 +02:00
|
|
|
if o == nil || len(*o) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2016-08-08 15:30:29 +02:00
|
|
|
|
2016-09-14 10:08:30 +02:00
|
|
|
{{$varNamePlural}} := {{$tableNameSingular}}Slice{}
|
2016-09-16 08:44:44 +02:00
|
|
|
var args []interface{}
|
|
|
|
for _, obj := range *o {
|
|
|
|
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), {{$varNameSingular}}PrimaryKeyMapping)
|
|
|
|
args = append(args, pkeyArgs...)
|
|
|
|
}
|
2016-08-08 15:30:29 +02:00
|
|
|
|
2017-03-15 17:35:44 +01:00
|
|
|
sql := "SELECT {{$schemaTable}}.* FROM {{$schemaTable}} WHERE " +
|
2017-04-01 20:11:01 +02:00
|
|
|
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), {{if .Dialect.IndexPlaceholders}}1{{else}}0{{end}}, {{$varNameSingular}}PrimaryKeyColumns, len(*o))
|
2016-08-08 15:30:29 +02:00
|
|
|
|
2016-09-15 05:59:55 +02:00
|
|
|
q := queries.Raw(exec, sql, args...)
|
2016-08-08 15:30:29 +02:00
|
|
|
|
2016-09-14 10:08:30 +02:00
|
|
|
err := q.Bind(&{{$varNamePlural}})
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "{{.PkgName}}: unable to reload all in {{$tableNameSingular}}Slice")
|
|
|
|
}
|
2016-08-08 15:30:29 +02:00
|
|
|
|
2016-09-14 10:08:30 +02:00
|
|
|
*o = {{$varNamePlural}}
|
2016-08-08 15:30:29 +02:00
|
|
|
|
2016-09-14 10:08:30 +02:00
|
|
|
return nil
|
2016-08-08 15:30:29 +02:00
|
|
|
}
|