{"id":13411547,"url":"https://github.com/JoseVL92/sqlalchemy_multiconnector","last_synced_at":"2025-03-14T17:30:55.379Z","repository":{"id":57678281,"uuid":"206091562","full_name":"JoseVL92/sqlalchemy_multiconnector","owner":"JoseVL92","description":"Easy connector for SQL Databases, support for sqlite, postgresql and mysql","archived":false,"fork":false,"pushed_at":"2023-12-11T18:27:41.000Z","size":72,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-20T03:20:26.873Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/JoseVL92.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-09-03T14:01:47.000Z","updated_at":"2023-12-03T01:34:20.000Z","dependencies_parsed_at":"2023-12-11T19:44:08.978Z","dependency_job_id":null,"html_url":"https://github.com/JoseVL92/sqlalchemy_multiconnector","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoseVL92%2Fsqlalchemy_multiconnector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoseVL92%2Fsqlalchemy_multiconnector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoseVL92%2Fsqlalchemy_multiconnector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoseVL92%2Fsqlalchemy_multiconnector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JoseVL92","download_url":"https://codeload.github.com/JoseVL92/sqlalchemy_multiconnector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243618635,"owners_count":20320269,"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":[],"created_at":"2024-07-30T20:01:14.421Z","updated_at":"2025-03-14T17:30:55.050Z","avatar_url":"https://github.com/JoseVL92.png","language":"Python","funding_links":[],"categories":["Web Development"],"sub_categories":["Python"],"readme":"# sqlalchemy-multiconnector  \nPython SQLAlchemy connector for SQL databases (sqlite, postgresql and mysql).  \nEasy resources CRUD management.  \nSupports multi-tenancy with multiple databases and/or multiple schemas.\n\n## Example of use\n```python\nfrom sqlalchemy import Boolean, Column, ForeignKey, Integer, String, Text  \nfrom sqlalchemy.orm import relationship  \nfrom sqlalchemy_multiconnector import BASE, SQLConnector, manage_session  \n  \n  \nDB_TYPE = 'postgresql'  # it also accepts 'mysql' and 'sqlite'\nDB_HOST = 'hostname'  \nDB_PORT = 5432\nDB_NAME = 'test'\nDB_USER = 'username'  \nDB_PASSWD = 'password'  \n  \n  \nclass User(BASE):\n    __tablename__ = 'users'  \n    id = Column(Integer, autoincrement=True, primary_key=True)  \n    username = Column(String)  \n    active = Column(Boolean, default=True)  \n    articles = relationship('Article', back_populates='user')  \n  \n  \nclass Article(BASE):  \n    __tablename__ = 'articles'  \n    id = Column(Integer, autoincrement=True, primary_key=True)  \n    title = Column(String)  \n    description = Column(Text, nullable=True)  \n    user_id = Column(Integer, ForeignKey(User.id))  \n    user = relationship('User', back_populates='articles')\n\n# If some schema should be used, you can specify it on object creation\ndb_connection = SQLConnector(DB_TYPE, DB_HOST, DB_NAME, DB_PORT,  \n                             db_schemas=['schema1', 'schema2'],\n                             db_user=DB_USER,\n                             db_passwd=DB_PASSWD)\n\n# or with 'schemas' property\ndb_connection.schemas = ['schema1', 'schema2']\n\n# or in 'create_tables' method\ndb_connection.create_tables(schemas=['schema1', 'schema2'])\n\n# add a user in schema1\nuser_id = db_connection.create_resource(User, {'username': 'Usuario', 'is_active': False}, return_id=True, schema_name='schema1')\n\n# add an article related to this user\nwith db_connection.session_scope(schema_name = 'schema1') as session:\n\tuser_owner = session.query(User).get(user_id)\n\tarticle_id = db_connection.create_resource(Article, {'title': 'Hi', 'user': user_owner}, session=session)\n\n# update article title\ndb_connection.update_resource(Article, pk=article_id, updated_fields: {'title': 'Hi again!'})\n\n# get and delete a specific resource and list all resources are also available\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJoseVL92%2Fsqlalchemy_multiconnector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJoseVL92%2Fsqlalchemy_multiconnector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJoseVL92%2Fsqlalchemy_multiconnector/lists"}