{"id":48660776,"url":"https://github.com/ehsanmok/sqlite","last_synced_at":"2026-04-15T07:03:41.176Z","repository":{"id":350414230,"uuid":"1205503614","full_name":"ehsanmok/sqlite","owner":"ehsanmok","description":"Safe and idiomatic SQLite binding for Mojo🔥 with ORM support","archived":false,"fork":false,"pushed_at":"2026-04-10T07:41:08.000Z","size":80,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-10T10:40:09.773Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://ehsanmok.github.io/sqlite/","language":"Mojo","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/ehsanmok.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2026-04-09T02:49:46.000Z","updated_at":"2026-04-10T07:41:13.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ehsanmok/sqlite","commit_stats":null,"previous_names":["ehsanmok/sqlite"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ehsanmok/sqlite","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehsanmok%2Fsqlite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehsanmok%2Fsqlite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehsanmok%2Fsqlite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehsanmok%2Fsqlite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ehsanmok","download_url":"https://codeload.github.com/ehsanmok/sqlite/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehsanmok%2Fsqlite/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31830158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T18:05:02.291Z","status":"online","status_checked_at":"2026-04-15T02:00:06.175Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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-10T10:06:12.869Z","updated_at":"2026-04-15T07:03:41.169Z","avatar_url":"https://github.com/ehsanmok.png","language":"Mojo","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sqlite\n\n[![CI](https://github.com/ehsanmok/sqlite/actions/workflows/ci.yml/badge.svg)](https://github.com/ehsanmok/sqlite/actions)\n[![Docs](https://github.com/ehsanmok/sqlite/actions/workflows/docs.yaml/badge.svg)](https://ehsanmok.github.io/sqlite)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)\n\nSQLite bindings for Mojo with a safe API, Pythonic context-manager\ntransactions, and an ORM layer powered by compile-time reflection via\n[morph](https://github.com/ehsanmok/morph).\n\n## Features\n\n- **Three-layer design**: raw FFI, safe `Database`/`Statement`/`Row` API, and\n  `morph`-based ORM\n- **Pythonic transactions**: `with db.transaction():` commits on success and\n  rolls back automatically on exception (identical to Python's `with conn:`)\n- **ORM**: `create_table`, `insert`, `query` driven by compile-time struct\n  reflection; no SQL to write for basic CRUD\n- **Rich type support**: `String`, `Int`, `Int64`, `Float64`, `Float32`,\n  `Bool`, `Optional[T]`\n- **Thoroughly tested**: unit, edge-case, and property-based fuzz tests via\n  [mozz](https://github.com/ehsanmok/mozz)\n\n## Quick Start\n\n### ORM\n\n```mojo\nfrom sqlite import Database, create_table, insert, query\n\n@fieldwise_init\nstruct Person(Defaultable, Movable):\n    var name: String\n    var age:  Int\n    var score: Float64\n\n    def __init__(out self):\n        self.name  = \"\"\n        self.age   = 0\n        self.score = 0.0\n\ndef main() raises:\n    var db = Database(\":memory:\")\n    create_table[Person](db, \"people\")\n    insert[Person](db, \"people\", Person(name=\"Alice\", age=30, score=9.5))\n    insert[Person](db, \"people\", Person(name=\"Bob\",   age=25, score=7.2))\n\n    var rows = query[Person](db, \"people\")\n    for i in range(len(rows)):\n        print(rows[i].name, rows[i].age, rows[i].score)\n    # Alice 30 9.5\n    # Bob   25 7.2\n```\n\n### Transactions\n\n`db.transaction()` supports Mojo's `with` statement, giving you the same\nauto-commit / auto-rollback semantics as Python's `with conn:`.\n\n#### Context-manager pattern (recommended)\n\n```mojo\nfrom sqlite import Database\n\ndef transfer(mut db: Database, from_id: Int, to_id: Int, amount: Int) raises:\n    with db.transaction():\n        db.execute(\n            \"UPDATE accounts SET balance = balance - \"\n            + String(amount) + \" WHERE id = \" + String(from_id)\n        )\n        db.execute(\n            \"UPDATE accounts SET balance = balance + \"\n            + String(amount) + \" WHERE id = \" + String(to_id)\n        )\n    # -\u003e COMMIT on success; ROLLBACK + re-raise if either UPDATE raised\n```\n\nFor explicit guard access (e.g., conditional rollback without raising), use\nthe `var tx` form. Mojo's `with/__exit__` protocol requires a non-consuming\n`__enter__`, so `with ... as tx:` would bind `tx` to `None`:\n\n```mojo\nvar tx = db.transaction()   # BEGIN\ndb.execute(\"INSERT ...\")\nif some_condition:\n    tx.rollback()           # abort without raising\n    return\ntx.commit()\n```\n\n#### Manual pattern (fine-grained control)\n\n```mojo\nvar tx = db.transaction()   # BEGIN\ndb.execute(\"INSERT ...\")\ntx.commit()                 # explicit COMMIT\n\n# Abandon without raising: immediate ROLLBACK\nvar tx2 = db.transaction()\ndb.execute(\"INSERT ...\")\n_ = tx2^                    # consume guard -\u003e ROLLBACK right here\n```\n\n### Raw prepared statements\n\n```mojo\nfrom sqlite import Database\n\ndef main() raises:\n    var db = Database(\":memory:\")\n    db.execute(\"CREATE TABLE t (id INTEGER, label TEXT)\")\n\n    var stmt = db.prepare(\"INSERT INTO t VALUES (?, ?)\")\n    stmt.bind_int(1, 42)\n    stmt.bind_text(2, \"hello\")\n    _ = stmt.step()\n\n    var q = db.prepare(\"SELECT id, label FROM t\")\n    while True:\n        var row = q.step()\n        if not row:\n            break\n        print(row.value().int_val(0), row.value().text_val(1))\n        # 42  hello\n```\n\n## Installation\n\nAdd sqlite to your project's `pixi.toml`:\n\n```toml\n[workspace]\nchannels = [\"https://conda.modular.com/max-nightly\", \"conda-forge\"]\npreview = [\"pixi-build\"]\n\n[dependencies]\nsqlite = { git = \"https://github.com/ehsanmok/sqlite.git\", tag = \"v0.1.0\" }\n```\n\nThen run:\n\n```bash\npixi install\n```\n\nFor the latest development version:\n\n```toml\n[dependencies]\nsqlite = { git = \"https://github.com/ehsanmok/sqlite.git\", branch = \"main\" }\n```\n\n## Examples\n\nProgressive examples live in [`examples/`](examples/):\n\n| File | What it shows |\n|---|---|\n| `01_hello_sqlite.mojo` | Open a database, `CREATE TABLE`, `INSERT`, `SELECT` |\n| `02_prepared_statements.mojo` | Bind parameters, iterate rows, reuse statements |\n| `03_all_types.mojo` | Every supported column type round-trip |\n| `04_orm_basics.mojo` | ORM `create_table` / `insert` / `query` |\n| `05_orm_optional.mojo` | `Optional` fields, `WHERE` / `ORDER BY` |\n| `06_contacts_app.mojo` | Realistic CRUD mini-app with transactions |\n| `07_transactions.mojo` | Bank-transfer demo: `with`, `as tx`, manual, `_ = tx^` |\n\nFull API reference: [ehsanmok.github.io/sqlite](https://ehsanmok.github.io/sqlite)\n\n## Development\n\n```bash\npixi run tests          # run all tests (db + ORM + fuzz)\npixi run test-db        # db layer only\npixi run test-orm       # ORM layer only\npixi run test-fuzz      # property-based fuzz tests\npixi run examples       # run all examples\npixi run example-07     # transactions example\npixi run bench          # micro-benchmarks\npixi run -e dev docs    # build and open API docs\npixi run format         # auto-format source\n```\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fehsanmok%2Fsqlite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fehsanmok%2Fsqlite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fehsanmok%2Fsqlite/lists"}