simple-db-connector


Namesimple-db-connector JSON
Version 0.1.3 PyPI version JSON
download
home_page
SummarySimple database connector for python
upload_time2023-12-01 16:17:55
maintainer
docs_urlNone
authorRene Schwertfeger
requires_python
license
keywords python database connector simple mysql mariadb sqlite sql connector db database-connector
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Simple_Python_DB_Connector

Python module for simple connection and editing of databases.

## Installation

To install the python module, enter the following code in the terminal. Remember, "python" must be swapped with the Python interpreter installed on your system:

```sh
python -m pip install simple-db-connector
```

## Usage Example

### Call Database Class

First of all, we call the "database" class. Im using the os modul to call my database parameter from my environment variables. I advise you to do this straight away, as it is very bad to have sensitive data such as passwords and IP addresses in plain text:

```python 
import  os
from  simple_db_connector  import  database

# Call the database class
db  =  database(
	os.environ["db_url"],
	os.environ["db_user"],
	os.environ["db_password"],
	os.environ["db_port"],
	os.environ["db_name"],
)
```

After we have called the class, we can also use the functions of the class. All functions are self-explanatory. Nevertheless, I will briefly explain the use of each function:

### *class* database.check_table 

##### Parameter
>table name: *string*

```python 
# Example Table Name
table_name = "test_table"

# if "test_table" exists return true, otherwise return false
print(db.check_table(table_name))
```

> It is also executed within the create_table function, so it is not necessary to execute this before you create a table.

### *class* database.create_table 

##### Parameter
	
>table name: *string*, table content: *dict*

```python 
# Example Table Name
table_name = "cars_table"

# Example Table Content
table_content = {
	"manufacture" : "toyoat",
	"model" : "Aygo X yalp",
	"ps" : 72, 
} 

# Example Table creation
db.create_table(table_name, table_content)
```

>This will create the table "cars_table" with the information contained in "test_content". In addition, a primary key field with the name "id" will be created too.  Currently this field is hard coded with a GUID field. In the near future, however, it will be possible to declare your own primary key field.

### *class* database.check_db_entry

##### Parameter

>table: *string*, search_parameter: *dict*
```python
# Example Table Name 
table_name =  "cars_table"  

# Example Search Parameter
search_parameter =  {
	"manufacture" : "toyoat"
}  

# Example Table creation 
db.check_db_entry(table_name, search_parameter)
```
>This will create the table "cars_table" with the information contained in "test_content". In addition, a primary key field with the name "ID" will be created too.  Currently this field is hard coded with a GUID field. In the near future, however, it will be possible to declare your own primary key field.

```python
# Example Table Name 
table_name =  "cars_table"  

# Example Search Parameter
search_parameter =  {
	"manufacture" : "toyoat",
	"model" : "Aygo X yalp",
}
# Example Search Operator
search_operator = ["AND"]

# Example Table creation 
db.check_db_entry(table_name, search_parameter, search_operator)
```
>It's also possible to have multiple search parameter

### *class* database.create_db_entry

##### Parameter
>table: *string*, data: *dict*, prime_key: *string*; default value = "id"

```python
# Example Table Name 
table_name =  "cars_table"  

# Example Table Content
table_content = {
	"manufacture" : "toyoat",
	"model" : "Aygo X yalp",
	"ps" : 72, 
} 

# Example Table prime key
prime_key = "id"
# To illustrate this, I have entered "id". However, if "prime_key" is empty, "id" is selected.

# Example 
db.create_db_entry(table_name, table_content, prime_key)
```

### *class* database.get_db_entrys

##### Parameter
>table: *string*, search_parameter: *dict*

```python
# Example Table Name 
table_name =  "cars_table"  

# Example Search Parameter
search_parameter =  {
	"manufacture" : "toyoat"
} 

# Example Table creation 
db.get_db_entrys(table_name, search_parameter)
```
```python
# Example Table Name 
table_name =  "cars_table"  

# Example Search Parameter
search_parameter =  {
	"manufacture" : "toyoat",
	"model" : "Aygo X yalp",
}
# Example Search Operator
search_operator = ["AND"]

# Example Table creation 
db.get_db_entrys(table_name, search_parameter, search_operator)
```
> As with check_db_entry, it is also possible to use several search parameters here

### *class* database.update_entry

##### Parameter
>table: *string*, search_parameter: *dict*, update_parameter *dict*

```python
# Example Table Name 
table_name =  "cars_table"  

# Example Search Parameter
search_parameter =  {
	"manufacture"  :  "toyoat"
}  
# Example Update Parameter
search_parameter =  {
	"manufacture"  :  "toyota"
} 

# Example Table creation 
db.update_entry(table_name, search_parameter)
```
```python
# Example Table Name 
table_name =  "cars_table"  

# Example Search Parameter
search_parameter =  {
	"manufacture" : "toyoat",
	"model" : "Aygo X yalp",
}
# Example Update Parameter
search_parameter =  {
	"manufacture"  :  "toyota"
	"model" : "Aygo X play",
} 
# Example Search Operator
search_operator = ["AND"]

# Example Table creation 
db.update_entry(table_name, search_parameter, search_operator)
```
> It's also possible to use multiple search and update parameter here

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "simple-db-connector",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python,database,connector,simple,mysql,mariadb,sqlite,sql,connector,db,database-connector",
    "author": "Rene Schwertfeger",
    "author_email": "<mail@reneschwertfeger.de>",
    "download_url": "https://files.pythonhosted.org/packages/01/71/dfce5e61e4281b652443c9790f86ddc608865bd383e044067caf9ff922f8/simple_db_connector-0.1.3.tar.gz",
    "platform": null,
    "description": "# Simple_Python_DB_Connector\n\nPython module for simple connection and editing of databases.\n\n## Installation\n\nTo install the python module, enter the following code in the terminal. Remember, \"python\" must be swapped with the Python interpreter installed on your system:\n\n```sh\npython -m pip install simple-db-connector\n```\n\n## Usage Example\n\n### Call Database Class\n\nFirst of all, we call the \"database\" class. Im using the os modul to call my database parameter from my environment variables. I advise you to do this straight away, as it is very bad to have sensitive data such as passwords and IP addresses in plain text:\n\n```python \nimport  os\nfrom  simple_db_connector  import  database\n\n# Call the database class\ndb  =  database(\n\tos.environ[\"db_url\"],\n\tos.environ[\"db_user\"],\n\tos.environ[\"db_password\"],\n\tos.environ[\"db_port\"],\n\tos.environ[\"db_name\"],\n)\n```\n\nAfter we have called the class, we can also use the functions of the class. All functions are self-explanatory. Nevertheless, I will briefly explain the use of each function:\n\n### *class* database.check_table \n\n##### Parameter\n>table name: *string*\n\n```python \n# Example Table Name\ntable_name = \"test_table\"\n\n# if \"test_table\" exists return true, otherwise return false\nprint(db.check_table(table_name))\n```\n\n> It is also executed within the create_table function, so it is not necessary to execute this before you create a table.\n\n### *class* database.create_table \n\n##### Parameter\n\t\n>table name: *string*, table content: *dict*\n\n```python \n# Example Table Name\ntable_name = \"cars_table\"\n\n# Example Table Content\ntable_content = {\n\t\"manufacture\" : \"toyoat\",\n\t\"model\" : \"Aygo X yalp\",\n\t\"ps\" : 72, \n} \n\n# Example Table creation\ndb.create_table(table_name, table_content)\n```\n\n>This will create the table \"cars_table\" with the information contained in \"test_content\". In addition, a primary key field with the name \"id\" will be created too.  Currently this field is hard coded with a GUID field. In the near future, however, it will be possible to declare your own primary key field.\n\n### *class* database.check_db_entry\n\n##### Parameter\n\n>table: *string*, search_parameter: *dict*\n```python\n# Example Table Name \ntable_name =  \"cars_table\"  \n\n# Example Search Parameter\nsearch_parameter =  {\n\t\"manufacture\" : \"toyoat\"\n}  \n\n# Example Table creation \ndb.check_db_entry(table_name, search_parameter)\n```\n>This will create the table \"cars_table\" with the information contained in \"test_content\". In addition, a primary key field with the name \"ID\" will be created too.  Currently this field is hard coded with a GUID field. In the near future, however, it will be possible to declare your own primary key field.\n\n```python\n# Example Table Name \ntable_name =  \"cars_table\"  \n\n# Example Search Parameter\nsearch_parameter =  {\n\t\"manufacture\" : \"toyoat\",\n\t\"model\" : \"Aygo X yalp\",\n}\n# Example Search Operator\nsearch_operator = [\"AND\"]\n\n# Example Table creation \ndb.check_db_entry(table_name, search_parameter, search_operator)\n```\n>It's also possible to have multiple search parameter\n\n### *class* database.create_db_entry\n\n##### Parameter\n>table: *string*, data: *dict*, prime_key: *string*; default value = \"id\"\n\n```python\n# Example Table Name \ntable_name =  \"cars_table\"  \n\n# Example Table Content\ntable_content = {\n\t\"manufacture\" : \"toyoat\",\n\t\"model\" : \"Aygo X yalp\",\n\t\"ps\" : 72, \n} \n\n# Example Table prime key\nprime_key = \"id\"\n# To illustrate this, I have entered \"id\". However, if \"prime_key\" is empty, \"id\" is selected.\n\n# Example \ndb.create_db_entry(table_name, table_content, prime_key)\n```\n\n### *class* database.get_db_entrys\n\n##### Parameter\n>table: *string*, search_parameter: *dict*\n\n```python\n# Example Table Name \ntable_name =  \"cars_table\"  \n\n# Example Search Parameter\nsearch_parameter =  {\n\t\"manufacture\" : \"toyoat\"\n} \n\n# Example Table creation \ndb.get_db_entrys(table_name, search_parameter)\n```\n```python\n# Example Table Name \ntable_name =  \"cars_table\"  \n\n# Example Search Parameter\nsearch_parameter =  {\n\t\"manufacture\" : \"toyoat\",\n\t\"model\" : \"Aygo X yalp\",\n}\n# Example Search Operator\nsearch_operator = [\"AND\"]\n\n# Example Table creation \ndb.get_db_entrys(table_name, search_parameter, search_operator)\n```\n> As with check_db_entry, it is also possible to use several search parameters here\n\n### *class* database.update_entry\n\n##### Parameter\n>table: *string*, search_parameter: *dict*, update_parameter *dict*\n\n```python\n# Example Table Name \ntable_name =  \"cars_table\"  \n\n# Example Search Parameter\nsearch_parameter =  {\n\t\"manufacture\"  :  \"toyoat\"\n}  \n# Example Update Parameter\nsearch_parameter =  {\n\t\"manufacture\"  :  \"toyota\"\n} \n\n# Example Table creation \ndb.update_entry(table_name, search_parameter)\n```\n```python\n# Example Table Name \ntable_name =  \"cars_table\"  \n\n# Example Search Parameter\nsearch_parameter =  {\n\t\"manufacture\" : \"toyoat\",\n\t\"model\" : \"Aygo X yalp\",\n}\n# Example Update Parameter\nsearch_parameter =  {\n\t\"manufacture\"  :  \"toyota\"\n\t\"model\" : \"Aygo X play\",\n} \n# Example Search Operator\nsearch_operator = [\"AND\"]\n\n# Example Table creation \ndb.update_entry(table_name, search_parameter, search_operator)\n```\n> It's also possible to use multiple search and update parameter here\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Simple database connector for python",
    "version": "0.1.3",
    "project_urls": null,
    "split_keywords": [
        "python",
        "database",
        "connector",
        "simple",
        "mysql",
        "mariadb",
        "sqlite",
        "sql",
        "connector",
        "db",
        "database-connector"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4fce9e868aca3127e8864baf373673f4020bdaa2e80928e5cbdd94a3168163e4",
                "md5": "343285ad3682b1bfef0f18913709e19e",
                "sha256": "56f58f3f76bad416d3aa4bdd41c2c2419b46948290b55ceee0b0562c2fa09d50"
            },
            "downloads": -1,
            "filename": "simple_db_connector-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "343285ad3682b1bfef0f18913709e19e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10034,
            "upload_time": "2023-12-01T16:17:53",
            "upload_time_iso_8601": "2023-12-01T16:17:53.573962Z",
            "url": "https://files.pythonhosted.org/packages/4f/ce/9e868aca3127e8864baf373673f4020bdaa2e80928e5cbdd94a3168163e4/simple_db_connector-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0171dfce5e61e4281b652443c9790f86ddc608865bd383e044067caf9ff922f8",
                "md5": "c67c0d0b2bb9667a836aafe164ae768a",
                "sha256": "b259147e02900fb2b0b1d7bc4c6fbd96d2134f4bb31f825cdf556a22100a390b"
            },
            "downloads": -1,
            "filename": "simple_db_connector-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "c67c0d0b2bb9667a836aafe164ae768a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5875,
            "upload_time": "2023-12-01T16:17:55",
            "upload_time_iso_8601": "2023-12-01T16:17:55.479562Z",
            "url": "https://files.pythonhosted.org/packages/01/71/dfce5e61e4281b652443c9790f86ddc608865bd383e044067caf9ff922f8/simple_db_connector-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-01 16:17:55",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "simple-db-connector"
}
        
Elapsed time: 0.15020s