Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add more helpers #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 32 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,33 +137,38 @@ Supposing you have a WordPress database and you need to modify certain meta, be

Each column stores a certain type of data, be it a name, username, email, etc. The `type` property in the config is used to define the type of data stored, and ultimately the type of random data to be inserted into the field. [https://github.com/dmgk/faker](https://github.com/dmgk/faker) is used for generating the fake data. These are the types currently supported:

| Type | Example output |
|------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `username` | `micah_pfeffer` |
| `password` | `5ccf672d5c73748146be6b37568efa57` |
| `email` | `[email protected]` |
| `url` | `http://sporerhamill.net/kyla.schmitt` |
| `name` | `Natasha Hartmann` |
| `firstName` | `Carolina` |
| `lastName` | `Kohler` |
| `phoneNumber` | `+49-131-0003060` |
| `billingAddressFull` | `Carolina Kohler 6071 Heaney Island Suite 553, Ebbaville Texas 37307 JP +49-131-0003060 [email protected]` |
| `addressFull` | `6071 Heaney Island Suite 553, Ebbaville Texas 37307` |
| `addressStreet` | `"586 Sylvester Turnpike"` |
| `addressCity` | `North Dessie` |
| `addressPostCode` | `31340` |
| `addressCountry` | `Uruguay` |
| `addressCountryCode` | `JP` |
| `paragraph` | `Lorem ipsum dolor sit amet, fabulas nostrum recteque vel ea, sit ut nemore similique. Ad per dicam molestie, nostro constituto duo ad. Ex scripta impedit cum, vidisse feugiat vivendum cum ad, liber senserit mediocrem pro.` |
| `shortString` | `wqFyJIrXYfVP7cLwqFyJIrXYfVP7cL` |
| `ipv4` | `121.204.82.227` |
| `companyName` | `Aufderhar LLC` |
| `companyNumber` | `123456789` |
| `creditCardNumber` | `1234-2121-1221-1211` |
| `creditCardExpiryDate` | `2015-11-11` |
| `creditCardType` | `mastercard` |
| `norwegianSSN` | `07026765743` |
| `purge` | |
| Type | Example output |
|------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `username` | `micah_pfeffer` |
| `password` | `5ccf672d5c73748146be6b37568efa57` |
| `email` | `[email protected]` |
| `url` | `http://sporerhamill.net/kyla.schmitt` |
| `name` | `Natasha Hartmann` |
| `firstName` | `Carolina` |
| `lastName` | `Kohler` |
| `personPrefix` | `Dr.` |
| `personTitle` | `Chief Functionality Orchestrator` |
| `phoneNumber` | `+49-131-0003060` |
| `billingAddressFull` | `Carolina Kohler 6071 Heaney Island Suite 553, Ebbaville Texas 37307 JP +49-131-0003060 [email protected]` |
| `addressFull` | `6071 Heaney Island Suite 553, Ebbaville Texas 37307` |
| `addressStreet` | `"586 Sylvester Turnpike"` |
| `addressSecondary` | `Apt. 411` |
| `addressCity` | `North Dessie` |
| `addressState` | `Maryland` |
| `addressPostCode` | `31340` |
| `addressCountry` | `Uruguay` |
| `addressCountryCode` | `JP` |
| `paragraph` | `Lorem ipsum dolor sit amet, fabulas nostrum recteque vel ea, sit ut nemore similique. Ad per dicam molestie, nostro constituto duo ad. Ex scripta impedit cum, vidisse feugiat vivendum cum ad, liber senserit mediocrem pro.` |
| `shortString` | `wqFyJIrXYfVP7cLwqFyJIrXYfVP7cL` |
| `ipv4` | `121.204.82.227` |
| `companyName` | `Aufderhar LLC` |
| `companySuffix` | `Inc` |
| `companyNumber` | `123456789` |
| `creditCardNumber` | `1234-2121-1221-1211` |
| `creditCardExpiryDate` | `2015-11-11` |
| `creditCardType` | `mastercard` |
| `norwegianSSN` | `07026765743` |
| `purge` | |

If you need another type, please feel free to add support and file a PR!

Expand Down
25 changes: 25 additions & 0 deletions internal/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,23 @@ func GetFakerFuncs() map[string]func(*sqlparser.SQLVal) *sqlparser.SQLVal {
"name": generateName,
"firstName": generateFirstName,
"lastName": generateLastName,
"personPrefix": generatePersonPrefix,
"personTitle": generatePersonTitle,
"phoneNumber": generatePhoneNumber,
"billingAddressFull": generateBillingAddress,
"addressFull": generateAddress,
"addressStreet": generateStreetAddress,
"addressSecondary": generateSecondaryStreetAddress,
"addressCity": generateCity,
"addressState": generateAddressState,
"addressPostCode": generatePostcode,
"addressCountry": generateCountry,
"addressCountryCode": generateCountryCode,
"paragraph": generateParagraph,
"shortString": generateShortString,
"ipv4": generateIPv4,
"companyName": generateCompanyName,
"companySuffix": generateCompanySuffix,
"companyNumber": generateCompanyNumber,
"creditCardNumber": generateCreditCardNumber,
"creditCardExpiryDate": generateCreditCardExpiryDate,
Expand Down Expand Up @@ -96,6 +101,14 @@ func generateLastName(value *sqlparser.SQLVal) *sqlparser.SQLVal {
return sqlparser.NewStrVal([]byte(faker.Name().LastName()))
}

func generatePersonPrefix(value *sqlparser.SQLVal) *sqlparser.SQLVal {
return sqlparser.NewStrVal([]byte(faker.Name().Prefix()))
}

func generatePersonTitle(value *sqlparser.SQLVal) *sqlparser.SQLVal {
return sqlparser.NewStrVal([]byte(faker.Name().Title()))
}

func generateParagraph(value *sqlparser.SQLVal) *sqlparser.SQLVal {
return sqlparser.NewStrVal([]byte(faker.Lorem().Sentence(3)))
}
Expand Down Expand Up @@ -124,6 +137,14 @@ func generateStreetAddress(value *sqlparser.SQLVal) *sqlparser.SQLVal {
return sqlparser.NewStrVal([]byte(faker.Address().StreetAddress()))
}

func generateSecondaryStreetAddress(value *sqlparser.SQLVal) *sqlparser.SQLVal {
return sqlparser.NewStrVal([]byte(faker.Address().SecondaryAddress()))
}

func generateAddressState(value *sqlparser.SQLVal) *sqlparser.SQLVal {
return sqlparser.NewStrVal([]byte(faker.Address().State()))
}

func generateCity(value *sqlparser.SQLVal) *sqlparser.SQLVal {
return sqlparser.NewStrVal([]byte(faker.Address().City()))
}
Expand Down Expand Up @@ -156,6 +177,10 @@ func generateCompanyName(value *sqlparser.SQLVal) *sqlparser.SQLVal {
return sqlparser.NewStrVal([]byte(faker.Company().Name()))
}

func generateCompanySuffix(value *sqlparser.SQLVal) *sqlparser.SQLVal {
return sqlparser.NewStrVal([]byte(faker.Company().Suffix()))
}

func generateCompanyNumber(value *sqlparser.SQLVal) *sqlparser.SQLVal {
return sqlparser.NewStrVal([]byte(faker.Number().Number(9)))
}
Expand Down