-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(seeder): add methods to Seeder to seed the tables
- Loading branch information
1 parent
a0706df
commit 58d4ae8
Showing
5 changed files
with
58 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package seeds | ||
|
||
import "github.com/bxcodec/faker/v3" | ||
|
||
// CustomerSeed seeds the database with customers. | ||
func (s Seed) CustomerSeed() { | ||
for i := 0; i < 100; i++ { | ||
// prepare the statement. | ||
stmt, _ := s.db.Prepare(`INSERT INTO customers(name, email) VALUES ($1, $2)`) | ||
// execute query. | ||
_, err := stmt.Exec(faker.Name(), faker.Email()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} |
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 @@ | ||
package seeds | ||
|
||
import ( | ||
"math/rand" | ||
|
||
"github.com/bxcodec/faker/v3" | ||
) | ||
|
||
// ProductSeed seeds product data. | ||
func (s Seed) ProductSeed() { | ||
for i := 0; i < 100; i++ { | ||
// prepare the statement. | ||
stmt, _ := s.db.Prepare(`INSERT INTO products(name, price) VALUES ($1, $2)`) | ||
// execute query. | ||
_, err := stmt.Exec(faker.Word(), rand.Float32()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} |
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,19 @@ | ||
package seeds | ||
|
||
import ( | ||
"github.com/bxcodec/faker/v3" | ||
) | ||
|
||
// UserSeed seeds the database with users. | ||
func (s Seed) UserSeed() { | ||
for i := 0; i < 100; i++ { | ||
|
||
// prepare the statement. | ||
stmt, _ := s.db.Prepare(`INSERT INTO users(username) VALUES ($1)`) | ||
// execute query. | ||
_, err := stmt.Exec(faker.Name()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} |
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