Skip to content

Commit

Permalink
Showing 7 changed files with 63 additions and 28 deletions.
2 changes: 1 addition & 1 deletion bdb/drivers/mysql.go
Original file line number Diff line number Diff line change
@@ -148,7 +148,7 @@ func (m *MySQLDriver) Columns(schema, tableName string) ([]bdb.Column, error) {
(select count(*) from information_schema.key_column_usage where table_schema = kcu.table_schema and table_name = tc.table_name and constraint_name = tc.constraint_name) = 1
) as is_unique
from information_schema.columns as c
where table_name = ? and table_schema = ?;
where table_name = ? and table_schema = ? and c.extra not like '%VIRTUAL%';
`, tableName, schema)

if err != nil {
14 changes: 10 additions & 4 deletions bdb/drivers/postgres.go
Original file line number Diff line number Diff line change
@@ -348,10 +348,13 @@ func (p *PostgresDriver) TranslateColumnType(c bdb.Column) bdb.Column {
// Make DBType something like ARRAYinteger for parsing with randomize.Struct
c.DBType = c.DBType + *c.ArrType
case "USER-DEFINED":
if c.UDTName == "hstore" {
switch c.UDTName {
case "hstore":
c.Type = "types.HStore"
c.DBType = "hstore"
} else {
case "citext":
c.Type = "null.String"
default:
c.Type = "string"
fmt.Fprintf(os.Stderr, "Warning: Incompatible data type detected: %s\n", c.UDTName)
}
@@ -387,10 +390,13 @@ func (p *PostgresDriver) TranslateColumnType(c bdb.Column) bdb.Column {
// Make DBType something like ARRAYinteger for parsing with randomize.Struct
c.DBType = c.DBType + *c.ArrType
case "USER-DEFINED":
if c.UDTName == "hstore" {
switch c.UDTName {
case "hstore":
c.Type = "types.HStore"
c.DBType = "hstore"
} else {
case "citext":
c.Type = "string"
default:
c.Type = "string"
fmt.Printf("Warning: Incompatible data type detected: %s\n", c.UDTName)
}
38 changes: 26 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
@@ -14,25 +14,25 @@ import (
"github.com/volatiletech/sqlboiler/boilingcore"
)

const sqlBoilerVersion = "2.6.0"
const sqlBoilerVersion = "2.7.0"

var (
cmdState *boilingcore.State
cmdConfig *boilingcore.Config
flagConfigFile string
cmdState *boilingcore.State
cmdConfig *boilingcore.Config
)

func main() {
var err error

// Too much happens between here and cobra's argument handling, for
// something so simple just do it immediately.
for _, arg := range os.Args {
if arg == "--version" {
fmt.Println("SQLBoiler v" + sqlBoilerVersion)
return
func initConfig() {
if len(flagConfigFile) != 0 {
viper.SetConfigFile(flagConfigFile)
if err := viper.ReadInConfig(); err != nil {
fmt.Println("Can't read config:", err)
os.Exit(1)
}
return
}

var err error
viper.SetConfigName("sqlboiler")

configHome := os.Getenv("XDG_CONFIG_HOME")
@@ -56,6 +56,17 @@ func main() {
// Ignore errors here, fallback to other validation methods.
// Users can use environment variables if a config is not found.
_ = viper.ReadInConfig()
}

func main() {
// Too much happens between here and cobra's argument handling, for
// something so simple just do it immediately.
for _, arg := range os.Args {
if arg == "--version" {
fmt.Println("SQLBoiler v" + sqlBoilerVersion)
return
}
}

// Set up the cobra root command
var rootCmd = &cobra.Command{
@@ -71,7 +82,10 @@ func main() {
SilenceUsage: true,
}

cobra.OnInitialize(initConfig)

// Set up the cobra root command flags
rootCmd.PersistentFlags().StringVarP(&flagConfigFile, "config", "c", "", "Supply the name of the config file to override the default lookup")
rootCmd.PersistentFlags().StringP("output", "o", "models", "The name of the folder to output to")
rootCmd.PersistentFlags().StringP("schema", "s", "", "schema name for drivers that support it (default psql: public, mssql: dbo)")
rootCmd.PersistentFlags().StringP("pkgname", "p", "models", "The name you wish to assign to your generated package")
4 changes: 2 additions & 2 deletions strmangle/strmangle_test.go
Original file line number Diff line number Diff line change
@@ -596,9 +596,9 @@ func TestReplaceReservedWords(t *testing.T) {
for i, test := range tests {
got := ReplaceReservedWords(test.Word)
if test.Replace && !strings.HasSuffix(got, "_") {
t.Errorf("%i) want suffixed (%s), got: %s", i, test.Word, got)
t.Errorf("%d) want suffixed (%s), got: %s", i, test.Word, got)
} else if !test.Replace && strings.HasSuffix(got, "_") {
t.Errorf("%i) want normal (%s), got: %s", i, test.Word, got)
t.Errorf("%d) want normal (%s), got: %s", i, test.Word, got)
}
}
}
13 changes: 12 additions & 1 deletion templates_test/singleton/boil_main_test.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var flagDebugMode = flag.Bool("test.sqldebug", false, "Turns on debug mode for SQL statements")
var flagConfigFile = flag.String("test.config", "", "Overrides the default config")

var (
dbMain tester
@@ -17,6 +18,9 @@ func TestMain(m *testing.M) {
}

rand.Seed(time.Now().UnixNano())

flag.Parse()

var err error

// Load configuration
@@ -33,7 +37,6 @@ func TestMain(m *testing.M) {
}

// Set DebugMode so we can see generated sql statements
flag.Parse()
boil.DebugMode = *flagDebugMode

if err = dbMain.setup(); err != nil {
@@ -59,6 +62,14 @@ func TestMain(m *testing.M) {
}

func initViper() error {
if flagConfigFile != nil && *flagConfigFile != "" {
viper.SetConfigFile(*flagConfigFile)
if err := viper.ReadInConfig(); err != nil {
return err
}
return nil
}

var err error

viper.SetConfigName("sqlboiler")
14 changes: 7 additions & 7 deletions testdata/Dockerfile
Original file line number Diff line number Diff line change
@@ -2,19 +2,19 @@
FROM ubuntu:16.04

ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin:/opt/mssql-tools/bin
ENV GODIST go1.8.linux-amd64.tar.gz

# Set up locales for sqlcmd (otherwise it breaks)
RUN locale-gen en_US.UTF-8 \
&& echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale \
&& echo "LANG=en_US.UTF-8" >> /etc/default/locale
ENV GODIST go1.10.2.linux-amd64.tar.gz

# Install bootstrap-y tools
RUN apt-get update \
&& apt-get install -y apt-transport-https software-properties-common python3-software-properties \
&& apt-add-repository ppa:git-core/ppa \
&& apt-get update \
&& apt-get install -y curl git
&& apt-get install -y curl git locales

# Set up locales for sqlcmd (otherwise it breaks)
RUN locale-gen en_US.UTF-8 \
&& echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale \
&& echo "LANG=en_US.UTF-8" >> /etc/default/locale

# Install database clients
# MySQL 8.0 is still in development, so we're using 5.7 which is already
6 changes: 5 additions & 1 deletion testdata/postgres_test_schema.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
CREATE EXTENSION IF NOT EXISTS citext;

CREATE TYPE workday AS ENUM('monday', 'tuesday', 'wednesday', 'thursday', 'friday');
CREATE TYPE faceyface AS ENUM('angry', 'hungry', 'bitter');

@@ -179,7 +181,9 @@ CREATE TABLE magic (
iii txid_snapshot NULL,
jjj txid_snapshot NOT NULL,
kkk xml NULL,
lll xml NOT NULL
lll xml NOT NULL,
mmm citext NULL,
nnn citext NOT NULL
);

create table owner (

0 comments on commit d2c38af

Please sign in to comment.