internalschema

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package internalschema is a schema package that lives under internal/, and exists so that the command is tested against one.

It is a fixture, but it is a real package in a real module rather than a scaffolded temp directory, for the reason cmd/sqlb/main_test.go gives about the blog example: a fixture module proves only that the fixture compiled.

What it guards is narrow and was a real hole. `sqlb generate` writes its driver to a temporary directory and compiles it against the target module; a driver outside the module cannot import a package under internal/, so this layout — which is the usual one for a repository whose modules are not part of its public surface — was refused outright with

use of internal package … not allowed

Nothing else in this repository is under internal/, so nothing else would have caught it.

It emits the models and the typed column facade into this directory, and nothing else. That is enough to prove the driver linked and the emitters ran; the manifest and the REST bodies would say the same thing about the mechanism and cost more to keep current. (The facade names the row struct, so the two are one artefact in practice — skipping the models leaves columns_gen.go referring to a type nobody emitted.)

Index

Constants

This section is empty.

Variables

View Source
var InternalWidgetCols = internalWidgetColumns{
	ID:        sqlb.Typed[string]("id"),
	Name:      sqlb.TextColumn[string]("name"),
	Status:    sqlb.TextColumn[string]("status"),
	CreatedAt: sqlb.Typed[time.Time]("created_at"),
	UpdatedAt: sqlb.Typed[time.Time]("updated_at"),
}

InternalWidgetCols are the typed columns of internal_widgets.

View Source
var Widget = schema.Table("internal_widgets",
	schema.UUID("id").PrimaryKey().Default(schema.GenUUIDv4()),
	schema.Varchar("name", 200).Searchable().Sortable(),
	schema.Varchar("status", 20).Default(schema.Value("draft")).Filterable(),
	schema.Timestamps(),
)

Widget is deliberately dull. The subject of the test is the import path this package sits at, not the table.

The varchar with a literal default is not incidental either: it is the shape that used to survive introspection with its cast attached and diff forever (see introspect.stripCast), so declaring one here keeps an example of it in a package that is regenerated by CI.

Functions

func SqlbProject

func SqlbProject() codegen.Project

SqlbProject is the convention function the command looks for.

Types

type InternalWidget

type InternalWidget struct {
	ID        string    `db:"id" json:"id" sqlb:"type:uuid,pk,default,filter,readonly"`
	Name      string    `db:"name" json:"name" sqlb:"type:varchar,filter,sort,search"`
	Status    string    `db:"status" json:"status" sqlb:"type:varchar,default,filter"`
	CreatedAt time.Time `db:"created_at" json:"created_at" sqlb:"type:timestamptz,default,sort,readonly"`
	UpdatedAt time.Time `db:"updated_at" json:"updated_at" sqlb:"type:timestamptz,default,sort,readonly"`
}

InternalWidget is a row of internal_widgets.

func (InternalWidget) TableName

func (InternalWidget) TableName() string

TableName is the table InternalWidget maps to.

type InternalWidgetUpdate

type InternalWidgetUpdate struct {
	// contains filtered or unexported fields
}

InternalWidgetUpdate is a typed update statement for internal_widgets.

func UpdateInternalWidget

func UpdateInternalWidget() *InternalWidgetUpdate

UpdateInternalWidget starts a typed update.

func (*InternalWidgetUpdate) SetCreatedAt

func (u *InternalWidgetUpdate) SetCreatedAt(v time.Time) *InternalWidgetUpdate

SetCreatedAt sets created_at.

func (*InternalWidgetUpdate) SetName

SetName sets name.

func (*InternalWidgetUpdate) SetStatus

SetStatus sets status.

func (*InternalWidgetUpdate) SetUpdatedAt

func (u *InternalWidgetUpdate) SetUpdatedAt(v time.Time) *InternalWidgetUpdate

SetUpdatedAt sets updated_at.

func (*InternalWidgetUpdate) Stmt

Stmt exposes the underlying statement for what the wrapper does not cover, such as Everything, SetExpr, Exec and One.

func (*InternalWidgetUpdate) Where

func (u *InternalWidgetUpdate) Where(preds ...sqlb.Pred) *InternalWidgetUpdate

Where narrows the affected rows.

Jump to

Keyboard shortcuts

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