From ef1c0341de1c67d83acc9bcbfb5983da67274326 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 17 Apr 2023 14:47:54 +0000 Subject: [PATCH] Bump gorm.io/driver/sqlite from 1.4.4 to 1.5.0 Bumps [gorm.io/driver/sqlite](/~https://github.com/go-gorm/sqlite) from 1.4.4 to 1.5.0. - [Release notes](/~https://github.com/go-gorm/sqlite/releases) - [Commits](/~https://github.com/go-gorm/sqlite/compare/v1.4.4...v1.5.0) --- updated-dependencies: - dependency-name: gorm.io/driver/sqlite dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 5 ++- vendor/gorm.io/driver/sqlite/ddlmod.go | 32 ++++++++++++------- .../gorm.io/driver/sqlite/error_translator.go | 21 ++++++++++++ vendor/gorm.io/driver/sqlite/sqlite.go | 7 +++- vendor/modules.txt | 2 +- 6 files changed, 51 insertions(+), 18 deletions(-) create mode 100644 vendor/gorm.io/driver/sqlite/error_translator.go diff --git a/go.mod b/go.mod index 6ea1c50b00..3cfd692ee6 100644 --- a/go.mod +++ b/go.mod @@ -50,7 +50,7 @@ require ( gopkg.in/AlecAivazis/survey.v1 v1.8.8 gorm.io/driver/mysql v1.4.7 gorm.io/driver/postgres v1.5.0 - gorm.io/driver/sqlite v1.4.4 + gorm.io/driver/sqlite v1.5.0 gorm.io/gorm v1.25.0 gvisor.dev/gvisor v0.0.0-20220817001344-846276b3dbc5 modernc.org/sqlite v1.21.1 diff --git a/go.sum b/go.sum index 6ec91fe6bd..10ba3d499d 100644 --- a/go.sum +++ b/go.sum @@ -454,10 +454,9 @@ gorm.io/driver/mysql v1.4.7 h1:rY46lkCspzGHn7+IYsNpSfEv9tA+SU4SkkB+GFX125Y= gorm.io/driver/mysql v1.4.7/go.mod h1:SxzItlnT1cb6e1e4ZRpgJN2VYtcqJgqnHxWr4wsP8oc= gorm.io/driver/postgres v1.5.0 h1:u2FXTy14l45qc3UeCJ7QaAXZmZfDDv0YrthvmRq1l0U= gorm.io/driver/postgres v1.5.0/go.mod h1:FUZXzO+5Uqg5zzwzv4KK49R8lvGIyscBOqYrtI1Ce9A= -gorm.io/driver/sqlite v1.4.4 h1:gIufGoR0dQzjkyqDyYSCvsYR6fba1Gw5YKDqKeChxFc= -gorm.io/driver/sqlite v1.4.4/go.mod h1:0Aq3iPO+v9ZKbcdiz8gLWRw5VOPcBOPUQJFLq5e2ecI= +gorm.io/driver/sqlite v1.5.0 h1:zKYbzRCpBrT1bNijRnxLDJWPjVfImGEn0lSnUY5gZ+c= +gorm.io/driver/sqlite v1.5.0/go.mod h1:kDMDfntV9u/vuMmz8APHtHF0b4nyBB7sfCieC6G8k8I= gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= -gorm.io/gorm v1.24.0/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA= gorm.io/gorm v1.24.7-0.20230306060331-85eaf9eeda11/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= gorm.io/gorm v1.25.0 h1:+KtYtb2roDz14EQe4bla8CbQlmb9dN3VejSai3lprfU= gorm.io/gorm v1.25.0/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= diff --git a/vendor/gorm.io/driver/sqlite/ddlmod.go b/vendor/gorm.io/driver/sqlite/ddlmod.go index 87886d242a..e6dcbc377c 100644 --- a/vendor/gorm.io/driver/sqlite/ddlmod.go +++ b/vendor/gorm.io/driver/sqlite/ddlmod.go @@ -16,12 +16,23 @@ var ( indexRegexp = regexp.MustCompile(fmt.Sprintf("(?is)CREATE(?: UNIQUE)? INDEX [%v]?[\\w\\d-]+[%v]? ON (.*)$", sqliteSeparator, sqliteSeparator)) tableRegexp = regexp.MustCompile(fmt.Sprintf("(?is)(CREATE TABLE [%v]?[\\w\\d-]+[%v]?)(?: \\((.*)\\))?", sqliteSeparator, sqliteSeparator)) separatorRegexp = regexp.MustCompile(fmt.Sprintf("[%v]", sqliteSeparator)) - columnsRegexp = regexp.MustCompile(fmt.Sprintf("\\([%v]?([\\w\\d]+)[%v]?(?:,[%v]?([\\w\\d]+)[%v]){0,}\\)", sqliteSeparator, sqliteSeparator, sqliteSeparator, sqliteSeparator)) + columnsRegexp = regexp.MustCompile(fmt.Sprintf("[(,][%v]?(\\w+)[%v]?", sqliteSeparator, sqliteSeparator)) columnRegexp = regexp.MustCompile(fmt.Sprintf("^[%v]?([\\w\\d]+)[%v]?\\s+([\\w\\(\\)\\d]+)(.*)$", sqliteSeparator, sqliteSeparator)) defaultValueRegexp = regexp.MustCompile("(?i) DEFAULT \\(?(.+)?\\)?( |COLLATE|GENERATED|$)") regRealDataType = regexp.MustCompile(`[^\d](\d+)[^\d]?`) ) +func getAllColumns(s string) []string { + allMatches := columnsRegexp.FindAllStringSubmatch(s, -1) + columns := make([]string, 0, len(allMatches)) + for _, matches := range allMatches { + if len(matches) > 1 { + columns = append(columns, matches[1]) + } + } + return columns +} + type ddl struct { head string fields []string @@ -98,15 +109,12 @@ func parseDDL(strs ...string) (*ddl, error) { } if strings.HasPrefix(fUpper, "PRIMARY KEY") { - matches := columnsRegexp.FindStringSubmatch(f) - if len(matches) > 1 { - for _, name := range matches[1:] { - for idx, column := range result.columns { - if column.NameValue.String == name { - column.PrimaryKeyValue = sql.NullBool{Bool: true, Valid: true} - result.columns[idx] = column - break - } + for _, name := range getAllColumns(f) { + for idx, column := range result.columns { + if column.NameValue.String == name { + column.PrimaryKeyValue = sql.NullBool{Bool: true, Valid: true} + result.columns[idx] = column + break } } } @@ -151,9 +159,9 @@ func parseDDL(strs ...string) (*ddl, error) { } } } else if matches := indexRegexp.FindStringSubmatch(str); len(matches) > 0 { - if columns := columnsRegexp.FindStringSubmatch(matches[1]); len(columns) == 1 { + for _, column := range getAllColumns(matches[1]) { for idx, c := range result.columns { - if c.NameValue.String == columns[0] { + if c.NameValue.String == column { c.UniqueValue = sql.NullBool{Bool: true, Valid: true} result.columns[idx] = c } diff --git a/vendor/gorm.io/driver/sqlite/error_translator.go b/vendor/gorm.io/driver/sqlite/error_translator.go new file mode 100644 index 0000000000..d0b936c583 --- /dev/null +++ b/vendor/gorm.io/driver/sqlite/error_translator.go @@ -0,0 +1,21 @@ +package sqlite + +import ( + "github.com/mattn/go-sqlite3" + + "gorm.io/gorm" +) + +var errCodes = map[string]sqlite3.ErrNoExtended{ + "uniqueConstraint": 2067, +} + +func (dialector Dialector) Translate(err error) error { + if sqliteErr, ok := err.(*sqlite3.Error); ok { + if sqliteErr.ExtendedCode == errCodes["uniqueConstraint"] { + return gorm.ErrDuplicatedKey + } + } + + return err +} diff --git a/vendor/gorm.io/driver/sqlite/sqlite.go b/vendor/gorm.io/driver/sqlite/sqlite.go index cb1afff5d6..8617f00b15 100644 --- a/vendor/gorm.io/driver/sqlite/sqlite.go +++ b/vendor/gorm.io/driver/sqlite/sqlite.go @@ -178,7 +178,12 @@ func (dialector Dialector) DataTypeOf(field *schema.Field) string { case schema.String: return "text" case schema.Time: - return "datetime" + // Distinguish between schema.Time and tag time + if val, ok := field.TagSettings["TYPE"]; ok { + return val + } else { + return "datetime" + } case schema.Bytes: return "blob" } diff --git a/vendor/modules.txt b/vendor/modules.txt index 464c5bb63f..bc3e5ab6ca 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -628,7 +628,7 @@ gorm.io/driver/mysql # gorm.io/driver/postgres v1.5.0 ## explicit; go 1.14 gorm.io/driver/postgres -# gorm.io/driver/sqlite v1.4.4 +# gorm.io/driver/sqlite v1.5.0 ## explicit; go 1.14 gorm.io/driver/sqlite # gorm.io/gorm v1.25.0