本文整理匯總了Golang中github.com/lann/squirrel.SelectBuilder.ToSql方法的典型用法代碼示例。如果您正苦於以下問題:Golang SelectBuilder.ToSql方法的具體用法?Golang SelectBuilder.ToSql怎麽用?Golang SelectBuilder.ToSql使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/lann/squirrel.SelectBuilder
的用法示例。
在下文中一共展示了SelectBuilder.ToSql方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SelectOne
func SelectOne(s gorp.SqlExecutor, builder squirrel.SelectBuilder, src interface{}) error {
sql, args, err := builder.ToSql()
if err != nil {
return err
}
return s.SelectOne(src, sql, args...)
}
示例2: Query
func (q SqlQuery) Query(ctx context.Context, sql sq.SelectBuilder) (*sqlx.Rows, error) {
sql = sql.PlaceholderFormat(sq.Dollar)
query, args, err := sql.ToSql()
if err != nil {
return nil, errors.Wrap(err, 1)
}
return q.QueryRaw(ctx, query, args)
}
示例3: Get
// Get gets a single row returned by the provided sql builder into the provided dest.
// dest must be a non-slice value of the correct record type.
func (q SqlQuery) Get(ctx context.Context, sql sq.SelectBuilder, dest interface{}) error {
sql = sql.PlaceholderFormat(sq.Dollar)
query, args, err := sql.ToSql()
if err != nil {
return errors.Wrap(err, 1)
}
return q.GetRaw(ctx, query, args, dest)
}
示例4: LoadValue
// loadValue uses QueryBuilder to run SELECT query and fetch single value from database,
// use it for getting ID or counter
func LoadValue(qb *squirrel.SelectBuilder, buf interface{}) error {
query, args, err := qb.ToSql()
if err != nil {
return err
}
err = components.App.Db.Unsafe().QueryRow(query, args...).Scan(buf)
if err != nil && err != sql.ErrNoRows {
return err
}
return nil
}
示例5: LoadStruct
func LoadStruct(qb *squirrel.SelectBuilder, buf interface{}) error {
query, args, err := qb.ToSql()
if err != nil {
return err
}
err = components.App.Db.Unsafe().Get(buf, query, args...)
if err != nil {
return err
}
return nil
}
示例6: Get
func (q SqlQuery) Get(ctx context.Context, sql sq.SelectBuilder, dest interface{}) error {
db := sqlx.NewDb(q.DB, "postgres")
sql = sql.PlaceholderFormat(sq.Dollar)
query, args, err := sql.ToSql()
if err != nil {
return err
}
return db.Get(dest, query, args...)
}
示例7: Select
func (q SqlQuery) Select(ctx context.Context, sql sq.SelectBuilder, dest interface{}) error {
db := sqlx.NewDb(q.DB, "postgres")
sql = sql.PlaceholderFormat(sq.Dollar)
query, args, err := sql.ToSql()
if err != nil {
return err
}
log.WithField(ctx, "sql", query).Info("Executing query")
return db.Select(dest, query, args...)
}