2016-02-23 09:27:32 +01:00
|
|
|
package cmds
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2016-03-27 17:03:14 +02:00
|
|
|
"text/template"
|
2016-02-23 09:27:32 +01:00
|
|
|
|
|
|
|
"github.com/BurntSushi/toml"
|
|
|
|
)
|
|
|
|
|
2016-03-28 10:17:41 +02:00
|
|
|
// sqlBoilerImports defines the list of default template imports.
|
2016-03-27 17:03:14 +02:00
|
|
|
var sqlBoilerImports = imports{
|
|
|
|
standard: importList{
|
|
|
|
`"errors"`,
|
|
|
|
`"fmt"`,
|
|
|
|
},
|
|
|
|
thirdparty: importList{
|
|
|
|
`"github.com/pobri19/sqlboiler/boil"`,
|
|
|
|
},
|
2016-03-21 04:52:36 +01:00
|
|
|
}
|
2016-02-23 09:27:32 +01:00
|
|
|
|
2016-03-28 10:17:41 +02:00
|
|
|
// sqlBoilerTestImports defines the list of default test template imports.
|
2016-03-27 17:03:14 +02:00
|
|
|
var sqlBoilerTestImports = imports{
|
|
|
|
standard: importList{
|
|
|
|
`"testing"`,
|
|
|
|
`"os"`,
|
|
|
|
`"os/exec"`,
|
|
|
|
`"fmt"`,
|
|
|
|
`"io/ioutil"`,
|
|
|
|
`"bytes"`,
|
|
|
|
`"errors"`,
|
|
|
|
},
|
|
|
|
thirdparty: importList{
|
|
|
|
`"github.com/BurntSushi/toml"`,
|
|
|
|
},
|
2016-03-21 04:52:36 +01:00
|
|
|
}
|
2016-03-20 16:57:25 +01:00
|
|
|
|
2016-03-27 17:03:14 +02:00
|
|
|
// sqlBoilerTypeImports imports are only included in the template output if the database
|
|
|
|
// requires one of the following special types. Check TranslateColumnType to see the type assignments.
|
|
|
|
var sqlBoilerTypeImports = map[string]imports{
|
|
|
|
"null.Int": imports{
|
|
|
|
thirdparty: importList{`"gopkg.in/guregu/null.v3"`},
|
|
|
|
},
|
|
|
|
"null.String": imports{
|
|
|
|
thirdparty: importList{`"gopkg.in/guregu/null.v3"`},
|
|
|
|
},
|
|
|
|
"null.Bool": imports{
|
|
|
|
thirdparty: importList{`"gopkg.in/guregu/null.v3"`},
|
|
|
|
},
|
|
|
|
"null.Float": imports{
|
|
|
|
thirdparty: importList{`"gopkg.in/guregu/null.v3"`},
|
|
|
|
},
|
|
|
|
"null.Time": imports{
|
|
|
|
thirdparty: importList{`"gopkg.in/guregu/null.v3"`},
|
|
|
|
},
|
|
|
|
"time.Time": imports{
|
|
|
|
standard: importList{`"time"`},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-03-28 10:17:41 +02:00
|
|
|
// sqlBoilerDriverTestImports defines the test template imports
|
2016-03-27 17:03:14 +02:00
|
|
|
// for the particular database interfaces
|
|
|
|
var sqlBoilerDriverTestImports = map[string]imports{
|
|
|
|
"postgres": imports{
|
|
|
|
standard: importList{`"database/sql"`},
|
|
|
|
thirdparty: importList{`_ "github.com/lib/pq"`},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// sqlBoilerTemplateFuncs is a map of all the functions that get passed into the templates.
|
|
|
|
// If you wish to pass a new function into your own template, add a pointer to it here.
|
|
|
|
var sqlBoilerTemplateFuncs = template.FuncMap{
|
|
|
|
"singular": singular,
|
|
|
|
"plural": plural,
|
|
|
|
"titleCase": titleCase,
|
|
|
|
"titleCaseSingular": titleCaseSingular,
|
|
|
|
"titleCasePlural": titleCasePlural,
|
|
|
|
"camelCase": camelCase,
|
|
|
|
"camelCaseSingular": camelCaseSingular,
|
|
|
|
"camelCasePlural": camelCasePlural,
|
|
|
|
"makeDBName": makeDBName,
|
|
|
|
"selectParamNames": selectParamNames,
|
|
|
|
"insertParamNames": insertParamNames,
|
|
|
|
"insertParamFlags": insertParamFlags,
|
|
|
|
"insertParamVariables": insertParamVariables,
|
|
|
|
"scanParamNames": scanParamNames,
|
|
|
|
"hasPrimaryKey": hasPrimaryKey,
|
|
|
|
"getPrimaryKey": getPrimaryKey,
|
|
|
|
"updateParamNames": updateParamNames,
|
|
|
|
"updateParamVariables": updateParamVariables,
|
|
|
|
}
|
2016-03-20 16:57:25 +01:00
|
|
|
|
2016-03-21 04:52:36 +01:00
|
|
|
// LoadConfigFile loads the toml config file into the cfg object
|
2016-04-03 08:21:45 +02:00
|
|
|
func (c *CmdData) LoadConfigFile(filename string) error {
|
2016-03-27 17:03:14 +02:00
|
|
|
cfg := &Config{}
|
|
|
|
|
2016-03-21 04:52:36 +01:00
|
|
|
_, err := toml.DecodeFile(filename, &cfg)
|
2016-02-23 09:27:32 +01:00
|
|
|
|
|
|
|
if os.IsNotExist(err) {
|
2016-03-27 17:03:14 +02:00
|
|
|
return fmt.Errorf("Failed to find the toml configuration file %s: %s", filename, err)
|
2016-02-23 09:27:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
2016-03-27 17:03:14 +02:00
|
|
|
return fmt.Errorf("Failed to decode toml configuration file: %s", err)
|
2016-02-23 09:27:32 +01:00
|
|
|
}
|
2016-03-20 16:57:25 +01:00
|
|
|
|
2016-03-27 17:03:14 +02:00
|
|
|
cmdData.Config = cfg
|
|
|
|
return nil
|
2016-02-23 09:27:32 +01:00
|
|
|
}
|