{"id":22138496,"url":"https://github.com/wabscale/bigsql","last_synced_at":"2025-07-25T14:16:52.502Z","repository":{"id":100129373,"uuid":"380627715","full_name":"wabscale/bigsql","owner":"wabscale","description":"ORM featuring dynamic model generation, with on the fly relationship detection and resolution","archived":false,"fork":false,"pushed_at":"2021-06-27T01:46:49.000Z","size":56,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-29T15:50:48.757Z","etag":null,"topics":["python","sql"],"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/wabscale.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":"2021-06-27T01:34:05.000Z","updated_at":"2023-05-01T02:23:23.000Z","dependencies_parsed_at":"2023-03-10T08:15:31.586Z","dependency_job_id":null,"html_url":"https://github.com/wabscale/bigsql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wabscale%2Fbigsql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wabscale%2Fbigsql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wabscale%2Fbigsql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wabscale%2Fbigsql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wabscale","download_url":"https://codeload.github.com/wabscale/bigsql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245251373,"owners_count":20584867,"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":["python","sql"],"created_at":"2024-12-01T20:10:06.997Z","updated_at":"2025-03-24T10:26:59.118Z","avatar_url":"https://github.com/wabscale.png","language":"Python","readme":"[![pipeline status](https://gitlab.com/b1g_J/bigsql/badges/master/pipeline.svg)](https://gitlab.com/b1g_J/bigsql/commits/master)\n\n\n[![coverage report](https://gitlab.com/b1g_J/bigsql/badges/master/coverage.svg)](https://gitlab.com/b1g_J/bigsql/commits/master)\n\n# big_SQL\nbig_SQL is an ORM features dynamic model generation, with on the fly relationship detection and resolution. \nIt uses a high level custom sql generator in its backend.\n\n### Static generation\nTo use the static models with bigSQL, all you need to do define your models same as other ORMs:\n```python\nfrom bigsql import *\n\nclass Test(StaticModel):\n    id = StaticColumn(Integer, primary_key=True, auto_increment=True)\n    a_string = StaticColumn(Varchar(128), references=\"Person.username\")\n    date = StaticColumn(DateTime)\n\ndb = big_SQL(\n    user='root',\n    pword='password',\n    host='127.0.0.1',\n    db='DB',\n)\n\ndb.create_all()\n\nt = Test(a_string='a string')\n\ndb.session.add(t)\n\ntry:\n    db.session.add(t)\n    db.session.commit()\nexcept big_ERROR as e:\n    print('onooooooz', e)\n    db.session.rollback()\n\n```\n\n### Static querying\nAfter we create an object, we will more than likely want to use it again at some point.\nHere is how you can query, modify then commit statically defined models\n```python\nfrom bigsql import *\nfrom datetime import datetime\n\nclass Test(StaticModel):\n    id = StaticColumn(Integer, primary_key=True, auto_increment=True)\n    a_string = StaticColumn(Varchar(128))\n    date = StaticColumn(DateTime)\n\ndb = big_SQL(\n    user='root',\n    pword='password',\n    host='127.0.0.1',\n    db='DB',\n)\n\ndb.create_all()\n\n# to query then modify an object\nt = Test.query.find(a_string='a string').first()\n\nt.date = datetime.now()\n\ntry:\n    db.session.commit()\nexcept big_ERROR as e:\n    print('onooooooz', e)\n    db.session.rollback()\n    \n# To delete an object:\nt = Test.query.find(a_string='another string').first()\n\ndb.session.delete(t)\n\ntry:\n    db.session.commit()\nexcept big_ERROR as e:\n    print('onooooooz', e)\n    db.session.rollback()\n\n``` \n\n\n\n### Dynamic generation\n\n#### Models\nThe really cool thing this ORM does is dynamic model generation. \nIf you already have a database with tables defined, you can \njust query existing tables, and bigsql will generate models for you.\n\n#### Relationships\nIf you have a defined foreign key relationship with another table \nalready defined, you don't need to tell bigsql about them. For an object \nwith foreign models, you can just access it as a attribute, and it will \nhand you an iterable object with all the associated object for the \ncurrent model (either dynamically or statically generated).\n\nFor example:\n\n```python\n\n\"\"\" Person structure\nCREATE TABLE Person\n(\n    username  VARCHAR(20),\n    PRIMARY KEY (username)\n);\n\"\"\"\n\n\"\"\" Photo structure\nCREATE TABLE Photo\n(\n    photoID      int NOT NULL AUTO_INCREMENT,\n    photoOwner   VARCHAR(20),\n    PRIMARY KEY (photoID),\n    FOREIGN KEY (photoOwner) REFERENCES Person (username) ON DELETE CASCADE\n);\n\"\"\"\n\nfrom bigsql import *\n\ndb = big_SQL(\n    user='root',\n    pword='password',\n    host='127.0.0.1',\n    db='DB',\n)\n\n# new_photo will be a dynamically generated model object\nadmin = db.query('Person').new(username='admin')\n# new_photo will be a dynamically generated model object\nnew_photo = db.query('Photo').new(photoOwner='admin')\n\ndb.session.add(admin)\ndb.session.add(new_photo)\n\ntry:\n    db.session.commit()\nexcept big_ERROR as e:\n    print('onooooooz', e)\n    db.session.rollback()\n\n# the relationship will be detected between Photo and Person, \n# so you can access either .photo or .photos on a Person object\n# and you will get all the associated photos for this user as a list\nadmins_photos = list(admin.photos)\n```\n\n### Sql Engine\n\nThe query engine is quite simple and easy to use. It sports the fluent influence style for readability. \n\n```python\nfrom bigsql import *\n\ndb = big_SQL(\n    user='root',\n    pword='password',\n    host='127.0.0.1',\n    db='DB',\n)\n\n# admin will be a dynamically generated model object\nadmin = db.sql.SELECTFROM('Person').WHERE(username='admin').first()\n\n# new_user will be a dynamically generated model object\nnew_user = db.sql.INSERT(username='new_user').INTO('Person').do()\n\n# to get the raw sql being generated for a query\nraw_sql, args = db.sql.SELECTFROM('Photo').JOIN('Person').WHERE(username='admin').gen()\n\n```\n\n# Maintainer\n- big_J | john@bigj.icu\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwabscale%2Fbigsql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwabscale%2Fbigsql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwabscale%2Fbigsql/lists"}