{"id":21802598,"url":"https://github.com/shaopson/ormlite","last_synced_at":"2026-05-10T19:49:07.934Z","repository":{"id":167173527,"uuid":"182081849","full_name":"shaopson/ORMlite","owner":"shaopson","description":"一个简单的Python ORM,支持sqlite3 mysql, 具有延迟查询，链式查询等功能; This is a simple ORM, support sqlite3,mysql","archived":false,"fork":false,"pushed_at":"2020-03-16T09:28:04.000Z","size":137,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-21T07:15:00.123Z","etag":null,"topics":["orm","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shaopson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-04-18T12:16:09.000Z","updated_at":"2021-03-12T07:33:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"3b03757f-c8f3-4168-93b8-f06664b64e86","html_url":"https://github.com/shaopson/ORMlite","commit_stats":null,"previous_names":["dev-shao/ormlite","shaopson/ormlite"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/shaopson/ORMlite","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaopson%2FORMlite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaopson%2FORMlite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaopson%2FORMlite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaopson%2FORMlite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shaopson","download_url":"https://codeload.github.com/shaopson/ORMlite/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaopson%2FORMlite/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32869721,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-10T13:40:02.631Z","status":"ssl_error","status_checked_at":"2026-05-10T13:40:02.145Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["orm","python3"],"created_at":"2024-11-27T11:29:38.684Z","updated_at":"2026-05-10T19:49:07.895Z","avatar_url":"https://github.com/shaopson.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ORMlite\n\n一个简单的Python ORM,支持sqlite3 mysql, 具有延迟查询，链式查询等功能\n接口模仿了Django的ORM框架 和Django ORM一样简单，易用，ORMlite不支持迁移功能(migrate)\n\n### 快速上手\n如果你使用过Django的ORM，那么你会感觉非常熟悉\n\n创建model,使用sqlite3\n```python\nimport ormlite\nfrom ormlite import configuration\nfrom ormlite.db.utils import create_tables\n\n#设置数据库\nconfiguration.conf_db({\n    \"ENGINE\":\"ormlite.db.sqlite3\",\n    \"NAME\":\"db.sqlite3\",\n})\n#开启Debug 查询时显示生成的sql语句\nconfiguration.debug = True\n\n#定义Model\nclass User(ormlite.Model):\n    id = ormlite.PrimaryKey()\n    name = ormlite.CharField(max_length=50)\n    sex = ormlite.CharField(max_length=1)\n    birthday = ormlite.DateField()\n\n#创建\ncreate_tables([User,],configuration.db)\n```\n\n\n创建对象\n\n```python\nimport datetime\nuser = User(name='test',sex='M',birthday=datetime.datetime(2020,1,1).date())\nuser.save()\n```\n\n简单查询\n```python\n#返回单个User实例\nuser = User.object.get(id=1)\n\n#获取全部User实例\nusers = User.object.all()\n\n#查询所有id大于10的实例\n# ge:\u003e=,  gt:\u003e, le:\u003c=, lt:\u003c\nusers = User.object.query(id__gt=10)\n\n#排除所有id大于10的实例\nusers = User.object.exclude(id__gt=10)\n\n#排序\nusers = User.object.all().sort('id')#正序\nusers = User.object.all().sort('-id')#反序\n\n#切片\nusers = User.object.all()[2:4]\n#第一个\nuser = User.object.all().first()\n#最后一个\nuser = User.object.all().last()\n\n#计数\ncount = User.object.all().count()\n\n#只查询某个字段(结果以键值对的格式返回)\nnames = User.object.all().values('name')\n#\u003cQuery [{'name': 'aa'}, {'name': 'bb'}, {'name': 'cc'}, {'name': 'dd'},...]\u003e\n\n#只查询某个字段(结果以列表的格式返回)\nnames = User.object.all().items('name')\n#\u003cQuery [('aa',), ('bb',), ('cc',), ('dd',),...]\u003e\n\n#列表降维\nnames = User.object.all().items('name',flat=True)\n#\u003cQuery ['aa', 'bb', 'cc', 'dd',]\u003e\n\n#数据聚合\nfrom ormlite.query import Count,Min,Max,Sum,Avg\nresult = User.object.all().values(count=Count('id'))\n#\u003cQuery [{'count': 10}]\u003e\n\n#分组计算\nresult = User.object.all().values(count=Count('name')).group('name')\n#[{'name': 'aa', 'count': 1}, {'name': 'bb', 'count': 1}, {'name': 'cc', 'count': 1}]\n```\n\n###数据库配置\n\n####sqlite3\n\n```\nfrom ormlite import configuration\nconfiguration.conf_db({\n    \"ENGINE\":\"ormlite.db.sqlite3\",\n    \"NAME\":\"db.sqlite3\",\n})\n```\n\n####mysql\n\n当使用mysql时，需要安装mysql-connector\n\n```\nfrom ormlite import configuration\nconfiguration.conf_db({\n    \"ENGINE\":\"ormlite.db.mysql\",\n    'NAME': 'ormlite',\n    'USER': 'root',\n    'PASSWORD': 'ormlite',\n    'HOST': 'localhost',\n    'PORT': '3306',\n    'OPTIONS': {\n        'autocommit': True,\n    }\n})\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaopson%2Formlite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshaopson%2Formlite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaopson%2Formlite/lists"}