surreal-orm-lite 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- surreal_orm_lite-0.2.0/.gitignore +80 -0
- surreal_orm_lite-0.2.0/CHANGELOG.md +41 -0
- surreal_orm_lite-0.2.0/LICENSE +21 -0
- surreal_orm_lite-0.2.0/Makefile +48 -0
- surreal_orm_lite-0.2.0/PKG-INFO +283 -0
- surreal_orm_lite-0.2.0/README.md +233 -0
- surreal_orm_lite-0.2.0/pyproject.toml +99 -0
- surreal_orm_lite-0.2.0/src/__init__.py +3 -0
- surreal_orm_lite-0.2.0/src/surreal_orm_lite/__init__.py +24 -0
- surreal_orm_lite-0.2.0/src/surreal_orm_lite/connection_manager.py +313 -0
- surreal_orm_lite-0.2.0/src/surreal_orm_lite/constants.py +20 -0
- surreal_orm_lite-0.2.0/src/surreal_orm_lite/enum.py +12 -0
- surreal_orm_lite-0.2.0/src/surreal_orm_lite/exceptions.py +54 -0
- surreal_orm_lite-0.2.0/src/surreal_orm_lite/model_base.py +212 -0
- surreal_orm_lite-0.2.0/src/surreal_orm_lite/py.typed +0 -0
- surreal_orm_lite-0.2.0/src/surreal_orm_lite/query_set.py +503 -0
- surreal_orm_lite-0.2.0/src/surreal_orm_lite/utils.py +6 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
.windsurfrules
|
|
7
|
+
|
|
8
|
+
# C extensions
|
|
9
|
+
*.so
|
|
10
|
+
|
|
11
|
+
# Distribution / packaging
|
|
12
|
+
dist/
|
|
13
|
+
build/
|
|
14
|
+
*.egg-info/
|
|
15
|
+
*.egg
|
|
16
|
+
MANIFEST
|
|
17
|
+
wheels/
|
|
18
|
+
*.whl
|
|
19
|
+
|
|
20
|
+
# Unit test / coverage reports
|
|
21
|
+
htmlcov/
|
|
22
|
+
.tox/
|
|
23
|
+
.nox/
|
|
24
|
+
.coverage
|
|
25
|
+
.coverage.*
|
|
26
|
+
coverage.xml
|
|
27
|
+
junit.xml
|
|
28
|
+
*.cover
|
|
29
|
+
*.py,cover
|
|
30
|
+
.pytest_cache/
|
|
31
|
+
.hypothesis/
|
|
32
|
+
|
|
33
|
+
# Jupyter Notebook
|
|
34
|
+
.ipynb_checkpoints
|
|
35
|
+
|
|
36
|
+
# Environment directories
|
|
37
|
+
.env
|
|
38
|
+
.dev-venv
|
|
39
|
+
.venv
|
|
40
|
+
.venv*/
|
|
41
|
+
env/
|
|
42
|
+
venv/
|
|
43
|
+
ENV/
|
|
44
|
+
|
|
45
|
+
# IDE settings
|
|
46
|
+
.idea/
|
|
47
|
+
.vscode/
|
|
48
|
+
*.swp
|
|
49
|
+
*.swo
|
|
50
|
+
.project
|
|
51
|
+
.pydevproject
|
|
52
|
+
.settings/
|
|
53
|
+
*.sublime-workspace
|
|
54
|
+
*.sublime-project
|
|
55
|
+
|
|
56
|
+
# Logs and databases
|
|
57
|
+
*.log
|
|
58
|
+
*.sqlite
|
|
59
|
+
*.db
|
|
60
|
+
surreal_data/
|
|
61
|
+
|
|
62
|
+
# OS generated files
|
|
63
|
+
.DS_Store
|
|
64
|
+
.DS_Store?
|
|
65
|
+
._*
|
|
66
|
+
.Spotlight-V100
|
|
67
|
+
.Trashes
|
|
68
|
+
ehthumbs.db
|
|
69
|
+
Thumbs.db
|
|
70
|
+
|
|
71
|
+
# Project specific
|
|
72
|
+
external_pkg_ref/
|
|
73
|
+
*.bak
|
|
74
|
+
*.tmp
|
|
75
|
+
.mypy_cache/
|
|
76
|
+
.ruff_cache/
|
|
77
|
+
.dmypy.json
|
|
78
|
+
dmypy.json
|
|
79
|
+
|
|
80
|
+
.claude/
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.2.0] - 2026-02-02
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Initial release of **Surreal ORM Lite**
|
|
13
|
+
- Support for official SurrealDB Python SDK 1.0.8
|
|
14
|
+
- Compatibility with SurrealDB 2.6.0
|
|
15
|
+
- Django-style ORM with `BaseSurrealModel` base class
|
|
16
|
+
- `QuerySet` with fluent query builder
|
|
17
|
+
- Filter lookups: `exact`, `gt`, `gte`, `lt`, `lte`, `in`, `contains`, `startswith`, etc.
|
|
18
|
+
- CRUD operations: `save()`, `update()`, `merge()`, `delete()`, `refresh()`
|
|
19
|
+
- `SurrealDBConnectionManager` for connection management
|
|
20
|
+
- HTTP and WebSocket connection support
|
|
21
|
+
- Custom primary key configuration via `SurrealConfigDict`
|
|
22
|
+
- Pydantic 2.x validation support
|
|
23
|
+
- Custom exceptions: `SurrealDbError`, `SurrealDbConnectionError`, etc.
|
|
24
|
+
- Full async/await support
|
|
25
|
+
- 97%+ test coverage
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- Migrated from custom SDK to official SurrealDB SDK 1.0.8
|
|
30
|
+
- Updated API to match SDK 1.0.8 response formats
|
|
31
|
+
- `signin()` now uses dictionary format: `{"username": ..., "password": ...}`
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
|
|
35
|
+
- Handle SDK 1.0.8 returning lists for single record `select()`
|
|
36
|
+
- Handle SDK 1.0.8 returning error strings instead of exceptions
|
|
37
|
+
- Escape special characters in record IDs (e.g., `@` in email addresses)
|
|
38
|
+
|
|
39
|
+
## [0.1.x] - Previous Versions
|
|
40
|
+
|
|
41
|
+
Previous versions were part of the SurrealDB-ORM project with a custom SDK implementation. This project (Surreal ORM Lite) is a fork focused on using the official SDK only.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Yannick Croteau
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
.DEFAULT_GOAL := all
|
|
2
|
+
sources = src
|
|
3
|
+
|
|
4
|
+
.PHONY: .uv # Check that uv is installed
|
|
5
|
+
.uv:
|
|
6
|
+
@uv --version || echo 'Please install uv: https://docs.astral.sh/uv/getting-started/installation/'
|
|
7
|
+
|
|
8
|
+
.PHONY: install # Install the package, dependencies, and pre-commit for local development
|
|
9
|
+
install: .uv
|
|
10
|
+
uv sync --frozen --group lint
|
|
11
|
+
uv run pre-commit install --install-hooks
|
|
12
|
+
|
|
13
|
+
.PHONY: format # Format the code
|
|
14
|
+
format:
|
|
15
|
+
uv run ruff format
|
|
16
|
+
uv run ruff check --fix --fix-only
|
|
17
|
+
|
|
18
|
+
.PHONY: lint # Lint the code
|
|
19
|
+
lint:
|
|
20
|
+
uv run ruff format --check
|
|
21
|
+
uv run ruff check
|
|
22
|
+
|
|
23
|
+
.PHONY: mypy
|
|
24
|
+
mypy:
|
|
25
|
+
uv run python -m mypy $(sources)
|
|
26
|
+
|
|
27
|
+
.PHONY: typecheck
|
|
28
|
+
typecheck:
|
|
29
|
+
uv run pyright
|
|
30
|
+
|
|
31
|
+
.PHONY: test
|
|
32
|
+
test:
|
|
33
|
+
uv run pytest
|
|
34
|
+
|
|
35
|
+
.PHONY: test-all-python # Run tests on Python 3.11 to 3.13
|
|
36
|
+
test-all-python:
|
|
37
|
+
uv run --python 3.11 coverage run -p -m pytest --junitxml=junit.xml -o junit_family=legacy
|
|
38
|
+
UV_PROJECT_ENVIRONMENT=.venv312 uv run --python 3.12 coverage run -p -m pytest
|
|
39
|
+
UV_PROJECT_ENVIRONMENT=.venv313 uv run --python 3.13 coverage run -p -m pytest
|
|
40
|
+
@uv run coverage xml -o coverage.xml
|
|
41
|
+
@uv run coverage report
|
|
42
|
+
|
|
43
|
+
.PHONY: html # Generate HTML coverage report
|
|
44
|
+
html: test-all-python
|
|
45
|
+
uv run coverage html -d htmlcov
|
|
46
|
+
|
|
47
|
+
.PHONY: all
|
|
48
|
+
all: format mypy lint typecheck test-all-python
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: surreal-orm-lite
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Lightweight Django-style ORM for SurrealDB using the official Python SDK. Async support with Pydantic validation.
|
|
5
|
+
Project-URL: Homepage, https://github.com/EulogySnowfall/surreal-orm-lite
|
|
6
|
+
Project-URL: Documentation, https://github.com/EulogySnowfall/surreal-orm-lite
|
|
7
|
+
Project-URL: Repository, https://github.com/EulogySnowfall/surreal-orm-lite.git
|
|
8
|
+
Project-URL: Issues, https://github.com/EulogySnowfall/surreal-orm-lite/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/EulogySnowfall/surreal-orm-lite/blob/main/CHANGELOG.md
|
|
10
|
+
Author-email: Yannick Croteau <croteau.yannick@gmail.com>
|
|
11
|
+
License: # MIT License
|
|
12
|
+
|
|
13
|
+
Copyright (c) 2024-2026 Yannick Croteau
|
|
14
|
+
|
|
15
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
17
|
+
in the Software without restriction, including without limitation the rights
|
|
18
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
furnished to do so, subject to the following conditions:
|
|
21
|
+
|
|
22
|
+
The above copyright notice and this permission notice shall be included in all
|
|
23
|
+
copies or substantial portions of the Software.
|
|
24
|
+
|
|
25
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
+
SOFTWARE.
|
|
32
|
+
License-File: LICENSE
|
|
33
|
+
Keywords: async,database,orm,pydantic,surrealdb
|
|
34
|
+
Classifier: Development Status :: 4 - Beta
|
|
35
|
+
Classifier: Framework :: Pydantic :: 2
|
|
36
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
37
|
+
Classifier: Operating System :: OS Independent
|
|
38
|
+
Classifier: Programming Language :: Python :: 3
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
43
|
+
Classifier: Topic :: Database
|
|
44
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
45
|
+
Classifier: Typing :: Typed
|
|
46
|
+
Requires-Python: >=3.11
|
|
47
|
+
Requires-Dist: pydantic>=2.12.5
|
|
48
|
+
Requires-Dist: surrealdb>=1.0.8
|
|
49
|
+
Description-Content-Type: text/markdown
|
|
50
|
+
|
|
51
|
+
# Surreal ORM Lite
|
|
52
|
+
|
|
53
|
+

|
|
54
|
+

|
|
55
|
+

|
|
56
|
+

|
|
57
|
+
[](https://codecov.io/gh/EulogySnowfall/SurrealDB-ORM-lite)
|
|
58
|
+
|
|
59
|
+
**Surreal ORM Lite** is a lightweight, Django-style ORM for [SurrealDB](https://surrealdb.com/) that uses the **official SurrealDB Python SDK**. It provides a simple and intuitive interface for database operations with full async support and Pydantic validation.
|
|
60
|
+
|
|
61
|
+
## Why This Project?
|
|
62
|
+
|
|
63
|
+
This ORM is designed to:
|
|
64
|
+
|
|
65
|
+
- Use the **official SurrealDB SDK** (`surrealdb>=1.0.8`) for maximum compatibility
|
|
66
|
+
- Stay **lightweight** with minimal dependencies
|
|
67
|
+
- Keep **up-to-date** with SurrealDB and SDK releases
|
|
68
|
+
- Provide **Django-style** query syntax that developers love
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Requirements
|
|
73
|
+
|
|
74
|
+
| Dependency | Version |
|
|
75
|
+
| ------------ | ---------------- |
|
|
76
|
+
| Python | 3.11+ |
|
|
77
|
+
| SurrealDB | 2.6.0+ |
|
|
78
|
+
| Official SDK | surrealdb>=1.0.8 |
|
|
79
|
+
| Pydantic | >=2.12.5 |
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Installation
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pip install surreal-orm-lite
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Or with uv:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
uv add surreal-orm-lite
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Quick Start
|
|
98
|
+
|
|
99
|
+
### 1. Configure the Connection
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from surreal_orm_lite import SurrealDBConnectionManager
|
|
103
|
+
|
|
104
|
+
SurrealDBConnectionManager.set_connection(
|
|
105
|
+
url="http://localhost:8000",
|
|
106
|
+
user="root",
|
|
107
|
+
password="root",
|
|
108
|
+
namespace="my_namespace",
|
|
109
|
+
database="my_database",
|
|
110
|
+
)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 2. Define a Model
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
from surreal_orm_lite import BaseSurrealModel
|
|
117
|
+
from pydantic import Field
|
|
118
|
+
|
|
119
|
+
class User(BaseSurrealModel):
|
|
120
|
+
id: str | None = None
|
|
121
|
+
name: str = Field(..., max_length=100)
|
|
122
|
+
email: str
|
|
123
|
+
age: int = Field(..., ge=0)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 3. CRUD Operations
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
# Create
|
|
130
|
+
user = User(name="Alice", email="alice@example.com", age=30)
|
|
131
|
+
await user.save()
|
|
132
|
+
|
|
133
|
+
# Read
|
|
134
|
+
user = await User.objects().get("alice_id")
|
|
135
|
+
users = await User.objects().filter(age__gte=18).exec()
|
|
136
|
+
|
|
137
|
+
# Update
|
|
138
|
+
user.age = 31
|
|
139
|
+
await user.update()
|
|
140
|
+
|
|
141
|
+
# Or partial update
|
|
142
|
+
await user.merge(age=31)
|
|
143
|
+
|
|
144
|
+
# Delete
|
|
145
|
+
await user.delete()
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### 4. QuerySet Methods
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
# Filter with Django-style lookups
|
|
152
|
+
users = await User.objects().filter(
|
|
153
|
+
age__gte=18,
|
|
154
|
+
name__startswith="A"
|
|
155
|
+
).exec()
|
|
156
|
+
|
|
157
|
+
# Ordering
|
|
158
|
+
users = await User.objects().order_by("name").exec()
|
|
159
|
+
users = await User.objects().order_by("age", OrderBy.DESC).exec()
|
|
160
|
+
|
|
161
|
+
# Pagination
|
|
162
|
+
users = await User.objects().limit(10).offset(20).exec()
|
|
163
|
+
|
|
164
|
+
# Select specific fields
|
|
165
|
+
results = await User.objects().select("name", "email").exec()
|
|
166
|
+
|
|
167
|
+
# Get first result
|
|
168
|
+
user = await User.objects().filter(name="Alice").first()
|
|
169
|
+
|
|
170
|
+
# Get all records
|
|
171
|
+
all_users = await User.objects().all()
|
|
172
|
+
|
|
173
|
+
# Custom query
|
|
174
|
+
results = await User.objects().query(
|
|
175
|
+
"SELECT * FROM User WHERE age > $min_age",
|
|
176
|
+
{"min_age": 21}
|
|
177
|
+
)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## Features
|
|
183
|
+
|
|
184
|
+
| Feature | Status |
|
|
185
|
+
| --------------------- | ------ |
|
|
186
|
+
| Async/await support | ✅ |
|
|
187
|
+
| Pydantic validation | ✅ |
|
|
188
|
+
| CRUD operations | ✅ |
|
|
189
|
+
| QuerySet with filters | ✅ |
|
|
190
|
+
| Django-style lookups | ✅ |
|
|
191
|
+
| Custom primary keys | ✅ |
|
|
192
|
+
| HTTP connections | ✅ |
|
|
193
|
+
| WebSocket connections | ✅ |
|
|
194
|
+
|
|
195
|
+
### Supported Filter Lookups
|
|
196
|
+
|
|
197
|
+
- `exact` (default)
|
|
198
|
+
- `gt`, `gte`, `lt`, `lte`
|
|
199
|
+
- `in`
|
|
200
|
+
- `contains`, `icontains`
|
|
201
|
+
- `startswith`, `istartswith`
|
|
202
|
+
- `endswith`, `iendswith`
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## Configuration Options
|
|
207
|
+
|
|
208
|
+
### Custom Primary Key
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
from surreal_orm_lite import BaseSurrealModel, SurrealConfigDict
|
|
212
|
+
|
|
213
|
+
class Product(BaseSurrealModel):
|
|
214
|
+
model_config = SurrealConfigDict(primary_key="sku")
|
|
215
|
+
|
|
216
|
+
sku: str
|
|
217
|
+
name: str
|
|
218
|
+
price: float
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Context Manager
|
|
222
|
+
|
|
223
|
+
```python
|
|
224
|
+
async with SurrealDBConnectionManager():
|
|
225
|
+
users = await User.objects().all()
|
|
226
|
+
# Connection automatically closed
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## Compatibility
|
|
232
|
+
|
|
233
|
+
This ORM is tested and compatible with:
|
|
234
|
+
|
|
235
|
+
| SurrealDB Version | SDK Version | Status |
|
|
236
|
+
| ----------------- | ----------- | ------------- |
|
|
237
|
+
| 2.6.0 | 1.0.8 | ✅ Tested |
|
|
238
|
+
| 2.5.x | 1.0.8 | ✅ Compatible |
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Contributing
|
|
243
|
+
|
|
244
|
+
Contributions are welcome! Please:
|
|
245
|
+
|
|
246
|
+
1. Fork the repository
|
|
247
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
248
|
+
3. Commit your changes (`git commit -m "Add amazing feature"`)
|
|
249
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
250
|
+
5. Open a Pull Request
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## Advanced Features?
|
|
255
|
+
|
|
256
|
+
This project prioritizes **stability and compatibility** with the official SurrealDB Python SDK. Due to current SDK limitations, some advanced features cannot be implemented here.
|
|
257
|
+
|
|
258
|
+
For a feature-rich ORM with relations, transactions, and more, see:
|
|
259
|
+
|
|
260
|
+
- **GitHub**: [SurrealDB-ORM](https://github.com/EulogySnowfall/SurrealDB-ORM/)
|
|
261
|
+
- **PyPI**: [surrealdb-orm](https://pypi.org/project/surrealdb-orm/)
|
|
262
|
+
|
|
263
|
+
When the official SDK supports additional features, they will be incorporated into this lite version.
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## License
|
|
268
|
+
|
|
269
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## Author
|
|
274
|
+
|
|
275
|
+
**Yannick Croteau**
|
|
276
|
+
GitHub: [@EulogySnowfall](https://github.com/EulogySnowfall)
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## Related Projects
|
|
281
|
+
|
|
282
|
+
- [SurrealDB](https://surrealdb.com/) - The database
|
|
283
|
+
- [surrealdb.py](https://github.com/surrealdb/surrealdb.py) - Official Python SDK
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
# Surreal ORM Lite
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
[](https://codecov.io/gh/EulogySnowfall/SurrealDB-ORM-lite)
|
|
8
|
+
|
|
9
|
+
**Surreal ORM Lite** is a lightweight, Django-style ORM for [SurrealDB](https://surrealdb.com/) that uses the **official SurrealDB Python SDK**. It provides a simple and intuitive interface for database operations with full async support and Pydantic validation.
|
|
10
|
+
|
|
11
|
+
## Why This Project?
|
|
12
|
+
|
|
13
|
+
This ORM is designed to:
|
|
14
|
+
|
|
15
|
+
- Use the **official SurrealDB SDK** (`surrealdb>=1.0.8`) for maximum compatibility
|
|
16
|
+
- Stay **lightweight** with minimal dependencies
|
|
17
|
+
- Keep **up-to-date** with SurrealDB and SDK releases
|
|
18
|
+
- Provide **Django-style** query syntax that developers love
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Requirements
|
|
23
|
+
|
|
24
|
+
| Dependency | Version |
|
|
25
|
+
| ------------ | ---------------- |
|
|
26
|
+
| Python | 3.11+ |
|
|
27
|
+
| SurrealDB | 2.6.0+ |
|
|
28
|
+
| Official SDK | surrealdb>=1.0.8 |
|
|
29
|
+
| Pydantic | >=2.12.5 |
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install surreal-orm-lite
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Or with uv:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
uv add surreal-orm-lite
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
### 1. Configure the Connection
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from surreal_orm_lite import SurrealDBConnectionManager
|
|
53
|
+
|
|
54
|
+
SurrealDBConnectionManager.set_connection(
|
|
55
|
+
url="http://localhost:8000",
|
|
56
|
+
user="root",
|
|
57
|
+
password="root",
|
|
58
|
+
namespace="my_namespace",
|
|
59
|
+
database="my_database",
|
|
60
|
+
)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 2. Define a Model
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from surreal_orm_lite import BaseSurrealModel
|
|
67
|
+
from pydantic import Field
|
|
68
|
+
|
|
69
|
+
class User(BaseSurrealModel):
|
|
70
|
+
id: str | None = None
|
|
71
|
+
name: str = Field(..., max_length=100)
|
|
72
|
+
email: str
|
|
73
|
+
age: int = Field(..., ge=0)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 3. CRUD Operations
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
# Create
|
|
80
|
+
user = User(name="Alice", email="alice@example.com", age=30)
|
|
81
|
+
await user.save()
|
|
82
|
+
|
|
83
|
+
# Read
|
|
84
|
+
user = await User.objects().get("alice_id")
|
|
85
|
+
users = await User.objects().filter(age__gte=18).exec()
|
|
86
|
+
|
|
87
|
+
# Update
|
|
88
|
+
user.age = 31
|
|
89
|
+
await user.update()
|
|
90
|
+
|
|
91
|
+
# Or partial update
|
|
92
|
+
await user.merge(age=31)
|
|
93
|
+
|
|
94
|
+
# Delete
|
|
95
|
+
await user.delete()
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 4. QuerySet Methods
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
# Filter with Django-style lookups
|
|
102
|
+
users = await User.objects().filter(
|
|
103
|
+
age__gte=18,
|
|
104
|
+
name__startswith="A"
|
|
105
|
+
).exec()
|
|
106
|
+
|
|
107
|
+
# Ordering
|
|
108
|
+
users = await User.objects().order_by("name").exec()
|
|
109
|
+
users = await User.objects().order_by("age", OrderBy.DESC).exec()
|
|
110
|
+
|
|
111
|
+
# Pagination
|
|
112
|
+
users = await User.objects().limit(10).offset(20).exec()
|
|
113
|
+
|
|
114
|
+
# Select specific fields
|
|
115
|
+
results = await User.objects().select("name", "email").exec()
|
|
116
|
+
|
|
117
|
+
# Get first result
|
|
118
|
+
user = await User.objects().filter(name="Alice").first()
|
|
119
|
+
|
|
120
|
+
# Get all records
|
|
121
|
+
all_users = await User.objects().all()
|
|
122
|
+
|
|
123
|
+
# Custom query
|
|
124
|
+
results = await User.objects().query(
|
|
125
|
+
"SELECT * FROM User WHERE age > $min_age",
|
|
126
|
+
{"min_age": 21}
|
|
127
|
+
)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Features
|
|
133
|
+
|
|
134
|
+
| Feature | Status |
|
|
135
|
+
| --------------------- | ------ |
|
|
136
|
+
| Async/await support | ✅ |
|
|
137
|
+
| Pydantic validation | ✅ |
|
|
138
|
+
| CRUD operations | ✅ |
|
|
139
|
+
| QuerySet with filters | ✅ |
|
|
140
|
+
| Django-style lookups | ✅ |
|
|
141
|
+
| Custom primary keys | ✅ |
|
|
142
|
+
| HTTP connections | ✅ |
|
|
143
|
+
| WebSocket connections | ✅ |
|
|
144
|
+
|
|
145
|
+
### Supported Filter Lookups
|
|
146
|
+
|
|
147
|
+
- `exact` (default)
|
|
148
|
+
- `gt`, `gte`, `lt`, `lte`
|
|
149
|
+
- `in`
|
|
150
|
+
- `contains`, `icontains`
|
|
151
|
+
- `startswith`, `istartswith`
|
|
152
|
+
- `endswith`, `iendswith`
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Configuration Options
|
|
157
|
+
|
|
158
|
+
### Custom Primary Key
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
from surreal_orm_lite import BaseSurrealModel, SurrealConfigDict
|
|
162
|
+
|
|
163
|
+
class Product(BaseSurrealModel):
|
|
164
|
+
model_config = SurrealConfigDict(primary_key="sku")
|
|
165
|
+
|
|
166
|
+
sku: str
|
|
167
|
+
name: str
|
|
168
|
+
price: float
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Context Manager
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
async with SurrealDBConnectionManager():
|
|
175
|
+
users = await User.objects().all()
|
|
176
|
+
# Connection automatically closed
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## Compatibility
|
|
182
|
+
|
|
183
|
+
This ORM is tested and compatible with:
|
|
184
|
+
|
|
185
|
+
| SurrealDB Version | SDK Version | Status |
|
|
186
|
+
| ----------------- | ----------- | ------------- |
|
|
187
|
+
| 2.6.0 | 1.0.8 | ✅ Tested |
|
|
188
|
+
| 2.5.x | 1.0.8 | ✅ Compatible |
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## Contributing
|
|
193
|
+
|
|
194
|
+
Contributions are welcome! Please:
|
|
195
|
+
|
|
196
|
+
1. Fork the repository
|
|
197
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
198
|
+
3. Commit your changes (`git commit -m "Add amazing feature"`)
|
|
199
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
200
|
+
5. Open a Pull Request
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Advanced Features?
|
|
205
|
+
|
|
206
|
+
This project prioritizes **stability and compatibility** with the official SurrealDB Python SDK. Due to current SDK limitations, some advanced features cannot be implemented here.
|
|
207
|
+
|
|
208
|
+
For a feature-rich ORM with relations, transactions, and more, see:
|
|
209
|
+
|
|
210
|
+
- **GitHub**: [SurrealDB-ORM](https://github.com/EulogySnowfall/SurrealDB-ORM/)
|
|
211
|
+
- **PyPI**: [surrealdb-orm](https://pypi.org/project/surrealdb-orm/)
|
|
212
|
+
|
|
213
|
+
When the official SDK supports additional features, they will be incorporated into this lite version.
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## License
|
|
218
|
+
|
|
219
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Author
|
|
224
|
+
|
|
225
|
+
**Yannick Croteau**
|
|
226
|
+
GitHub: [@EulogySnowfall](https://github.com/EulogySnowfall)
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## Related Projects
|
|
231
|
+
|
|
232
|
+
- [SurrealDB](https://surrealdb.com/) - The database
|
|
233
|
+
- [surrealdb.py](https://github.com/surrealdb/surrealdb.py) - Official Python SDK
|