{"id":39337202,"url":"https://github.com/dan1elt0m/sadel","last_synced_at":"2026-01-18T02:13:31.844Z","repository":{"id":251273714,"uuid":"836917633","full_name":"dan1elt0m/sadel","owner":"dan1elt0m","description":"SQLModel helper class for upserting records.","archived":false,"fork":false,"pushed_at":"2025-10-14T19:22:57.000Z","size":86,"stargazers_count":11,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-20T19:26:58.760Z","etag":null,"topics":["alembic","asyncio","database","pydantic","sqlalchemy","sqlmodel","upsert"],"latest_commit_sha":null,"homepage":"","language":"Python","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/dan1elt0m.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}},"created_at":"2024-08-01T20:41:29.000Z","updated_at":"2025-10-14T19:22:06.000Z","dependencies_parsed_at":"2024-08-01T23:05:28.699Z","dependency_job_id":"07b274ab-2a94-4e89-8513-30a9311ba9ab","html_url":"https://github.com/dan1elt0m/sadel","commit_stats":null,"previous_names":["dan1elt0m/sadel"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/dan1elt0m/sadel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dan1elt0m%2Fsadel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dan1elt0m%2Fsadel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dan1elt0m%2Fsadel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dan1elt0m%2Fsadel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dan1elt0m","download_url":"https://codeload.github.com/dan1elt0m/sadel/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dan1elt0m%2Fsadel/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28526569,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T00:39:45.795Z","status":"online","status_checked_at":"2026-01-18T02:00:07.578Z","response_time":98,"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":["alembic","asyncio","database","pydantic","sqlalchemy","sqlmodel","upsert"],"created_at":"2026-01-18T02:13:31.767Z","updated_at":"2026-01-18T02:13:31.817Z","avatar_url":"https://github.com/dan1elt0m.png","language":"Python","readme":"[![CodeQL](https://github.com/dan1elt0m/sadel/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/dan1elt0m/sadel/actions/workflows/codeql-analysis.yml)\n[![Dependabot Updates](https://github.com/dan1elt0m/sadel/actions/workflows/dependabot/dependabot-updates/badge.svg)](https://github.com/dan1elt0m/sadel/actions/workflows/dependabot/dependabot-updates)\n[![test](https://github.com/dan1elt0m/sadel/actions/workflows/test.yml/badge.svg)](https://github.com/dan1elt0m/sadel/actions/workflows/test.yml)\n[![codecov](https://codecov.io/github/dan1elt0m/sadel/graph/badge.svg?token=NECZRE656C)](https://codecov.io/github/dan1elt0m/sadel)\n![Python Version from PEP 621 TOML](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2Fdan1elt0m%2Fsadel%2Fmain%2Fpyproject.toml)\n\n\n# Sadel \n\nSadel is a helper class for upserting records with [SQLModel](https://sqlmodel.tiangolo.com/). \n\n### Installation\n```bash\npip install sadel\n```\n\n#### Example upsert\n```python\nfrom sadel import Sadel\nfrom sqlalchemy.ext.asyncio import create_async_engine\nfrom sqlmodel import Field, create_engine, select, or_\nfrom sqlmodel.ext.asyncio.session import AsyncSession\n\nclass Hero(Sadel, table=True):\n    __tablename__ = \"hero\" \n    _upsert_index_elements = {\"id\"}\n\n    id: int | None = Field(default=None, primary_key=True)\n    name: str\n    secret_name: str\n    age: int | None = None\n\n# Create\nsqlite_url_async = \"sqlite+aiosqlite:///database.db\" \nasync_engine = create_async_engine(sqlite_url_async, echo=True, future=True)\n\n\nhero = Hero(name=\"Deadpond\", secret_name=\"Dive Wilson\")\n\nasync with AsyncSession(async_engine) as session:\n    # Upsert the record\n    await Hero.upsert(hero, session)\n    \n    # Fetch the upserted record\n    result = (\n        (await session.exec(select(Hero).where(Hero.name == \"Deadpond\")))\n        .all()\n    )\n\n    print(result)\n```\nOutput:\n```text\n[Hero(id=1, name='Deadpond', secret_name='Dive Wilson', age=None, created_on=datetime.datetime(2024, 8, 1, 19, 39, 7), modified_on=None)]\n```\n### Example batch upsert\n```python\nhero_1 = Hero(name=\"Deadpond\", secret_name=\"Dive Wilson\")\nhero_2 = Hero(name=\"Spider-Boy\", secret_name=\"Pedro Parqueador\")\nhero_3 = Hero(name=\"Rusty-Man\", secret_name=\"Tommy Sharp\", age=48)\n\nasync with AsyncSession(async_engine) as session:\n    await Hero.batch_upsert([hero_1, hero_2, hero_3], session)\n    result = (\n        (\n            await session.exec(\n               select(Hero).where(or_(Hero.name == \"Deadpond\",  Hero.name == \"Spider-Boy\", Hero.name == \"Rusty-Man\"))\n            )\n        )\n        .all()\n    )\n    print(result)\n```\nOutput:\n```text\n[Hero(id=1, name='Deadpond', secret_name='Dive Wilson',age=None, created_on=datetime.datetime(2024, 8, 1, 19, 39, 7), modified_on=None), \nHero(id=2, name='Spider-Boy\", secret_name='Pedro Parqueador',age=None, created_on=datetime.datetime(2024, 8, 1, 19, 39, 7), modified_on=None),\nHero(id=3, name='Rusty-Man', secret_name='Tommy Sharp', age=48, created_on=datetime.datetime(2024, 8, 1, 19, 39, 7), modified_on=None)]\n```\n\n### Example update record\n```python\nasync with AsyncSession(async_engine) as session:\n    # Upsert the record\n    hero = Hero(name=\"Deadpond\", secret_name=\"Dive Wilson\", age=25)\n    await Hero.upsert(hero, session)\n\n    # Update the record\n    hero.age = 30\n    # Upsert the updated record\n    await Hero.upsert(hero, session)\n\n    # Fetch the updated record\n    result = (\n        (await session.exec(select(Hero).where(Hero.name == \"Deadpond\")))\n        .scalars()\n        .all()\n    )\n\n    print(result)\n```\nOutput:\n```text\n[Hero(id=1, name='Deadpond', secret_name='Dive Wilson', age=30, created_on=datetime.datetime(2024, 8, 1, 19, 39, 7), modified_on=datetime.datetime(2024, 8, 1, 19, 39, 8))]\n```\n\n### Features\n- Upsert and batch_upsert functions.\n- For auditing, automatically adds and manages `created_on` and `modified_on` columns to your table (timezones are supported).\n- Validates your data before upserting using Pydantic validate_model method (not supported in SQLModel)\n- Asyncio\n- Compatible with Alembic\n- Specify the (PK) columns to use for upserting using `_upsert_index_elements` attribute\n- Ignore specific columns from updating using `_upsert_exclude_fields` attribute\n\n### Contributing\n- Fork the repository\n- Create a new branch\n- Make your changes\n- Raise a PR\n\n### License\nThis project is licensed under the terms of the [MIT License](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdan1elt0m%2Fsadel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdan1elt0m%2Fsadel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdan1elt0m%2Fsadel/lists"}