{"id":22802579,"url":"https://github.com/code-specialist/database-setup-tools","last_synced_at":"2025-04-19T20:21:48.300Z","repository":{"id":64435237,"uuid":"568431593","full_name":"code-specialist/database-setup-tools","owner":"code-specialist","description":"Easy to understand and use python tools that help you to create databases and interact with them","archived":false,"fork":false,"pushed_at":"2024-07-25T20:14:26.000Z","size":323,"stargazers_count":4,"open_issues_count":9,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-29T12:51:19.458Z","etag":null,"topics":["database","database-connector","database-management","fastapi","fastapi-sqlalchemy","sqlalchemy","sqlalchemy-python","sqlmodel"],"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/code-specialist.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":"2022-11-20T14:15:06.000Z","updated_at":"2024-06-05T10:31:28.000Z","dependencies_parsed_at":"2024-04-25T08:26:11.717Z","dependency_job_id":"a0f46b74-b793-42b9-b55b-d5c5a32e4e52","html_url":"https://github.com/code-specialist/database-setup-tools","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-specialist%2Fdatabase-setup-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-specialist%2Fdatabase-setup-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-specialist%2Fdatabase-setup-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-specialist%2Fdatabase-setup-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/code-specialist","download_url":"https://codeload.github.com/code-specialist/database-setup-tools/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249792483,"owners_count":21326353,"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":["database","database-connector","database-management","fastapi","fastapi-sqlalchemy","sqlalchemy","sqlalchemy-python","sqlmodel"],"created_at":"2024-12-12T09:06:37.044Z","updated_at":"2025-04-19T20:21:48.283Z","avatar_url":"https://github.com/code-specialist.png","language":"Python","readme":"# Database Setup Tools for SQLModel / SQLAlchemy\n\n[![CodeQL](https://github.com/code-specialist/database-setup-tools/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/code-specialist/database-setup-tools/actions/workflows/github-code-scanning/codeql)\n[![Test](https://github.com/code-specialist/database-setup-tools/actions/workflows/test.yaml/badge.svg)](https://github.com/code-specialist/database-setup-tools/actions/workflows/test.yaml)\n\nSimplified database lifecycle and session management based on [SQLModel](https://sqlmodel.tiangolo.com/) / [SQLAlchemy](https://www.sqlalchemy.org/).\n\nAny contributions are welcome! But we only accept pull requests that come with tests.\n\n## Installation\n\n```bash\npip install database-setup-tools\n```\n\n## Features\n\n- **Database creation on app startup**\n- Thread-safe database **session manager**\n- Opinionated towards `SQLModel` but feasible with any other framework or pure `sqlalchemy`\n- Easily use a local database in your tests\n\n## Usage\n\nIn order to use this library, you need some SQLModel or SQLAlchemy tables and a URI to connect to your database.\nWith this in place, the `DatabaseSetup` instance can be created - which contains all provided tools and also automatically\ncreates the database including all tables.\n\n```python\nfrom sqlmodel import Field, SQLModel\nfrom database_setup_tools import DatabaseSetup\n\n\nclass User(SQLModel, table=True):\n    \"\"\" User database entity / table \"\"\"\n    id: int = Field(index=True, primary_key=True)\n    name: str\n\n\n# create database \u0026 tables, establish connection with session pool\ndatabase_setup = DatabaseSetup(\n    model_metadata = SQLModel.metadata,\n    database_uri=\"postgresql+psycopg2://postgres:postgres@localhost:5432/database\",\n)\n```\n\n\u003e Note: The `DatabaseSetup` class acts as singleton, so if you create multiple instances with the same\n\u003e set of parameters, you will always get the same instance back instead of creating a new one.\n\nAfter the setup is created, you can get a scoped session via the provided session manager and use it\nfor database transactions.\n\n```python\n# get scoped session\nsession = next(database_setup.session_manager.get_session())\n\n# do stuff in session\nuser = User(name=\"Alice\")\nsession.add(user)\nsession.commit()\n```\n\nThe `DatabaseSetup` instance also provides lifecycle methods allowing to manually control the database:\n\n```python\ndatabase_setup.create_database()\ndatabase_setup.drop_database()\n```\n\n## Development\n\n### Testing\n\n1. Spin up databases for local integration tests: `docker-compose -f tests/docker-compose.yaml up -d`\n1. Create virtual environment \u0026 install dependencies: `poetry install`\n1. Run tests: `poetry run pytest`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-specialist%2Fdatabase-setup-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcode-specialist%2Fdatabase-setup-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-specialist%2Fdatabase-setup-tools/lists"}