本文整理汇总了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)
}
示例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)
}
示例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)
}
}
示例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)
}
示例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)
}
}
示例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)
}
示例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
}
示例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)
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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)
}
示例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)
}
示例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
}