Skip to content
This repository was archived by the owner on Sep 12, 2019. It is now read-only.

Commit 6dd4d30

Browse files
committed
Update github.com/stellar/go
1 parent 250aafb commit 6dd4d30

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+4975
-257
lines changed

src/github.com/stellar/gateway/bridge/handlers/request_handler_payment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (rh *RequestHandler) Payment(w http.ResponseWriter, r *http.Request) {
220220
}
221221

222222
memoType = destinationObject.MemoType
223-
memo = destinationObject.Memo
223+
memo = destinationObject.Memo.Value
224224
}
225225

226226
var memoMutator interface{}

src/github.com/stellar/gateway/bridge/handlers/request_handler_payment_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func TestRequestHandlerPayment(t *testing.T) {
268268
&federation.NameResponse{
269269
AccountID: "GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632",
270270
MemoType: "text",
271-
Memo: "125",
271+
Memo: federation.Memo{"125"},
272272
},
273273
nil,
274274
).Once()

src/github.com/stellar/gateway/compliance/handlers/request_handler_send.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func (rh *RequestHandler) HandlerSend(c web.C, w http.ResponseWriter, r *http.Re
175175
Nonce: rh.NonceGenerator.Generate(),
176176
Transaction: compliance.Transaction{
177177
SenderInfo: senderInfo,
178-
Route: destinationObject.Memo,
178+
Route: destinationObject.Memo.Value,
179179
Extra: request.ExtraMemo,
180180
},
181181
}

src/github.com/stellar/gateway/compliance/handlers/request_handler_send_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func TestRequestHandlerSend(t *testing.T) {
135135
).Return(&federation.NameResponse{
136136
AccountID: "GAMVF7G4GJC4A7JMFJWLUAEIBFQD5RT3DCB5DC5TJDEKQBBACQ4JZVEE",
137137
MemoType: "text",
138-
Memo: "bob",
138+
Memo: federation.Memo{"bob"},
139139
}, nil).Once()
140140

141141
mockStellartomlResolver.On(
@@ -252,7 +252,7 @@ func TestRequestHandlerSend(t *testing.T) {
252252
).Return(&federation.NameResponse{
253253
AccountID: "GAMVF7G4GJC4A7JMFJWLUAEIBFQD5RT3DCB5DC5TJDEKQBBACQ4JZVEE",
254254
MemoType: "text",
255-
Memo: "bob",
255+
Memo: federation.Memo{"bob"},
256256
}, nil).Once()
257257

258258
mockStellartomlResolver.On(

src/github.com/stellar/gateway/db/repository.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ type RepositoryInterface interface {
1717

1818
// Repository helps getting data from DB
1919
type Repository struct {
20-
repo *db.Repo
20+
repo *db.Session
2121
log *logrus.Entry
2222
}
2323

2424
// NewRepository creates a new Repository using driver
2525
func NewRepository(driver Driver) (r Repository) {
26-
r.repo = &db.Repo{DB: driver.DB()}
26+
r.repo = &db.Session{DB: driver.DB()}
2727
r.log = logrus.WithFields(logrus.Fields{
2828
"service": "Repository",
2929
})

vendor/manifest

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
"revision": "5c4df71dfe9ac89ef6287afc05e4c1b16ae65a1e",
88
"branch": "master"
99
},
10+
{
11+
"importpath": "github.com/Masterminds/squirrel",
12+
"repository": "https://github.com/Masterminds/squirrel",
13+
"revision": "20f192218cf52a73397fa2df45bdda720f3e47c8",
14+
"branch": "v1"
15+
},
1016
{
1117
"importpath": "github.com/Sirupsen/logrus",
1218
"repository": "https://github.com/Sirupsen/logrus",
@@ -458,7 +464,7 @@
458464
{
459465
"importpath": "github.com/stellar/go",
460466
"repository": "https://github.com/stellar/go",
461-
"revision": "2f5094023dd16538a61a0ad2820d9a2a3ba9afba",
467+
"revision": "d73c794a1a2352e7020ad728697aaa5664bc62fa",
462468
"branch": "master"
463469
},
464470
{
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Squirrel
2+
The Masterminds
3+
Copyright (C) 2014-2015, Lann Martin
4+
Copyright (C) 2015-2016, Google
5+
Copyright (C) 2015, Matt Farina and Matt Butcher
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Squirrel - fluent SQL generator for Go
2+
3+
```go
4+
import "gopkg.in/Masterminds/squirrel.v1"
5+
```
6+
or if you prefer using `master` (which may be arbitrarily ahead of or behind `v1`):
7+
8+
**NOTE:** as of Go 1.6, `go get` correctly clones the Github default branch (which is `v1` in this repo).
9+
```go
10+
import "github.com/Masterminds/squirrel"
11+
```
12+
13+
[![GoDoc](https://godoc.org/github.com/Masterminds/squirrel?status.png)](https://godoc.org/github.com/Masterminds/squirrel)
14+
[![Build Status](https://travis-ci.org/Masterminds/squirrel.svg?branch=v1)](https://travis-ci.org/Masterminds/squirrel)
15+
16+
_**Note:** This project has moved from `github.com/lann/squirrel` to
17+
`github.com/Masterminds/squirrel`. Lann remains the architect of the
18+
project, but we're helping him curate.
19+
20+
**Squirrel is not an ORM.** For an application of Squirrel, check out
21+
[structable, a table-struct mapper](https://github.com/technosophos/structable)
22+
23+
24+
Squirrel helps you build SQL queries from composable parts:
25+
26+
```go
27+
import sq "github.com/Masterminds/squirrel"
28+
29+
users := sq.Select("*").From("users").Join("emails USING (email_id)")
30+
31+
active := users.Where(sq.Eq{"deleted_at": nil})
32+
33+
sql, args, err := active.ToSql()
34+
35+
sql == "SELECT * FROM users JOIN emails USING (email_id) WHERE deleted_at IS NULL"
36+
```
37+
38+
```go
39+
sql, args, err := sq.
40+
Insert("users").Columns("name", "age").
41+
Values("moe", 13).Values("larry", sq.Expr("? + 5", 12)).
42+
ToSql()
43+
44+
sql == "INSERT INTO users (name,age) VALUES (?,?),(?,? + 5)"
45+
```
46+
47+
Squirrel can also execute queries directly:
48+
49+
```go
50+
stooges := users.Where(sq.Eq{"username": []string{"moe", "larry", "curly", "shemp"}})
51+
three_stooges := stooges.Limit(3)
52+
rows, err := three_stooges.RunWith(db).Query()
53+
54+
// Behaves like:
55+
rows, err := db.Query("SELECT * FROM users WHERE username IN (?,?,?,?) LIMIT 3",
56+
"moe", "larry", "curly", "shemp")
57+
```
58+
59+
Squirrel makes conditional query building a breeze:
60+
61+
```go
62+
if len(q) > 0 {
63+
users = users.Where("name LIKE ?", fmt.Sprint("%", q, "%"))
64+
}
65+
```
66+
67+
Squirrel wants to make your life easier:
68+
69+
```go
70+
// StmtCache caches Prepared Stmts for you
71+
dbCache := sq.NewStmtCacher(db)
72+
73+
// StatementBuilder keeps your syntax neat
74+
mydb := sq.StatementBuilder.RunWith(dbCache)
75+
select_users := mydb.Select("*").From("users")
76+
```
77+
78+
Squirrel loves PostgreSQL:
79+
80+
```go
81+
psql := sq.StatementBuilder.PlaceholderFormat(sq.Dollar)
82+
83+
// You use question marks for placeholders...
84+
sql, _, _ := psql.Select("*").From("elephants").Where("name IN (?,?)", "Dumbo", "Verna")
85+
86+
/// ...squirrel replaces them using PlaceholderFormat.
87+
sql == "SELECT * FROM elephants WHERE name IN ($1,$2)"
88+
89+
90+
/// You can retrieve id ...
91+
query := sq.Insert("nodes").
92+
Columns("uuid", "type", "data").
93+
Values(node.Uuid, node.Type, node.Data).
94+
Suffix("RETURNING \"id\"").
95+
RunWith(m.db).
96+
PlaceholderFormat(sq.Dollar)
97+
98+
query.QueryRow().Scan(&node.id)
99+
```
100+
101+
You can escape question mask by inserting two question marks:
102+
103+
```sql
104+
SELECT * FROM nodes WHERE meta->'format' ??| array[?,?]
105+
```
106+
107+
will generate with the Dollar Placeholder:
108+
109+
```sql
110+
SELECT * FROM nodes WHERE meta->'format' ?| array[$1,$2]
111+
```
112+
113+
114+
115+
## License
116+
117+
Squirrel is released under the
118+
[MIT License](http://www.opensource.org/licenses/MIT).
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package squirrel
2+
3+
import (
4+
"bytes"
5+
"errors"
6+
7+
"github.com/lann/builder"
8+
)
9+
10+
func init() {
11+
builder.Register(CaseBuilder{}, caseData{})
12+
}
13+
14+
// sqlizerBuffer is a helper that allows to write many Sqlizers one by one
15+
// without constant checks for errors that may come from Sqlizer
16+
type sqlizerBuffer struct {
17+
bytes.Buffer
18+
args []interface{}
19+
err error
20+
}
21+
22+
// WriteSql converts Sqlizer to SQL strings and writes it to buffer
23+
func (b *sqlizerBuffer) WriteSql(item Sqlizer) {
24+
if b.err != nil {
25+
return
26+
}
27+
28+
var str string
29+
var args []interface{}
30+
str, args, b.err = item.ToSql()
31+
32+
if b.err != nil {
33+
return
34+
}
35+
36+
b.WriteString(str)
37+
b.WriteByte(' ')
38+
b.args = append(b.args, args...)
39+
}
40+
41+
func (b *sqlizerBuffer) ToSql() (string, []interface{}, error) {
42+
return b.String(), b.args, b.err
43+
}
44+
45+
// whenPart is a helper structure to describe SQLs "WHEN ... THEN ..." expression
46+
type whenPart struct {
47+
when Sqlizer
48+
then Sqlizer
49+
}
50+
51+
func newWhenPart(when interface{}, then interface{}) whenPart {
52+
return whenPart{newPart(when), newPart(then)}
53+
}
54+
55+
// caseData holds all the data required to build a CASE SQL construct
56+
type caseData struct {
57+
What Sqlizer
58+
WhenParts []whenPart
59+
Else Sqlizer
60+
}
61+
62+
// ToSql implements Sqlizer
63+
func (d *caseData) ToSql() (sqlStr string, args []interface{}, err error) {
64+
if len(d.WhenParts) == 0 {
65+
err = errors.New("case expression must contain at lease one WHEN clause")
66+
67+
return
68+
}
69+
70+
sql := sqlizerBuffer{}
71+
72+
sql.WriteString("CASE ")
73+
if d.What != nil {
74+
sql.WriteSql(d.What)
75+
}
76+
77+
for _, p := range d.WhenParts {
78+
sql.WriteString("WHEN ")
79+
sql.WriteSql(p.when)
80+
sql.WriteString("THEN ")
81+
sql.WriteSql(p.then)
82+
}
83+
84+
if d.Else != nil {
85+
sql.WriteString("ELSE ")
86+
sql.WriteSql(d.Else)
87+
}
88+
89+
sql.WriteString("END")
90+
91+
return sql.ToSql()
92+
}
93+
94+
// CaseBuilder builds SQL CASE construct which could be used as parts of queries.
95+
type CaseBuilder builder.Builder
96+
97+
// ToSql builds the query into a SQL string and bound args.
98+
func (b CaseBuilder) ToSql() (string, []interface{}, error) {
99+
data := builder.GetStruct(b).(caseData)
100+
return data.ToSql()
101+
}
102+
103+
// what sets optional value for CASE construct "CASE [value] ..."
104+
func (b CaseBuilder) what(expr interface{}) CaseBuilder {
105+
return builder.Set(b, "What", newPart(expr)).(CaseBuilder)
106+
}
107+
108+
// When adds "WHEN ... THEN ..." part to CASE construct
109+
func (b CaseBuilder) When(when interface{}, then interface{}) CaseBuilder {
110+
// TODO: performance hint: replace slice of WhenPart with just slice of parts
111+
// where even indices of the slice belong to "when"s and odd indices belong to "then"s
112+
return builder.Append(b, "WhenParts", newWhenPart(when, then)).(CaseBuilder)
113+
}
114+
115+
// What sets optional "ELSE ..." part for CASE construct
116+
func (b CaseBuilder) Else(expr interface{}) CaseBuilder {
117+
return builder.Set(b, "Else", newPart(expr)).(CaseBuilder)
118+
}

0 commit comments

Comments
 (0)