Created
May 12, 2022 23:34
-
-
Save manakuro/26921a850662f150889fd868047f9fa5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package seed | |
import ( | |
"context" | |
"log" | |
"planetscale-witn-ent/datastore" | |
"planetscale-witn-ent/ent" | |
) | |
// Seed truncate table and generates new data. | |
func Seed() { | |
client := newDBClient() | |
defer client.Close() | |
ctx := context.Background() | |
client.DisableForeignKeyChecks() | |
client.DisableSQLSafeUpdates() | |
User(ctx, client) | |
client.EnableForeignKeyChecks() | |
} | |
func newDBClient() *ent.Client { | |
client, err := datastore.NewClient(datastore.NewClientOptions{}) | |
if err != nil { | |
log.Fatalf("failed opening mysql client: %v", err) | |
} | |
return client | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment