Skip to main content

A mysql db layer for python3, based on nakagami/CyMySQL

Project description

rdmysql3: A simple db layer based on CyMysql for Python 3.x

Installation

pip install [--no-deps] rdmysql3

Usage:

from datetime import datetime, date
from rdmysql3 import (Database, Table, Daily,
        Row, Expr, And, Or, iter_query_daily)
import settings

Database.configures.update(settings.MYSQL_CONFS)

class UserProfile(Table):
    __dbkey__ = 'user'
    __tablename__ = 't_user_profiles'
    __indexes__ = ['username']

class UserEvent(Daily):
    __dbkey__ = "default"
    __tablename__ = "t_user_events"

query = UserProfile().filter_by(username = 'ryan')
ryan = query.one(model = Row)
if ryan:
    print ryan.to_dict()
    now = datetime.now()
    today = now.strftime('%Y%m%d')
    ryan['changed_at'] = now.strftime('%Y-%m-%d %H:%M:%S')
    ryan.change('nickname', 'Ryan-%s' % today)
    query.save(ryan)
    print(query.db.sqls)


def get_all_logins(model):
    q = model.filter_by(category="login").order_by("id", "DESC")
    return q.all(model=Row, reset=True)
query = UserEvent()
rows = iter_query_daily(query, get_all_logins,
        stop=date(2024,3,1), fuse=True)
print(query.db.sqls)

Methods of Table

There are some methods for class named 'Table':

insert      param *rows
            param **kwargs

delete      param **where

update      param changes : dict
            param **where

save        param changes : dict / object
            param indexes : list (optional default=[])

filter      param expr : Expr / str
            param *args

filter_by   param **where

order_by    param field     : str
            param direction : 'ASC' / 'DESC' (optional default='ASC')

group_by    param field : str

all         param coulmns : str (optional default='*')
            param limit   : int (optional default=0)
            param offset  : int (optional default=0)

one         param coulmns : str   (optional default='*')
            param model   : class (optional default=dict)

apply       param name : str
            param *args
            param **kwargs

count,sum,max,min,avg       param *args
                            param **kwargs

Methods of Monthly/Weekly/Daily

Monthly is a subclass of Table, There are other two methods for Monthly:

backward    param monthes : int (optional default=1)

forward     param monthes : int (optional default=1)

set_date    param curr_date : date

migrate     param prev_date : date (When curr_has_suffix is False)

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

rdmysql3-0.3.8.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

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

rdmysql3-0.3.8-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file rdmysql3-0.3.8.tar.gz.

File metadata

  • Download URL: rdmysql3-0.3.8.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for rdmysql3-0.3.8.tar.gz
Algorithm Hash digest
SHA256 eff29051823532a6d1cf52a550e8beac74ae96dbd29fb5871bbd403a4aeaa3e5
MD5 0f3fdd536214e323e0c5982ffd13b6c8
BLAKE2b-256 733c7e36063959c9eb9e6cf0308505327ebba2442d041170b594cceeed0d6edb

See more details on using hashes here.

File details

Details for the file rdmysql3-0.3.8-py3-none-any.whl.

File metadata

  • Download URL: rdmysql3-0.3.8-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for rdmysql3-0.3.8-py3-none-any.whl
Algorithm Hash digest
SHA256 609ecccf383e30d2f4e7ab98169d5247c2690ed1a296293c2c7dba66d97d9772
MD5 e85ef69c8eeb25d66b0c7e8e0450ed19
BLAKE2b-256 622d18e7c877564f5404eaaddd64dd729abcecda882f5edcb99fbb833bed5420

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