{"id":24782267,"url":"https://github.com/vizonex/sqltable","last_synced_at":"2025-07-22T09:08:59.998Z","repository":{"id":274252352,"uuid":"922363616","full_name":"Vizonex/SQLTable","owner":"Vizonex","description":"A Msgspec Sqlalchemy Library","archived":false,"fork":false,"pushed_at":"2025-03-09T19:26:41.000Z","size":70,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T05:32:49.981Z","etag":null,"topics":["dataclasses","jsonserialization","msgpack","msgspec","orm","python","python3","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/Vizonex.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":"2025-01-26T01:51:33.000Z","updated_at":"2025-03-10T06:56:46.000Z","dependencies_parsed_at":"2025-03-03T04:26:05.028Z","dependency_job_id":"48733d13-a0d5-47cd-8c57-73276b18633a","html_url":"https://github.com/Vizonex/SQLTable","commit_stats":null,"previous_names":["vizonex/sqltable"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Vizonex/SQLTable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vizonex%2FSQLTable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vizonex%2FSQLTable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vizonex%2FSQLTable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vizonex%2FSQLTable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Vizonex","download_url":"https://codeload.github.com/Vizonex/SQLTable/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vizonex%2FSQLTable/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266463431,"owners_count":23932898,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["dataclasses","jsonserialization","msgpack","msgspec","orm","python","python3","sqlalchemy"],"created_at":"2025-01-29T11:16:39.988Z","updated_at":"2025-07-22T09:08:59.953Z","avatar_url":"https://github.com/Vizonex.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQLTable\nA Library Inspired by SQLModel that merges Msgspec and SQLAlchemy together. \n\n\n\n## Why SQLTable?\n\n- SQLModel is a little sluggish at times and it's spaghetti-code shows.\n- SQLTable retains many API Features from SQLAlchemy and has Mapped Api baked into the project\n- Msgspec is easier to work with than Pydantic to some degrees and with it's backend written in\n  `C` it's got all the speed required.\n- __SQLTable's__ relationship colums \u0026 decoder \u0026 encoders work as they are supposed to.\n- What SQLTable has over SQLModel is that it's Sessions and Engines can be used directly from SQLAlchemy\n  Itself rather than needing a third party Session subclass to use which make tools like `aiohttp_sqlalchemy`\n  desirable again.\n- __SQLTable__ comes with an `AsyncSQLTable` Class that uses `AsyncAttrs`\n- Json enocder is built-in to __SQLTable__ itself for when you need a quick and dirty method for writing an HTTP Server API Response \n- Why write a class twice with msgspec.Struct and Sqlalchemy's DeclarativeBase when you only need to do it once with SQLTable? \n\nAs a fan of __SQLModel__ I was fond of the way it worked over just sqlalchemy but as \nI started using it more, but I soon noticed many flaws as well as a large amount of unrequired spaghetti-code.\nAs I started to dig out the problems I was experiencing such as lag in load-times, relationships not \nloading into the json responses as well as the slow response times to pull requests I finally decided \nenough was enough and if I would be honest I am kinda glad I found msgspec soon after to satisfy this \nslowness as well as cut time-consumptions down. Originally I was going to develop my own library called\n[CyClass](https://github.com/Vizonex/Cyclass) \u0026 [HeapStruct](https://github.com/Vizonex/heapstruct)\ndue to the difficulty of wrapping msgspec to sqlalchemy but as time rolled on, I began to find/discover many intresting \nways to make the libraries work correctly together.\nI relate a lot to my first experince making a library which was [winloop](https://github.com/Vizonex/winloop).\n\nThere will still be cases where you might need SQLModel still so I will see about thinking of ways you could use \nboth of them at the same time.\n\nI hope SQLTable will be the future of databases and I can't wait to see what you \u0026 other people will end up \ndoing with it. \n\n## Examples\nWhat if we wanted to write a proxy service? SQLTable Adapts many aspects from SQLAlchemy, SQLModel and msgspec \nand binds them all together\n```python\nfrom sqltable import SQLTable\nfrom sqltable.orm import Mapped, mapped_column\nfrom sqlalchemy import create_engine, Integer, String, Enum as EnumType\nfrom python_socks import ProxyType\n\nclass ProxyTable(SQLTableDecoderMixin, SQLTable, table=True):    \n    host:Mapped[str]\n    port:Mapped[int]\n    type:Mapped[ProxyType] = mapped_column(EnumType(ProxyType), default=ProxyType.HTTP)\n    id:Mapped[int] = mapped_column(Integer, primary_key=True, default=None)\n\n```\n\nThe personality of the code from SQLModel Remains relatively the same but Mapped API is used instead as directed by the SQLAlchemy Dev's \nrecommendations. Json Enocders are built in but you could also add in the `SQLTableDecoderMixin` If you plan to webscrape \nan ajax api of some sort in your project. However just know that some setups may not work because it requires the json to be directly decoded \nbecause otherwise the _sa_instance_state variable that is made will not load properly when you go to dump items into your database...\n\n```python\nfrom sqltable import SQLTable, SQLTableDecoderMixin\nfrom sqltable.orm import Mapped, mapped_column\nfrom python_socks import ProxyType\n\n\nclass ProxyTable(SQLTableDecoderMixin, SQLTable, table=True):    \n    host:Mapped[str]\n    port:Mapped[int]\n    type:Mapped[ProxyType] = ProxyType.HTTP\n    id:Mapped[int] = mapped_column(primary_key=True, default=None)\n\n\nproxy = ProxyTable(\"127.0.0.1\", 9150, ProxyType.SOCKS5)\n# Json Response is b'{\"host\":\"127.0.0.1\",\"port\":9150,\"type\":2,\"id\":null}'\nprint(proxy.encode())\nprint(ProxyTable.decode(b'{\"host\":\"127.0.0.1\",\"port\":9150,\"type\":2,\"id\":null}'))\n```\n \n# TODOS\n- [ ] Pypi Release, We're extremely close to `0.0.1` maybe within the next few days. Depends on how fast I can code.\n- [ ] Test Suite\n- [ ] Splitting out the SQLTableDecoderMixin with more subclasses and special hook for different classes and different decoders to combine that msgspec provides\n- [ ] Maybe a custom URL Variable using `msgspec.Struct` as an experimental feature? \n- [ ] A Class called `IDTable` \u0026 `AsyncIDTable` to bind an `id` with an Integer or NULL to the final column of every class Variable this may or may not be typehinted on the dataclass transformation\n- [x] AsyncTable\n- [x] SQLTable Base\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvizonex%2Fsqltable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvizonex%2Fsqltable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvizonex%2Fsqltable/lists"}