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
}
예제 #2
0
// checkImport returns true if the package(id) imports given package(path).
func checkImport(q *qbs.Qbs, path string, id int64) bool {
	pinfo := &PkgInfo{
		Id: id,
	}
	err := q.Find(pinfo)
	if err != nil {
		return false
	}

	decl := new(PkgDecl)
	cond := qbs.NewCondition("pid = ?", pinfo.Id).And("tag = ?", "")
	err = q.Condition(cond).Find(decl)
	if err != nil {
		return false
	}

	if strings.Index(decl.Imports, path) == -1 {
		return false
	}

	return true
}
예제 #3
0
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
}
예제 #4
0
파일: example.go 프로젝트: nonempty/qbs
func FindUserById(q *qbs.Qbs, id int64) (*User, error) {
	user := new(User)
	user.Id = id
	err := q.Find(user)
	return user, err
}