From eb8eb0372298bf1ea76b06d3e91a6545418ace93 Mon Sep 17 00:00:00 2001 From: Sami Jnih Date: Mon, 11 Nov 2024 09:46:06 +0100 Subject: [PATCH] Feature: Additional person and company Faker attributes (#35) --- README.md | 59 ++++++++++++++++++++----------------- internal/helpers/helpers.go | 25 ++++++++++++++++ 2 files changed, 57 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index cc013bb..ad81e71 100644 --- a/README.md +++ b/README.md @@ -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` | `maritza@farrell.org` | -| `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 maritza@farrell.org` | -| `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` | `maritza@farrell.org` | +| `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 maritza@farrell.org` | +| `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! diff --git a/internal/helpers/helpers.go b/internal/helpers/helpers.go index 97f6c23..bc8e08e 100644 --- a/internal/helpers/helpers.go +++ b/internal/helpers/helpers.go @@ -28,11 +28,15 @@ 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, @@ -40,6 +44,7 @@ func GetFakerFuncs() map[string]func(*sqlparser.SQLVal) *sqlparser.SQLVal { "shortString": generateShortString, "ipv4": generateIPv4, "companyName": generateCompanyName, + "companySuffix": generateCompanySuffix, "companyNumber": generateCompanyNumber, "creditCardNumber": generateCreditCardNumber, "creditCardExpiryDate": generateCreditCardExpiryDate, @@ -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))) } @@ -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())) } @@ -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))) }