本文整理汇总了Golang中github.com/jmoiron/sqlx.Stmt.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang Stmt.Get方法的具体用法?Golang Stmt.Get怎么用?Golang Stmt.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jmoiron/sqlx.Stmt
的用法示例。
在下文中一共展示了Stmt.Get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetByID
func (maker *courseMaker) GetByID(id int64) (*Course, error) {
var (
err error
get_course string = queries["get_course"]
get_course_members string = queries["get_course_members"]
get_course_teachers string = queries["get_course_teachers"]
course *Course = NewCourse()
studentIDs []int64 = []int64{}
teacherIDs []int64 = []int64{}
stmt *sqlx.Stmt
acid util.AcidTx
)
// Get the course's name.
acid = func(tx *sqlx.Tx) {
// Add the course
stmt, err = tx.Preparex(get_course)
PanicOnError(err)
err = stmt.Get(course, id)
PanicOnError(err)
// Get the rows out of course_members
stmt, err = tx.Preparex(get_course_members)
PanicOnError(err)
err = stmt.Select(&studentIDs, id)
PanicOnError(err)
// Get the rows out of course_teachers
stmt, err = tx.Preparex(get_course_teachers)
PanicOnError(err)
stmt.Select(&teacherIDs, id)
PanicOnError(err)
for _, studentID := range studentIDs {
student, err := StudentStore.GetByID(studentID)
PanicOnError(err)
course.Students = append(course.Students, student)
}
for _, teacherID := range teacherIDs {
teacher, err := TeacherStore.GetByID(teacherID)
PanicOnError(err)
course.Teachers = append(course.Teachers, teacher)
}
}
err = util.AcidCtx(acid, maker)
if err != nil {
return nil, err
}
return course, nil
}
示例2: GetAndMarshal
func GetAndMarshal(query string, db Execer, destination interface{}, args ...interface{}) (err error) {
var stmt *sqlx.Stmt
var acid AcidTx = func(tx *sqlx.Tx) {
stmt, err = tx.Preparex(query)
if err != nil {
panic(err)
}
if err = stmt.Get(destination, args...); err != nil {
panic(err)
}
}
AcidCtx(acid, db)
return err
}