sqlboiler/templates_test/singleton/boil_queries_test.tpl

36 lines
834 B
Smarty
Raw 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-13 07:43:29 +02:00
var rgxPGFkey = regexp.MustCompile(`(?m)(?s)^ALTER TABLE ONLY.*?ADD CONSTRAINT.*?FOREIGN KEY.*?;\n`)
var rgxMySQLkey = regexp.MustCompile(`(?m)((,\n)?\s+CONSTRAINT.*?FOREIGN KEY.*?\n)+`)
2016-09-13 07:43:29 +02:00
func newFKeyDestroyer(reader io.Reader) io.Reader {
return &fKeyDestroyer{
reader: reader,
}
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-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-13 07:43:29 +02:00
f.buf = bytes.NewBuffer(rgxMySQLkey.ReplaceAll(rgxPGFkey.ReplaceAll(all, []byte{}), []byte{}))
}
2016-09-13 07:43:29 +02:00
return f.buf.Read(b)
}