{"id":30338087,"url":"https://github.com/floatliang/sqlorm4es","last_synced_at":"2025-08-18T06:06:41.604Z","repository":{"id":57470616,"uuid":"214474029","full_name":"floatliang/sqlorm4es","owner":"floatliang","description":"A simple and expressive (like peewee) sql-like orm for elasticsearch.","archived":false,"fork":false,"pushed_at":"2019-12-20T15:44:03.000Z","size":63,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-03T23:03:31.458Z","etag":null,"topics":["elasticsearch","orm","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/floatliang.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":"2019-10-11T15:45:04.000Z","updated_at":"2024-08-28T08:32:21.000Z","dependencies_parsed_at":"2022-09-26T17:31:40.571Z","dependency_job_id":null,"html_url":"https://github.com/floatliang/sqlorm4es","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/floatliang/sqlorm4es","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatliang%2Fsqlorm4es","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatliang%2Fsqlorm4es/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatliang%2Fsqlorm4es/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatliang%2Fsqlorm4es/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/floatliang","download_url":"https://codeload.github.com/floatliang/sqlorm4es/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatliang%2Fsqlorm4es/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270804107,"owners_count":24648807,"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-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","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":["elasticsearch","orm","sql"],"created_at":"2025-08-18T06:02:08.641Z","updated_at":"2025-08-18T06:06:41.595Z","avatar_url":"https://github.com/floatliang.png","language":"Python","readme":"### sqlorm4es\r\n\r\nA simple and expressive (like peewee) sql-like orm for elasticsearch.\r\n\r\n#### Examples\r\n\r\n* Defining index model in a Django way:\r\n\r\n```python\r\nfrom sqlorm4es import *\r\n\r\nclass LogCenter(BaseModel):\r\n    __index__ = 'lala'\r\n    __database__ = {\r\n        \"host\": \"127.0.0.1:9200\"\r\n    }\r\n\r\n    ok = Boolean(default=True)\r\n    lineno = Integer(required=True)\r\n    message = Text(default='xixi')\r\n    timestamp = Date(name=\"@timestamp\", timezone=\"+8\")\r\n    bigbrother = Object(\r\n        head=Text(),\r\n        hand=Object(\r\n            finger=Float(),\r\n            nail=Boolean()\r\n        )\r\n    )\r\n```\r\n\r\n* Search elasticsearch in a expressive way:\r\n\r\n```python\r\nres = LogCenter.select(LogCenter.ok, LogCenter.lineno, 'max(lineno)') \\\r\n    .where(((LogCenter.ok == False) \u0026 (LogCenter.message != 'error')) |\r\n           (LogCenter.timestamp \u003e= '2017-10-12') |\r\n           (LogCenter.bigbrother.head \u003e\u003e ' ( tough; soft, medium soft ) '))\\\r\n    .execute()\r\n```\r\n\r\n* Note that and(\u0026)/or(|) expression in where can be nested\r\n* Also support group by aggregation: MAX, MIN, AVG, SUM, COUNT...\r\n* Also support order by, LIMIT, OFFSET:\r\n\r\n```python\r\nres = LogCenter.select('max(lineno)')\\\r\n    .group_by(LogCenter.ok, LogCenter.timestamp)\\\r\n    .order_by((LogCenter.timestamp, 'asc'))\\\r\n    .execute()\r\n```\r\n* Manipulate document like a normal python object, value will be validated when assigning it (eg. value in Date Field all stored as UTC):\r\n```python\r\nnew_log = LogCenter(ok=False, message='oops', timestamp='2019-10-10')\r\nnew_log.bigbrother = {\r\n    \"head\": 'tough',\r\n    \"hand\": {\r\n        \"finger\": \"long\",\r\n        \"nail\": \"clean\"\r\n    }\r\n}\r\n```\r\n* Create a single document:\r\n```python\r\nnew_log.save()\r\n```\r\n* **Insert, Delete, Update and Index operation**: Coming soon...\r\n\r\n#### Install\r\nSqlorm4es has been packaged to pypi, so just need one simple command to install it:\r\n```shell\r\npip install sqlorm4es\r\n```\r\n\r\n#### Elasticsearch driver\r\nSqlorm4es implemented a simple almost lock-free connection pool based on official Elasticsearch client. As it is lock-free, so i am not sure whether it is thread-safe, but it works fine under my own multi-thread tests :)\r\n* Note that if you did not set config of your model, it will use the default config as below:\r\n```python\r\nconfig = {\r\n    'hosts': ['127.0.0.1:9200'],\r\n    'maxsize': 20,\r\n    'sniff_on_start': False,\r\n    'sniff_on_connection_fail': False,\r\n    'sniff_timeout': .1,\r\n    'sniffer_timeout': None,\r\n    'retry_on_timeout': False,\r\n    'timeout': 60,\r\n}\r\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffloatliang%2Fsqlorm4es","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffloatliang%2Fsqlorm4es","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffloatliang%2Fsqlorm4es/lists"}