本文整理汇总了Golang中github.com/russross/meddler.QueryRow函数的典型用法代码示例。如果您正苦于以下问题:Golang QueryRow函数的具体用法?Golang QueryRow怎么用?Golang QueryRow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了QueryRow函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: GetReport
func (a *AccountHandler) GetReport(w rest.ResponseWriter, r *rest.Request) {
var report AccountReport
report.AccountCode = r.PathParam("accountCode")
report.Timestamp = r.PathParam("timestamp")
existing := new(core.Account)
err := meddler.QueryRow(a.db, existing, "SELECT * FROM account WHERE account_code = $1", report.AccountCode)
if err != nil {
a.u.HandleError(err, w, r)
return
}
created, err := time.Parse(time.RFC3339Nano, report.Timestamp)
if err != nil {
a.u.HandleError(err, w, r)
return
}
var snap core.AccountSnapshot
err = meddler.QueryRow(a.db, &snap, "SELECT * FROM account_snapshot WHERE account_id = $1 AND created = $2", existing.Id, created)
if err != nil {
a.u.HandleError(err, w, r)
return
}
err = meddler.QueryAll(a.db, &report.Positions, "SELECT * FROM v_account_position WHERE account_snapshot_id = $1", snap.Id)
if err != nil {
a.u.HandleError(err, w, r)
return
}
err = meddler.QueryRow(a.db, &report.Balance, "SELECT * FROM v_account_amount WHERE account_snapshot_id = $1", snap.Id)
if err != nil {
a.u.HandleError(err, w, r)
return
}
w.Header().Add("Cache-Control", "private, max-age=31556926")
w.WriteJson(&report)
}
开发者ID:jacktang,项目名称:ibconnect.go,代码行数:39,代码来源:account_handler.go
示例17: GetLatest
func (a *AccountHandler) GetLatest(w rest.ResponseWriter, r *rest.Request) {
code := r.PathParam("accountCode")
latest := new(core.AccountSnapshotLatest)
err := meddler.QueryRow(a.db, latest, "SELECT * FROM v_account_snapshot_latest WHERE account_code = $1", code)
if err != nil {
a.u.HandleError(err, w, r)
return
}
path := fmt.Sprintf("/v1/accounts/%s/%s", code, latest.Latest.Format(time.RFC3339Nano))
url := r.UrlFor(path, make(map[string][]string))
w.Header().Add("Location", url.String())
w.WriteHeader(http.StatusSeeOther)
}
开发者ID:jacktang,项目名称:ibconnect.go,代码行数:14,代码来源:account_handler.go
示例18: LtiProblemSet
// LtiProblem handles /lti/problem/:unique requests.
// It creates the user/course/assignment if necessary, creates a session,
// and redirects the user to the main UI URL.
func LtiProblemSet(w http.ResponseWriter, r *http.Request, tx *sql.Tx, form LTIRequest, params martini.Params, session sessions.Session) {
unique := params["unique"]
if unique == "" {
loggedHTTPErrorf(w, http.StatusBadRequest, "malformed URL: missing unique ID for problem")
return
}
if unique != url.QueryEscape(unique) {
loggedHTTPErrorf(w, http.StatusBadRequest, "unique ID must be URL friendly: %s is escaped as %s", unique, url.QueryEscape(unique))
return
}
now := time.Now()
// load the problem set
problemSet := new(ProblemSet)
if err := meddler.QueryRow(tx, problemSet, `SELECT * FROM problem_sets WHERE unique_id = $1`, unique); err != nil {
loggedHTTPDBNotFoundError(w, err)
return
}
// load the course
course, err := getUpdateCourse(tx, &form, now)
if err != nil {
loggedHTTPErrorf(w, http.StatusInternalServerError, "db error: %v", err)
return
}
// load the user
user, err := getUpdateUser(tx, &form, now)
if err != nil {
loggedHTTPErrorf(w, http.StatusInternalServerError, "db error: %v", err)
return
}
// load the assignment
asst, err := getUpdateAssignment(tx, &form, now, course, problemSet, user)
if err != nil {
loggedHTTPErrorf(w, http.StatusInternalServerError, "db error: %v", err)
return
}
// sign the user in
session.Set("id", user.ID)
// redirect to the console
//http.Redirect(w, r, fmt.Sprintf("/#/assignment/%d", asst.ID), http.StatusSeeOther)
_ = asst
http.Redirect(w, r, "/v2/users/me/cookie", http.StatusSeeOther)
}
开发者ID:RidleyLarsen,项目名称:codegrinder,代码行数:52,代码来源:lti.go
示例19: FindOne
func (sr *SQL) FindOne(r *Request, rp RequestParams, id string) (*Record, error) {
v := reflect.New(sr.Type).Interface()
id_sql_name := sr.GetIdFieldName(v)
err := meddler.QueryRow(sr.DB, v, "SELECT * FROM "+sr.Table+" WHERE "+id_sql_name+"=?", id)
if err == sql.ErrNoRows {
return nil, nil
}
if err != nil {
return nil, err
}
return &Record{
Id: id,
Attributes: v,
}, nil
}
开发者ID:liamzdenek,项目名称:go-jsonapi,代码行数:15,代码来源:SQL.go
示例20: GetAssignment
// GetAssignment handles requests to /v2/assignments/:assignment_id,
// returning the given assignment.
func GetAssignment(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
}
assignment := new(Assignment)
if currentUser.Admin {
err = meddler.QueryRow(tx, assignment, `SELECT * FROM assignments WHERE id = $1`, assignmentID)
} else {
err = meddler.QueryRow(tx, assignment, `SELECT assignments.* `+
`FROM assignments JOIN user_assignments ON assignments.id = user_assignments.assignment_id `+
`WHERE id = $1 AND user_assignments.user_id = $2`,
assignmentID, currentUser.ID)
}
if err != nil {
loggedHTTPDBNotFoundError(w, err)
return
}
render.JSON(http.StatusOK, assignment)
}
开发者ID:RidleyLarsen,项目名称:codegrinder,代码行数:26,代码来源:user.go
注:本文中的github.com/russross/meddler.QueryRow函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论