From 257278b7e5ecef74cac0f1da761f6a934e020f9b Mon Sep 17 00:00:00 2001 From: Michelle Laurenti Date: Mon, 22 Jul 2024 17:48:19 +0200 Subject: [PATCH] remove conversion of bool to int --- create.go | 14 +------------- oracle.go | 14 ++++---------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/create.go b/create.go index c896405..e6560ce 100644 --- a/create.go +++ b/create.go @@ -95,19 +95,7 @@ func Create(db *gorm.DB) { if !db.DryRun { for idx, vals := range values.Values { - // HACK HACK: replace values one by one, assuming its value layout will be the same all the time, i.e. aligned - for idx, val := range vals { - switch v := val.(type) { - case bool: - if v { - val = 1 - } else { - val = 0 - } - } - - stmt.Vars[idx] = val - } + copy(stmt.Vars, vals) // and then we insert each row one by one then put the returning values back (i.e. last return id => smart insert) // we keep track of the index so that the sub-reflected value is also correct diff --git a/oracle.go b/oracle.go index 11309f5..2e223f5 100644 --- a/oracle.go +++ b/oracle.go @@ -166,15 +166,7 @@ var numericPlaceholder = regexp.MustCompile(`:(\d+)`) func (d Dialector) Explain(sql string, vars ...interface{}) string { return logger.ExplainSQL(sql, numericPlaceholder, `'`, funk.Map(vars, func(v interface{}) interface{} { - switch v := v.(type) { - case bool: - if v { - return 1 - } - return 0 - default: - return v - } + return v }).([]interface{})...) } @@ -186,7 +178,9 @@ func (d Dialector) DataTypeOf(field *schema.Field) string { var sqlType string switch field.DataType { - case schema.Bool, schema.Int, schema.Uint, schema.Float: + case schema.Bool: + sqlType = "VARCHAR2(5)" + case schema.Int, schema.Uint, schema.Float: sqlType = "INTEGER" switch {