ddl

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 2 Imported by: 0

README

ddl

Runtime DDL over tinywasm/storage: CreateTable/DropTable/CreateDatabase/Sync/SyncSchema, plus the executable ddl/conformance contract for SQL backends. A sibling of tinywasm/orm, not a dependency of it — see docs/ARCHITECTURE.md for the design.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColumnInfo added in v0.0.2

type ColumnInfo struct {
	Name    string
	Type    string
	NotNull bool
	PK      bool
}

ColumnInfo describes a single column returned by SchemaInspector.

type Compiler added in v0.0.2

type Compiler interface {
	CompileDDL(s Stmt, m model.Model) (query string, args []any, err error)
}

Compiler is implemented by dialect adapters (sqlt, postgres). It renders a DDL Stmt to engine SQL. It is the DDL counterpart of storage.Compiler (which stays DML-only).

type DB added in v0.0.2

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

DB applies schema changes through a storage.Conn: Exec for the compiled DDL, and Compile (the DML half storage.Conn already carries) for Sync's safe-drop SELECT probe. No separate DML compiler argument is needed — storage.Conn already unifies Executor+Compiler.

func New

func New(conn storage.Conn, ddlCompiler Compiler) *DB

func (*DB) CreateDatabase added in v0.0.2

func (d *DB) CreateDatabase(name string) error

CreateDatabase creates a new database. No model.Model needed — OpCreateDatabase only carries the database name.

func (*DB) CreateTable added in v0.0.2

func (d *DB) CreateTable(m model.Model) error

CreateTable creates a new table for the given model.

func (*DB) DropTable added in v0.0.2

func (d *DB) DropTable(m model.Model) error

DropTable drops the table for the given model.

func (*DB) SetLog added in v0.0.2

func (d *DB) SetLog(fn func(...any))

func (*DB) Sync added in v0.0.2

func (d *DB) Sync(models ...model.Model) error

Sync reconciles the database to match the given models.

func (*DB) SyncSchema added in v0.0.2

func (d *DB) SyncSchema(table string, fields []model.Field) error

SyncSchema reconciles one table to the given fields, with no model instance.

type Op added in v0.0.2

type Op int

Op is a DDL operation (schema), distinct from storage's DML Action.

const (
	OpCreateTable Op = iota
	OpDropTable
	OpCreateDatabase
	OpAddColumn
	OpRenameColumn
	OpDropColumn
)

type RenameProvider added in v0.0.2

type RenameProvider interface {
	OldNames() map[string]string
}

RenameProvider is implemented by generated models when db:"old_name=X" tags are present.

type SchemaInspector added in v0.0.2

type SchemaInspector interface {
	Tables() ([]string, error)
	Columns(table string) ([]ColumnInfo, error)
}

SchemaInspector is optionally implemented by storage.Conn to expose broader schema introspection. If the adapter does not implement it, the db_schema MCP tool is not registered.

type Stmt added in v0.0.2

type Stmt struct {
	Op       Op
	Table    string
	Database string
	Column   *model.Field // for AddColumn/RenameColumn — full field metadata needed to render the type
	OldName  string       // for RenameColumn
	// ColumnName carries a bare column name for operations that don't need type info —
	// currently only OpDropColumn (you can't "add" or "rename to" a column without knowing
	// its type, but dropping only needs the name). Deliberately separate from Column: giving
	// DropColumn a *model.Field would force callers to fabricate a fake Field just to carry a
	// string, which is worse than a second field that's simply unused by the other Ops.
	ColumnName string
}

Stmt is one DDL statement to run through a storage.Conn.

type TableIntrospector added in v0.0.2

type TableIntrospector interface {
	TableColumns(table string) ([]string, error)
}

TableIntrospector is optionally implemented by the injected storage.Conn to retrieve column names.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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