当前位置: 首页>>代码示例>>Golang>>正文


Golang meddler.QueryRow函数代码示例

本文整理汇总了Golang中github.com/russross/meddler.QueryRow函数的典型用法代码示例。如果您正苦于以下问题:Golang QueryRow函数的具体用法?Golang QueryRow怎么用?Golang QueryRow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了QueryRow函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetAssignmentProblemStepCommitLast

// GetUserAssignmentProblemStepCommitLast handles requests to /v2/assignments/:assignment_id/problems/:problem_id/steps/:step/commits/last,
// returning the most recent commit for the given step of the given problem of the given assignment.
func GetAssignmentProblemStepCommitLast(w http.ResponseWriter, tx *sql.Tx, params martini.Params, currentUser *User, render render.Render) {
	assignmentID, err := parseID(w, "assignment_id", params["assignment_id"])
	if err != nil {
		return
	}
	problemID, err := parseID(w, "problem_id", params["problem_id"])
	if err != nil {
		return
	}
	step, err := parseID(w, "step", params["step"])
	if err != nil {
		return
	}

	commit := new(Commit)

	if currentUser.Admin {
		err = meddler.QueryRow(tx, commit, `SELECT * FROM commits WHERE assignment_id = $1 AND problem_id = $2 AND step = $3 ORDER BY created_at DESC LIMIT 1`, assignmentID, problemID, step)
	} else {
		err = meddler.QueryRow(tx, commit, `SELECT commits.* `+
			`FROM commits JOIN user_assignments ON commits.assignment_id = user_assignments.assignment_id `+
			`WHERE commits.assignment_id = $1 AND problem_id = $2 AND step = $3 AND user_assignments.user_id = $4 `+
			`ORDER BY created_at DESC LIMIT 1`,
			assignmentID, problemID, step, currentUser.ID)
	}

	if err != nil {
		loggedHTTPDBNotFoundError(w, err)
		return
	}

	render.JSON(http.StatusOK, commit)
}
开发者ID:RidleyLarsen,项目名称:codegrinder,代码行数:35,代码来源:user.go

示例2: GetProblemStep

// GetProblemStep handles a request to /v2/problems/:problem_id/steps/:step,
// returning a single problem step.
func GetProblemStep(w http.ResponseWriter, tx *sql.Tx, params martini.Params, currentUser *User, render render.Render) {
	problemID, err := parseID(w, "problem_id", params["problem_id"])
	if err != nil {
		return
	}
	step, err := parseID(w, "step", params["step"])
	if err != nil {
		return
	}

	problemStep := new(ProblemStep)

	if currentUser.Admin || currentUser.Author {
		err = meddler.QueryRow(tx, problemStep, `SELECT * FROM problem_steps WHERE problem_id = $1 AND step = $2`, problemID, step)
	} else {
		err = meddler.QueryRow(tx, problemStep, `SELECT problem_steps.* `+
			`FROM problem_steps JOIN user_problems ON problem_steps.problem_id = user_problems.problem_id `+
			`WHERE user_problems.user_id = $1 AND problem_steps.problem_id = $2 AND problem_steps.step = $3`,
			currentUser.ID, problemID, step)
	}

	if err != nil {
		loggedHTTPDBNotFoundError(w, err)
		return
	}

	render.JSON(http.StatusOK, problemStep)
}
开发者ID:RidleyLarsen,项目名称:codegrinder,代码行数:30,代码来源:problem.go

示例3: TestMigrateRenameTable

func TestMigrateRenameTable(t *testing.T) {
	defer tearDown()
	if err := setUp(); err != nil {
		t.Fatalf("Error preparing database: %q", err)
	}

	mgr := New(db)
	if err := mgr.Add(&revision1{}).Migrate(); err != nil {
		t.Fatalf("Can not migrate: %q", err)
	}

	loadFixture(t)

	if err := mgr.Add(&revision2{}).Migrate(); err != nil {
		t.Fatalf("Can not migrate: %q", err)
	}

	sample := Sample{}
	if err := meddler.QueryRow(db, &sample, `SELECT * FROM examples WHERE id = ?`, 2); err != nil {
		t.Fatalf("Can not fetch data: %q", err)
	}

	if sample.Imel != "[email protected]" {
		t.Errorf("Column doesn't match. Expect: %s, got: %s", "[email protected]", sample.Imel)
	}
}
开发者ID:Jyggafey,项目名称:drone,代码行数:26,代码来源:migrate_test.go

示例4: Put

// Put inserts an object into the blobstore.
func (db *Blobstore) Put(path string, data []byte) error {
	var blob = Blob{}
	meddler.QueryRow(db, &blob, rebind(blobQuery), path)
	blob.Path = path
	blob.Data = string(data)
	return meddler.Save(db, blobTable, &blob)
}
开发者ID:carnivalmobile,项目名称:drone,代码行数:8,代码来源:blob.go

示例5: TestRenameColumn

func TestRenameColumn(t *testing.T) {
	defer tearDown()
	if err := setUp(); err != nil {
		t.Fatalf("Error preparing database: %q", err)
	}

	mgr := New(db)
	if err := mgr.Add(&revision1{}, &revision4{}).MigrateTo(1); err != nil {
		t.Fatalf("Can not migrate: %q", err)
	}

	loadFixture(t)

	if err := mgr.MigrateTo(4); err != nil {
		t.Fatalf("Can not migrate: %q", err)
	}

	row := RenameSample{}
	if err := meddler.QueryRow(db, &row, `SELECT * FROM samples WHERE id = 3;`); err != nil {
		t.Fatalf("Can not query database: %q", err)
	}

	if row.Email != "[email protected]" {
		t.Errorf("Expect %s, got %s", "[email protected]", row.Email)
	}
}
开发者ID:Jyggafey,项目名称:drone,代码行数:26,代码来源:migrate_test.go

示例6: Put

// Put inserts an object into the blobstore.
func (b *Blobstore) Put(path string, data []byte) error {
	var blob = resource.Blob{}
	meddler.QueryRow(b, &blob, queryBlob, path)
	blob.Path = path
	blob.Data = string(data)
	return meddler.Save(b, tableBlob, &blob)
}
开发者ID:drone,项目名称:drone-dart,代码行数:8,代码来源:blobstore.go

示例7: GetSessionInfoByPublicID

// GetSessionInfoByPublicID returns a SessionInfo object for a session, identified
// by its publicID and userID.
func (s *Store) GetSessionInfoByPublicID(publicID string, userID int) (*SessionInfo, error) {
	result := &SessionInfo{}
	err := meddler.QueryRow(s.sqlDB, result,
		`SELECT 
			uploads.title AS title, 
			uploads.public_id AS public_id, 
			uploads.user_id AS user_id, 
			sessions.ended AS ended 
			FROM uploads, sessions 
			WHERE sessions.upload_id = uploads.id AND
				sessions.public_id = ?`, publicID)
	if err != nil {
		return nil, err
	}
	// XXX ugly hack.
	formatted := result.Ended.Format(time.RFC3339)
	if formatted != "0001-01-01T00:00:00Z" {
		result.EndedJSON = formatted
	}

	err = meddler.QueryRow(s.sqlDB, &result,
		`SELECT 
			commands.page AS page
			FROM commands, sessions
			WHERE sessions.id = commands.session_id AND
				sessions.public_id = ?
			ORDER BY commands.timestamp DESC LIMIT 1`, publicID)
	if err != nil {
		result.Page = 1
	}

	var cmds []*Command

	err = meddler.QueryAll(s.sqlDB, &cmds,
		`SELECT
			*
			FROM commands
			WHERE commands.session_id = (SELECT id FROM sessions WHERE public_id = ?)
			ORDER BY commands.timestamp`, publicID)
	if err != nil {
		return nil, err
	}
	result.Cmds = cmds
	result.IsOwner = (userID != 0 && result.UserID == userID)

	return result, err
}
开发者ID:joinmytalk,项目名称:satsuma,代码行数:49,代码来源:db.go

示例8: PostPerm

// PostPerm saves permission in the datastore.
func (db *Permstore) PostPerm(perm *model.Perm) error {
	var _perm = new(model.Perm)
	meddler.QueryRow(db, _perm, rebind(permQuery), perm.UserID, perm.RepoID)
	if _perm.ID != 0 {
		perm.ID = _perm.ID
	}
	return meddler.Save(db, permTable, perm)
}
开发者ID:voxxit,项目名称:drone,代码行数:9,代码来源:perm.go

示例9: GetByName

func (db *repoStore) GetByName(owner, name string) (*model.Repo, error) {
	repo := new(model.Repo)
	err := meddler.QueryRow(db, repo, repoNameQuery, owner, name)
	if err != nil {
		return nil, err
	}
	return repo, nil
}
开发者ID:mikkeloscar,项目名称:maze,代码行数:8,代码来源:repos.go

示例10: SetSecret

func (db *datastore) SetSecret(sec *model.Secret) error {
	var got = new(model.Secret)
	var err = meddler.QueryRow(db, got, rebind(secretNameQuery), sec.RepoID, sec.Name)
	if err == nil && got.ID != 0 {
		sec.ID = got.ID // update existing id
	}
	return meddler.Save(db, secretTable, sec)
}
开发者ID:Ablu,项目名称:drone,代码行数:8,代码来源:secret.go

示例11: GetOwnerForSession

// GetOwnerForSession returns the userID and numeric sessionID for a session, identified
// by its publicID.
func (s *Store) GetOwnerForSession(publicID string) (userID int, sessionID int, err error) {
	ownerData := struct {
		UserID int `meddler:"user_id"`
		ID     int `meddler:"session_id"`
	}{}
	err = meddler.QueryRow(s.sqlDB, &ownerData, "SELECT uploads.user_id AS user_id, sessions.id AS session_id FROM uploads, sessions WHERE sessions.public_id = ? AND sessions.upload_id = uploads.id LIMIT 1", publicID)
	return ownerData.UserID, ownerData.ID, err
}
开发者ID:joinmytalk,项目名称:satsuma,代码行数:10,代码来源:db.go

示例12: GetUploadByPublicID

// GetUploadByPublicID returns an Upload object, identified by its
// publicID and userID.
func (s *Store) GetUploadByPublicID(publicID string, userID int) (*Upload, error) {
	uploadEntry := &Upload{}

	err := meddler.QueryRow(s.sqlDB, uploadEntry, "select id from uploads where public_id = ? and user_id = ?", publicID, userID)
	if err != nil {
		uploadEntry = nil
	}
	return uploadEntry, err
}
开发者ID:joinmytalk,项目名称:satsuma,代码行数:11,代码来源:db.go

示例13: Write

func (db *logstore) Write(job *model.Job, r io.Reader) error {
	var log = new(model.Log)
	var err = meddler.QueryRow(db, log, rebind(logQuery), job.ID)
	if err != nil {
		log = &model.Log{JobID: job.ID}
	}
	log.Data, _ = ioutil.ReadAll(r)
	return meddler.Save(db, logTable, log)
}
开发者ID:fclairamb,项目名称:drone,代码行数:9,代码来源:logs.go

示例14: SaveMember

// Creates a new Member.
func SaveMember(user, team int64, role string) error {
	r := Role{}
	if err := meddler.QueryRow(db, &r, roleFindStmt, user, team); err == nil {
		r.Role = role
		return meddler.Save(db, memberTable, &r)
	}

	r.UserID = user
	r.TeamID = team
	r.Role = role
	return meddler.Save(db, memberTable, &r)
}
开发者ID:Jyggafey,项目名称:drone,代码行数:13,代码来源:members.go

示例15: BenchmarkMeddlerRow

func BenchmarkMeddlerRow(b *testing.B) {
	var user *User
	var err error

	for n := 0; n < b.N; n++ {
		user = &User{}
		err = meddler.QueryRow(db, user, SelectUserPkeyStmt, 1)
		if err != nil {
			panic(err)
		}
	}
	result = user
}
开发者ID:scotthelm,项目名称:sqlgen,代码行数:13,代码来源:type_test.go


注:本文中的github.com/russross/meddler.QueryRow函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。