{"id":14065720,"url":"https://github.com/iurisilvio/bottle-sqlalchemy","last_synced_at":"2025-03-17T12:08:39.221Z","repository":{"id":1619093,"uuid":"2290470","full_name":"iurisilvio/bottle-sqlalchemy","owner":"iurisilvio","description":"Bottle SQLAlchemy plugin","archived":false,"fork":false,"pushed_at":"2018-05-18T14:29:43.000Z","size":42,"stargazers_count":126,"open_issues_count":0,"forks_count":20,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-03T21:56:24.211Z","etag":null,"topics":["bottlepy","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iurisilvio.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}},"created_at":"2011-08-29T19:08:55.000Z","updated_at":"2025-01-22T06:45:07.000Z","dependencies_parsed_at":"2022-08-23T16:51:25.252Z","dependency_job_id":null,"html_url":"https://github.com/iurisilvio/bottle-sqlalchemy","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iurisilvio%2Fbottle-sqlalchemy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iurisilvio%2Fbottle-sqlalchemy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iurisilvio%2Fbottle-sqlalchemy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iurisilvio%2Fbottle-sqlalchemy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iurisilvio","download_url":"https://codeload.github.com/iurisilvio/bottle-sqlalchemy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244031021,"owners_count":20386534,"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":["bottlepy","python","sqlalchemy"],"created_at":"2024-08-13T07:04:39.822Z","updated_at":"2025-03-17T12:08:39.200Z","avatar_url":"https://github.com/iurisilvio.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"This bottle-sqlalchemy plugin integrates SQLAlchemy with your Bottle\napplication. It injects a SQLAlchemy session in your route and handle the session cycle.\n\nUsage Example:\n\n``` python\nimport bottle\nfrom bottle import HTTPError\nfrom bottle.ext import sqlalchemy\nfrom sqlalchemy import create_engine, Column, Integer, Sequence, String\nfrom sqlalchemy.ext.declarative import declarative_base\n\nBase = declarative_base()\nengine = create_engine('sqlite:///:memory:', echo=True)\n\napp = bottle.Bottle()\nplugin = sqlalchemy.Plugin(\n    engine, # SQLAlchemy engine created with create_engine function.\n    Base.metadata, # SQLAlchemy metadata, required only if create=True.\n    keyword='db', # Keyword used to inject session database in a route (default 'db').\n    create=True, # If it is true, execute `metadata.create_all(engine)` when plugin is applied (default False).\n    commit=True, # If it is true, plugin commit changes after route is executed (default True).\n    use_kwargs=False # If it is true and keyword is not defined, plugin uses **kwargs argument to inject session database (default False).\n)\n\napp.install(plugin)\n\nclass Entity(Base):\n    __tablename__ = 'entity'\n    id = Column(Integer, Sequence('id_seq'), primary_key=True)\n    name = Column(String(50))\n\n    def __init__(self, name):\n        self.name = name\n\n    def __repr__(self):\n        return \"\u003cEntity('%d', '%s')\u003e\" % (self.id, self.name)\n\n\n@app.get('/:name')\ndef show(name, db):\n    entity = db.query(Entity).filter_by(name=name).first()\n    if entity:\n        return {'id': entity.id, 'name': entity.name}\n    return HTTPError(404, 'Entity not found.')\n\n@app.put('/:name')\ndef put_name(name, db):\n    entity = Entity(name)\n    db.add(entity)\n\n@app.get('/spam/:eggs', sqlalchemy=dict(use_kwargs=True))\n@bottle.view('some_view')\ndef route_with_view(eggs, db):\n    # do something useful here\n```    \n\n\nIt is up to you create engine and metadata, because SQLAlchemy has\na lot of options to do it. The plugin just handle the SQLAlchemy\nsession.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiurisilvio%2Fbottle-sqlalchemy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiurisilvio%2Fbottle-sqlalchemy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiurisilvio%2Fbottle-sqlalchemy/lists"}