Seed provenance + inventory: source links and seed lots (#50) (#64)
Build image / build-and-push (push) Successful in 8s
Build image / build-and-push (push) Successful in 8s
Co-authored-by: Steve Dudenhoeffer <[email protected]>
This commit was merged in pull request #64.
This commit is contained in:
@@ -11,13 +11,13 @@ import (
|
||||
|
||||
// plantColumns lists plants columns in the order scanPlant expects.
|
||||
const plantColumns = `id, owner_id, name, category, spacing_cm, color, icon,
|
||||
days_to_maturity, notes, version, created_at, updated_at`
|
||||
days_to_maturity, source_url, vendor, notes, version, created_at, updated_at`
|
||||
|
||||
func scanPlant(s scanner) (*domain.Plant, error) {
|
||||
var p domain.Plant
|
||||
if err := s.Scan(
|
||||
&p.ID, &p.OwnerID, &p.Name, &p.Category, &p.SpacingCM, &p.Color, &p.Icon,
|
||||
&p.DaysToMaturity, &p.Notes, &p.Version, &p.CreatedAt, &p.UpdatedAt,
|
||||
&p.DaysToMaturity, &p.SourceURL, &p.Vendor, &p.Notes, &p.Version, &p.CreatedAt, &p.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -111,10 +111,11 @@ func (d *DB) GetPlant(ctx context.Context, id int64) (*domain.Plant, error) {
|
||||
// migration only, never through this path.
|
||||
func (d *DB) CreatePlant(ctx context.Context, p *domain.Plant) (*domain.Plant, error) {
|
||||
created, err := scanPlant(d.sql.QueryRowContext(ctx,
|
||||
`INSERT INTO plants (owner_id, name, category, spacing_cm, color, icon, days_to_maturity, notes)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`INSERT INTO plants (owner_id, name, category, spacing_cm, color, icon, days_to_maturity, source_url, vendor, notes)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
RETURNING `+plantColumns,
|
||||
p.OwnerID, p.Name, p.Category, p.SpacingCM, p.Color, p.Icon, p.DaysToMaturity, p.Notes,
|
||||
p.OwnerID, p.Name, p.Category, p.SpacingCM, p.Color, p.Icon, p.DaysToMaturity,
|
||||
p.SourceURL, p.Vendor, p.Notes,
|
||||
))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("store: insert plant: %w", err)
|
||||
@@ -130,12 +131,13 @@ func (d *DB) UpdatePlant(ctx context.Context, p *domain.Plant) (*domain.Plant, e
|
||||
updated, err := scanPlant(d.sql.QueryRowContext(ctx,
|
||||
`UPDATE plants
|
||||
SET name = ?, category = ?, spacing_cm = ?, color = ?, icon = ?,
|
||||
days_to_maturity = ?, notes = ?,
|
||||
days_to_maturity = ?, source_url = ?, vendor = ?, notes = ?,
|
||||
version = version + 1,
|
||||
updated_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now')
|
||||
WHERE id = ? AND version = ?
|
||||
RETURNING `+plantColumns,
|
||||
p.Name, p.Category, p.SpacingCM, p.Color, p.Icon, p.DaysToMaturity, p.Notes,
|
||||
p.Name, p.Category, p.SpacingCM, p.Color, p.Icon, p.DaysToMaturity,
|
||||
p.SourceURL, p.Vendor, p.Notes,
|
||||
p.ID, p.Version,
|
||||
))
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
|
||||
Reference in New Issue
Block a user