Compare commits

...

5 Commits

Author SHA1 Message Date
sudo pacman -Syu 387fef2780
Merge pull request #4 from haunt98/dependabot/go_modules/github.com/k1LoW/tbls-1.56.8
chore(deps): bump github.com/k1LoW/tbls from 1.56.6 to 1.56.8
2022-11-10 02:06:44 -08:00
dependabot[bot] 05990f1359
chore(deps): bump github.com/k1LoW/tbls from 1.56.6 to 1.56.8
Bumps [github.com/k1LoW/tbls](https://github.com/k1LoW/tbls) from 1.56.6 to 1.56.8.
- [Release notes](https://github.com/k1LoW/tbls/releases)
- [Changelog](https://github.com/k1LoW/tbls/blob/main/CHANGELOG.md)
- [Commits](https://github.com/k1LoW/tbls/compare/v1.56.6...v1.56.8)

---
updated-dependencies:
- dependency-name: github.com/k1LoW/tbls
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-10 08:09:43 +00:00
sudo pacman -Syu 5e310a594d
Merge pull request #3 from haunt98/dependabot/go_modules/github.com/urfave/cli/v2-2.23.5
chore(deps): bump github.com/urfave/cli/v2 from 2.23.4 to 2.23.5
2022-11-09 00:34:15 -08:00
dependabot[bot] ee33207226
chore(deps): bump github.com/urfave/cli/v2 from 2.23.4 to 2.23.5
Bumps [github.com/urfave/cli/v2](https://github.com/urfave/cli) from 2.23.4 to 2.23.5.
- [Release notes](https://github.com/urfave/cli/releases)
- [Changelog](https://github.com/urfave/cli/blob/main/docs/CHANGELOG.md)
- [Commits](https://github.com/urfave/cli/compare/v2.23.4...v2.23.5)

---
updated-dependencies:
- dependency-name: github.com/urfave/cli/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-09 08:12:36 +00:00
sudo pacman -Syu 6f4457605b
feat: ParseDatabaseType receive tbls column 2022-11-07 00:36:07 +07:00
4 changed files with 17 additions and 18 deletions

4
go.mod
View File

@ -5,9 +5,9 @@ go 1.18
require (
github.com/brianvoe/gofakeit/v6 v6.19.0
github.com/go-sql-driver/mysql v1.6.0
github.com/k1LoW/tbls v1.56.6
github.com/k1LoW/tbls v1.56.8
github.com/make-go-great/color-go v0.4.1
github.com/urfave/cli/v2 v2.23.4
github.com/urfave/cli/v2 v2.23.5
)
require (

8
go.sum
View File

@ -356,8 +356,8 @@ github.com/k1LoW/duration v1.1.0 h1:KEIL/aAGL//DnGMCiMrxSgRcVw4nM0ur6KSC9kEBsDo=
github.com/k1LoW/duration v1.1.0/go.mod h1:MEWYmZ4Agei4RDvERiInjZAhcZStYLp6y7+ZrpaAMJQ=
github.com/k1LoW/expand v0.1.0 h1:WnExzFli09OzQ2cZpaOiUjP+/sZ6DBpHQWWJAsWAZPY=
github.com/k1LoW/expand v0.1.0/go.mod h1:CojQ4SR1YvdeC4Srw8pTtF9PRnGr5pUvAkiNfdAwRQg=
github.com/k1LoW/tbls v1.56.6 h1:9JvNnfm50rQkMpKKKlwbv8WnkVVucKFOYlKFbJJzyG4=
github.com/k1LoW/tbls v1.56.6/go.mod h1:c+8MiulH0hgufPAovWSlRpVXFVxJSTs5P2/pbN4PdHI=
github.com/k1LoW/tbls v1.56.8 h1:Qy4sF+9PlacIL+jepsHZPl2we59Fmt9VZtccMLU99dU=
github.com/k1LoW/tbls v1.56.8/go.mod h1:c+8MiulH0hgufPAovWSlRpVXFVxJSTs5P2/pbN4PdHI=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.13.1/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
@ -492,8 +492,8 @@ github.com/tklauser/go-sysconf v0.3.5/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITn
github.com/tklauser/numcpus v0.2.1/go.mod h1:9aU+wOc6WjUIZEwWMP62PL/41d65P+iks1gBkr4QyP8=
github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZFu0T9wgjM=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/urfave/cli/v2 v2.23.4 h1:gcaHwki8kGX6lfp2zz7irxu7eZkcIl1Xapt6XW0Ynqc=
github.com/urfave/cli/v2 v2.23.4/go.mod h1:1CNUng3PtjQMtRzJO4FMXBQvkGtuYRxxiR9xMa7jMwI=
github.com/urfave/cli/v2 v2.23.5 h1:xbrU7tAYviSpqeR3X4nEFWUdB/uDZ6DE+HxmRU7Xtyw=
github.com/urfave/cli/v2 v2.23.5/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.0.2 h1:akYIkZ28e6A96dkWNJQu3nmCzH3YfwMPQExUYDaRv7w=

View File

@ -7,31 +7,30 @@ import (
"time"
"github.com/brianvoe/gofakeit/v6"
tblsschema "github.com/k1LoW/tbls/schema"
)
var ErrNotSupportDatabaseType = errors.New("not support database type")
// varchar(123)
// timestamp
func ParseDatabaseType(databaseTypeStr string) (DatabaseType, error) {
func ParseDatabaseType(column *tblsschema.Column) (DatabaseType, error) {
switch {
case strings.HasPrefix(strings.ToLower(databaseTypeStr), "varchar"):
case strings.HasPrefix(strings.ToLower(column.Type), "varchar"):
dtVarchar := DTVarchar{}
if _, err := fmt.Sscanf(databaseTypeStr, "varchar(%d)", &dtVarchar.Length); err != nil {
return nil, fmt.Errorf("fmt: failed to sscanf [%s]: %w", databaseTypeStr, err)
if _, err := fmt.Sscanf(column.Type, "varchar(%d)", &dtVarchar.Length); err != nil {
return nil, fmt.Errorf("fmt: failed to sscanf [%s]: %w", column.Type, err)
}
return &dtVarchar, nil
case strings.HasPrefix(strings.ToLower(databaseTypeStr), "bigint"):
case strings.HasPrefix(strings.ToLower(column.Type), "bigint"):
return &DTBigint{}, nil
case strings.HasPrefix(strings.ToLower(databaseTypeStr), "int"):
case strings.HasPrefix(strings.ToLower(column.Type), "int"):
return &DTInt{}, nil
case strings.EqualFold(databaseTypeStr, "timestamp"):
case strings.EqualFold(column.Type, "timestamp"):
return &DTTimestamp{}, nil
case strings.EqualFold(databaseTypeStr, "json"):
case strings.EqualFold(column.Type, "json"):
return &DTJSON{}, nil
default:
return nil, fmt.Errorf("not support database type [%s]: %w", databaseTypeStr, ErrNotSupportDatabaseType)
return nil, fmt.Errorf("not support database type [%s]: %w", column.Type, ErrNotSupportDatabaseType)
}
}

View File

@ -225,7 +225,7 @@ func (p *populator) prepareInsert(tableName string) ([]string, []string, []func(
questionMarks := make([]string, 0, len(table.Columns))
argFns := make([]func() any, 0, len(table.Columns))
for _, column := range table.Columns {
dt, err := ParseDatabaseType(column.Type)
dt, err := ParseDatabaseType(column)
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to parse database type [%s]: %w", column.Type, err)
}