{"id":19329977,"url":"https://github.com/asynq-io/sqlargon","last_synced_at":"2025-06-12T02:05:29.760Z","repository":{"id":248829051,"uuid":"829450748","full_name":"asynq-io/sqlargon","owner":"asynq-io","description":"SQLAlchemy utils for Postgres and Sqlite","archived":false,"fork":false,"pushed_at":"2025-05-22T17:48:31.000Z","size":994,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-12T02:05:27.971Z","etag":null,"topics":["asyncio","python","sqlalchemy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/asynq-io.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}},"created_at":"2024-07-16T13:00:41.000Z","updated_at":"2025-05-22T17:47:15.000Z","dependencies_parsed_at":"2024-07-17T10:28:18.202Z","dependency_job_id":"2ba4e9f4-5932-4be2-bada-699ace1e8d1c","html_url":"https://github.com/asynq-io/sqlargon","commit_stats":null,"previous_names":["asynq-io/sqlargon"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/asynq-io/sqlargon","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asynq-io%2Fsqlargon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asynq-io%2Fsqlargon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asynq-io%2Fsqlargon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asynq-io%2Fsqlargon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asynq-io","download_url":"https://codeload.github.com/asynq-io/sqlargon/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asynq-io%2Fsqlargon/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259382263,"owners_count":22848833,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["asyncio","python","sqlalchemy"],"created_at":"2024-11-10T02:32:58.267Z","updated_at":"2025-06-12T02:05:29.737Z","avatar_url":"https://github.com/asynq-io.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQLArgon\n\n![CI](https://github.com/asynq-io/sqlargon/workflows/CI/badge.svg)\n![Build](https://github.com/asynq-io/sqlargon/workflows/Publish/badge.svg)\n![License](https://img.shields.io/github/license/asynq-io/sqlargon)\n![Python](https://img.shields.io/pypi/pyversions/sqlargon)\n![Format](https://img.shields.io/pypi/format/sqlargon)\n![PyPi](https://img.shields.io/pypi/v/sqlargon)\n![Mypy](https://img.shields.io/badge/mypy-checked-blue)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v1.json)](https://github.com/charliermarsh/ruff)\n[![security: bandit](https://img.shields.io/badge/security-bandit-yellow.svg)](https://github.com/PyCQA/bandit)\n\n\n*Wrapper around SQLAlchemy async session, core and Postgres native features*\n\n---\nVersion: 0.6.10\n\nDocumentation: https://asynq-io.github.io/sqlargon/\n\nRepository: https://github.com/asynq-io/sqlargon\n\n---\n\n## About\n\nThis library provides glue code to use sqlalchemy async sessions, core queries and orm models\nfrom one object which provides somewhat of repository pattern. This solution has few advantages:\n\n- no need to pass `session` object to every function/method. It is stored (and optionally injected) in repository object\n- write data access queries in one place\n- no need to import `insert`,`update`, `delete`, `select` from sqlalchemy over and over again\n- Implicit cast of results to `.scalars().all()` or `.one()`\n- Your view model (e.g. FastAPI routes) does not need to know about the underlying storage. Repository class can be replaced at any moment any object providing similar interface.\n\n## Usage\n\n```python\nimport sqlalchemy as sa\nfrom sqlalchemy.orm import Mapped\nfrom sqlargon import GUID, GenerateUUID, Database, Base, SQLAlchemyRepository\n\ndb = Database(url=...)\n\nclass User(Base):\n        id = sa.Column(\n            GUID(), primary_key=True, server_default=GenerateUUID(), nullable=False\n        )\n        name: Mapped[str] = sa.Column(sa.Unicode(255))\n\n\nclass UserRepository(SQLAlchemyRepository[User]):\n\n    async def get_user_by_name(self, name: str):\n        # custom user function\n        return await self.select().filter_by(name=name).one()\n\nuser_repository = UserRepository(db)\n\n# select\nawait user_repository.all()\nawait user_repository.list(User.name == \"test\", User.id \u003e= 18)\n\n\n# insert\nuser = await user_repository.insert({\"name\": \"test\"}).one()\n\nawait user_repository.commit()\n\n\n\n# delete\nawait user_repository.delete().filter(name=\"John\").one()\n\n# custom sqlalchemy core functions\n\nusers = await user_repository.select().join(...).filter(\n    User.name == \"test\"\n).filter_by(...).order_by(User.created_at).limit(2).all()\n\n```\n\n## Sessions\n\nManager object needs `sqlalchemy.ext.asyncio.AsyncSession`, but it's possible\nto provide the session object by yourself, by subclassing Manager class e.g.\n\n```python\nfrom sqlargon import Database, SQLAlchemyRepository\nfrom fastapi import Depends\n\ndb = Database(url=\"sqlite+aiosqlite:///:memory:\")\n\n\nclass UserRepository(SQLAlchemyRepository[User]):\n    ...\n\n\n\n    \nfrom fastapi import FastAPI\n\napp = FastAPI()\n\n\n@app.get(\"/users\")\nasync def get_users(user_repository: UserRepository = db.Depends(UserRepository)):\n    return await user_repository.all()\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasynq-io%2Fsqlargon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasynq-io%2Fsqlargon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasynq-io%2Fsqlargon/lists"}