-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
bubbler.go
51 lines (42 loc) · 1.04 KB
/
bubbler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package fizz
import (
"os"
"strings"
"github.com/gobuffalo/plush/v4"
)
type BubbleType int
type Bubbler struct {
Translator
data []string
}
func NewBubbler(t Translator) *Bubbler {
return &Bubbler{
Translator: t,
data: []string{},
}
}
func (b *Bubbler) String() string {
return strings.Join(b.data, "\n")
}
func (b *Bubbler) Bubble(s string) (string, error) {
f := fizzer{b}
ctx := plush.NewContextWith(map[string]interface{}{
"exec": f.Exec(os.Stdout),
"create_table": f.CreateTable,
"change_column": f.ChangeColumn,
"add_column": f.AddColumn,
"drop_column": f.DropColumn,
"rename_column": f.RenameColumn,
"raw": f.RawSQL,
"sql": f.RawSQL,
"add_index": f.AddIndex,
"drop_index": f.DropIndex,
"rename_index": f.RenameIndex,
"add_foreign_key": f.AddForeignKey,
"drop_foreign_key": f.DropForeignKey,
"drop_table": f.DropTable,
"rename_table": f.RenameTable,
})
err := plush.RunScript(s, ctx)
return b.String(), err
}