Skip to content
/ pysql Public
forked from viverlxl/pysql

封装python原生的pymysql,简单易用

License

Notifications You must be signed in to change notification settings

Miudodo/pysql

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pysql

INSTALL

​ python setup.py install

IMPORT

​ from pysql import DataClient

USE
from pysql import DataClient
DATABASE = {
  "test": {
    "host": "localhost",
    "port": 3306,
    "username": "root",
    "password": "",
    "schema": "test"
  },
  "test2": {
    "host": "localhost",
    "port": 3306,
    "username": "root",
    "password": "",
    "schema":"mysql",
  }
}
"""
you can write databases config in your project setting file
then in project you can:
"app is your project"
dataClient = DataClient(app.settings.DATABASE)
for key, value in app.settings:
 setattr(app, key, dataClient.get_db_by_name(key))
then you can get dataBase connect object like this:
	test = app.test
	test2 = app.test2
"""
dataClient = DataClient(DATABASE)
test = dataClient.get_db_by_name("test")
sql_statement = "select * from test"
data = test.query(sql_statement)
from item in data:
  print(item['name'])
 """
output:
里斯
  王五
  张三
  王五
  哈哈
 """
OTHER

if you need more detials see test file

About

封装python原生的pymysql,简单易用

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%