42 lines
1.7 KiB
Go
Executable File
42 lines
1.7 KiB
Go
Executable File
package gmodel
|
|
|
|
import "context"
|
|
|
|
func (t *FsProductModel3dLightModel) FindAll(ctx context.Context) (resp []FsProductModel3dLight, err error) {
|
|
err = t.db.WithContext(ctx).Model(&FsProductModel3dLight{}).Find(&resp).Error
|
|
return resp, err
|
|
}
|
|
func (l *FsProductModel3dLightModel) FindOne(ctx context.Context, id int64) (resp *FsProductModel3dLight, err error) {
|
|
err = l.db.WithContext(ctx).Model(&FsProductModel3dLight{}).Where("`id` = ? and `status` = ?", id, 1).Take(&resp).Error
|
|
return resp, err
|
|
}
|
|
func (l *FsProductModel3dLightModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsProductModel3dLight, err error) {
|
|
if len(ids) == 0 {
|
|
return
|
|
}
|
|
err = l.db.WithContext(ctx).Model(&FsProductModel3dLight{}).Where("`id` in (?) and `status` = ?", ids, 1).Find(&resp).Error
|
|
return resp, err
|
|
}
|
|
func (l *FsProductModel3dLightModel) GetAll(ctx context.Context) (resp []FsProductModel3dLight, err error) {
|
|
err = l.db.WithContext(ctx).Model(&FsProductModel3dLight{}).Where("`status` = ?", 1).Find(&resp).Error
|
|
return resp, err
|
|
}
|
|
|
|
func (l *FsProductModel3dLightModel) Create(ctx context.Context, data *FsProductModel3dLight) error {
|
|
return l.db.WithContext(ctx).Create(&data).Error
|
|
}
|
|
func (l *FsProductModel3dLightModel) Update(ctx context.Context, id int64, data *FsProductModel3dLight) error {
|
|
return l.db.WithContext(ctx).Where("`id` = ?", id).Updates(data).Error
|
|
}
|
|
func (l *FsProductModel3dLightModel) GetAllByIdsWithoutStatus(ctx context.Context, ids []int64, fields ...string) (resp []FsProductModel3dLight, err error) {
|
|
if len(ids) == 0 {
|
|
return
|
|
}
|
|
db := l.db.WithContext(ctx).Model(&FsProductModel3dLight{}).Where("`id` in (?)", ids)
|
|
if len(fields) != 0 {
|
|
db = db.Select(fields[0])
|
|
}
|
|
err = db.Find(&resp).Error
|
|
return resp, err
|
|
}
|