1 Star 0 Fork 0

阿债 / rdmysql

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

rdmysql: a simple db layer based on ultra-mysql

Installation

pip install [--no-deps] rdmysql

It required umysql. If you use pypy, use https://github.com/NextThought/ultramysql instand of it.

Usage:

from datetime import datetime
from rdmysql import Database, Table, Row, Expr, And, Or
import settings

Database.configures.update(settings.MYSQL_CONFS)

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

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')
    changed_at = now.strftime('%Y-%m-%d %H:%M:%S')
    ryan.change('nickname', 'Ryan-%s' % today)
    ryan.change('changed_at', changed_at)
    query.save(ryan)
    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

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)
# MIT license. See http://www.opensource.org/licenses/mit-license.php Copyright (c) 2012 Desmos, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

A simple db layer base on ultra-mysql 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/azhai/rdmysql.git
git@gitee.com:azhai/rdmysql.git
azhai
rdmysql
rdmysql
master

搜索帮助