spp-localSQL


Namespp-localSQL JSON
Version 0.2.3 PyPI version JSON
download
home_pagehttps://gitee.com/liehuozhuoxin/local-database-operations
Summary一个简单的 SQLite 数据库助手类
upload_time2024-12-08 02:58:16
maintainerNone
docs_urlNone
authorShiPanPan
requires_python>=3.6
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # localSQL

`localSQL` 是一个简单的 SQLite 数据库操作助手类,旨在帮助用户在 Python 中快速管理 SQLite 数据库,包括创建表、插入记录、更新插入(Upsert)、查询和删除记录等常见操作。

## 安装:

你可以通过以下命令安装 `localSQL` 包:

--- 
```
pip install localSQL
```

--- 

## 使用方法

### 1. 导入并创建数据库对象

```python
from localSQL import SQLiteDB

# 创建数据库对象
db = SQLiteDB('example.db')
```


### 2. 创建表
```python
db.create_table('locations', {
    "id": "INTEGER PRIMARY KEY AUTOINCREMENT",
    "time": "TEXT NOT NULL",
    "region": "TEXT NOT NULL",
    "address": "TEXT NOT NULL",
    "name": "TEXT NOT NULL",
    "phone": "TEXT NOT NULL",
    "is_added": "BOOLEAN NOT NULL"
})
```
### 3. 插入记录
```python
db.insert_record('locations', {
    "time": "2024-12-07 11:00:00",
    "region": "河南洛阳A",
    "address": "洛阳市新安县老城河南88号",
    "name": "李四",
    "phone": "15037995595871",
    "is_added": False
})
```


### 4. 更新或插入记录(Upsert)
```python
db.upsert_record('locations', {
    "time": "2024-12-07 11:30:00",  # 更新时间
    "region": "河南洛阳A",
    "address": "洛阳市新安县老城河南88号",
    "name": "李四",
    "phone": "15037995595871",
    "is_added": True  # 更新状态为已添加
}, conditions=["phone"])  # 根据手机号判断是否存在记录
```
### 5. 删除记录
```python
使用 delete_record 方法删除符合条件的记录。例如:

python
复制代码
db.delete_record('locations', {"region": "河南洛阳A"})
```
### 6. 查询记录
```python
records = db.query_records('locations', {"region": "河南洛阳A"})
print("查询到的记录:")
for record in records:
    print(record)
```
### 7. 关闭数据库连接
```python
db.close()
```
---
许可证
该项目采用 MIT 许可证,详情请查看 LICENSE 文件。

### 5. **LICENSE 文件(可选)**

如果你选择使用 MIT 许可证,`LICENSE` 文件的内容可以是:

MIT License

Copyright (c) 2024 Your Name

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

            

Raw data

            {
    "_id": null,
    "home_page": "https://gitee.com/liehuozhuoxin/local-database-operations",
    "name": "spp-localSQL",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": null,
    "author": "ShiPanPan",
    "author_email": "417833515@qq.com",
    "download_url": "https://files.pythonhosted.org/packages/8e/4e/1df88cb082b1de268a9ae2cadfe438abb95e47a6a2ec5996648d9380c50f/spp_localsql-0.2.3.tar.gz",
    "platform": null,
    "description": "# localSQL\r\n\r\n`localSQL` \u662f\u4e00\u4e2a\u7b80\u5355\u7684 SQLite \u6570\u636e\u5e93\u64cd\u4f5c\u52a9\u624b\u7c7b\uff0c\u65e8\u5728\u5e2e\u52a9\u7528\u6237\u5728 Python \u4e2d\u5feb\u901f\u7ba1\u7406 SQLite \u6570\u636e\u5e93\uff0c\u5305\u62ec\u521b\u5efa\u8868\u3001\u63d2\u5165\u8bb0\u5f55\u3001\u66f4\u65b0\u63d2\u5165\uff08Upsert\uff09\u3001\u67e5\u8be2\u548c\u5220\u9664\u8bb0\u5f55\u7b49\u5e38\u89c1\u64cd\u4f5c\u3002\r\n\r\n## \u5b89\u88c5:\r\n\r\n\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5 `localSQL` \u5305\uff1a\r\n\r\n--- \r\n```\r\npip install localSQL\r\n```\r\n\r\n--- \r\n\r\n## \u4f7f\u7528\u65b9\u6cd5\r\n\r\n### 1. \u5bfc\u5165\u5e76\u521b\u5efa\u6570\u636e\u5e93\u5bf9\u8c61\r\n\r\n```python\r\nfrom localSQL import SQLiteDB\r\n\r\n# \u521b\u5efa\u6570\u636e\u5e93\u5bf9\u8c61\r\ndb = SQLiteDB('example.db')\r\n```\r\n\r\n\r\n### 2. \u521b\u5efa\u8868\r\n```python\r\ndb.create_table('locations', {\r\n    \"id\": \"INTEGER PRIMARY KEY AUTOINCREMENT\",\r\n    \"time\": \"TEXT NOT NULL\",\r\n    \"region\": \"TEXT NOT NULL\",\r\n    \"address\": \"TEXT NOT NULL\",\r\n    \"name\": \"TEXT NOT NULL\",\r\n    \"phone\": \"TEXT NOT NULL\",\r\n    \"is_added\": \"BOOLEAN NOT NULL\"\r\n})\r\n```\r\n### 3. \u63d2\u5165\u8bb0\u5f55\r\n```python\r\ndb.insert_record('locations', {\r\n    \"time\": \"2024-12-07 11:00:00\",\r\n    \"region\": \"\u6cb3\u5357\u6d1b\u9633A\",\r\n    \"address\": \"\u6d1b\u9633\u5e02\u65b0\u5b89\u53bf\u8001\u57ce\u6cb3\u535788\u53f7\",\r\n    \"name\": \"\u674e\u56db\",\r\n    \"phone\": \"15037995595871\",\r\n    \"is_added\": False\r\n})\r\n```\r\n\r\n\r\n### 4. \u66f4\u65b0\u6216\u63d2\u5165\u8bb0\u5f55\uff08Upsert\uff09\r\n```python\r\ndb.upsert_record('locations', {\r\n    \"time\": \"2024-12-07 11:30:00\",  # \u66f4\u65b0\u65f6\u95f4\r\n    \"region\": \"\u6cb3\u5357\u6d1b\u9633A\",\r\n    \"address\": \"\u6d1b\u9633\u5e02\u65b0\u5b89\u53bf\u8001\u57ce\u6cb3\u535788\u53f7\",\r\n    \"name\": \"\u674e\u56db\",\r\n    \"phone\": \"15037995595871\",\r\n    \"is_added\": True  # \u66f4\u65b0\u72b6\u6001\u4e3a\u5df2\u6dfb\u52a0\r\n}, conditions=[\"phone\"])  # \u6839\u636e\u624b\u673a\u53f7\u5224\u65ad\u662f\u5426\u5b58\u5728\u8bb0\u5f55\r\n```\r\n### 5. \u5220\u9664\u8bb0\u5f55\r\n```python\r\n\u4f7f\u7528 delete_record \u65b9\u6cd5\u5220\u9664\u7b26\u5408\u6761\u4ef6\u7684\u8bb0\u5f55\u3002\u4f8b\u5982\uff1a\r\n\r\npython\r\n\u590d\u5236\u4ee3\u7801\r\ndb.delete_record('locations', {\"region\": \"\u6cb3\u5357\u6d1b\u9633A\"})\r\n```\r\n### 6. \u67e5\u8be2\u8bb0\u5f55\r\n```python\r\nrecords = db.query_records('locations', {\"region\": \"\u6cb3\u5357\u6d1b\u9633A\"})\r\nprint(\"\u67e5\u8be2\u5230\u7684\u8bb0\u5f55\uff1a\")\r\nfor record in records:\r\n    print(record)\r\n```\r\n### 7. \u5173\u95ed\u6570\u636e\u5e93\u8fde\u63a5\r\n```python\r\ndb.close()\r\n```\r\n---\r\n\u8bb8\u53ef\u8bc1\r\n\u8be5\u9879\u76ee\u91c7\u7528 MIT \u8bb8\u53ef\u8bc1\uff0c\u8be6\u60c5\u8bf7\u67e5\u770b LICENSE \u6587\u4ef6\u3002\r\n\r\n### 5. **LICENSE \u6587\u4ef6\uff08\u53ef\u9009\uff09**\r\n\r\n\u5982\u679c\u4f60\u9009\u62e9\u4f7f\u7528 MIT \u8bb8\u53ef\u8bc1\uff0c`LICENSE` \u6587\u4ef6\u7684\u5185\u5bb9\u53ef\u4ee5\u662f\uff1a\r\n\r\nMIT License\r\n\r\nCopyright (c) 2024 Your Name\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "\u4e00\u4e2a\u7b80\u5355\u7684 SQLite \u6570\u636e\u5e93\u52a9\u624b\u7c7b",
    "version": "0.2.3",
    "project_urls": {
        "Homepage": "https://gitee.com/liehuozhuoxin/local-database-operations"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fa8a58f69dc87408c42597bd1728abe128247bba45e96ce71a0c6cdff5460268",
                "md5": "441324299cb970599b881e6a464b9694",
                "sha256": "4411fd30781ba0847bf152fc385366c83f1cd95071ea8100095dc0a40d7241ad"
            },
            "downloads": -1,
            "filename": "spp_localSQL-0.2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "441324299cb970599b881e6a464b9694",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 5231,
            "upload_time": "2024-12-08T02:58:14",
            "upload_time_iso_8601": "2024-12-08T02:58:14.730081Z",
            "url": "https://files.pythonhosted.org/packages/fa/8a/58f69dc87408c42597bd1728abe128247bba45e96ce71a0c6cdff5460268/spp_localSQL-0.2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8e4e1df88cb082b1de268a9ae2cadfe438abb95e47a6a2ec5996648d9380c50f",
                "md5": "38ec9b9d8757d6e06f5b3c0f93a89669",
                "sha256": "650806d55102aa5a5ae7aa0df0b238141e21f2dab530debd06cb5dde4eddff75"
            },
            "downloads": -1,
            "filename": "spp_localsql-0.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "38ec9b9d8757d6e06f5b3c0f93a89669",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 4917,
            "upload_time": "2024-12-08T02:58:16",
            "upload_time_iso_8601": "2024-12-08T02:58:16.614850Z",
            "url": "https://files.pythonhosted.org/packages/8e/4e/1df88cb082b1de268a9ae2cadfe438abb95e47a6a2ec5996648d9380c50f/spp_localsql-0.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-08 02:58:16",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "spp-localsql"
}
        
Elapsed time: 0.39342s