Skip to main content

A comprehensive data access layer for Vortex apps

Project description

LDC Vortex Data Layer

A comprehensive data access layer for Vortex Django applications, providing database operations, Redis caching, entity mappers, and business flow operations.

Features

Module Description
Base Layer Database connection management, query execution, transaction handling
Entity Mappers Data mappers for loans, investments, wallets, accounts, lenders, etc.
Flow Operations Business logic flows (redemption, repayment, portfolio, dashboard)
Redis Integration Unified caching layer with type-safe get/set operations
Cache Manager High-level caching patterns with fallback to database
Constants Centralized constants for transaction types, statuses, filters
Helpers Date utilities, generic utilities, master account caching

Installation

pip install LDC_Vortex-Datalayer

Requirements

  • Python 3.10+
  • Django 5.2+
  • PostgreSQL (with psycopg 3.x)
  • Redis 5.0+

Quick Start

Django Settings Configuration

# Database Configuration
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'vortex_db',
        'USER': 'your_user',
        'PASSWORD': 'your_password',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}

# Redis Configuration
IOS_REDIS_CACHE = "redis://localhost:6379/0"

Using Base Data Layer

from vortex_datalayer.base_layer import BaseDataLayer

class UserRepository(BaseDataLayer):
    def __init__(self):
        super().__init__(db_alias="default")
    
    def get_user_by_id(self, user_id: int) -> dict:
        sql = "SELECT * FROM users WHERE id = %s"
        return self.execute_fetch_one(sql, params=[user_id])
    
    def get_active_users(self) -> list:
        sql = "SELECT * FROM users WHERE status = 'ACTIVE'"
        return self.execute_fetch_all(sql)

Using Redis Utilities

from vortex_datalayer import redis_utils

# Get with automatic type conversion
user = redis_utils.get("user:123", dict)      # Returns dict or None
count = redis_utils.get("counter", int)        # Returns int or None
name = redis_utils.get("name", str)            # Returns str or None
data = redis_utils.get("key")                  # Returns raw bytes (backward compatible)

# Set with automatic serialization
redis_utils.set("user:123", {"name": "John", "age": 30}, ttl=3600)
redis_utils.set("counter", 42, ttl=1800)

# Other operations
redis_utils.delete("user:123")
redis_utils.exists("user:123")
redis_utils.keys("user:*")

Using Cache Manager

from vortex_datalayer.cache_manager import CacheManager

# Get or set pattern with database fallback
result = CacheManager.get_or_set(
    cache_identifier="user_123",
    db_callback=lambda: fetch_user_from_db(123),
    cache_key_prefix="USER_DATA",
    ttl=1800,
    return_type=dict
)

# Invalidate cache
CacheManager.invalidate("user_123", cache_key_prefix="USER_DATA")

Using Constants

from vortex_datalayer.constants import TransactionStatus, LoanStatus, WalletTransactionType

if transaction.status == TransactionStatus.SUCCESS:
    print("Transaction completed")

if loan.status == LoanStatus.FUNDED:
    process_funded_loan(loan)

Using Entity Mappers

from vortex_datalayer.entity.loan import Loan
from vortex_datalayer.entity.wallet_transaction import WalletTransaction

# Loan operations
loan_repo = Loan()
loan_details = loan_repo.get_loan_by_id(loan_id)

# Wallet transactions
wallet_repo = WalletTransaction()
transactions = wallet_repo.get_transaction_list(lender_id, filters)

Package Structure

vortex_datalayer/
├── base_layer.py          # Base database operations
├── redis_utils.py         # Redis connection and operations
├── cache_manager.py       # High-level caching patterns
├── constants.py           # Centralized constants
├── entity/                # Data mappers
│   ├── loan.py
│   ├── wallet_transaction.py
│   ├── lender.py
│   └── ...
├── flow/                  # Business logic flows
│   ├── redemption_processing.py
│   ├── repayment_consumption.py
│   ├── cp_dashboard_summary.py
│   └── ...
├── helper/                # Utility helpers
│   ├── date_utils.py
│   ├── generic_utils.py
│   └── master_account_helper.py
├── ddl/                   # Database DDL scripts
├── job_mappers/           # Job-specific mappers
└── stored_procedures/     # PostgreSQL stored procedures

Deploying to PyPI

Build and Upload

# Install build tools
pip install build twine

# Clean and build
rm -rf build/ dist/ *.egg-info/
python -m build

# Upload to PyPI
twine upload dist/*

Version Management

Update version in setup.py:

version = "0.0.2"

License

Proprietary - LenDenClub Internal Use Only

Author

Sonu Sharma - sonu.sharma@lendenclub.com

Support

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

ldc_vortex_datalayer-0.0.2.tar.gz (114.1 kB view details)

Uploaded Source

Built Distribution

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

ldc_vortex_datalayer-0.0.2-py3-none-any.whl (159.2 kB view details)

Uploaded Python 3

File details

Details for the file ldc_vortex_datalayer-0.0.2.tar.gz.

File metadata

  • Download URL: ldc_vortex_datalayer-0.0.2.tar.gz
  • Upload date:
  • Size: 114.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for ldc_vortex_datalayer-0.0.2.tar.gz
Algorithm Hash digest
SHA256 b4b75bd68087c4836cc4467ed405050623200b896621c43c5bafc026cd195d1a
MD5 e5a5cc4cc55a8fbfec95b5ae013ecb57
BLAKE2b-256 552548d6f39b3fdba89b5c5347acc5322506d2d3caf4806ceec195541b633ce2

See more details on using hashes here.

File details

Details for the file ldc_vortex_datalayer-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for ldc_vortex_datalayer-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0dae7e8a6c3894b5356e716b19323c50dc6646edb6fa1ffd0500855426c4038b
MD5 487d94e72040e9e65954f48bbc89d2a9
BLAKE2b-256 6752384eb4169785a89b01e788b107d0f712f02afdc07e10cdb68a4b48b3fc5b

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