Usage Sample
''''''''''''
.. code::
import sqlexecutorx as db
if __name__ == '__main__':
db.init('test.db', driver='sqlite3', debug=True)
# or
db.init("postgres://user:password@127.0.0.1:5432/testdb", driver='psycopg2', pool_size=5, debug=True)
# or
db.init(host='127.0.0.1', port='5432', user='xxx', password='xxx', database='testdb', driver='psycopg2')
# if driver is 'pymysql' or 'mysql.connector' of MySQL, the select_key is 'SELECT LAST_INSERT_ID()'
select_key = "SELECT currval('person_id_seq')"
id = db.save(select_key, 'INSERT INTO person(name, age) VALUES(%s,%s)', 'wangwu', 38)
persons = db.select('select id, name, age from person')
# result:
# (3, 'zhangsan', 15)
# (4, 'lisi', 26)
# (5, 'wangwu', 38)
# (6, 'zhaoliu', 45)
persons = db.select_one('select id, name, age from person where name = %s', 'zhangsan')
# result:
# (3, 'zhangsan', 15)
args = [
('ζε', 55),
('ηδΊ', 35),
]
db.batch_execute('INSERT INTO person(name,age) VALUES(%s,%s)', *args)
db.close()
Transaction
''''''''''''
.. code::
from sqlexecutorx import with_transaction, transaction
@with_transaction
def test_transaction():
insert_func(....)
update_func(....)
def test_transaction2():
with transaction():
insert_func(....)
update_func(....)
Raw data
{
"_id": null,
"home_page": "https://gitee.com/summry/sqlexecutorx",
"name": "sqlexecutorx",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "SQL, MySQL, PostgreSQL, SQLite, Database, Python, RDB",
"author": "summy",
"author_email": "xiazhongbiao@126.com",
"download_url": "https://files.pythonhosted.org/packages/85/78/f5cca810ded783a2b8090f5ffa0ed75efd4b4ecedd89d4b39368a7c27a4b/sqlexecutorx-1.0.0.tar.gz",
"platform": null,
"description": "Usage Sample\n''''''''''''\n\n.. code::\n\n import sqlexecutorx as db\n\n if __name__ == '__main__':\n db.init('test.db', driver='sqlite3', debug=True)\n\n # or\n db.init(\"postgres://user:password@127.0.0.1:5432/testdb\", driver='psycopg2', pool_size=5, debug=True)\n\n # or\n db.init(host='127.0.0.1', port='5432', user='xxx', password='xxx', database='testdb', driver='psycopg2')\n\n # if driver is 'pymysql' or 'mysql.connector' of MySQL, the select_key is 'SELECT LAST_INSERT_ID()'\n select_key = \"SELECT currval('person_id_seq')\"\n\n id = db.save(select_key, 'INSERT INTO person(name, age) VALUES(%s,%s)', 'wangwu', 38)\n\n persons = db.select('select id, name, age from person')\n # result:\n # (3, 'zhangsan', 15)\n # (4, 'lisi', 26)\n # (5, 'wangwu', 38)\n # (6, 'zhaoliu', 45)\n\n persons = db.select_one('select id, name, age from person where name = %s', 'zhangsan')\n # result:\n # (3, 'zhangsan', 15)\n\n args = [\n ('\u674e\u56db', 55),\n ('\u738b\u4e94', 35),\n ]\n db.batch_execute('INSERT INTO person(name,age) VALUES(%s,%s)', *args)\n\n db.close()\n\nTransaction\n''''''''''''\n\n.. code::\n\n from sqlexecutorx import with_transaction, transaction\n\n @with_transaction\n def test_transaction():\n insert_func(....)\n update_func(....)\n\n\n def test_transaction2():\n with transaction():\n insert_func(....)\n update_func(....)\n\n\n",
"bugtrack_url": null,
"license": null,
"summary": "A simple thread safe sql executor for Python with connection pool. Support MySQL, PostgreSQL, SQLite etc.",
"version": "1.0.0",
"project_urls": {
"Homepage": "https://gitee.com/summry/sqlexecutorx"
},
"split_keywords": [
"sql",
" mysql",
" postgresql",
" sqlite",
" database",
" python",
" rdb"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8578f5cca810ded783a2b8090f5ffa0ed75efd4b4ecedd89d4b39368a7c27a4b",
"md5": "6c1a829181ad89f4c009cc122dc9e8da",
"sha256": "abcf4b584234dbef7a432a4147babd1d7840e55821261c14537849beff0b3d23"
},
"downloads": -1,
"filename": "sqlexecutorx-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "6c1a829181ad89f4c009cc122dc9e8da",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 12764,
"upload_time": "2024-05-11T00:29:57",
"upload_time_iso_8601": "2024-05-11T00:29:57.934458Z",
"url": "https://files.pythonhosted.org/packages/85/78/f5cca810ded783a2b8090f5ffa0ed75efd4b4ecedd89d4b39368a7c27a4b/sqlexecutorx-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-11 00:29:57",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "sqlexecutorx"
}