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 trans
@trans
def test_transaction():
insert_func(....)
update_func(....)
def test_transaction2():
with trans():
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/ff/bb/cbaa63ea5ca87bceba0dc298e924f8a893a2ff0a00d10701300ff7efbf52/sqlexecutorx-1.8.2.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 trans\n\n @trans\n def test_transaction():\n insert_func(....)\n update_func(....)\n\n\n def test_transaction2():\n with trans():\n insert_func(....)\n update_func(....)\n\n\n",
"bugtrack_url": null,
"license": null,
"summary": "A easy\u3001simple thread safe sql executor for Python with connection pool. Support MySQL, PostgreSQL, SQLite etc.",
"version": "1.8.2",
"project_urls": {
"Homepage": "https://gitee.com/summry/sqlexecutorx"
},
"split_keywords": [
"sql",
" mysql",
" postgresql",
" sqlite",
" database",
" python",
" rdb"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ffbbcbaa63ea5ca87bceba0dc298e924f8a893a2ff0a00d10701300ff7efbf52",
"md5": "3328338fa82f45239e9988ee81f7d354",
"sha256": "28110dd0caedde7bfd53576721079d4da57cb026e58ef4d73fe80567a1445d6b"
},
"downloads": -1,
"filename": "sqlexecutorx-1.8.2.tar.gz",
"has_sig": false,
"md5_digest": "3328338fa82f45239e9988ee81f7d354",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 14985,
"upload_time": "2024-07-24T05:47:51",
"upload_time_iso_8601": "2024-07-24T05:47:51.776006Z",
"url": "https://files.pythonhosted.org/packages/ff/bb/cbaa63ea5ca87bceba0dc298e924f8a893a2ff0a00d10701300ff7efbf52/sqlexecutorx-1.8.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-24 05:47:51",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "sqlexecutorx"
}