sqlboiler/templates_test/singleton/boil_queries_test.tpl

39 lines
866 B
Smarty
Raw Permalink Normal View History

var dbNameRand *rand.Rand
func MustTx(transactor boil.Transactor, err error) boil.Transactor {
if err != nil {
panic(fmt.Sprintf("Cannot create a transactor: %s", err))
}
return transactor
}
2016-09-14 06:46:58 +02:00
var rgxPGFkey = regexp.MustCompile(`(?m)^ALTER TABLE ONLY .*\n\s+ADD CONSTRAINT .*? FOREIGN KEY .*?;\n`)
2016-09-13 07:43:29 +02:00
var rgxMySQLkey = regexp.MustCompile(`(?m)((,\n)?\s+CONSTRAINT.*?FOREIGN KEY.*?\n)+`)
2016-09-14 06:46:58 +02:00
func newFKeyDestroyer(regex *regexp.Regexp, reader io.Reader) io.Reader {
2016-09-13 07:43:29 +02:00
return &fKeyDestroyer{
reader: reader,
2016-09-14 06:46:58 +02:00
rgx: regex,
}
2016-09-13 07:43:29 +02:00
}
2016-09-13 07:43:29 +02:00
type fKeyDestroyer struct {
reader io.Reader
buf *bytes.Buffer
2016-09-14 06:46:58 +02:00
rgx *regexp.Regexp
}
2016-09-13 07:43:29 +02:00
func (f *fKeyDestroyer) Read(b []byte) (int, error) {
if f.buf == nil {
all, err := ioutil.ReadAll(f.reader)
if err != nil {
return 0, err
}
2016-09-14 06:46:58 +02:00
f.buf = bytes.NewBuffer(f.rgx.ReplaceAll(all, []byte{}))
}
2016-09-13 07:43:29 +02:00
return f.buf.Read(b)
}