一键导入
codegen
Use when generating liteorm code — typed columns from a Go type, models from a live DB, typed Go from annotated SQL, the sqlc plugin, or porting gorm tags.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when generating liteorm code — typed columns from a Go type, models from a live DB, typed Go from annotated SQL, the sqlc plugin, or porting gorm tags.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when storing large or growing binary content (files, uploads, blobs) in SQLite as streamed io.ReaderAt/io.WriterAt instead of loading whole []byte — the orm.LOB field + liteorm.org/dialect/sqlite/lob.
Use when working with liteorm's declarative orm front-end — model structs and tags, AutoMigrate, the orm.Repo, associations (Load/Attach), hooks, or soft delete.
Use when liteorm code behaves unexpectedly, or proactively before writing it, to avoid the common gotchas around loading, soft delete, types, and dialect-gated operators.
Use when migrating a gorm codebase to liteorm — running models on gorm tags as-is, rewriting them to native orm tags, and adjusting for what differs.
Use when adding vector (sqlite-vec), full-text (FTS5), or hybrid RRF search to liteorm's SQLite backend.
Use when capturing, applying, inverting, or concatenating SQLite changesets (the SESSION extension) for audit logs, one-way replication, or undo — the liteorm.org/dialect/sqlite/changeset package. SQLite backend only.
| name | codegen |
| description | Use when generating liteorm code — typed columns from a Go type, models from a live DB, typed Go from annotated SQL, the sqlc plugin, or porting gorm tags. |
liteorm.org/gen emits Go from three inputs. There is also a sqlc process plugin and a gorm tag porter. All paths are driver-free: FromDB takes a liteorm.Session, the caller wires the backend.
FromType[T] reflects over an existing model; WriteColumns emits a typed TColumns struct so predicates get compile-time COLUMN safety on top of the runtime-validated query.Col.
import "liteorm.org/gen"
err := gen.WriteColumns(out /* io.Writer */, "models", gen.FromType[User]())
Generated usage:
query.Select[User](db).Filter(UserColumns.Email.Eq("ada@x.io")).All(ctx)
When a table has no Go type yet, introspect it and emit struct + TableName + columns:
models, _ := gen.FromDB(ctx, sess, "users", "orders")
_ = gen.WriteModels(out, "models", models...)
FromType + WriteColumns is "struct is the source of truth, emit columns"; FromDB + WriteModels is "DB is the source of truth, emit the struct too."
Parse sqlc-style -- name: X :cmd files into typed functions over the liteorm runtime. Result/arg Go types come from companion directives (this path does not parse SQL):
-- name: GetUser :one
-- liteorm:result User
-- liteorm:arg id int64
SELECT id, name FROM users WHERE id = ?;
qs, _ := gen.ParseQueries(src) // src is the .sql file contents
_ = gen.WriteQueries(out, "main", qs) // emits GetUser(ctx, sess, id) (User, error)
Commands: :one (T, error; ErrNoRows when empty), :many ([]T, error), :exec (error), :execrows (int64 affected), :execresult (liteorm.Result), :execlastid (int64). :one/:many need a -- liteorm:result <Type> directive (unless the result is a scalar like int64/string, which is scanned directly). Args default to any and argN when undeclared.
Wire it with go generate:
//go:generate go run ./generate
For teams already on sqlc: sqlc parses schema + queries and invokes sqlc-gen-liteorm as a process plugin, which emits the same liteorm-runtime typed functions. Configure in sqlc.yaml:
version: "2"
plugins:
- name: liteorm
process:
cmd: sqlc-gen-liteorm
sql:
- schema: schema.sql
queries: query.sql
engine: postgresql
codegen:
- plugin: liteorm
out: db
options: { package: db }
This path does parse SQL (sqlc does it), so result/arg types are inferred — no liteorm: directives needed.
Rewrite gorm:"..." struct tags into native orm:"..." tags (and gorm.DeletedAt → sql.NullTime + soft_delete) on Go source, so a gorm codebase can drop the gorm dependency. It edits only tag literals and that one field type; everything else stays byte-for-byte.
out, notes, err := gen.PortSource(src /* []byte of Go source */)
// out = rewritten source; notes = []gen.Note{Pos, Message} (dropped keys, import hints)
After porting, run goimports -w (gorm.io/gorm is now unused; database/sql is required). The orm package reads gorm tags natively, so porting is about cleanliness, not making it work.
WriteColumns/WriteModels/WriteQueries gofmt their output and error if it won't parse — fix the input types, not the generated file (it's DO NOT EDIT).:one/:many non-scalar result without a -- liteorm:result directive is an error.