Skip to content
This repository has been archived by the owner on Nov 22, 2018. It is now read-only.

Commit

Permalink
Export the list type.
Browse files Browse the repository at this point in the history
This change is considered to be a non breaking one. Previously, clients
were able to keep instances of list solely by inferring its type in the
short variable declaration syntax (":=") and pass it back to DB.Execute.
Existing code, if any, should thus compile without changes.

Fixes #19
  • Loading branch information
Jan Mercl committed Dec 5, 2013
1 parent ebb3d88 commit ccb9505
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
6 changes: 4 additions & 2 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func rnds16(rng *rand.Rand, n int) string {
return strings.Join(a, "")
}

func benchmarkSelect(b *testing.B, n int, sel list, ts testDB) {
func benchmarkSelect(b *testing.B, n int, sel List, ts testDB) {
db, err := ts.setup()
if err != nil {
b.Error(err)
Expand Down Expand Up @@ -390,7 +390,9 @@ func TestString(t *testing.T) {
continue
}

_ = l.String()
if s := l.String(); len(s) == 0 {
t.Fatal("List.String() returned empty string")
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"time"
)

//TODO agg bigint, bigrat, time, duration
//DONE agg bigint, bigrat, time, duration

var builtin = map[string]struct {
f func([]interface{}, map[interface{}]interface{}) (interface{}, error)
Expand Down
15 changes: 8 additions & 7 deletions ql.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ const (
stCollectingTriggered
)

type list struct {
type List struct {
l []stmt
}

func (l list) String() string {
// String implements fmt.Stringer
func (l List) String() string {
var b bytes.Buffer
f := strutil.IndentFormatter(&b, "\t")
for _, s := range l.l {
Expand Down Expand Up @@ -806,21 +807,21 @@ func (db *DB) Run(ctx *TCtx, ql string, arg ...interface{}) (rs []Recordset, ind
// DB.Execute or an error if any.
//
// Compile is safe for concurrent use by multiple goroutines.
func Compile(src string) (list, error) {
func Compile(src string) (List, error) {
l := newLexer(src)
if yyParse(l) != 0 {
return list{}, l.errs[0]
return List{}, l.errs[0]
}

return list{l.list}, nil
return List{l.list}, nil
}

// MustCompile is like Compile but panics if the ql statements in src cannot be
// compiled. It simplifies safe initialization of global variables holding
// compiled statement lists for DB.Execute.
//
// MustCompile is safe for concurrent use by multiple goroutines.
func MustCompile(src string) list {
func MustCompile(src string) List {
list, err := Compile(src)
if err != nil {
panic("ql: Compile(" + strconv.Quote(src) + "): " + err.Error()) // panic ok here
Expand Down Expand Up @@ -908,7 +909,7 @@ func MustCompile(src string) list {
// Durability: Transactions are durable. A two phase commit protocol and a
// write ahead log is used. Database is recovered after a crash from the write
// ahead log automatically on open.
func (db *DB) Execute(ctx *TCtx, l list, arg ...interface{}) (rs []Recordset, index int, err error) {
func (db *DB) Execute(ctx *TCtx, l List, arg ...interface{}) (rs []Recordset, index int, err error) {
tnl0 := -1

var s stmt
Expand Down
4 changes: 2 additions & 2 deletions storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const sample = `
COMMIT;
`

func parse(t *testing.T, src string) (ls list, err error) {
func parse(t *testing.T, src string) (ls List, err error) {
//dbg("----\n%s----\n", src)
//t.Log(src)

Expand All @@ -203,7 +203,7 @@ func parse(t *testing.T, src string) (ls list, err error) {
return
}

return list{l.list}, nil
return List{l.list}, nil
}

// Test provides a testing facility for alternative storage implementations.
Expand Down

0 comments on commit ccb9505

Please sign in to comment.