{"id":15187556,"url":"https://github.com/spratiher9/bajra","last_synced_at":"2026-03-03T17:05:00.057Z","repository":{"id":57413805,"uuid":"451983534","full_name":"Spratiher9/Bajra","owner":"Spratiher9","description":"An efficient raw SQL ORM","archived":false,"fork":false,"pushed_at":"2022-01-25T19:56:16.000Z","size":434,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-09T13:36:49.202Z","etag":null,"topics":["apis","database","mysql","object-oriented","orm","postgres","postgresql","python3","webapp"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/bajra/","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/Spratiher9.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":"2022-01-25T17:52:07.000Z","updated_at":"2022-01-25T19:51:38.000Z","dependencies_parsed_at":"2022-09-05T03:52:44.767Z","dependency_job_id":null,"html_url":"https://github.com/Spratiher9/Bajra","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Spratiher9%2FBajra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Spratiher9%2FBajra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Spratiher9%2FBajra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Spratiher9%2FBajra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Spratiher9","download_url":"https://codeload.github.com/Spratiher9/Bajra/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240859766,"owners_count":19869213,"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":["apis","database","mysql","object-oriented","orm","postgres","postgresql","python3","webapp"],"created_at":"2024-09-27T18:23:59.883Z","updated_at":"2026-03-03T17:05:00.021Z","avatar_url":"https://github.com/Spratiher9.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bajra [![Bajra](https://img.shields.io/pypi/v/Bajra.svg?style=flat-square)](https://pypi.org/project/bajra/)\n\n![bajra](https://i.ibb.co/r2DmPqb/bajra.png)\n\nBajra is a simple ORM API *(for MySQL and PostGreSQL)* that provide helpers to manage raw SQL in Python applications.\n\n# What Bajra can do?\n\nBajra allows you to write raw SQL and forget about cursors, and it's related data structures like tuples or dicts. \nAlso allows you to write your query by pieces, making the whole thing more readable.\n\nLet's see a few examples!\n\n## Fetching results made simple\n\n```python\nfrom bajra import Bajra\nfrom bajra.engines.postgres import PostgreSQLEngine\n\ncater = Bajra(PostgreSQLEngine(dsn=\"YOUR-DATABASE-DSN\"))\nrows = cater.fetchall(\"SELECT name, surname FROM test\")  # That command returns a RowResult you can iterate\nfor row in rows:\n    print(row.name)  # You can access to the data with dot notation.\n    print(row['name'])  # Also as a dict-like object.\n```\n\n## Querying with arguments. No more pain.\n\n```python\nfrom bajra import Bajra\nfrom bajra.engines.postgres import PostgreSQLEngine\n\ncater = Bajra(PostgreSQLEngine(dsn=\"YOUR-DATABASE-DSN\"))\nrow = cater.fetchone(\"SELECT name, surname FROM test WHERE name = %s\", (\"John\", ))\nprint(row.name)  # John\nprint(row.surname)  # Costa\n\nrow = cater.fetchone(\"SELECT name, surname FROM test WHERE name = %(name)s\", {'name': 'John'})\nprint(row.name)  # John\nprint(row.surname)  # Costa\n\nrow = cater.fetchone(\"SELECT name, surname FROM test WHERE name = %(name)s\", name='John')\nprint(row.name)  # John\nprint(row.surname)  # Costa\n```\n\n## Querying piece by piece\n```python\nfrom bajra import Bajra\nfrom bajra.engines.postgres import PostgreSQLEngine\n\ncater = Bajra(PostgreSQLEngine(dsn=\"YOUR-DATABASE-DSN\"))\nquery = cater.query(\"SELECT * FROM test\")\nquery.append(\"WHERE name = %(name)s\", name=\"John\")\nrow = cater.fetchone(query)\nrow.name  # John\nrow.surname  # Costa\n```\n\n## Execute all the things.\n```python\nfrom bajra import Bajra\nfrom bajra.engines.postgres import PostgreSQLEngine\n\ncater = Bajra(PostgreSQLEngine(dsn=\"YOUR-DATABASE-DSN\"))\nquery = cater.query(\"INSERT INTO test (name, surname) VALUES\")\nquery.append(\"(%(name)s, %(surname)s)\", name=\"Thomas\", surname=\"Jefferson\")\n\nresult = cater.execute(query)\nprint(result.lastrowid)  # Last Row ID of the last query. (If the engine supports it.)\nprint(result.rowcount)  # How many rows retrieve the last query. (If the engine supports it.)\nprint(result.rownumber)  # Number of rows affected by the last query. (If engine supports it.)\n```\n\n## Transactions\n```python\nfrom bajra import Bajra\nfrom bajra.engines.postgres import PostgreSQLEngine\n\ncater = Bajra(PostgreSQLEngine(dsn=\"YOUR-DATABASE-DSN\"))\ncater.begin()\nquery = cater.query(\"INSERT INTO test (name, surname) VALUES\")\nquery.append(\"(%(name)s, %(surname)s)\", name=\"Marie-Cole\", surname=\"Ross\")\n\nresult = cater.execute(query)\nprint(result.lastrowid)  # Last Row ID of the last query. (If the engine supports it.)\nprint(result.rowcount)  # How many rows retrieve the last query. (If the engine supports it.)\nprint(result.rownumber)  # Number of rows affected by the last query. (If engine supports it.)\n\ncater.commit()\n```\n\n## Transactions within a context manager\n```python\nfrom bajra import Bajra\nfrom bajra.engines.postgres import PostgreSQLEngine\n\n\ndef callback_on_exception(_cater, exc_type, exc_value, traceback):\n    print(exc_type)  # \u003cclass 'psycopg2.ProgrammingError'\u003e\n\n\ncater = Bajra(PostgreSQLEngine(dsn=\"YOUR-DATABASE-DSN\"))\n\nwith cater.transaction(rollback_on_exc=True, callback_exc=callback_on_exception):\n    cater.execute(\"INSERT INTO test (name, surname) VALUES %s, %s\", (\"Augustus\", \"Zuma\"))\n\nrow = cater.fetchone(\"SELECT * FROM test WHERE name=%s AND surname=%s\", (\"Augustus\", \"Zuma\"))\nprint(row)  # None, Bajra has perfomed a rollback due to a exception.\n```\n\n# Collaborators Welcome!\n\nIf you have an idea you want to contribute in Bajra, clone the repo and raise a pull request with your feature!\n\n![Made with love in India](https://madewithlove.now.sh/in?colorB=%23f9861a\u0026template=flat-square)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspratiher9%2Fbajra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspratiher9%2Fbajra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspratiher9%2Fbajra/lists"}