{"id":48528939,"url":"https://github.com/tinywasm/orm","last_synced_at":"2026-04-07T23:30:44.769Z","repository":{"id":340844792,"uuid":"1167769870","full_name":"tinywasm/orm","owner":"tinywasm","description":"tiny orm data base adapter","archived":false,"fork":false,"pushed_at":"2026-03-31T15:11:38.000Z","size":236,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-31T17:25:55.897Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tinywasm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["cdvelop"]}},"created_at":"2026-02-26T17:01:06.000Z","updated_at":"2026-03-31T15:11:38.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/tinywasm/orm","commit_stats":null,"previous_names":["cdvelop/orm"],"tags_count":39,"template":false,"template_full_name":null,"purl":"pkg:github/tinywasm/orm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinywasm%2Form","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinywasm%2Form/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinywasm%2Form/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinywasm%2Form/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tinywasm","download_url":"https://codeload.github.com/tinywasm/orm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinywasm%2Form/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31533823,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T16:28:08.000Z","status":"ssl_error","status_checked_at":"2026-04-07T16:28:06.951Z","response_time":105,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-04-07T23:30:43.884Z","updated_at":"2026-04-07T23:30:44.758Z","avatar_url":"https://github.com/tinywasm.png","language":"Go","funding_links":["https://github.com/sponsors/cdvelop"],"categories":[],"sub_categories":[],"readme":"# tinywasm/orm\n\u003cimg src=\"docs/img/badges.svg\"\u003e\n\n**Ultra-lightweight, strongly-typed ORM engineered for WebAssembly and backend environments.**\n\n## Features\n\n- **Zero Reflection**: Interface-driven schema via `github.com/tinywasm/fmt`\n- **Isomorphic**: Same generated code works in Go (backend) and WASM (frontend)\n- **Three Layers**: DB persistence, JSON transport, and Form UI — from one struct definition\n- **Code Generator**: `ormc` CLI generates boilerplate from struct tags\n\n## Installation\n\n```bash\ngo get github.com/tinywasm/orm\ngo install github.com/tinywasm/orm/cmd/ormc@latest\n```\n\n## Three Layers, One Struct\n\n`ormc` generates code for three layers depending on the directive and tags present:\n\n| Layer | Concern | Controlled by | Generated |\n|-------|---------|---------------|-----------|\n| **DB** | Persistence (tables, queries, CRUD) | `db:` tags | `ModelName()`, `ReadOne*`, `ReadAll*`, `T_`, `FieldDB` |\n| **JSON** | Transport (serialization) | `json:` tags | `OmitEmpty` in schema |\n| **Form** | UI (input widgets, validation) | `input:` tags + directive | `Widget` in schema, `Validate()` |\n\n### Directives\n\n| Directive | DB layer | Form layer | Use case |\n|-----------|----------|------------|----------|\n| *(none)* | Yes | No | DB-only struct (config, logs, metrics) |\n| `// ormc:form` | Yes | Yes | Business entity with UI (user, product) |\n| `// ormc:formonly` | No | Yes | Transport/UI struct without DB (login request, RPC params) |\n\n## Quick Start\n\n### 1. Define your structs\n\n```go\npackage user\n\n// ormc:form — DB + Form: full CRUD with UI rendering\ntype User struct {\n    ID      string\n    Name    string\n    Email   string `db:\"unique\" input:\"email\"`\n    Bio     string `json:\",omitempty\" input:\"textarea\"`\n    Address Address\n}\n\n// ormc:formonly — Form only: validation + UI, no DB\ntype Address struct {\n    Street string\n    City   string\n    Zip    string `input:\"number\"`\n}\n```\n\n`ormc` auto-detects: `ID` as PK, field names as column/JSON names, default `input.Text()` widget for string fields. Only add tags when overriding defaults.\n\n### 2. Generate\n\n```bash\normc\n```\n\nGenerates `model_orm.go` next to each source file.\n\n\u003e [!TIP]\n\u003e `ormc` automatically runs `go get` for required dependencies and `go mod tidy` if a `go.mod` is detected.\n\n### 3. Use it\n\n```go\nfunc GetActiveUsers(db *orm.DB) ([]*user.User, error) {\n    return user.ReadAllUser(\n        db.Query(\u0026user.User{}).\n            Where(user.User_.Email).Like(\"%@gmail.com\").\n            Limit(10),\n    )\n}\n```\n\n## Tags Reference\n\n### `db:` — DB layer\n\n| Tag | Effect |\n|-----|--------|\n| `db:\"pk\"` | Marks field as primary key (auto-detected for `ID` fields) |\n| `db:\"unique\"` | Unique constraint |\n| `db:\"not_null\"` | NOT NULL constraint |\n| `db:\"autoincrement\"` | Auto-increment (numeric fields only) |\n| `db:\"ref=table\"` | Foreign key to table (default column: `id`) |\n| `db:\"ref=table:col\"` | Foreign key to specific column |\n| `db:\"-\"` | Exclude field from schema entirely |\n\nDB flags are grouped in `Field.DB *FieldDB` (nil for `formonly` structs). Helpers: `field.IsPK()`, `field.IsUnique()`, `field.IsAutoInc()`.\n\n\u003e **String PKs:** must be set by caller via `github.com/tinywasm/unixid` before `db.Create()`. The ORM does not generate IDs.\n\n### `json:` — JSON layer\n\n| Tag | Effect |\n|-----|--------|\n| `json:\",omitempty\"` | Sets `OmitEmpty: true` in schema |\n| `json:\"-\"` | Exclude from JSON (field still in schema for DB/Form) |\n\n### `input:` — Form layer\n\n| Tag | Effect |\n|-----|--------|\n| `input:\"email\"` | `Widget: input.Email()` |\n| `input:\"textarea\"` | `Widget: input.Textarea()` |\n| `input:\"password\"` | `Widget: input.Password()` |\n| `input:\"number\"` | `Widget: input.Number()` |\n| `input:\"required\"` | `NotNull: true` |\n| `input:\"min=2,max=100\"` | `Permitted: fmt.Permitted{Minimum: 2, Maximum: 100}` |\n| `input:\"letters,spaces\"` | `Permitted: fmt.Permitted{Letters: true, Spaces: true}` |\n| `input:\"-\"` | No widget (field skipped in form rendering) |\n\nAvailable widget types: `text`, `email`, `password`, `textarea`, `phone`, `number`, `date`, `hour`, `ip`, `rut`, `address`, `checkbox`, `datalist`, `select`, `radio`, `filepath`, `gender`.\n\n`ormc` generates `Validate(action byte)` calling `fmt.ValidateFields(action, m)`. Validation runs for `'c'` (create), `'u'` (update), and `'d'` (delete, PK only).\n\n## Schema Types\n\n| Go Type | FieldType |\n|---|---|\n| `string` | `fmt.FieldText` |\n| `int`, `int32`, `int64`, `uint`, `uint32`, `uint64` | `fmt.FieldInt` |\n| `float32`, `float64` | `fmt.FieldFloat` |\n| `bool` | `fmt.FieldBool` |\n| `[]byte` | `fmt.FieldBlob` |\n| struct (nested) | `fmt.FieldStruct` |\n| `time.Time` | not allowed — use `int64` + `tinywasm/time` |\n\n## API Reference\n\n### DB Operations\n\n```go\ndb := orm.New(executor, compiler)\n\ndb.Create(\u0026user)\ndb.Update(\u0026user, orm.Eq(User_.ID, user.ID))\ndb.Delete(\u0026user, orm.Eq(User_.ID, user.ID))\ndb.CreateTable(\u0026User{})\ndb.DropTable(\u0026User{})\n```\n\n`Update` and `Delete` require at least one condition (compile-time enforced):\n\n```go\ndb.Update(\u0026res, orm.Eq(Reservation_.ID, res.ID))  // one condition\ndb.Update(\u0026cfg, orm.Eq(Config_.TenantID, tid),     // multiple conditions\n                orm.Eq(Config_.Key, key))\ndb.Update(\u0026res)                                     // compile error\n```\n\n### Query Builder\n\n```go\nuser.ReadAllUser(\n    db.Query(\u0026user.User{}).\n        Where(user.User_.Email).Like(\"%@example.com\").\n        OrderBy(user.User_.Name).Asc().\n        Limit(10).Offset(20),\n)\n```\n\nChainable: `Where(col)` → `.Eq()`, `.Neq()`, `.Gt()`, `.Gte()`, `.Lt()`, `.Lte()`, `.Like()`, `.In()` | `OrderBy(col)` → `.Asc()`, `.Desc()` | `Limit(n)`, `Offset(n)`, `GroupBy(cols...)`\n\n### Interfaces\n\n| Interface | Methods |\n|-----------|---------|\n| `Compiler` | `Compile(Query, Model) (Plan, error)` |\n| `Executor` | `Exec()`, `QueryRow()`, `Query()`, `Close()` |\n| `TxExecutor` | `Executor` + `BeginTx()` |\n| `TxBoundExecutor` | `Executor` + `Commit()`, `Rollback()` |\n\n## ormc — Code Generation\n\nRun from the **project root**. Scans subdirectories for `model.go` / `models.go`:\n\n```\nproject/\n  modules/\n    user/model.go      → modules/user/model_orm.go\n    product/models.go  → modules/product/model_orm.go\n```\n\n```go\n//go:generate ormc\n```\n\n**Generated per struct:**\n\n| What | When |\n|------|------|\n| `Schema() []Field`, `Pointers() []any` | Always |\n| `Validate(action byte) error` | When struct has validation rules or is a form |\n| `ModelName() string` | DB structs only (not `formonly`) |\n| `T_` metadata struct | DB structs only |\n| `ReadOneT()`, `ReadAllT()` | DB structs only |\n\n**Programmatic API:**\n\n| Method | Description |\n|--------|-------------|\n| `NewOrmc() *Ormc` | Create handler; `rootDir` defaults to `\".\"` |\n| `SetLog(func(...any))` | Set warning/info log function |\n| `SetRootDir(dir string)` | Set scan root |\n| `Run() error` | Scan and generate |\n| `GenerateForStruct(name, file string) error` | Generate for a single struct |\n| `ParseStruct(name, file string) (StructInfo, error)` | Parse struct metadata only |\n| `GenerateForFile(infos []StructInfo, file string) error` | Write all infos to one `_orm.go` |\n\n## More Documentation\n\n- [Architecture](docs/ARQUITECTURE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinywasm%2Form","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinywasm%2Form","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinywasm%2Form/lists"}