Esempio n. 1
0
func (network *Network) Delete(db *gorp.DbMap) error {
	if len(network.UUID) > 0 {
		_, err := db.Delete(network)
		return err
	}

	return nil
}
Esempio n. 2
0
func (device *NetworkDevice) Delete(db *gorp.DbMap) error {
	device.Network = nil

	if len(device.UUID) > 0 {
		_, err := db.Delete(device)
		return err
	}

	return nil
}
Esempio n. 3
0
func ProductsDelete(db *gorp.DbMap, params martini.Params, render render.Render) {
	id, _ := strconv.ParseInt(params["id"], 0, 64)
	_, err := db.Delete(&models.Product{Id: id})

	if err == nil {
		render.JSON(204, "No content")
	} else {
		render.JSON(404, "Not found") // Let's just say that's the reason
	}
}
Esempio n. 4
0
File: jail.go Progetto: virtbsd/jail
func (jail *Jail) Delete(db *gorp.DbMap) error {
	if len(jail.UUID) == 0 {
		/* No UUID means we haven't even persisted to the DB, yet */
		return nil
	}

	for _, device := range jail.NetworkDevices {
		device.Delete(db)
	}

	for _, option := range jail.Options {
		db.Delete(option)
	}

	for _, mount := range jail.Mounts {
		db.Delete(mount)
	}

	for _, route := range jail.Routes {
		db.Delete(route)
	}

	db.Delete(jail)
	return nil
}
func DeleteTask(r render.Render, params martini.Params, db *gorp.DbMap) {
	id, err := strconv.Atoi(params["id"])
	if err != nil {
		r.JSON(400, map[string]string{"message": "id must be an integer"})
		return
	}
	count, err := db.Delete(&Task{Id: id})
	if err != nil {
		log.Printf("Failed deleting task %v: %v", id, err)
		r.JSON(500, map[string]string{"messaage": "Failed to delete task"})
		return
	}
	if count != 1 {
		r.JSON(404, map[string]string{"message": "Task not found"})
		return
	}
	r.JSON(200, map[string]string{})
}
func main() {
	var (
		dbMap *gorp.DbMap
		user  *User
		iUser interface{}
	)

	dbMap = SetupDb()

	//START CODE OMIT
	dbMap.Insert(&User{Id: 1, FirstName: "John", LastName: "Doe"})
	PrintTable(dbMap)

	iUser, _ = dbMap.Get(User{}, 1)
	user = iUser.(*User)

	user.FirstName = "James"
	dbMap.Update(user)
	PrintTable(dbMap)

	dbMap.Delete(user)
	PrintTable(dbMap)
	//END CODE OMIT
}
Esempio n. 7
0
func DeletePage(db *gorp.DbMap, p *Page) error {
	_, err := db.Delete(p)
	return err
}
Esempio n. 8
0
func (m *Menu) RemoveItem(db *gorp.DbMap, item *MenuItem) error {
	_, err := db.Delete(item)
	return err
}