本文整理匯總了Golang中appengine/data.NewConn函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewConn函數的具體用法?Golang NewConn怎麽用?Golang NewConn使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewConn函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: updateTest
func updateTest(wr srv.WrapperRequest, t *Test) error {
old, err := getTestById(wr, t.Id)
if err != nil {
return fmt.Errorf("updatetest: %v", err)
}
if wr.NU.ID() != old.AuthorId {
return fmt.Errorf("updatetest: %s", users.ERR_NOTOPERATIONALLOWED)
}
// invariant fields
t.TimeStamp = old.TimeStamp
t.AuthorId = old.AuthorId
q := data.NewConn(wr, "tests")
err = q.Put(t)
err = checkExercises(wr, t, err)
err = deleteExercises(wr, t, err)
err = addExercises(wr, t, err)
err = deleteUsersAllowed(wr, t, err)
err = addUsersAllowed(wr, t, err)
err = deleteTestTags(wr, t, err)
err = addTestTags(wr, t, err)
if err != nil {
return fmt.Errorf("updatetest: %v", err)
}
return nil
}
示例2: loadExercises
// Fill the exercises array in the test
func loadExercises(wr srv.WrapperRequest, t *Test, err error) error {
if err != nil {
return err
}
testEx := NewExerciseBuffer()
qry := data.NewConn(wr, "tests-exercises")
qry.AddFilter("TestId =", t.Id)
err = qry.GetMany(&testEx)
if err != nil {
return err
}
t.Exercises = testEx
// check if the test will be loaded for a student, in this case
// do not read the solutions of the questions
withSolution := true
if wr.NU.GetRole() < users.ROLE_TEACHER {
withSolution = false
}
// now, load the questions struct for each exercise
for i := range t.Exercises {
var q *questions.Question
if withSolution {
q, _ = questions.GetQuestById(wr, t.Exercises[i].QuestId)
} else {
q, _ = questions.GetQuestByIdWithoutSol(wr, t.Exercises[i].QuestId)
}
t.Exercises[i].Quest = q
}
return nil
}
示例3: getCurrentUser
func getCurrentUser(wr *srv.WrapperRequest) error {
//var nu nusers.NUser
var nu appusers.AppUser
nus := users.NewNUserBuffer()
u := wr.U
if u == nil {
return errors.New("No user session founded")
}
q := data.NewConn(*wr, "users")
q.AddFilter("Mail =", u.Email)
err := q.GetMany(&nus)
if len(nus) <= 0 {
// If the session users not in the datastore we use de admin
// users of the app
if wr.IsAdminRequest() {
//nu = nusers.New(u.Email, "Administrador", nusers.ROLE_ADMIN)
nu = GetDefaultUser(u.Email)
} else {
return errors.New("No user id found")
}
} else {
nu = nus[0]
}
wr.NU = nu
return err
}
示例4: deleteUser
func deleteUser(wr srv.WrapperRequest, nu *NUser) error {
q := data.NewConn(wr, "users")
err := q.Delete(nu)
err = deleteUserTags(wr, nu, err)
if err != nil {
return fmt.Errorf("deleteuser: %v", err)
}
return nil
}
示例5: addQuestTags
// Add the tags of the question to the database
func addQuestTags(wr srv.WrapperRequest, q *Question) error {
for _, tag := range q.Tags {
qry := data.NewConn(wr, "questions-tags")
qt := &QuestionTag{QuestId: q.Id, Tag: tag}
err := qry.Put(qt)
if err != nil {
return err
}
}
return nil
}
示例6: getExerciseById
func getExerciseById(wr srv.WrapperRequest, ExerciseId int64) (*Exercise, error) {
ex := new(Exercise)
qry := data.NewConn(wr, "tests-exercises")
ex.Id = ExerciseId
err := qry.Get(ex)
if err != nil {
return nil, fmt.Errorf("getexercisebyid: %v", err)
}
return ex, nil
}
示例7: deleteTest
func deleteTest(wr srv.WrapperRequest, t *Test) error {
q := data.NewConn(wr, "tests")
err := q.Delete(t)
err = deleteExercises(wr, t, err)
err = deleteUsersAllowed(wr, t, err)
err = deleteTestTags(wr, t, err)
if err != nil {
return fmt.Errorf("deletetest: %v", err)
}
return nil
}
示例8: addTestTags
// Add the tags in the test to the database
func addTestTags(wr srv.WrapperRequest, t *Test, err error) error {
if err != nil {
return err
}
q := data.NewConn(wr, "tests-tags")
for _, tag := range t.Tags {
tt := &TestTag{TestId: t.Id, Tag: tag}
err := q.Put(tt)
if err != nil {
return err
}
}
return nil
}
示例9: addExercises
// Add the exercises in the test to the database
func addExercises(wr srv.WrapperRequest, t *Test, err error) error {
if err != nil {
return err
}
q := data.NewConn(wr, "tests-exercises")
for _, ex := range t.Exercises {
ex.TestId = t.Id
err := q.Put(ex)
if err != nil {
return err
}
}
return nil
}
示例10: addUserTags
func addUserTags(wr srv.WrapperRequest, nu *NUser, err error) error {
if err != nil {
return err
}
q := data.NewConn(wr, "users-tags")
for _, tag := range nu.Tags {
ut := &UserTag{UserId: nu.Id, Tag: tag}
err := q.Put(ut)
if err != nil {
return fmt.Errorf("addusertags: %v", err)
}
}
return nil
}
示例11: addUsersAllowed
// Add the users allowed in the test to the database
func addUsersAllowed(wr srv.WrapperRequest, t *Test, err error) error {
if err != nil {
return err
}
q := data.NewConn(wr, "tests-users")
for _, uid := range t.UList {
tu := &TestUser{Id: 0, TestId: t.Id, UserId: uid}
err := q.Put(tu)
if err != nil {
return err
}
}
return nil
}
示例12: getUserById
func getUserById(wr srv.WrapperRequest, id int64) (*NUser, error) {
nu := new(NUser)
nu.Id = id
q := data.NewConn(wr, "users")
err := q.Get(nu)
if err != nil {
return nu, fmt.Errorf("getuserbyid: %v: %s", err, ERR_USERNOTFOUND)
}
nu.Tags, err = getUserTags(wr, nu)
if err != nil {
return nu, fmt.Errorf("getuserbyid: %v", err)
}
return nu, nil
}
示例13: getUsersAllowed
// Return the users allowed for this tests
func getUsersAllowed(wr srv.WrapperRequest, t *Test) ([]*users.NUser, error) {
nus := make([]*users.NUser, 0)
qu := data.NewConn(wr, "users")
for i := range t.UList {
us := new(users.NUser)
us.SetID(t.UList[i])
err := qu.Get(us)
if err != nil {
continue
}
nus = append(nus, us)
}
return nus, nil
}
示例14: GetAnswersById
func GetAnswersById(wr srv.WrapperRequest, id int64) (*Answer, error) {
a := NewAnswer(-1, -1)
qry := data.NewConn(wr, "answers")
a.Id = id
err := qry.Get(a)
if err != nil {
return a, errors.New(ERR_ANSWERNOTFOUND)
}
getAnswerBody(wr, a)
return a, nil
}
示例15: getUserByMail
func getUserByMail(wr srv.WrapperRequest, email string) (*NUser, error) {
nus := NewNUserBuffer()
nu := new(NUser)
q := data.NewConn(wr, "users")
q.AddFilter("Mail =", email)
q.GetMany(&nus)
if len(nus) == 0 {
return nu, fmt.Errorf("%s", ERR_USERNOTFOUND)
}
nu = nus[0]
nu.Tags, _ = getUserTags(wr, nu)
return nu, nil
}