Skip to content

Instantly share code, notes, and snippets.

@manakuro
Created May 12, 2022 23:34
Show Gist options
  • Save manakuro/26921a850662f150889fd868047f9fa5 to your computer and use it in GitHub Desktop.
Save manakuro/26921a850662f150889fd868047f9fa5 to your computer and use it in GitHub Desktop.
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