dbseed

package
v0.5.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package dbseed applies version-control-owned dataset files to the framework-owned database pool.

It is the single place where Popcorn Web talks to github.com/shibukawa/dbtestify, so the CLI seed command and the test helpers share one dataset contract.

Index

Constants

View Source
const DefaultDir = "testdata/seed"

DefaultDir is the dataset directory relative to the project root for the CLI and to the test package directory for tests.

View Source
const Extension = ".yaml"

Extension is the only dataset file extension.

Variables

This section is empty.

Functions

func Apply

func Apply(ctx context.Context, exec Executor, dialect Dialect, inTransaction bool, paths []string) error

Apply loads each dataset through exec in the given order.

exec stays owned by the caller. Pass inTransaction when exec is already inside a transaction, in which case dbtestify neither commits nor rolls back and the caller's rollback undoes the seeding. Otherwise each dataset is applied in its own transaction. The first failure stops the run.

A dataset's own _operation block selects the per-table operation. dbtestify reads operations from the option struct rather than from the parsed dataset, so the caller has to carry them across — its CLI and HTTP API do the same. Omitting that step silently clear-inserts every table.

func Assert

func Assert(ctx context.Context, exec Executor, dialect Dialect, inTransaction bool, paths []string) (bool, string, error)

Assert compares the database against each dataset and returns a plain-text diff for every mismatching table.

An exec already inside a transaction observes that transaction's uncommitted writes; a pool does not.

The boolean reports whether every dataset matched. A non-nil error means the comparison could not run at all.

func Resolve

func Resolve(directory string, names []string) ([]string, error)

Resolve turns dataset names into file paths under directory.

An empty names slice selects every dataset in the directory in lexical order. A name may omit the .yaml extension.

Types

type Dialect

type Dialect = dbtestify.Dialect

Dialect is the SQL flavor a dataset is applied with.

func ResolveDialect

func ResolveDialect(dsn string) (Dialect, error)

ResolveDialect derives the dialect from a driver://dsn configuration value.

type Executor

type Executor = dbtestify.Executor

Executor is the statement target datasets are applied through: dbtestify's driver-agnostic execution interface since its v0.5.0. A database/sql handle enters through FromSQL, the framework executor seam through FromRuntime.

func FromRuntime

func FromRuntime(executor sqlbind.SQLExecutor) Executor

FromRuntime adapts a framework executor — the pool-level executor of a connection or the executor of an open transaction scope — to Executor. A native executor queries through its QueryRows; a database/sql handle goes through FromSQL. A nil executor returns nil, which Apply and Assert report as "no database to seed".

func FromSQL

func FromSQL(handle dbtestify.SQLHandle) Executor

FromSQL adapts a *sql.DB, *sql.Tx, or *sql.Conn to Executor. A *sql.DB is remembered as a pool, so Seed can open its per-dataset transaction on it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL