Skip to main content

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

  1. Clone the repository:
git clone https://github.com/manticore-tech/manticore-cockroachdb.git
cd manticore-cockroachdb
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # Linux/Mac
venv\Scripts\activate     # Windows
  1. Install development dependencies:
pip install -e .[dev]
  1. 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

manticore_cockroachdb-0.1.1.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

manticore_cockroachdb-0.1.1-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

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

Hashes for manticore_cockroachdb-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fe89dc4622c931beb10a67881d0d447b0d50924485123decf25c3975c088636a
MD5 763ba7be896461cda7e6301788fa4c84
BLAKE2b-256 b24def7f8d32011bc8a0ab2b6203a5499e6d009f66274fa5df3e668c3e4fb8fc

See more details on using hashes here.

File details

Details for the file manticore_cockroachdb-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for manticore_cockroachdb-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1aafeccbba1f23a4c4904a806194e946fd02df49dc2a16afeaeac2091db845b0
MD5 e415825380727ebdb3e1a8d593366054
BLAKE2b-256 890a27885f38af9858083de58d3b7318bd5f80b08162ad7c982b41cbded1293d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page