An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

github.com/mhiro2/seedling

Package seedling is a dependency-aware test data builder for Go and SQL databases. seedling is designed for tests that need real inserted rows, but do not want to manually wire foreign keys across multiple tables. You define explicit blueprints in Go, provide the insert callbacks for your own DB layer, and seedling plans the dependency graph, fills foreign keys, and executes inserts in the correct order. Without seedling, tests often manually create each parent row in dependency order: With seedling, the same test can focus on the row it actually cares about: Register a Blueprint for each model that seedling should create: DBTX is intentionally opaque. Your insert callback and your call sites must agree on the concrete handle type passed as db. Then create rows directly in your tests: If you want to inspect the graph before executing inserts, use Build or BuildE, then call Plan.Validate, Plan.DebugString, Plan.DryRunString, Plan.Insert, or Plan.InsertE. Blueprint A blueprint defines how to create one model type: default field values, primary-key metadata, relations, and insert/delete callbacks. Relation Relations describe graph edges such as belongs-to, has-many, and many-to-many. seedling uses them to expand the graph and bind keys. Option Options customize a single insert/build call. Common examples are Set, Use, Ref, Omit, When, and With. Plan and Result Build returns a plan for inspection or validation before execution. Reusing a Plan reuses its AfterInsert callbacks too, so state captured by those closures carries across executions. InsertOne returns a Result so you can access the root record and any related inserted nodes. InsertManyE returns a BatchResult with the batch roots plus cleanup/debug helpers for the full execution graph, including root-scoped lookup helpers such as BatchResult.NodeAt and BatchResult.NodesForRoot. Session A session can bind a registry or database handle across repeated calls. When you use database/sql, NewTestSession can open a transaction and roll it back automatically at test cleanup time. For a lighter alternative, WithTx returns a *sql.Tx directly with automatic rollback on cleanup: For pgx users, the companion package github.com/mhiro2/seedling/seedlingpgx provides the same pattern for pgx transactions: Reuse an existing parent row with Use: Customize an auto-created relation with Ref. This also explicitly enables optional relations: Generate multiple rows with InsertMany and Seq: Or inspect / clean up the full batch execution with InsertManyE: InsertMany batch-shares auto-created belongs-to relations when the same relation path resolves to the same static option tree after Seq and SeqRef are expanded. Relation-local Use, With, Generate, When, and rand-driven options disable sharing for that relation. Skip unnecessary relations with Only: Generate deterministic fake values with Generate, WithSeed, and the seedling/faker subpackage. seedling does not generate SQL at runtime. Your blueprint owns the Insert and optional Delete callbacks, so the library works with any DB abstraction. Install seedling-gen with Homebrew (brew install --cask mhiro2/tap/seedling-gen) or go install github.com/mhiro2/seedling/cmd/seedling-gen@latest. The seedling-gen CLI can generate blueprint skeletons from multiple sources: Use `seedling-gen --explain` to inspect parsed tables, foreign keys, and inferred blueprint relations before generating code. Use `--json` for the same report in machine-readable form. Frequently used APIs:

Ecosystem
proxy.golang.org
Latest Release
v0.2.4
5 days ago
Versions
7
Links
Registry proxy.golang.org
Source Repository
Docs Documentation
JSON API View JSON
CodeMeta codemeta.json
Package Details
PURL pkg:golang/github.com/mhiro2/seedling
spec
License MIT
Namespace github.com/mhiro2
First Release 19 days ago
Last Synced about 14 hours ago
Repository
Stars 1 on GitHub
Forks 0 on GitHub
Rankings on proxy.golang.org
Overall Top 5.1%