High-performance CockroachDB client library with connection pooling, migrations, and transaction management
Project description
"""# Manticore CockroachDB Client
A high-performance, production-ready CockroachDB client library for Python with connection pooling, transaction retries, and comprehensive CRUD operations.
Copyright (c) 2024 Manticore Technologies. All rights reserved.
Features
- Connection pooling for optimal performance
- Automatic transaction retries with exponential backoff
- Comprehensive CRUD operations with batch support
- Schema migrations with versioning and rollback support
- Type-safe operations with proper error handling
- Extensive test coverage (90%+)
- Production-ready with logging and monitoring
Installation
pip install manticore-cockroachdb
For development:
pip install manticore-cockroachdb[dev]
Quick Start
from manticore_cockroachdb import Database
# Initialize database connection
db = Database(
host="localhost",
port=26257,
database="mydb",
user="root",
password="",
sslmode="disable"
)
# Create a table
db.create_table(
"users",
{
"id": "UUID PRIMARY KEY DEFAULT gen_random_uuid()",
"name": "TEXT NOT NULL",
"email": "TEXT UNIQUE NOT NULL",
"created_at": "TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP"
}
)
# Insert a record
user = db.insert("users", {
"name": "John Doe",
"email": "john@example.com"
})
# Query records
users = db.select(
"users",
where={"email": "john@example.com"}
)
# Update a record
updated = db.update(
"users",
{"name": "John Smith"},
{"email": "john@example.com"}
)
# Delete a record
db.delete("users", {"email": "john@example.com"})
# Batch operations
users_data = [
{"name": "User 1", "email": "user1@example.com"},
{"name": "User 2", "email": "user2@example.com"}
]
created = db.batch_insert("users", users_data)
Transaction Management
# Using transaction context manager
with db.transaction() as conn:
with conn.cursor() as cur:
cur.execute(
"UPDATE accounts SET balance = balance - %s WHERE id = %s",
[100, "acc1"]
)
cur.execute(
"UPDATE accounts SET balance = balance + %s WHERE id = %s",
[100, "acc2"]
)
# Using transaction with retry logic
def transfer_funds(conn, from_id, to_id, amount):
with conn.cursor() as cur:
cur.execute(
"UPDATE accounts SET balance = balance - %s WHERE id = %s",
[amount, from_id]
)
cur.execute(
"UPDATE accounts SET balance = balance + %s WHERE id = %s",
[amount, to_id]
)
db.run_in_transaction(lambda conn: transfer_funds(conn, "acc1", "acc2", 100))
Schema Migrations
from manticore_cockroachdb import Database, Migrator
db = Database()
migrator = Migrator(db)
# Create a migration
migrator.create_migration(
"create_users",
"""
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL
)
""",
"DROP TABLE users"
)
# Apply migrations
migrator.migrate() # Apply all pending migrations
migrator.migrate(target_version=1) # Apply up to version 1
migrator.migrate(target_version=0) # Revert all migrations
Development
- Clone the repository:
git clone https://github.com/manticore-tech/manticore-cockroachdb.git
cd manticore-cockroachdb
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # Linux/Mac
venv\Scripts\activate # Windows
- Install development dependencies:
pip install -e .[dev]
- Run tests:
pytest tests/
License
This software is proprietary and confidential. Copyright (c) 2024 Manticore Technologies. All rights reserved.
Support
For enterprise support, please contact support@manticoretech.com or visit our website at https://manticoretech.com.
For bug reports and feature requests, please open an issue on our GitHub repository."""
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file manticore_cockroachdb-0.1.1.tar.gz.
File metadata
- Download URL: manticore_cockroachdb-0.1.1.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe89dc4622c931beb10a67881d0d447b0d50924485123decf25c3975c088636a
|
|
| MD5 |
763ba7be896461cda7e6301788fa4c84
|
|
| BLAKE2b-256 |
b24def7f8d32011bc8a0ab2b6203a5499e6d009f66274fa5df3e668c3e4fb8fc
|
File details
Details for the file manticore_cockroachdb-0.1.1-py3-none-any.whl.
File metadata
- Download URL: manticore_cockroachdb-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1aafeccbba1f23a4c4904a806194e946fd02df49dc2a16afeaeac2091db845b0
|
|
| MD5 |
e415825380727ebdb3e1a8d593366054
|
|
| BLAKE2b-256 |
890a27885f38af9858083de58d3b7318bd5f80b08162ad7c982b41cbded1293d
|