Rename Exclude -> Blacklist
This commit is contained in:
parent
c65c1f6a2c
commit
16b6a2b176
10 changed files with 40 additions and 41 deletions
12
README.md
12
README.md
|
@ -223,12 +223,12 @@ not to pass them through the command line or environment variables:
|
|||
| Name | Default |
|
||||
| --- | --- |
|
||||
| basedir | none |
|
||||
| schema | "public" |
|
||||
| schema | "public" |
|
||||
| pkgname | "models" |
|
||||
| output | "models" |
|
||||
| whitelist | [ ] |
|
||||
| exclude | [ ] |
|
||||
| tag | [ ] |
|
||||
| whitelist | [] |
|
||||
| blacklist | [] |
|
||||
| tag | [] |
|
||||
| debug | false |
|
||||
| no-hooks | false |
|
||||
| no-tests | false |
|
||||
|
@ -261,14 +261,14 @@ Examples:
|
|||
sqlboiler postgres
|
||||
|
||||
Flags:
|
||||
-b, --basedir string The base directory has the templates and templates_test folders
|
||||
-b, --blacklist stringSlice Do not include these tables in your generated package
|
||||
-w, --whitelist stringSlice Only include these tables in your generated package
|
||||
-x, --exclude stringSlice Tables to be excluded from the generated package
|
||||
-s, --schema string The name of your database schema, for databases that support real schemas (default "public")
|
||||
-p, --pkgname string The name you wish to assign to your generated package (default "models")
|
||||
-o, --output string The name of the folder to output to (default "models")
|
||||
-t, --tag stringSlice Struct tags to be included on your models in addition to json, yaml, toml
|
||||
-d, --debug Debug mode prints stack traces on error
|
||||
--basedir string The base directory has the templates and templates_test folders
|
||||
--no-auto-timestamps Disable automatic timestamps for created_at/updated_at
|
||||
--no-hooks Disable hooks feature for your models
|
||||
--no-tests Disable generated go test files
|
||||
|
|
|
@ -9,12 +9,12 @@ import (
|
|||
type MockDriver struct{}
|
||||
|
||||
// TableNames returns a list of mock table names
|
||||
func (m *MockDriver) TableNames(schema string, whitelist, exclude []string) ([]string, error) {
|
||||
func (m *MockDriver) TableNames(schema string, whitelist, blacklist []string) ([]string, error) {
|
||||
if len(whitelist) > 0 {
|
||||
return whitelist, nil
|
||||
}
|
||||
tables := []string{"pilots", "jets", "airports", "licenses", "hangars", "languages", "pilot_languages"}
|
||||
return strmangle.SetComplement(tables, exclude), nil
|
||||
return strmangle.SetComplement(tables, blacklist), nil
|
||||
}
|
||||
|
||||
// Columns returns a list of mock columns
|
||||
|
|
|
@ -73,9 +73,8 @@ func (m *MySQLDriver) UseLastInsertID() bool {
|
|||
|
||||
// TableNames connects to the postgres database and
|
||||
// retrieves all table names from the information_schema where the
|
||||
// table schema is public. It excludes common migration tool tables
|
||||
// such as gorp_migrations
|
||||
func (m *MySQLDriver) TableNames(schema string, whitelist, exclude []string) ([]string, error) {
|
||||
// table schema is public.
|
||||
func (m *MySQLDriver) TableNames(schema string, whitelist, blacklist []string) ([]string, error) {
|
||||
var names []string
|
||||
|
||||
query := fmt.Sprintf(`select table_name from information_schema.tables where table_schema = ?`)
|
||||
|
@ -85,10 +84,10 @@ func (m *MySQLDriver) TableNames(schema string, whitelist, exclude []string) ([]
|
|||
for _, w := range whitelist {
|
||||
args = append(args, w)
|
||||
}
|
||||
} else if len(exclude) > 0 {
|
||||
query += fmt.Sprintf("and table_name not in (%s);", strings.Repeat(",?", len(exclude))[1:])
|
||||
for _, e := range exclude {
|
||||
args = append(args, e)
|
||||
} else if len(blacklist) > 0 {
|
||||
query += fmt.Sprintf("and table_name not in (%s);", strings.Repeat(",?", len(blacklist))[1:])
|
||||
for _, b := range blacklist {
|
||||
args = append(args, b)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -82,8 +82,8 @@ func (p *PostgresDriver) UseLastInsertID() bool {
|
|||
|
||||
// TableNames connects to the postgres database and
|
||||
// retrieves all table names from the information_schema where the
|
||||
// table schema is schema. It uses a whitelist and exclude list.
|
||||
func (p *PostgresDriver) TableNames(schema string, whitelist, exclude []string) ([]string, error) {
|
||||
// table schema is schema. It uses a whitelist and blacklist.
|
||||
func (p *PostgresDriver) TableNames(schema string, whitelist, blacklist []string) ([]string, error) {
|
||||
var names []string
|
||||
|
||||
query := fmt.Sprintf(`select table_name from information_schema.tables where table_schema = ?`)
|
||||
|
@ -93,10 +93,10 @@ func (p *PostgresDriver) TableNames(schema string, whitelist, exclude []string)
|
|||
for _, w := range whitelist {
|
||||
args = append(args, w)
|
||||
}
|
||||
} else if len(exclude) > 0 {
|
||||
query += fmt.Sprintf("and table_name not in (%s);", strmangle.Placeholders(len(exclude), 1, 1))
|
||||
for _, e := range exclude {
|
||||
args = append(args, e)
|
||||
} else if len(blacklist) > 0 {
|
||||
query += fmt.Sprintf("and table_name not in (%s);", strmangle.Placeholders(len(blacklist), 1, 1))
|
||||
for _, b := range blacklist {
|
||||
args = append(args, b)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import "github.com/pkg/errors"
|
|||
// Interface for a database driver. Functionality required to support a specific
|
||||
// database type (eg, MySQL, Postgres etc.)
|
||||
type Interface interface {
|
||||
TableNames(schema string, whitelist, exclude []string) ([]string, error)
|
||||
TableNames(schema string, whitelist, blacklist []string) ([]string, error)
|
||||
Columns(schema, tableName string) ([]Column, error)
|
||||
PrimaryKeyInfo(schema, tableName string) (*PrimaryKey, error)
|
||||
ForeignKeyInfo(schema, tableName string) ([]ForeignKey, error)
|
||||
|
@ -25,11 +25,11 @@ type Interface interface {
|
|||
}
|
||||
|
||||
// Tables returns the metadata for all tables, minus the tables
|
||||
// specified in the exclude slice.
|
||||
func Tables(db Interface, schema string, whitelist, exclude []string) ([]Table, error) {
|
||||
// specified in the blacklist.
|
||||
func Tables(db Interface, schema string, whitelist, blacklist []string) ([]Table, error) {
|
||||
var err error
|
||||
|
||||
names, err := db.TableNames(schema, whitelist, exclude)
|
||||
names, err := db.TableNames(schema, whitelist, blacklist)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unable to get table names")
|
||||
}
|
||||
|
|
|
@ -13,12 +13,12 @@ func (m mockDriver) UseLastInsertID() bool { return false }
|
|||
func (m mockDriver) Open() error { return nil }
|
||||
func (m mockDriver) Close() {}
|
||||
|
||||
func (m mockDriver) TableNames(whitelist, exclude []string) ([]string, error) {
|
||||
func (m mockDriver) TableNames(whitelist, blacklist []string) ([]string, error) {
|
||||
if len(whitelist) > 0 {
|
||||
return whitelist, nil
|
||||
}
|
||||
tables := []string{"pilots", "jets", "airports", "licenses", "hangars", "languages", "pilot_languages"}
|
||||
return strmangle.SetComplement(tables, exclude), nil
|
||||
return strmangle.SetComplement(tables, blacklist), nil
|
||||
}
|
||||
|
||||
// Columns returns a list of mock columns
|
||||
|
|
|
@ -8,7 +8,7 @@ type Config struct {
|
|||
OutFolder string
|
||||
BaseDir string
|
||||
WhitelistTables []string
|
||||
ExcludeTables []string
|
||||
BlacklistTables []string
|
||||
Tags []string
|
||||
Debug bool
|
||||
NoTests bool
|
||||
|
|
12
main.go
12
main.go
|
@ -63,8 +63,8 @@ func main() {
|
|||
rootCmd.PersistentFlags().StringP("output", "o", "models", "The name of the folder to output to")
|
||||
rootCmd.PersistentFlags().StringP("schema", "s", "public", "The name of your database schema, for databases that support real schemas")
|
||||
rootCmd.PersistentFlags().StringP("pkgname", "p", "models", "The name you wish to assign to your generated package")
|
||||
rootCmd.PersistentFlags().StringP("basedir", "b", "", "The base directory has the templates and templates_test folders")
|
||||
rootCmd.PersistentFlags().StringSliceP("exclude", "x", nil, "Tables to be excluded from the generated package")
|
||||
rootCmd.PersistentFlags().StringP("basedir", "", "", "The base directory has the templates and templates_test folders")
|
||||
rootCmd.PersistentFlags().StringSliceP("blacklist", "b", nil, "Do not include these tables in your generated package")
|
||||
rootCmd.PersistentFlags().StringSliceP("whitelist", "w", nil, "Only include these tables in your generated package")
|
||||
rootCmd.PersistentFlags().StringSliceP("tag", "t", nil, "Struct tags to be included on your models in addition to json, yaml, toml")
|
||||
rootCmd.PersistentFlags().BoolP("debug", "d", false, "Debug mode prints stack traces on error")
|
||||
|
@ -118,12 +118,12 @@ func preRun(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
|
||||
// BUG: https://github.com/spf13/viper/issues/200
|
||||
// Look up the value of ExcludeTables & Tags directly from PFlags in Cobra if we
|
||||
// Look up the value of blacklist, whitelist & tags directly from PFlags in Cobra if we
|
||||
// detect a malformed value coming out of viper.
|
||||
// Once the bug is fixed we'll be able to move this into the init above
|
||||
cmdConfig.ExcludeTables = viper.GetStringSlice("exclude")
|
||||
if len(cmdConfig.ExcludeTables) == 1 && strings.HasPrefix(cmdConfig.ExcludeTables[0], "[") {
|
||||
cmdConfig.ExcludeTables, err = cmd.PersistentFlags().GetStringSlice("exclude")
|
||||
cmdConfig.BlacklistTables = viper.GetStringSlice("blacklist")
|
||||
if len(cmdConfig.BlacklistTables) == 1 && strings.HasPrefix(cmdConfig.BlacklistTables[0], "[") {
|
||||
cmdConfig.BlacklistTables, err = cmd.PersistentFlags().GetStringSlice("blacklist")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ func New(config *Config) (*State, error) {
|
|||
return nil, errors.Wrap(err, "unable to connect to the database")
|
||||
}
|
||||
|
||||
err = s.initTables(config.Schema, config.WhitelistTables, config.ExcludeTables)
|
||||
err = s.initTables(config.Schema, config.WhitelistTables, config.BlacklistTables)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unable to initialize tables")
|
||||
}
|
||||
|
@ -241,9 +241,9 @@ func (s *State) initDriver(driverName string) error {
|
|||
}
|
||||
|
||||
// initTables retrieves all "public" schema table names from the database.
|
||||
func (s *State) initTables(schema string, whitelist, exclude []string) error {
|
||||
func (s *State) initTables(schema string, whitelist, blacklist []string) error {
|
||||
var err error
|
||||
s.Tables, err = bdb.Tables(s.Driver, schema, whitelist, exclude)
|
||||
s.Tables, err = bdb.Tables(s.Driver, schema, whitelist, blacklist)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable to fetch table data")
|
||||
}
|
||||
|
|
|
@ -37,10 +37,10 @@ func TestNew(t *testing.T) {
|
|||
}()
|
||||
|
||||
config := &Config{
|
||||
DriverName: "mock",
|
||||
PkgName: "models",
|
||||
OutFolder: out,
|
||||
ExcludeTables: []string{"hangars"},
|
||||
DriverName: "mock",
|
||||
PkgName: "models",
|
||||
OutFolder: out,
|
||||
BlacklistTables: []string{"hangars"},
|
||||
}
|
||||
|
||||
state, err = New(config)
|
||||
|
|
Loading…
Add table
Reference in a new issue