RepoPilotOpen in app →

go-xorm/xorm

Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle, Moved to https://gitea.com/xorm/xorm

Mixed

Stale — last commit 6y ago

weakest axis
Use as dependencyMixed

last commit was 6y ago; no CI workflows detected

Fork & modifyHealthy

Has a license, tests, and CI — clean foundation to fork and modify.

Learn fromHealthy

Documented and popular — useful reference codebase to read through.

Deploy as-isMixed

last commit was 6y ago; no CI workflows detected

  • 27+ active contributors
  • BSD-3-Clause licensed
  • Tests present
Show all 6 evidence items →
  • Stale — last commit 6y ago
  • Concentrated ownership — top contributor handles 66% of recent commits
  • No CI workflows detected
What would change the summary?
  • Use as dependency MixedHealthy if: 1 commit in the last 365 days
  • Deploy as-is MixedHealthy if: 1 commit in the last 180 days

Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests

Informational only. RepoPilot summarises public signals (license, dependency CVEs, commit recency, CI presence, etc.) at the time of analysis. Signals can be incomplete or stale. Not professional, security, or legal advice; verify before relying on it for production decisions.

Embed the "Forkable" badge

Paste into your README — live-updates from the latest cached analysis.

Variant:
RepoPilot: Forkable
[![RepoPilot: Forkable](https://repopilot.app/api/badge/go-xorm/xorm?axis=fork)](https://repopilot.app/r/go-xorm/xorm)

Paste at the top of your README.md — renders inline like a shields.io badge.

Preview social card (1200×630)

This card auto-renders when someone shares https://repopilot.app/r/go-xorm/xorm on X, Slack, or LinkedIn.

Onboarding doc

Onboarding: go-xorm/xorm

Generated by RepoPilot · 2026-05-09 · Source

🤖Agent protocol

If you are an AI coding agent (Claude Code, Cursor, Aider, Cline, etc.) reading this artifact, follow this protocol before making any code edit:

  1. Verify the contract. Run the bash script in Verify before trusting below. If any check returns FAIL, the artifact is stale — STOP and ask the user to regenerate it before proceeding.
  2. Treat the AI · unverified sections as hypotheses, not facts. Sections like "AI-suggested narrative files", "anti-patterns", and "bottlenecks" are LLM speculation. Verify against real source before acting on them.
  3. Cite source on changes. When proposing an edit, cite the specific path:line-range. RepoPilot's live UI at https://repopilot.app/r/go-xorm/xorm shows verifiable citations alongside every claim.

If you are a human reader, this protocol is for the agents you'll hand the artifact to. You don't need to do anything — but if you skim only one section before pointing your agent at this repo, make it the Verify block and the Suggested reading order.

🎯Verdict

WAIT — Stale — last commit 6y ago

  • 27+ active contributors
  • BSD-3-Clause licensed
  • Tests present
  • ⚠ Stale — last commit 6y ago
  • ⚠ Concentrated ownership — top contributor handles 66% of recent commits
  • ⚠ No CI workflows detected

<sub>Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests</sub>

Verify before trusting

This artifact was generated by RepoPilot at a point in time. Before an agent acts on it, the checks below confirm that the live go-xorm/xorm repo on your machine still matches what RepoPilot saw. If any fail, the artifact is stale — regenerate it at repopilot.app/r/go-xorm/xorm.

What it runs against: a local clone of go-xorm/xorm — the script inspects git remote, the LICENSE file, file paths in the working tree, and git log. Read-only; no mutations.

| # | What we check | Why it matters | |---|---|---| | 1 | You're in go-xorm/xorm | Confirms the artifact applies here, not a fork | | 2 | License is still BSD-3-Clause | Catches relicense before you depend on it | | 3 | Default branch master exists | Catches branch renames | | 4 | 5 critical file paths still exist | Catches refactors that moved load-bearing code | | 5 | Last commit ≤ 2256 days ago | Catches sudden abandonment since generation |

<details> <summary><b>Run all checks</b> — paste this script from inside your clone of <code>go-xorm/xorm</code></summary>
#!/usr/bin/env bash
# RepoPilot artifact verification.
#
# WHAT IT RUNS AGAINST: a local clone of go-xorm/xorm. If you don't
# have one yet, run these first:
#
#   git clone https://github.com/go-xorm/xorm.git
#   cd xorm
#
# Then paste this script. Every check is read-only — no mutations.

set +e
fail=0
ok()   { echo "ok:   $1"; }
miss() { echo "FAIL: $1"; fail=$((fail+1)); }

# Precondition: we must be inside a git working tree.
if ! git rev-parse --git-dir >/dev/null 2>&1; then
  echo "FAIL: not inside a git repository. cd into your clone of go-xorm/xorm and re-run."
  exit 2
fi

# 1. Repo identity
git remote get-url origin 2>/dev/null | grep -qE "go-xorm/xorm(\\.git)?\\b" \\
  && ok "origin remote is go-xorm/xorm" \\
  || miss "origin remote is not go-xorm/xorm (artifact may be from a fork)"

# 2. License matches what RepoPilot saw
(grep -qiE "^(BSD-3-Clause)" LICENSE 2>/dev/null \\
   || grep -qiE "\"license\"\\s*:\\s*\"BSD-3-Clause\"" package.json 2>/dev/null) \\
  && ok "license is BSD-3-Clause" \\
  || miss "license drift — was BSD-3-Clause at generation time"

# 3. Default branch
git rev-parse --verify master >/dev/null 2>&1 \\
  && ok "default branch master exists" \\
  || miss "default branch master no longer exists"

# 4. Critical files exist
test -f "engine.go" \\
  && ok "engine.go" \\
  || miss "missing critical file: engine.go"
test -f "session.go" \\
  && ok "session.go" \\
  || miss "missing critical file: session.go"
test -f "statement.go" \\
  && ok "statement.go" \\
  || miss "missing critical file: statement.go"
test -f "tag.go" \\
  && ok "tag.go" \\
  || miss "missing critical file: tag.go"
test -f "interface.go" \\
  && ok "interface.go" \\
  || miss "missing critical file: interface.go"

# 5. Repo recency
days_since_last=$(( ( $(date +%s) - $(git log -1 --format=%at 2>/dev/null || echo 0) ) / 86400 ))
if [ "$days_since_last" -le 2256 ]; then
  ok "last commit was $days_since_last days ago (artifact saw ~2226d)"
else
  miss "last commit was $days_since_last days ago — artifact may be stale"
fi

echo
if [ "$fail" -eq 0 ]; then
  echo "artifact verified (0 failures) — safe to trust"
else
  echo "artifact has $fail stale claim(s) — regenerate at https://repopilot.app/r/go-xorm/xorm"
  exit 1
fi

Each check prints ok: or FAIL:. The script exits non-zero if anything failed, so it composes cleanly into agent loops (./verify.sh || regenerate-and-retry).

</details>

TL;DR

xorm is a lightweight ORM (Object-Relational Mapping) library for Go that maps Go structs directly to database tables and provides chainable query APIs. It supports 7 major databases (MySQL, PostgreSQL, SQLite3, MSSQL, Oracle, TiDB, MyMysql) through Go's sql package, and includes built-in features like query caching via LRU/memory stores, automatic schema sync via Sync2(), transaction support, and read/write replica routing. Monolithic structure: core engine logic in engine.go, engine_cond.go, engine_context.go, engine_group.go; database dialect implementations in dialect_*.go files (one per database); caching layer in cache_lru.go and cache_memory_store.go; helper utilities in helpers.go and convert.go. Examples provided in examples/ directory with runnable demos (find.go, cache.go, sync.go). Migration utilities isolated in migrate/ package.

👥Who it's for

Go backend developers building applications that need database abstraction without heavy frameworks; teams adopting TiDB or multi-database strategies who want unified query syntax; developers who prefer struct-first schema definition over migrations.

🌱Maturity & risk

This repository is archived and unmaintained — the README explicitly states 'HAS BEEN MOVED TO https://gitea.com/xorm/xorm . THIS REPOSITORY WILL NOT BE UPDATED ANY MORE.' It has CircleCI/Drone CI configured and test coverage via codecov, but the GitHub mirror is frozen. The codebase shows mature patterns (good test coverage with _test.go files throughout, multiple dialect implementations) but active development has moved elsewhere.

High risk for new projects: This GitHub repository is explicitly archived with no further updates; all active development is on Gitea. Using this mirror means missing bug fixes and security patches. Dependency chain is relatively shallow (core, builder, plus database drivers) but driver maturity varies (Oracle marked experimental). No recent commit data provided, but the archival notice indicates stagnation.

Active areas of work

Nothing — this is an archived repository. Active development has moved to the Gitea instance at https://gitea.com/xorm/xorm. Any commits, PRs, or issues should be tracked there instead.

🚀Get running

Clone the archived repo (for reference only): git clone https://github.com/go-xorm/xorm.git && cd xorm. To work with the active codebase, migrate to: git clone https://gitea.com/xorm/xorm. Install dependencies: go mod download. Run tests: go test ./...

Daily commands: No server to run — this is a library. To verify the codebase: go test ./... runs the full test suite (cache_test.go, engine_context_test.go, dialect_*_test.go, etc.). Examples can be executed individually: go run examples/find.go (requires a configured database connection in the example file).

🗺️Map of the codebase

  • engine.go — Core Engine struct and initialization—the primary entry point for all ORM operations and database connections.
  • session.go — Session abstraction that wraps query execution, transactions, and statement building—used by nearly all database operations.
  • statement.go — SQL statement construction and management—central to query building and dialect-agnostic SQL generation.
  • tag.go — Struct tag parsing and column mapping—enables struct ↔ table reflection and ORM declarative configuration.
  • interface.go — Core interface definitions (Dialect, Logger, ContextCache, etc.)—defines the contract for all pluggable components.
  • xorm.io/core — External dependency providing core types and column/table metadata—foundational for schema introspection and type conversion.
  • xorm.io/builder — External dependency for SQL builder—enables chainable, safe SQL clause construction.

🛠️How to make changes

Add a new database dialect (e.g., for a new SQL variant)

  1. Create a new file dialect_<dbname>.go in the root directory following the pattern of dialect_postgres.go. (dialect_postgres.go)
  2. Implement the Dialect interface from interface.go: define SQL generation methods (GetIndexes, CreateTableSQL, etc.) and type mappings. (interface.go)
  3. Register the dialect in engine.go's NewEngine or equivalent initialization function. (engine.go)
  4. Add test coverage in dialect_<dbname>_test.go following existing patterns. (dialect_postgres_test.go)

Add a new struct tag feature (e.g., custom column constraint)

  1. Extend struct tag parsing in tag.go by adding a new tag constant (e.g., xorm:"notnull") and parse logic in parseFieldName or related functions. (tag.go)
  2. Update tag-related tests in tag_test.go and tag_<feature>_test.go to verify parsing. (tag_test.go)
  3. Modify statement.go or dialect-specific files to emit the constraint in generated SQL (e.g., in CreateTableSQL). (statement.go)
  4. Update session_schema.go if the tag affects schema synchronization logic (Sync, CreateTable). (session_schema.go)

Add a new query method (e.g., custom Find variant)

  1. Add the chainable method to session.go (or engine_cond.go if it's an Engine-level helper), following the pattern of existing Find, Get, Count methods. (session.go)
  2. Use statement.go to build the SQL query: call statement.genSelectSQL() or similar helpers. (statement.go)
  3. Call rows.go's ScanMap or ScanSlice to map database results into Go structs. (rows.go)
  4. Add test coverage in session_find_test.go or a new session_<method>_test.go file. (session_find_test.go)

Implement a custom processor hook (e.g., audit logging on every update)

  1. Define your Processor type conforming to the Processor interface in interface.go. (interface.go)
  2. Implement Before/After hooks for the operation (e.g., BeforeUpdate, AfterUpdate). (processors.go)
  3. Register the processor in session.go via the AddProcessor method or in engine.go for global processors. (session.go)
  4. Add tests in processors_test.go to verify hook invocation and side effects. (processors_test.go)

🔧Why these technologies

  • Go 1.11+ with struct tags — Enables compile-time declarative mapping via tags (xorm:"pk", xorm:"version", etc.) without external code generation for most use cases.
  • Multiple database drivers (mysql, postgres, sqlite3, mssql, oracle) — Decouples ORM logic from vendor-specific SQL via pluggable Dialect interface; users choose driver at engine creation time.
  • Session abstraction wrapping database/sql — Provides transaction support, statement reuse, and query state management without exposing raw *sql.Tx/Conn to all callers.
  • In-memory LRU cache for query results — Accelerates repeated queries on hot data without external cache infrastructure; trades memory for latency reduction.
  • Reflection for struct ↔ table mapping — Eliminates boilerplate CRUD generation and mapping code; allows dynamic schema discovery and sync.

⚖️Trade-offs already made

  • Struct tag-based configuration vs. explicit builder methods
    • Why: Tags are compact and co-located with field definitions; builders require chained calls but are more explicit.
    • Consequence: Tag syntax is dense and harder to debug; typos

🪤Traps & gotchas

No go.sum or vendor/ directory means dependencies are fetched fresh — ensure go mod download completes before testing. Each dialect_*.go file imports a different driver (e.g., 'github.com/lib/pq' for Postgres); tests require the corresponding database running or will skip. The migrate/ package is minimal; full migration logic is in the Gitea version. Context caching (context_cache.go) is opt-in but thread-unsafe if not used carefully with Sessions. Example files hardcode database connections — modify DSN before running.

🏗️Architecture

💡Concepts to learn

  • Dialect Pattern — xorm abstracts database differences (SQL syntax, type mappings, reserved keywords) via the Dialect interface — understanding dialect_*.go files is key to supporting new databases
  • LRU Cache (Least Recently Used) — cache_lru.go implements query result caching with bounded memory; critical for xorm's performance optimization feature mentioned in features list
  • Struct Tags for ORM Mapping — xorm uses Go struct tags (e.g., xorm:"varchar(200)" in README example) to define column types and constraints — this is non-obvious Go metaprogramming central to the lib
  • Read/Write Replica Splitting — engine_group.go and engine_group_policy.go route write operations to master, reads to replicas — understanding this is crucial for scaling deployments mentioned in features
  • Context Caching Strategy — context_cache.go shows request-scoped caching (cache per context) vs global caching — affects concurrency safety and memory usage in high-concurrency services
  • Optimistic Locking — Listed as a feature in README; relies on version columns to detect concurrent modifications without database locks — look for version/timestamp handling in engine.go updates
  • Type Conversion & Value Reflection — convert.go maps between Go types (int, time.Time, string) and database types (VARCHAR, DATETIME, INT) using reflection — essential for the struct ↔ table mapping feature
  • xorm/xorm — The active maintained fork of this project on Gitea — migrate here for bug fixes and new features instead of using this archived GitHub mirror
  • jinzhu/gorm — Alternative Go ORM with similar struct-to-table mapping, wider adoption, and active maintenance; consider if xorm's feature set doesn't fit
  • upper/db — Lightweight Go database abstraction library with fewer databases supported but simpler API; good if you want less magic than xorm
  • xorm/builder — SQL query builder used by xorm for composing WHERE/JOIN clauses; imported as xorm.io/builder in go.mod
  • xorm/core — Shared core types and interfaces (TableInfo, ColumnInfo, Dialect base) used across xorm ecosystem; imported as xorm.io/core in go.mod

🪄PR ideas

To work on one of these in Claude Code or Cursor, paste: Implement the "<title>" PR idea from CLAUDE.md, working through the checklist as the task list.

Add comprehensive test coverage for session_cols.go operations

session_cols.go handles critical column selection logic for queries, but session_cols_test.go appears minimal based on the file structure. This module is central to XORM's query building and lacks thorough edge case testing for scenarios like: nullable columns, column aliasing, joined table columns, and dynamic column selection in different database dialects.

  • [ ] Review existing tests in session_cols_test.go and identify untested code paths
  • [ ] Add tests for column selection across all supported dialects (MySQL, PostgreSQL, SQLite3, MSSQL, Oracle)
  • [ ] Add edge case tests: empty column lists, duplicate columns, non-existent columns, and special characters in column names
  • [ ] Add integration tests for column selection with joins and subqueries
  • [ ] Run coverage analysis on session_cols.go and aim for >90% coverage

Implement missing dialect-specific tests for Oracle (dialect_oracle.go)

The repo has dedicated test files for MySQL, PostgreSQL, and SQLite3 (dialect_*_test.go), but Oracle dialect lacks a corresponding test file. Given Oracle's unique SQL syntax (e.g., ROWNUM, different type casting), this is a significant gap that could catch database-specific bugs early.

  • [ ] Create dialect_oracle_test.go following the pattern of dialect_postgres_test.go and dialect_mysql_test.go
  • [ ] Add tests for Oracle-specific SQL generation: identity columns, ROWNUM pagination, type conversions
  • [ ] Test Oracle-specific features like sequence handling and CLOB/BLOB data types
  • [ ] Add tests for schema introspection against Oracle databases
  • [ ] Consider adding Oracle database connection tests in CI if infrastructure allows

Add comprehensive tests for engine_cond.go conditional query building

engine_cond.go handles WHERE clause construction, a critical part of any ORM. There's no corresponding engine_cond_test.go file, meaning complex conditional logic (AND/OR operators, nested conditions, operator precedence) lacks test coverage. This is foundational to query correctness.

  • [ ] Create engine_cond_test.go with tests for basic WHERE conditions (=, !=, >, <, IN, LIKE, BETWEEN)
  • [ ] Add tests for complex boolean logic: nested AND/OR conditions, operator precedence, De Morgan's law scenarios
  • [ ] Add tests for prepared statement parameter binding with conditions
  • [ ] Test SQL injection prevention with parameterized conditions
  • [ ] Add dialect-specific tests to ensure generated SQL is correct for each supported database
  • [ ] Test edge cases: NULL comparisons, empty conditions, conditions on non-existent columns

🌿Good first issues

  • Add comprehensive unit tests for convert.go type conversion edge cases (date/time formats across databases) — currently only has basic helper tests
  • Create a troubleshooting guide in docs/ documenting common 'driver not found' errors and dialect selection for each supported database — currently only README mentions drivers
  • Implement missing test coverage for dialect_oracle.go (marked as experimental) — currently no dialect_oracle_test.go exists; start with a basic CRUD test scaffold

Top contributors

Click to expand

📝Recent commits

Click to expand
  • f39e5d9 — Update README.md (lunny)
  • 33fc33b — add support custom type Nullfloat64 (#1450) (lunny)
  • 57a49c6 — fix bug when query map condtion with no quote (#1449) (lunny)
  • 6a47ef9 — Don't warn when bool column default is 1 but not true (#1447) (lunny)
  • 4857995 — Fix sync2 with custom table name (#1445) (lunny)
  • da95db5 — fix bug when update with setexpr (#1446) (lunny)
  • db25dfc — add tidb tests on drone ci (#1444) (lunny)
  • 98db3ef — improve sync2 (#1443) (lunny)
  • c5ee68f — Fix wrong dbmetas (#1442) (lunny)
  • a5702e5 — Fix default value parse bugs (#1437) (lunny)

🔒Security observations

  • High · Outdated and Vulnerable Dependencies — go.mod, go.sum. The go.mod file contains several outdated dependencies with known security vulnerabilities. Notable issues: github.com/go-sql-driver/mysql v1.4.1 (released 2019, multiple CVEs), github.com/mattn/go-sqlite3 v1.10.0 (outdated), github.com/jackc/pgx v3.6.0 (deprecated major version), and xorm.io/core v0.7.2-0.20190928055935-90aeac8d08eb (pre-release version). These dependencies have not been updated for several years and likely contain patched security vulnerabilities. Fix: Update all dependencies to their latest stable versions. Run 'go get -u' and verify compatibility with current Go versions (currently targeting Go 1.11, which is also outdated). Establish a dependency management and patching strategy.
  • High · SQL Injection Vulnerability Risk — session_raw.go, session_query.go, session_cond.go, engine_cond.go. The codebase implements an ORM that supports raw SQL operations (evident from session_raw.go, session_query.go). Given the file names like 'session_cond.go' and 'engine_cond.go' which handle conditions, there is significant risk of SQL injection if user input is not properly parameterized when building dynamic queries. The presence of raw SQL support without clear evidence of parameterization enforcement increases vulnerability surface. Fix: Conduct thorough code review focusing on query building logic. Ensure all dynamic query construction uses parameterized queries exclusively. Implement input validation and sanitization for all user-supplied data. Add security-focused unit tests for SQL injection scenarios. Document best practices for safe query usage.
  • High · Repository No Longer Maintained — README.md. The README explicitly states 'xorm HAS BEEN MOVED TO https://gitea.com/xorm/xorm . THIS REPOSITORY WILL NOT BE UPDATED ANY MORE.' This GitHub repository is abandoned and will not receive security patches, bug fixes, or updates. Using this repository in production applications poses significant long-term security risks. Fix: Migrate to the actively maintained repository at https://gitea.com/xorm/xorm. Do not use this GitHub repository for new projects. For existing projects, plan a migration timeline to the official maintained version.
  • Medium · Ancient Go Version Targeting — go.mod. The project targets Go 1.11 (released August 2018), which is ancient by current standards. Go 1.11 reached end-of-life in August 2019. This version lacks numerous security patches, performance improvements, and modern language features. Compatibility with modern security tools may be limited. Fix: Update the minimum Go version to at least 1.19 or higher (current stable is 1.21+). Verify codebase compatibility with modern Go versions. This will enable access to security patches and modern tooling.
  • Medium · Insufficient Input Validation in Database Operations — session_insert.go, session_update.go, session_delete.go, session_find.go. Multiple session files (session_insert.go, session_update.go, session_delete.go) perform database operations based on user input. Without explicit evidence of comprehensive input validation and type checking, there is risk of unexpected behavior, data corruption, or injection attacks through improperly validated struct fields or query parameters. Fix: Implement comprehensive input validation for all database operations. Validate field types, lengths, and values before database operations. Add bounds checking and sanity validation. Implement type safety checks for all user-supplied data used in queries.
  • Medium · No Evidence of Security Headers or CORS Configuration — engine.go, logger.go, session.go. While this is an ORM library (not a web server), applications built with this library need security controls. There is no evidence of built-in security headers, CORS protection, or authentication mechanisms documented. Developers may not implement these critical controls. Fix: Create security documentation and guidelines for developers using this ORM. Recommend that applications implement security headers, CORS policies, authentication/authorization, and input validation at the application layer.
  • Low · Limited Security Documentation — undefined. The repository lacks comprehensive security documentation, secure coding guidelines, and vulnerability disclosure policy. This makes it difficult for users to understand security implications and report vulnerabilities. Fix: undefined

LLM-derived; treat as a starting point, not a security audit.


Generated by RepoPilot. Verdict based on maintenance signals — see the live page for receipts. Re-run on a new commit to refresh.

Mixed signals · go-xorm/xorm — RepoPilot