Git Product home page Git Product logo

db_orm's Introduction

DB_ORM

一个python连接操作多种数据库的api包括使用ORM(sqlalchemy)

暂添加了sqlite、mysql和postgresql

使用:

  1. git clone
  2. 切换到工程主目录建立env和依赖
virtualenv dbenv # 建立虚拟环境dbenv
source dbenv/bin/activate  # 激活python虚拟环境,windows下进入dbenv/bin目录
运行activate
# 如果你是用pyvenv或者conda env等都可以
pip install -r requirements.txt  # 安装依赖项
  1. 进入config文件夹,修改配置文件db.fig
# 各数据库参数可根据你本地安装环境配置,
# 例如只安装了postgresql,则只设置postgresql下各项配置,engine=1
[dbtype]
db0 = mysql
db1 = postgresql
db2 = sqlite

[mysql]
host = 127.0.0.1
dbname = testdb
user = test
password = test
port = 3306

[postgresql]
host = 127.0.0.1
dbname = testdb
user = test
password = test
port = 5432

[sqlite]
dbname = testdb
# engine
#使用sqlalchemy的engine
#默认为0(mysql),可根据你的本地数据库和虚拟环境使用不同的engine
# 0-mysql,1-postgresql,2-sqlite
[engine]
dbindex = 0
  1. 配置logger文件夹下mylog.py下的logging模块需要读取的dictConfig
log_dir = BASE_DIR + '/logs'  # log文件在主目录的logs文件下
if not os.path.exists(log_dir):
    os.mkdir(log_dir)

log_path = os.path.join(log_dir, 'test.log')  # log文件名
  1. 确保已经进入dbenv虚拟环境,未进入请运行:
source activate dbenv/bin/activate # windwods请使用上面提到的相应方法

在主目录再运行简单的测试程序

python tests/test_db.py  # 测试普通的数据库增删改查
python tests/orm.py  # 测试ORM
python tests/logger.py  # 测试logger模块

db_orm's People

Contributors

cgdeeplearn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.