Documentation ¶
Index ¶
- Variables
- func DB(dbFile string) (db *sql.DB, err error)
- func InsertFile(ctx context.Context, file string, insertFunc insertF, db *sql.DB) (err error, ts *time.Time)
- func SchemaLoad(db *sql.DB, schemaFile string) (err error)
- func Seed(ctx context.Context, dbF string, schemaF string, dataF string, table string, ...) (db *sql.DB, err error)
Constants ¶
This section is empty.
Variables ¶
View Source
var GENERATOR_FUNCTIONS map[string]generatorF = map[string]generatorF{ "github_standards": func(ctx context.Context, num int, db *sql.DB) (err error) { mu := &sync.Mutex{} wg := sync.WaitGroup{} owner := fake.String(12) tx, err := db.Begin() if err != nil { return } defer tx.Rollback() q := ghs.New(db) qtx := q.WithTx(tx) slog.Info("starting generation", slog.String("for", "github_standards")) tick := testhelpers.T() for x := 0; x < num; x++ { wg.Add(1) go func(i int) { mu.Lock() g := ghs.Fake(nil, &owner) qtx.Insert(ctx, g.Insertable()) mu.Unlock() wg.Done() }(x) } wg.Wait() slog.Info("generation complete", slog.String("seconds", tick.Stop().Seconds()), slog.String("for", "github_standards")) return tx.Commit() }, }
map of funcs that inset data from files
View Source
var INSERT_FUNCTIONS map[string]insertF = map[string]insertF{ "github_standards": func(ctx context.Context, fileContent []byte, db *sql.DB) (err error) { repos := []*ghs.GithubStandard{} repos, err = convert.Unmarshals[*ghs.GithubStandard](fileContent) if err != nil { return } mu := &sync.Mutex{} wg := sync.WaitGroup{} tx, err := db.Begin() if err != nil { return } defer tx.Rollback() q := ghs.New(db) qtx := q.WithTx(tx) slog.Debug("inserting content", slog.String("for", "github_standards"), slog.Int("count", len(repos))) tick := testhelpers.T() for _, item := range repos { wg.Add(1) go func(g *ghs.GithubStandard) { mu.Lock() qtx.Insert(ctx, g.Insertable()) mu.Unlock() wg.Done() }(item) } wg.Wait() slog.Info("insert complete", slog.Int("count", len(repos)), slog.String("seconds", tick.Stop().Seconds()), slog.String("for", "github_standards")) return tx.Commit() }, }
Functions ¶
func InsertFile ¶
func SchemaLoad ¶
SchemaLoad generates a schema from a sqlc file whose filepath is passed
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.