{"id":17343058,"url":"https://github.com/taogeyt/pydbclib","last_synced_at":"2025-04-14T19:53:43.608Z","repository":{"id":62579790,"uuid":"106537660","full_name":"taogeYT/pydbclib","owner":"taogeYT","description":"Python database toolkit for humans","archived":false,"fork":false,"pushed_at":"2023-05-28T14:58:59.000Z","size":112,"stargazers_count":20,"open_issues_count":2,"forks_count":3,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-12T06:46:59.548Z","etag":null,"topics":["database","dict","forhumans","hive","mysql","oracle","postgres","sql","sqlalchemy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/taogeYT.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-11T10:05:20.000Z","updated_at":"2024-05-23T02:38:47.000Z","dependencies_parsed_at":"2022-11-03T21:01:12.938Z","dependency_job_id":null,"html_url":"https://github.com/taogeYT/pydbclib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taogeYT%2Fpydbclib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taogeYT%2Fpydbclib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taogeYT%2Fpydbclib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taogeYT%2Fpydbclib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/taogeYT","download_url":"https://codeload.github.com/taogeYT/pydbclib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248951997,"owners_count":21188421,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","dict","forhumans","hive","mysql","oracle","postgres","sql","sqlalchemy"],"created_at":"2024-10-15T16:08:12.583Z","updated_at":"2025-04-14T19:53:43.580Z","avatar_url":"https://github.com/taogeYT.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pydbclib\n\nPydbclib is Python Database Connectivity Lib, a general database operation toolkit for **Python 3.6+**\n\n## Installation:\n```shell script\npip3 install pydbclib\n```\n\n## Example:\n\n```python\nfrom pydbclib import connect\n# 使用with上下文，可以自动提交，自动关闭连接\nwith connect(\"sqlite:///:memory:\") as db:\n    db.execute('create table foo(a integer, b varchar(20))')\n    # 统一使用':[name]'形式的SQL的占位符\n    db.execute(\"insert into foo(a,b) values(:a,:b)\", [{\"a\": 1, \"b\": \"one\"}]*4)\n    print(db.read(\"select * from foo\").get_one())\n    print(db.read(\"select * from foo\").get_all())\n    print(db.read(\"select * from foo\").to_df())\n    \n    # 对表常用操作的封装\n    table = db.get_table(\"foo\")\n    table.insert([{\"a\": 2, \"b\": \"two\"}]*2)  # 插入两条记录\n    table.find({\"b\": \"two\"}).get_all()  # 查出b='two'的所有记录\n    table.update({\"a\": 2, \"b\": \"two\"}, {\"b\": \"2\"})  # 将a=2 and b='two'的所有记录的b字段值更新为'2'\n    table.find({\"a\": 2}).get_all()  # 查出a=2的所有记录\n    table.delete({\"a\": 2})  # 删除a=2的所有记录\n```\n\n#### 常用数据库连接示例  \nCommon Driver  \n\n    # 使用普通数据库驱动连接，driver参数指定驱动包名称\n    # 例如pymysql包driver='pymysql',connect函数其余的参数和driver参数指定的包的创建连接参数一致\n    # 连接mysql\n    db = pydbclib.connect(user=\"user\", password=\"password\", database=\"test\", driver=\"pymysql\")\n    # 连接oracle\n    db = pydbclib.connect('user/password@local:1521/xe', driver=\"cx_Oracle\")\n    # 通过odbc方式连接\n    db = pydbclib.connect('DSN=mysqldb;UID=user;PWD=password', driver=\"pyodbc\")  \n    # 通过已有驱动连接方式连接\n    import pymysql\n    con = pymysql.connect(user=\"user\", password=\"password\", database=\"test\")\n    db = pydbclib.connect(driver=con)\n\nSqlalchemy Driver\n\n    # 使用Sqlalchemy包来连接数据库，drvier参数默认为'sqlalchemy'\n    # 连接oracle\n    db = pydbclib.connect(\"oracle://user:password@local:1521/xe\")\n    # 连接mysql\n    db = pydbclib.connect(\"mysql+pyodbc://:@mysqldb\")\n    # 通过已有engine连接\n    from sqlalchemy import create_engine\n    engine = create_engine(\"mysql+pymysql://user:password@localhost:3306/test\")\n    db = pydbclib.connect(driver=engine)\n\n\n\n### 详细使用文档 \n\nhttps://blog.csdn.net/li_yatao/article/details/79685992\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaogeyt%2Fpydbclib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftaogeyt%2Fpydbclib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaogeyt%2Fpydbclib/lists"}