示例#1
0
func updateImportInfo(q *qbs.Qbs, path string, pid int, add bool) {
	// Save package information.
	info := new(PkgInfo)
	err := q.WhereEqual("path", path).Find(info)
	if err == nil {
		// Check if pid exists in this project.
		i := strings.Index(info.ImportPid, "$"+strconv.Itoa(pid)+"|")
		switch {
		case i == -1 && add: // Add operation and does not contain.
			info.ImportPid += "$" + strconv.Itoa(pid) + "|"
			info.ImportedNum++
			_, err = q.Save(info)
			if err != nil {
				beego.Error("models.updateImportInfo(): add:", path, err)
			}
		case i > -1 && !add: // Delete operation and contains.
			info.ImportPid = strings.Replace(info.ImportPid, "$"+strconv.Itoa(pid)+"|", "", 1)
			info.ImportedNum--
			_, err = q.Save(info)
			if err != nil {
				beego.Error("models.updateImportInfo(): delete:", path, err)
			}
		}
	}

	// Error means this project does not exist, simply skip.
}
示例#2
0
//保存
func (this *Episode) Save(q *qbs.Qbs) bool {
	_, err := q.Save(this)
	if err != nil {
		fmt.Println(err)
		return false
	}
	return true
}
示例#3
0
文件: example.go 项目: nonempty/qbs
func UpdateOneUser(q *qbs.Qbs, id int64, name string) (affected int64, err error) {
	user, err := FindUserById(q, id)
	if err != nil {
		return 0, err
	}
	user.Name = name
	return q.Save(user)
}
示例#4
0
//保存
func (p *Person) Save(q *qbs.Qbs) bool {
	_, err := q.Save(p)
	if err != nil {
		fmt.Println(err)
		return false
	}
	return true
}
示例#5
0
文件: user.go 项目: river-lee/qishare
//保存
func (u *User) Save(q *qbs.Qbs) bool {
	if u.Password != "" {
		//u.HashedPassword = EncryptPassword(u.Password)
	}

	_, err := q.Save(u)
	if err != nil {
		fmt.Println(err)
		return false
	}
	return true
}
示例#6
0
func (self *testObjUdid) PostQbs(value interface{}, pb PBundle, q *qbs.Qbs) (interface{}, error) {
	self.testCallCount++
	in := value.(*HouseWireUdid)
	house := &HouseUdid{Id: in.Id, Address: in.Addr, Zip: in.ZipCode}
	if house.Id == "" {
		house.Id = UDID()
	}
	if _, err := q.Save(house); err != nil {
		return nil, err
	}

	return &HouseWireUdid{Id: house.Id, Addr: house.Address, ZipCode: house.Zip}, nil
}
示例#7
0
func (self *testObj) PostQbs(value interface{}, pb PBundle, q *qbs.Qbs) (interface{}, error) {
	self.testCallCount++
	in := value.(*HouseWire)
	house := &House{Address: in.Addr, Zip: in.ZipCode}
	if _, err := q.Save(house); err != nil {
		return nil, err
	}

	//simulate an error AFTER the save!
	switch self.failPost {
	case force_panic:
		panic("testing panic handling")
	case force_error:
		return nil, errors.New("testing error handling")
	}

	return &HouseWire{Id: house.Id, Addr: house.Address, ZipCode: house.Zip}, nil
}
func main() {
	var (
		q    *qbs.Qbs
		user *User
	)

	q = SetupDb()
	defer q.Close()

	profile := &Profile{Homepage: "www.example.com", Interests: "Golang", Id: 1}
	q.Save(profile)
	q.Save(&User{Id: 1, FirstName: "John", LastName: "Doe", Age: 25, ProfileId: 1})

	//START CODE OMIT
	user = &User{Id: 1}
	q.Find(user)

	fmt.Printf("%+v\n", user)
	fmt.Printf("%+v\n", user.Profile)
	//END CODE OMIT
}
func main() {
	var (
		q    *qbs.Qbs
		user *User
	)

	q = SetupDb()
	defer q.Close()

	//START CODE OMIT
	q.Save(&User{Id: 1, FirstName: "John", LastName: "Doe", Age: 25})
	PrintTable(q)

	user = &User{Id: 1}
	q.Find(user)

	user.FirstName = "James"
	q.Save(user)
	PrintTable(q)

	q.Delete(user)
	PrintTable(q)
	//END CODE OMIT
}
func main() {
	var (
		q *qbs.Qbs
	)

	q = SetupDb()
	defer q.Close()

	//START SETUP OMIT
	q.Save(&User{
		Id:        1,
		FirstName: "John",
		LastName:  "Doe",
		Age:       24,
	})

	q.Save(&User{
		Id:        2,
		FirstName: "Jane",
		LastName:  "Doe",
		Age:       52,
	})

	q.Save(&User{
		Id:        3,
		FirstName: "Joe",
		LastName:  "Shmoe",
		Age:       10,
	})
	//END SETUP OMIT

	//START CODE OMIT

	var users []*User
	q.Condition(qbs.NewCondition("last_name = ?", "Doe").Or("age < ?", 12)).Limit(2).OrderByDesc("age").FindAll(&users)
	for _, user := range users {
		fmt.Printf("%+v,", user)
	}
	fmt.Println()

	//END CODE OMIT
}
示例#11
0
文件: example.go 项目: nonempty/qbs
func CreateUser(q *qbs.Qbs) (*User, error) {
	user := new(User)
	user.Name = "Green"
	_, err := q.Save(user)
	return user, err
}
示例#12
0
func updateImportInfo(q *qbs.Qbs, path string, pid, rank int, add bool) {
	spid := strconv.Itoa(pid)

	// Save package information.
	info := new(hv.PkgInfo)
	err := q.WhereEqual("import_path", path).Find(info)
	if err == nil {
		// Check if pid exists in this project.
		refPids := strings.Split(info.RefPids, "|")
		i := getRefIndex(refPids, spid)

		if add {
			// Add operation.
			if i == -1 {
				refPids = append(refPids, spid)
				i = len(refPids) - 1
			}

			info.RefPids = strings.Join(refPids, "|")
			info.RefNum = len(refPids)
			if info.RefNum > 0 && strings.HasPrefix(info.RefPids, "|") {
				info.RefPids = info.RefPids[1:]
				info.RefNum--
			}

			_, err = q.Save(info)
			if err != nil {
				beego.Error("models.updateImportInfo -> add:", path, err)
			}

		} else if i > -1 {
			// Delete operation
			refPids = append(refPids[:i], refPids[i+1:]...)

			info.RefPids = strings.Join(refPids, "|")
			info.RefNum = len(refPids)
			if info.RefNum > 0 && strings.HasPrefix(info.RefPids, "|") {
				info.RefPids = info.RefPids[1:]
				info.RefNum--
			}

			_, err = q.Save(info)
			if err != nil {
				beego.Error("models.updateImportInfo -> delete:", path, err)
			}
		}
		return
	}

	if add {
		// Record imports.
		pimp := new(PkgImport)
		q.WhereEqual("path", path).Find(pimp)
		pimp.Path = path
		pimps := strings.Split(pimp.Imports, "|")
		i := getRefIndex(pimps, spid)
		if i == -1 {
			pimps = append(pimps, spid)
			pimp.Imports = strings.Join(pimps, "|")
			_, err = q.Save(pimp)
			if err != nil {
				beego.Error("models.updateImportInfo -> record import:", path, err)
			}
		}
	}
}