本文整理汇总了Golang中github.com/lann/squirrel.Select函数的典型用法代码示例。如果您正苦于以下问题:Golang Select函数的具体用法?Golang Select怎么用?Golang Select使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Select函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Select
// Get executes the query, returning any found results
func (q LedgerStateQuery) Select(ctx context.Context, dest interface{}) error {
hSql := sq.
Select("MAX(sequence) as horizonsequence").
From("history_ledgers")
scSql := sq.
Select("MAX(ledgerseq) as stellarcoresequence").
From("ledgerheaders")
var result LedgerState
err := q.Horizon.Get(ctx, hSql, &result)
if err != nil {
return err
}
err = q.Core.Get(ctx, scSql, &result)
if err != nil {
return err
}
setOn([]LedgerState{result}, dest)
return nil
}
开发者ID:zenododobird,项目名称:horizon,代码行数:27,代码来源:query_ledger_state.go
示例2: Query
func Query(src interface{}, tableName string, values url.Values) (sql string, args []interface{}, err error) {
builder := squirrel.Select("*").From(tableName)
// add where clause
for key, value := range values {
nBuilder, err := whereValueForKey(builder, src, key, value[0])
if err != nil {
return "", []interface{}{}, err
}
builder = nBuilder
}
// add order if it exists
if oVal := values.Get(KeyOrder); oVal != "" {
field, order, err := orderFromValue(src, oVal)
if err != nil {
return "", []interface{}{}, err
}
builder = builder.OrderBy(field + " " + string(order))
}
// add limit and offset
builder = builder.Limit(uintFromKey(values, KeyLimit, 1000))
builder = builder.Offset(uintFromKey(values, KeyOffset, 0))
return builder.ToSql()
}
开发者ID:nancyandrews,项目名称:MobileMainStreet,代码行数:27,代码来源:query.go
示例3: SelectAllEquipmentInfo
func SelectAllEquipmentInfo(dbm *gorp.DbMap) ([]EquipmentInfo, error) {
var results []EquipmentInfo
q := sq.Select(
`"EquipmentInfo"."ID"`,
`"EquipmentInfo"."CertifiedName"`,
`"RadioAccessTechnology"."Description" AS EquipmentType`,
`"EquipmentInfo"."Model"`,
`"EquipmentInfo"."AuthNumber"`,
`"EquipmentInfo"."RadioType"`,
`"EquipmentInfo"."IsApplied1421"`,
`"EquipmentInfo"."AuthDate"`,
`"EquipmentInfo"."Note"`,
`"EquipmentInfo"."File"`,
).From(
"EquipmentInfo",
).LeftJoin(
`"RadioAccessTechnology" ON "EquipmentInfo"."EquipmentType" = "RadioAccessTechnology"."EquipmentType"`,
)
sql, _, err := q.ToSql()
if err != nil {
return results, err
}
if _, err := dbm.Select(&results, sql); err != nil {
return nil, err
}
return results, nil
}
开发者ID:daisuzu,项目名称:giteki,代码行数:31,代码来源:models.go
示例4: Read
func (p *Place) Read(tx *sql.Tx) error {
row := sq.Select("*").Where(sq.Eq{"id": p.ID}).RunWith(tx).QueryRow()
if err := row.Scan(p.Row()...); err != nil {
return err
}
return nil
}
开发者ID:GeorgeMac,项目名称:outing,代码行数:7,代码来源:place.go
示例5: BenchmarkSquirrelBuilderComplex
func BenchmarkSquirrelBuilderComplex(b *testing.B) {
arg_eq1 := squirrel.Eq{"f": 2, "x": "hi"}
arg_eq2 := map[string]interface{}{"g": 3}
arg_eq3 := squirrel.Eq{"h": []int{1, 2, 3}}
b.ResetTimer()
for n := 0; n < b.N; n++ {
squirrel.Select("a", "b", "z", "y", "x").
Distinct().
From("c").
Where("d = ? OR e = ?", 1, "wat").
Where(arg_eq1).
Where(arg_eq2).
Where(arg_eq3).
GroupBy("i").
GroupBy("ii").
GroupBy("iii").
Having("j = k").
Having("jj = ?", 1).
Having("jjj = ?", 2).
OrderBy("l").
OrderBy("l").
OrderBy("l").
Limit(7).
Offset(8).
ToSql()
}
}
开发者ID:c4pt0r,项目名称:golang-sql-benchmark,代码行数:28,代码来源:sql_builder_benchmark_test.go
示例6: StateFetch
//StateFetch fetches the state of the specified resource
func (tx *Transaction) StateFetch(s *schema.Schema, filter transaction.Filter) (state transaction.ResourceState, err error) {
if !s.StateVersioning() {
err = fmt.Errorf("Schema %s does not support state versioning.", s.ID)
return
}
cols := makeStateColumns(s)
q := sq.Select(cols...).From(quote(s.GetDbTableName()))
q, _ = addFilterToQuery(s, q, filter, true)
sql, args, err := q.ToSql()
if err != nil {
return
}
logQuery(sql, args...)
rows, err := tx.transaction.Queryx(sql, args...)
if err != nil {
return
}
defer rows.Close()
if !rows.Next() {
err = fmt.Errorf("No resource found")
return
}
data := map[string]interface{}{}
rows.MapScan(data)
err = decodeState(data, &state)
return
}
开发者ID:vozhyk-,项目名称:gohan,代码行数:28,代码来源:sql.go
示例7: QueryQuestions
func QueryQuestions(db *sqlx.DB, authorId int, query string, offset int) ([]Question, error) {
qs := []Question{}
qry := sq.Select("*").From("questions")
if authorId != 0 {
qry = qry.Where("author_id = ?", authorId)
}
if query != "" {
word := fmt.Sprint("%", query, "%")
qry = qry.Where("(title LIKE ? OR question LIKE ?)", word, word)
}
if offset > 0 {
qry = qry.Offset(uint64(offset))
}
qry = qry.OrderBy("created_at DESC")
qry = qry.PlaceholderFormat(sq.Dollar)
sql, params, err := qry.ToSql()
if err != nil {
return qs, err
} else {
err := db.Select(&qs, sql, params...)
dbErr := dbError(err)
return qs, dbErr
}
}
开发者ID:cjwirth,项目名称:askme,代码行数:27,代码来源:question.go
示例8: TransactionsByLedger
// TransactionsByLedger is a query that loads all rows from `txhistory` where
// ledgerseq matches `Sequence.`
func (q *Q) TransactionsByLedger(dest interface{}, seq int32) error {
sql := sq.Select("ctxh.*").
From("txhistory ctxh").
OrderBy("ctxh.txindex ASC").
Where("ctxh.ledgerseq = ?", seq)
return q.Select(dest, sql)
}
开发者ID:FihlaTV,项目名称:horizon,代码行数:10,代码来源:transaction.go
示例9: Select
func (q SequenceByAddressQuery) Select(ctx context.Context, dest interface{}) error {
sql := sq.
Select("seqnum as sequence", "accountid as address").
From("accounts").
Where(sq.Eq{"accountid": q.Addresses})
return q.SqlQuery.Select(ctx, sql, dest)
}
开发者ID:zenododobird,项目名称:horizon,代码行数:8,代码来源:query_sequence_by_address.go
示例10: LedgerHeaderBySequence
// LedgerHeaderBySequence is a query that loads a single row from the
// `ledgerheaders` table.
func (q *Q) LedgerHeaderBySequence(dest interface{}, seq int32) error {
sql := sq.Select("clh.*").
From("ledgerheaders clh").
Limit(1).
Where("clh.ledgerseq = ?", seq)
return q.Get(dest, sql)
}
开发者ID:FihlaTV,项目名称:horizon,代码行数:10,代码来源:ledger_header.go
示例11: builderApplication
func (r *DaoResource) builderApplication() *sq.SelectBuilder {
builder := sq.Select(
"id", "token", "provider_id", "platform", "provider",
"name", "attributes", "created_at", "updated_at").
From(model.TableApplications)
return &builder
}
开发者ID:kihamo,项目名称:shadow-sender,代码行数:8,代码来源:application.go
示例12: SequencesForAddresses
// SequencesForAddresses loads the current sequence number for every accountid
// specified in `addys`
func (q *Q) SequencesForAddresses(dest interface{}, addys []string) error {
sql := sq.
Select("seqnum as sequence", "accountid as address").
From("accounts").
Where(sq.Eq{"accountid": addys})
return q.Select(dest, sql)
}
开发者ID:FihlaTV,项目名称:horizon,代码行数:10,代码来源:account.go
示例13: TransactionByHash
// TransactionByHash is a query that loads a single row from the `txhistory`.
func (q *Q) TransactionByHash(dest interface{}, hash string) error {
sql := sq.Select("ctxh.*").
From("txhistory ctxh").
Limit(1).
Where("ctxh.txid = ?", hash)
return q.Get(dest, sql)
}
开发者ID:FihlaTV,项目名称:horizon,代码行数:9,代码来源:transaction.go
示例14: ValidateToken
func ValidateToken(s gorp.SqlExecutor, memberID int64, token string) error {
query := squirrel.Select("*").From(TableNameToken).
Where(squirrel.Eq{"MemberID": memberID, "Value": token})
tokens := []*Token{}
sqlutil.Select(s, query, &tokens)
if len(tokens) == 0 {
return fmt.Errorf("token not found")
}
return nil
}
开发者ID:nancyandrews,项目名称:MobileMainStreet,代码行数:10,代码来源:token.go
示例15: GetID
func GetID(dbmap *gorp.DbMap, m CrudResource, id interface{}) error {
query := squirrel.Select("*").
From(m.TableName()).
Where(squirrel.Eq{"ID": id})
if err := sqlutil.SelectOne(dbmap, query, m); err != nil {
message := fmt.Sprintf("Could not find %s.", m.TableName())
return httperr.New(http.StatusNotFound, message, err)
}
return nil
}
开发者ID:nancyandrews,项目名称:MobileMainStreet,代码行数:10,代码来源:crud.go
示例16: GetEndpointByToken
func (r *DaoResource) GetEndpointByToken(token string) (*model.Endpoint, error) {
var entity model.Endpoint
q := sq.Select("id", "token", "provider_id", "application_id", "attributes", "created_at", "updated_at", "enabled").
From(model.TableEndpoints).
Where("token = ?", token)
err := r.Storage.SelectOne(&entity, &q)
return &entity, err
}
开发者ID:kihamo,项目名称:shadow-sender,代码行数:10,代码来源:endpoint.go
示例17: GetAllProfiles
func GetAllProfiles(user_id int, timestamp int64) []profile.Profile {
query := squirrel.Select(`
id, user_id, timestamp,
agent, level, ap,
unique_portals_visited, portals_discovered, xm_collected,
hacks, resonators_deployed, links_created, control_fields_created, mind_units_captured,
longest_link_ever_created, largest_control_field, xm_recharged, portals_captured,
unique_portals_captured, mods_deployed,
resonators_destroyed, portals_neutralized, enemy_links_destroyed, enemy_control_fields_destroyed,
distance_walked,
max_time_portal_held, max_time_link_maintained, max_link_length_x_days, max_time_field_held,
largest_field_mus_x_days,
glyph_hack_points, consecutive_days_hacking,
unique_missions_completed,
agents_successfully_recruited,
innovator
`).From("tiers_profiles").OrderBy("timestamp ASC")
query = query.Where(
squirrel.And{
squirrel.Eq{"user_id": user_id},
squirrel.Expr("timestamp >= ?", timestamp),
},
)
// XXX: Handle errors.
rows, _ := query.RunWith(db).Query()
defer rows.Close()
var profiles []profile.Profile
for rows.Next() {
var p profile.Profile
rows.Scan(
&p.Id, &p.UserId, &p.Timestamp,
&p.Nick, &p.Level, &p.AP,
&p.UniquePortalsVisited, &p.PortalsDiscovered, &p.XMCollected,
&p.Hacks, &p.ResonatorsDeployed, &p.LinksCreated, &p.ControlFieldsCreated, &p.MindUnitsCaptured,
&p.LongestLinkEverCreated, &p.LargestControlField, &p.XMRecharged, &p.PortalsCaptured,
&p.UniquePortalsCaptured, &p.ModsDeployed,
&p.ResonatorsDestroyed, &p.PortalsNeutralized, &p.EnemyLinksDestroyed, &p.EnemyControlFieldsDestroyed,
&p.DistanceWalked,
&p.MaxTimePortalHeld, &p.MaxTimeLinkMaintained, &p.MaxLinkLengthXDays, &p.MaxTimeFieldHeld,
&p.LargestFieldMUsXDays,
&p.GlyphHackPoints, &p.ConsecutiveDaysHacking,
&p.UniqueMissionsCompleted,
&p.AgentsSuccessfullyRecruited,
&p.InnovatorLevel,
)
profiles = append(profiles, p)
}
return profiles
}
开发者ID:haste,项目名称:tiers,代码行数:55,代码来源:user.go
示例18: Select
func (q ConnectedAssetsQuery) Select(ctx context.Context, dest interface{}) error {
assets, ok := dest.(*[]xdr.Asset)
if !ok {
return errors.New("dest is not *[]xdr.Asset")
}
var (
t xdr.AssetType
c string
i string
)
err := q.SellingAsset.Extract(&t, &c, &i)
if err != nil {
return err
}
sql := sq.Select(
"buyingassettype AS type",
"coalesce(buyingassetcode, '') AS code",
"coalesce(buyingissuer, '') AS issuer").
From("offers").
Where(sq.Eq{"sellingassettype": t}).
GroupBy("buyingassettype", "buyingassetcode", "buyingissuer")
if t != xdr.AssetTypeAssetTypeNative {
sql = sql.Where(sq.Eq{"sellingassetcode": c, "sellingissuer": i})
}
var rows []struct {
Type xdr.AssetType
Code string
Issuer string
}
err = q.SqlQuery.Select(ctx, sql, &rows)
if err != nil {
return err
}
results := make([]xdr.Asset, len(rows))
*assets = results
for i, r := range rows {
results[i], err = assetFromDB(r.Type, r.Code, r.Issuer)
if err != nil {
return err
}
}
return nil
}
开发者ID:zenododobird,项目名称:horizon,代码行数:54,代码来源:query_connected_assets.go
示例19: FindUsers
func FindUsers() ([]User, error) {
qb := squirrel.Select("*").From("user")
var users []User
err := db.LoadCollection(&qb, &users)
if err != nil {
return nil, err
}
return users, nil
}
开发者ID:nizsheanez,项目名称:ria,代码行数:11,代码来源:user.go
示例20: FindByIdInTable
func (*Loader) FindByIdInTable(tableName string, id int, buf interface{}) error {
qb := squirrel.Select("*").
From(tableName).
Where("id = ?", id)
err := LoadStruct(&qb, buf)
if err != nil {
return err
}
return nil
}
开发者ID:nizsheanez,项目名称:ria,代码行数:12,代码来源:loader.go
注:本文中的github.com/lann/squirrel.Select函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论