cinchdb 0.1.4__tar.gz → 0.1.5__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.
- {cinchdb-0.1.4 → cinchdb-0.1.5}/PKG-INFO +1 -1
- {cinchdb-0.1.4 → cinchdb-0.1.5}/pyproject.toml +1 -1
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/core/database.py +16 -2
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/managers/data.py +38 -17
- {cinchdb-0.1.4 → cinchdb-0.1.5}/.gitignore +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/LICENSE +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/README.md +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/__init__.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/__main__.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/cli/__init__.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/cli/commands/__init__.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/cli/commands/branch.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/cli/commands/codegen.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/cli/commands/column.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/cli/commands/database.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/cli/commands/query.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/cli/commands/remote.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/cli/commands/table.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/cli/commands/tenant.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/cli/commands/view.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/cli/handlers/__init__.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/cli/handlers/codegen_handler.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/cli/main.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/cli/utils.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/config.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/core/__init__.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/core/connection.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/core/initializer.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/core/maintenance.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/core/path_utils.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/managers/__init__.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/managers/branch.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/managers/change_applier.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/managers/change_comparator.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/managers/change_tracker.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/managers/codegen.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/managers/column.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/managers/merge_manager.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/managers/query.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/managers/table.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/managers/tenant.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/managers/view.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/models/__init__.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/models/base.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/models/branch.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/models/change.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/models/database.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/models/project.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/models/table.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/models/tenant.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/models/view.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/utils/__init__.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/utils/name_validator.py +0 -0
- {cinchdb-0.1.4 → cinchdb-0.1.5}/src/cinchdb/utils/sql_validator.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: cinchdb
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.5
|
4
4
|
Summary: A Git-like SQLite database management system with branching and multi-tenancy
|
5
5
|
Project-URL: Homepage, https://github.com/russellromney/cinchdb
|
6
6
|
Project-URL: Documentation, https://russellromney.github.io/cinchdb
|
@@ -371,10 +371,24 @@ class CinchDB:
|
|
371
371
|
data: Record data as dictionary
|
372
372
|
|
373
373
|
Returns:
|
374
|
-
Inserted record with generated fields
|
374
|
+
Inserted record with generated fields (id, created_at, updated_at)
|
375
|
+
|
376
|
+
Examples:
|
377
|
+
# Simple insert
|
378
|
+
db.insert("users", {"name": "John", "email": "john@example.com"})
|
379
|
+
|
380
|
+
# Insert with custom ID
|
381
|
+
db.insert("products", {"id": "prod-123", "name": "Widget", "price": 9.99})
|
375
382
|
"""
|
376
383
|
if self.is_local:
|
377
|
-
|
384
|
+
# Initialize data manager if needed
|
385
|
+
if self._data_manager is None:
|
386
|
+
from cinchdb.managers.data import DataManager
|
387
|
+
self._data_manager = DataManager(
|
388
|
+
self.project_dir, self.database, self.branch, self.tenant
|
389
|
+
)
|
390
|
+
# Use the new create_from_dict method
|
391
|
+
return self._data_manager.create_from_dict(table, data)
|
378
392
|
else:
|
379
393
|
# Remote insert - use new data CRUD endpoint
|
380
394
|
result = self._make_request(
|
@@ -93,14 +93,15 @@ class DataManager:
|
|
93
93
|
results = self.select(model_class, limit=1, id=record_id)
|
94
94
|
return results[0] if results else None
|
95
95
|
|
96
|
-
def
|
97
|
-
"""Create a new record.
|
96
|
+
def create_from_dict(self, table_name: str, data: Dict[str, Any]) -> Dict[str, Any]:
|
97
|
+
"""Create a new record from a dictionary.
|
98
98
|
|
99
99
|
Args:
|
100
|
-
|
100
|
+
table_name: Name of the table to insert into
|
101
|
+
data: Dictionary containing the record data
|
101
102
|
|
102
103
|
Returns:
|
103
|
-
|
104
|
+
Dictionary with created record including generated ID and timestamps
|
104
105
|
|
105
106
|
Raises:
|
106
107
|
ValueError: If record with same ID already exists
|
@@ -109,22 +110,20 @@ class DataManager:
|
|
109
110
|
# Check maintenance mode
|
110
111
|
check_maintenance_mode(self.project_root, self.database, self.branch)
|
111
112
|
|
112
|
-
|
113
|
-
|
114
|
-
# Prepare data for insertion
|
115
|
-
data = instance.model_dump()
|
113
|
+
# Make a copy to avoid modifying the original
|
114
|
+
record_data = data.copy()
|
116
115
|
|
117
116
|
# Generate ID if not provided
|
118
|
-
if not
|
119
|
-
|
117
|
+
if not record_data.get("id"):
|
118
|
+
record_data["id"] = str(uuid.uuid4())
|
120
119
|
|
121
120
|
# Set timestamps
|
122
121
|
now = datetime.now()
|
123
|
-
|
124
|
-
|
122
|
+
record_data["created_at"] = now
|
123
|
+
record_data["updated_at"] = now
|
125
124
|
|
126
125
|
# Build INSERT query
|
127
|
-
columns = list(
|
126
|
+
columns = list(record_data.keys())
|
128
127
|
placeholders = [f":{col}" for col in columns]
|
129
128
|
query = f"""
|
130
129
|
INSERT INTO {table_name} ({", ".join(columns)})
|
@@ -133,17 +132,39 @@ class DataManager:
|
|
133
132
|
|
134
133
|
with DatabaseConnection(self.db_path) as conn:
|
135
134
|
try:
|
136
|
-
conn.execute(query,
|
135
|
+
conn.execute(query, record_data)
|
137
136
|
conn.commit()
|
138
137
|
|
139
|
-
# Return
|
140
|
-
return
|
138
|
+
# Return the created record data
|
139
|
+
return record_data
|
141
140
|
except Exception as e:
|
142
141
|
conn.rollback()
|
143
142
|
if "UNIQUE constraint failed" in str(e):
|
144
|
-
raise ValueError(f"Record with ID {
|
143
|
+
raise ValueError(f"Record with ID {record_data['id']} already exists")
|
145
144
|
raise
|
146
145
|
|
146
|
+
def create(self, instance: T) -> T:
|
147
|
+
"""Create a new record from a model instance.
|
148
|
+
|
149
|
+
Args:
|
150
|
+
instance: Model instance to create
|
151
|
+
|
152
|
+
Returns:
|
153
|
+
Created model instance with populated ID and timestamps
|
154
|
+
|
155
|
+
Raises:
|
156
|
+
ValueError: If record with same ID already exists
|
157
|
+
MaintenanceError: If branch is in maintenance mode
|
158
|
+
"""
|
159
|
+
table_name = self._get_table_name(type(instance))
|
160
|
+
data = instance.model_dump()
|
161
|
+
|
162
|
+
# Use the new create_from_dict method
|
163
|
+
created_data = self.create_from_dict(table_name, data)
|
164
|
+
|
165
|
+
# Return updated instance
|
166
|
+
return type(instance)(**created_data)
|
167
|
+
|
147
168
|
def save(self, instance: T) -> T:
|
148
169
|
"""Save (upsert) a record - insert if new, update if exists.
|
149
170
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|