Skip to main content

Common Database Connector

Cache / Redis

from cdbc.cache import Redis
redis_host = 'redis'
redis_port = 16382
redis_db = 1

c = Redis(redis_host=redis_host, redis_port=redis_port, redis_db=redis_db)
c.create_redis_conn()

c.kvs()
c.set('a', 'b')
c.get('a')
kvs = {
    'a1': 1,
    'b1': 2,
    'c1': 3
}
c.set(batch=True, kvs=kvs)
c.kvs()

SQL / PostgreSQL

import random
import string
import time
import json

from cdbc.postgresql import PG

host = 'freedbs'
port = 15432
database = 'testdb02'
user = 'postgresql-user'
password = 'postgresql-Passw0rd'

p = PG(host=host, port=port, database=database, user=user, password=password)

p.create_pg_conn()
p.select('select version();')
p.select('select count(1) from table1;')

# pool mode
p.create_pg_pool()
p.select_from_pool('select version();')
p.select_from_pool('select count(1) from table1;')

### Select
p = PG(host=host, port=port, database=database, user=user, password=password)
p.create_pg_conn()

for _ in range(5):
    sql = 'select count(1) from table1'
    p.select(sql=sql)
    time.sleep(1)

    
for _ in range(5):
    sql = 'select count(1) from table1'
    p.select_from_pool(sql=sql)
    time.sleep(1)
    
### Insert



p = PG(host=host, port=port, database=database, user=user, password=password)
table = 'table1'
columns = 'col1, col2, col3'
p.create_pg_conn()

for _ in range(10):
    value1 = ''.join([random.choice(string.ascii_lowercase + string.digits) for _n in range(10)])
    value2 = ''.join([random.choice(string.ascii_lowercase + string.digits) for _n in range(10)])
    k = ''.join([random.choice(string.ascii_lowercase + string.digits) for _n in range(5)])
    v = ''.join([random.choice(string.ascii_lowercase + string.digits) for _n in range(5)])
    values = "'" + value1 + "'" + ', '\
         + "'" + value2 + "'" + ', '\
         + "'" + json.dumps({k:v}) + "'"
    cvs = [columns, values]
    p.insert(table=table, cvs=cvs)

# insert via pg pool 
p.create_pg_pool()
for _ in range(10):
    value1 = ''.join([random.choice(string.ascii_lowercase + string.digits) for _n in range(10)])
    value2 = ''.join([random.choice(string.ascii_lowercase + string.digits) for _n in range(10)])
    k = ''.join([random.choice(string.ascii_lowercase + string.digits) for _n in range(5)])
    v = ''.join([random.choice(string.ascii_lowercase + string.digits) for _n in range(5)])
    values = "'" + value1 + "'" + ', '\
         + "'" + value2 + "'" + ', '\
         + "'" + json.dumps({k:v}) + "'"
    cvs = [columns, values]
    p.insert_with_pool(table=table, cvs=cvs)

MessageQueue/RabbitMQ

Consumer

from cdbc.message import RabbitMQ
import json

host = 'freedbs'
port = 15603
user = 'rabbitmq-user'
password = 'rabbitmq-user-Passw0rd'
exchange = 'exchange-test'
queue = 'queue-test'

def call_back(ch, method, properties, body):
    message = json.loads(body.decode())
    print(message)
    ch.basic_ack(delivery_tag=method.delivery_tag)
    print("%r" % body)

# if __name__ == '__main__':
q = RabbitMQ(
    user = user, 
    password = password, 
    enable_ssl = False,
    host = host, 
    port = port,
    v_host = '/',
    exchange = exchange, 
    queue= queue,
)
q.create_channel()
q.create_queue()
q.connect_exchange()
q.run_consumer(call_back)

Producer

from cdbc.message import RabbitMQ
import json

host = 'freedbs'
port = 15603
user = 'rabbitmq-user'
password = 'rabbitmq-user-Passw0rd'
exchange = 'exchange-test'
queue = 'queue-test'

q = RabbitMQ(
    user = user, 
    password = password, 
    enable_ssl = False,
    host = host, 
    port = port,
    v_host = '/',
    exchange = exchange, 
    queue= queue,
)

q.create_channel()
q.send_msg("""{"abc":"123"}""")

Metadata

Release files for cdbc 0.0.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cdbc 0.0.15
File Size Uploaded Provenance Actions
cdbc-0.0.15.tar.gz 4.0 kB Without provenance Details for cdbc-0.0.15.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cdbc 0.0.15
File Interpreter ABI Platform Actions
cdbc-0.0.15-py3-none-any.whl Python 3 none any Details for cdbc-0.0.15-py3-none-any.whl

Total release size: 8.8 kB

Release files / cdbc-0.0.15.tar.gz

Download URL cdbc-0.0.15.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
66890de9172c00642b447c96caa9b2aa1f611e85afa5066d2bb0a68b1e87462e
BLAKE2b-256 checksum
How to use checksums
72f939b048b15eb89ea38b70e909f608e38d80691d7c66cb4def64705420839c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release files / cdbc-0.0.15-py3-none-any.whl

Download URL cdbc-0.0.15-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6c0f057c4fb3248005b82022ac0a1c27064788306455fa7f8417488f5983ef5c
BLAKE2b-256 checksum
How to use checksums
112240cf37b7dd211adda9c72a942da36b00ca8d0f2c47fb8881be6dc6182433
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Security for cdbc 0.0.15

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page