Delete method working example
This commit is contained in:
22
app/main.go
22
app/main.go
@ -31,6 +31,10 @@ type CertFilter struct {
|
|||||||
Timestamps *[]time.Time `filterfield:"field=created_at,operator=IN"`
|
Timestamps *[]time.Time `filterfield:"field=created_at,operator=IN"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CompanyFilter struct {
|
||||||
|
IsActive *bool `filterfield:"field=is_active,operator=EQ"`
|
||||||
|
}
|
||||||
|
|
||||||
func doMagic(db *gorm.DB) {
|
func doMagic(db *gorm.DB) {
|
||||||
var err error
|
var err error
|
||||||
query := db
|
query := db
|
||||||
@ -140,6 +144,21 @@ func doSave(db *gorm.DB) {
|
|||||||
fmt.Printf("New company id: %s\n", company.Id.String())
|
fmt.Printf("New company id: %s\n", company.Id.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func doDelete(db *gorm.DB) {
|
||||||
|
repo := repository.RepoBase[models.Company]{}
|
||||||
|
repo.Init(db, nil)
|
||||||
|
|
||||||
|
filter := CompanyFilter{
|
||||||
|
IsActive: &FALSE,
|
||||||
|
}
|
||||||
|
|
||||||
|
deletedCount, err := repo.Delete(filter)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Printf(">> DELETED: %d\n", deletedCount)
|
||||||
|
}
|
||||||
|
|
||||||
func doExists(db *gorm.DB) {
|
func doExists(db *gorm.DB) {
|
||||||
repo := repository.RepoBase[models.Cert]{}
|
repo := repository.RepoBase[models.Cert]{}
|
||||||
repo.Init(db, nil)
|
repo.Init(db, nil)
|
||||||
@ -167,7 +186,8 @@ func main() {
|
|||||||
// doMagic(db)
|
// doMagic(db)
|
||||||
// doList(db)
|
// doList(db)
|
||||||
// doCount(db)
|
// doCount(db)
|
||||||
doSave(db)
|
// doSave(db)
|
||||||
|
doDelete(db)
|
||||||
// doGet(db)
|
// doGet(db)
|
||||||
// doExists(db)
|
// doExists(db)
|
||||||
// inheritance.DoInheritanceTest()
|
// inheritance.DoInheritanceTest()
|
||||||
|
|||||||
Reference in New Issue
Block a user