-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #325 from stephenafamo/template-restructure
Refactor template parsing and organisation
- Loading branch information
Showing
35 changed files
with
258 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
gen/bobgen-mysql/templates/models/bob_mysql_blocks.bob.go.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{{- define "helpers/where_variables"}} | ||
{{$.Importer.Import (printf "github.com/stephenafamo/bob/dialect/%s/dialect" $.Dialect)}} | ||
var ( | ||
SelectWhere = Where[*dialect.SelectQuery]() | ||
UpdateWhere = Where[*dialect.UpdateQuery]() | ||
DeleteWhere = Where[*dialect.DeleteQuery]() | ||
) | ||
{{- end -}} | ||
|
||
{{define "unique_constraint_error_detection_method" -}} | ||
{{$.Importer.Import "strings"}} | ||
{{$.Importer.Import "mysqlDriver" "github.com/go-sql-driver/mysql"}} | ||
func (e *UniqueConstraintError) Is(target error) bool { | ||
err, ok := target.(*mysqlDriver.MySQLError) | ||
if !ok { | ||
return false | ||
} | ||
return err.Number == 1062 && strings.Contains(err.Message, e.s) | ||
} | ||
{{end -}} |
54 changes: 0 additions & 54 deletions
54
gen/bobgen-mysql/templates/models/singleton/bob_mysql_blocks.bob.go.tpl
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
32 changes: 32 additions & 0 deletions
32
gen/bobgen-sqlite/templates/models/bob_sqlite_blocks.bob.go.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{{- define "helpers/join_variables"}} | ||
var ( | ||
SelectJoins = getJoins[*dialect.SelectQuery] | ||
UpdateJoins = getJoins[*dialect.UpdateQuery] | ||
) | ||
{{end -}} | ||
|
||
{{define "unique_constraint_error_detection_method" -}} | ||
func (e *UniqueConstraintError) Is(target error) bool { | ||
{{if not (eq $.DriverName "modernc.org/sqlite" "github.com/mattn/go-sqlite3")}} | ||
return false | ||
{{else}} | ||
{{$errType := ""}} | ||
{{$codeGetter := ""}} | ||
{{$.Importer.Import "strings"}} | ||
{{if eq $.DriverName "modernc.org/sqlite"}} | ||
{{$.Importer.Import "sqliteDriver" $.DriverName}} | ||
{{$errType = "*sqliteDriver.Error"}} | ||
{{$codeGetter = "Code()"}} | ||
{{else}} | ||
{{$.Importer.Import $.DriverName}} | ||
{{$errType = "sqlite3.Error"}} | ||
{{$codeGetter = "ExtendedCode"}} | ||
{{end}} | ||
err, ok := target.({{$errType}}) | ||
if !ok { | ||
return false | ||
} | ||
return err.{{$codeGetter}} == 2067 && strings.Contains(err.Error(), e.s) | ||
{{end}} | ||
} | ||
{{end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.