Skip to content

Commit 9bb90f5

Browse files
committed
Refactor schema operations to be auto-transactional in tests
- Updated multiple test files to remove explicit transaction blocks for schema operations. - Ensured that document and vertex types are created without wrapping them in transactions, leveraging the auto-transactional behavior of the database. - Improved readability and maintainability of test code by simplifying transaction management.
1 parent b950baa commit 9bb90f5

67 files changed

Lines changed: 3267 additions & 2838 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bindings/python/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Native Python bindings for ArcadeDB - the multi-model database that supports Graph, Document, Key/Value, Search Engine, Time Series, and Vector models.
44

5-
**Status**: ✅ Production Ready | **Tests**: 204 Passing | **Platforms**: 6 Supported
5+
**Status**: ✅ Production Ready | **Tests**: 221 Passing | **Platforms**: 6 Supported
66

77
---
88

@@ -45,7 +45,7 @@ We publish development versions (`X.Y.Z.devN`) for every push to main when `pom.
4545
```python
4646
import arcadedb_embedded as arcadedb
4747

48-
# Create database (context manager for automatic cleanup)
48+
# Create database (context manager for automatic open and close)
4949
with arcadedb.create_database("/tmp/mydb") as db:
5050
# Create schema
5151
db.command("sql", "CREATE DOCUMENT TYPE Person")
@@ -76,7 +76,7 @@ with arcadedb.create_database("/tmp/mydb") as db:
7676
-**High performance**: Direct JVM integration via JPype
7777
- 🔒 **ACID transactions**: Full transaction support
7878
- 🎯 **Vector storage**: Store and query vector embeddings with JVector indexing
79-
- 📥 **Data import**: Built-in CSV, XML, ArcadeDB JSONL import
79+
- 📥 **Data import**: Built-in CSV and ArcadeDB JSONL import
8080

8181
---
8282

@@ -94,12 +94,12 @@ The `arcadedb-embedded` package is platform-specific and self-contained:
9494

9595
| Platform | Wheel Size | JRE Size | Installed Size | Tests |
9696
| ------------- | ---------- | -------- | -------------- | ------------- |
97-
| Windows ARM64 | 209.4M | 47.6M | ~274M | 204 passed ✅ |
98-
| macOS ARM64 | 210.8M | 53.9M | ~280M | 204 passed ✅ |
99-
| macOS Intel | 211.9M | 55.3M | ~281M | 204 passed ✅ |
100-
| Windows x64 | 211.6M | 51.6M | ~278M | 204 passed ✅ |
101-
| Linux ARM64 | 214.1M | 61.8M | ~288M | 204 passed ✅ |
102-
| Linux x64 | 215.0M | 62.7M | ~289M | 204 passed ✅ |
97+
| Windows ARM64 | 209.4M | 47.6M | ~274M | 221 passed ✅ |
98+
| macOS ARM64 | 210.8M | 53.9M | ~280M | 221 passed ✅ |
99+
| macOS Intel | 211.9M | 55.3M | ~281M | 221 passed ✅ |
100+
| Windows x64 | 211.6M | 51.6M | ~278M | 221 passed ✅ |
101+
| Linux ARM64 | 214.1M | 61.8M | ~288M | 221 passed ✅ |
102+
| Linux x64 | 215.0M | 62.7M | ~289M | 221 passed ✅ |
103103

104104
**Note**: Some JARs are excluded to optimize package size (e.g., gRPC wire protocol). See `jar_exclusions.txt` for details.
105105

@@ -109,7 +109,7 @@ Import: `import arcadedb_embedded as arcadedb`
109109

110110
## 🧪 Testing
111111

112-
**Status**: 204 tests + 7 example scripts passing on all 6 platforms
112+
**Status**: 221 tests + 7 example scripts passing on all 6 platforms
113113

114114
```bash
115115
# Run all tests
@@ -209,7 +209,7 @@ arcadedb_embedded/
209209
├── transactions.py # TransactionContext manager
210210
├── schema.py # Schema management API
211211
├── vector.py # Vector search and JVector indexing
212-
├── importer.py # Data import (CSV, XML)
212+
├── importer.py # Data import (CSV, JSONL)
213213
├── exporter.py # Data export (JSONL, GraphML, GraphSON, CSV)
214214
├── batch.py # Batch operations context
215215
├── async_executor.py # Asynchronous query execution

bindings/python/docs/api-access-methods.md

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@ import arcadedb_embedded as arcadedb
2121

2222
# Direct database access - NO server needed
2323
with arcadedb.create_database("/tmp/mydb") as db:
24-
# Create schema
25-
db.command("sql", "CREATE DOCUMENT TYPE Person")
24+
# Create schema (auto-transactional)
25+
db.schema.create_document_type("Person")
26+
db.schema.create_property("Person", "name", "STRING")
27+
db.schema.create_property("Person", "age", "INTEGER")
2628

2729
# Insert data (requires transaction)
2830
with db.transaction():
29-
db.command("sql", "INSERT INTO Person SET name = 'Alice', age = 30")
31+
person = db.new_document("Person")
32+
person.set("name", "Alice")
33+
person.set("age", 30)
34+
person.save()
3035

31-
# Query data
36+
# Query data (SQL is fine for reads)
3237
result = db.query("sql", "SELECT FROM Person WHERE age > 25")
3338
for record in result:
3439
print(f"Name: {record.get('name')}")
@@ -46,10 +51,17 @@ server.start()
4651
try:
4752
db = server.create_database("mydb")
4853

49-
# Same Java API calls as standalone
54+
# Schema operations are auto-transactional
55+
db.schema.create_document_type("Person")
56+
db.schema.create_property("Person", "name", "STRING")
57+
db.schema.create_property("Person", "age", "INTEGER")
58+
59+
# Data operations require explicit transactions
5060
with db.transaction():
51-
db.command("sql", "CREATE DOCUMENT TYPE Person")
52-
db.command("sql", "INSERT INTO Person SET name = 'Alice', age = 30")
61+
person = db.new_document("Person")
62+
person.set("name", "Alice")
63+
person.set("age", 30)
64+
person.save()
5365

5466
result = db.query("sql", "SELECT FROM Person WHERE age > 25")
5567
for record in result:
@@ -111,6 +123,9 @@ try:
111123
}
112124
)
113125
assert response.status_code == 200
126+
# Note: HTTP commands are auto-transactional per request. For multi-statement atomicity, use
127+
# the HTTP transactional endpoints or perform batch writes with the embedded API via
128+
# `with db.transaction():`.
114129

115130
# Query data via HTTP
116131
response = requests.post(
@@ -144,9 +159,17 @@ try:
144159
# Create database using Java API (fastest)
145160
db = server.create_database("hybriddb")
146161

162+
# Schema operations are auto-transactional
163+
db.schema.create_document_type("Person")
164+
db.schema.create_property("Person", "name", "STRING")
165+
db.schema.create_property("Person", "age", "INTEGER")
166+
167+
# Data operations require explicit transactions
147168
with db.transaction():
148-
db.command("sql", "CREATE DOCUMENT TYPE Person")
149-
db.command("sql", "INSERT INTO Person SET name = 'Alice', age = 30")
169+
person = db.new_document("Person")
170+
person.set("name", "Alice")
171+
person.set("age", 30)
172+
person.save()
150173

151174
# Query same data using HTTP API (remote access)
152175
auth = HTTPBasicAuth("root", "password123")

bindings/python/docs/api/async_executor.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ import arcadedb_embedded as arcadedb
426426
import time
427427

428428
# Create database
429-
db = arcadedb.create_database("./async_demo", create_if_not_exists=True)
429+
db = arcadedb.create_database("./async_demo")
430430

431431
# Create schema
432432
with db.transaction():
@@ -502,6 +502,16 @@ print(f"Speedup: {sync_time / async_time:.1f}x")
502502

503503
## Best Practices
504504

505+
### 0. Set a Commit Cadence
506+
507+
```python
508+
async_exec = db.async_executor()
509+
async_exec.set_commit_every(500) # Ensures async writes are persisted transactionally
510+
```
511+
512+
- Configure `set_commit_every()` for every async workload so writes are grouped into transactions.
513+
- Tune the batch size to balance commit overhead and memory.
514+
505515
### 1. Always Close the Executor
506516

507517
```python

bindings/python/docs/api/batch.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ db.batch_context(
4949
```python
5050
import arcadedb_embedded as arcadedb
5151

52-
db = arcadedb.create_database("./mydb", create_if_not_exists=True)
52+
db = arcadedb.create_database("./mydb")
5353

5454
# Create schema
5555
with db.transaction():
@@ -358,7 +358,7 @@ with db.batch_context(
358358
import arcadedb_embedded as arcadedb
359359
import time
360360

361-
db = arcadedb.create_database("./bulk_db", create_if_not_exists=True)
361+
db = arcadedb.create_database("./bulk_db")
362362

363363
# Create schema
364364
with db.transaction():

bindings/python/docs/api/database.md

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ import arcadedb_embedded as arcadedb
3131

3232
db = arcadedb.create_database("/tmp/mydb")
3333
try:
34-
# Use database
35-
db.command("sql", "CREATE DOCUMENT TYPE Person")
34+
# Schema operations are auto-transactional
35+
db.schema.create_document_type("Person")
36+
db.schema.create_property("Person", "name", "STRING")
3637
finally:
3738
db.close()
3839
```
@@ -72,7 +73,7 @@ Open an existing database.
7273
```python
7374
with arcadedb.open_database("/tmp/mydb") as db:
7475
result = db.query("sql", "SELECT FROM Person")
75-
print(f"Found {len(result)} records")
76+
print(f"Found {len(list(result))} records")
7677
```
7778

7879
---
@@ -201,30 +202,39 @@ Execute a command (write operation). Commands modify data and **require a transa
201202
**Example:**
202203

203204
```python
204-
# Must be in a transaction
205-
with db.transaction():
206-
# Create type
207-
db.command("sql", "CREATE DOCUMENT TYPE Person")
205+
# Schema operations are auto-transactional
206+
db.schema.create_document_type("Person")
207+
db.schema.create_property("Person", "name", "STRING")
208+
db.schema.create_property("Person", "age", "INTEGER")
208209

209-
# Insert data
210-
db.command("sql", "INSERT INTO Person SET name = ?, age = ?", "Alice", 30)
210+
# Data operations must be in a transaction
211+
with db.transaction():
212+
doc = db.new_document("Person")
213+
doc.set("name", "Alice")
214+
doc.set("age", 30)
215+
doc.save()
211216

212-
# Update data
213-
db.command("sql", "UPDATE Person SET age = 31 WHERE name = 'Alice'")
217+
# Update data via API
218+
doc.set("age", 31)
219+
doc.save()
214220

215221
# Delete data
216-
db.command("sql", "DELETE FROM Person WHERE name = 'Alice'")
222+
db.delete(doc)
217223
```
218224

219225
!!! warning "Transaction Required"
220226
Write operations must be wrapped in a transaction:
221227
```python
222228
# ✅ Correct
223229
with db.transaction():
224-
db.command("sql", "INSERT INTO Person SET name = 'Alice'")
230+
doc = db.new_document("Person")
231+
doc.set("name", "Alice")
232+
doc.save()
225233

226234
# ❌ Will fail
227-
db.command("sql", "INSERT INTO Person SET name = 'Alice'")
235+
doc = db.new_document("Person")
236+
doc.set("name", "Alice")
237+
# doc.save() outside a transaction will raise
228238
```
229239

230240
---
@@ -245,8 +255,10 @@ Create a transaction context manager.
245255

246256
```python
247257
with db.transaction():
248-
db.command("sql", "INSERT INTO Person SET name = 'Alice'")
249-
db.command("sql", "INSERT INTO Person SET name = 'Bob'")
258+
for name in ["Alice", "Bob"]:
259+
doc = db.new_document("Person")
260+
doc.set("name", name)
261+
doc.save()
250262
# Automatic commit on success, rollback on exception
251263
```
252264

@@ -256,8 +268,10 @@ with db.transaction():
256268
# Alternative: manual control
257269
db.begin()
258270
try:
259-
db.command("sql", "INSERT INTO Person SET name = 'Alice'")
260-
db.command("sql", "INSERT INTO Person SET name = 'Bob'")
271+
for name in ["Alice", "Bob"]:
272+
doc = db.new_document("Person")
273+
doc.set("name", name)
274+
doc.save()
261275
db.commit()
262276
except Exception as e:
263277
db.rollback()
@@ -668,7 +682,18 @@ from arcadedb_embedded import ArcadeDBError
668682

669683
try:
670684
with arcadedb.create_database("/tmp/mydb") as db:
671-
db.command("sql", "INVALID SQL")
685+
# Schema operations are auto-transactional
686+
db.schema.create_document_type("User")
687+
db.schema.create_property("User", "email", "STRING")
688+
db.schema.create_index("User", ["email"], unique=True)
689+
690+
# Data operations require an explicit transaction
691+
with db.transaction():
692+
doc = db.new_document("User")
693+
doc.set("email", "alice@example.com").save()
694+
695+
dup = db.new_document("User")
696+
dup.set("email", "alice@example.com").save()
672697
except ArcadeDBError as e:
673698
print(f"Error: {e}")
674699
```
@@ -694,7 +719,8 @@ db.close()
694719
```python
695720
# ✅ Good
696721
with db.transaction():
697-
db.command("sql", "INSERT INTO Person SET name = 'Alice'")
722+
person = db.new_document("Person")
723+
person.set("name", "Alice").save()
698724

699725
# ❌ Will fail
700726
db.command("sql", "INSERT INTO Person SET name = 'Alice'")

bindings/python/docs/api/record-wrappers.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import arcadedb_embedded as arcadedb
2424
from arcadedb_embedded.graph import Document, Vertex, Edge
2525

2626
with arcadedb.create_database("/tmp/mydb") as db:
27-
with db.transaction():
28-
db.schema.create_document_type("Note")
27+
# Schema operations are auto-transactional
28+
db.schema.create_document_type("Note")
2929

3030
# Create a document
3131
with db.transaction():
@@ -188,8 +188,8 @@ traversing edges.
188188
### Creating Vertices
189189

190190
```python
191-
with db.transaction():
192-
db.schema.create_vertex_type("Person")
191+
# Schema operations are auto-transactional
192+
db.schema.create_vertex_type("Person")
193193

194194
with db.transaction():
195195
alice = db.new_vertex("Person")

0 commit comments

Comments
 (0)