★贡献:ThinkSQL 类似 ThinkPHP 的数据库引擎,集成sql_helper(https:///hcymysql/sql_helper)

※ThinkSQL地址: https://pypi.org/project/think-sql/

Project description

ThinkSQL 类似 ThinkPHP 的数据库引擎

Install

pip install think-sql

How to use

1. simple demo

    Database: test Table: user

    example dict params

from think_sql.database import DB

config = {
    'host': '127.0.0.1',
    'port': 3306,
    'username': 'root',
    'password': 'root',
    'database': 'test',
}

with DB(config) as db:
    data = db.table('user').where('id',1).find()
    print(data)

    example dsn str

from think_sql.database import DB

with DB("root:'root'@127.0.0.1:3306/test") as db:
    data = db.table('user').where('id',1).find()
    print(data)

    example DBConfig

from think_sql.database import DB
from think_sql.util import DBConfig
config = DBConfig(
  host='127.0.0.1',
  port=3306,
  username='root',
  password='root',
  database='test',
)
with DB(config) as db:
    data = db.table('user').where('id',1).find()
    print(data)

result

{
  "id": 1,
  "username": "hbh112233abc",
  "age": "36",
  "address": "FUJIAN.XIAMEN"
}