dgdb


Namedgdb JSON
Version 1.0.0a3 PyPI version JSON
download
home_pagehttps://gitlab.com/gng-group/dgdb.git
SummaryDB clients
upload_time2025-07-15 02:57:42
maintainerNone
docs_urlNone
authorMalanris
requires_python>=3.10
licenseMIT License
keywords sqlalchemy client postgresql mssql oracle
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            **Separate DB client from DivineGift**

# How to use it

## Install this packages before use

* cx_Oracle             - Oracle driver
* sqlalchemy-pytds      - MSSQL driver
* psycopg2-binary       - Postgres driver

## Usage

You should define dict with db_conn creditional.
For example:

### Oracle
Install oracle driver:
```
pip install cx_oracle
```
```
db_conn = {
    "db_user": "dbuser",             # username
    "db_pass": "dbpass",             # password
    "db_host": "dbhost",             # host (ip, fqdn). could be empty if we connect via tns
    "db_port": "",                   # port (string). could be empty if we connect via tns
    "db_name": "dbname",             # database name
    "db_schm": "",                   # db scheme if not equal username
    "dialect": "oracle"              # if use cx_Oracle or oracle+another_dialect
}
```
### MSSQL
Install mssql driver:
```
pip install sqlalchemy-pytds
```
```
db_conn = {
    "db_user": "dbuser",             # username
    "db_pass": "dbpass",             # password
    "db_host": "",                   # host (ip, fqdn). could be empty if we connect via tns
    "db_port": "",                   # port (string). could be empty if we connect via tns
    "db_name": "dbname",             # database name
    "db_schm": "",                   # db scheme if not equal username
    "dialect": "mssql+pytds"         # mssql dialect
}
```
### Postgres
Install postgres driver:
```
pip install psycopg2
```
```
db_conn = {
    "db_user": "dbuser",             # username
    "db_pass": "dbpass",             # password
    "db_host": "",                   # host (ip, fqdn). could be empty if we connect via tns
    "db_port": "",                   # port (string). could be empty if we connect via tns
    "db_name": "dbname",             # database name
    "db_schm": "",                   # db scheme if not equal username
    "dialect": "postgresql+psycopg2" # dialect
}
```

### Create connection

Use class DBClient to create connection to DB. Old-styled functions, which contained in *divinegift.db* module directly, are deprecated but still works.
```
from divinegift.db import DBClient
connection = DBClient(db_conn)            # db_conn - variable which was described above
# Describe which fields you wants to method get_conn will returned (possible fields are 'engine', 'conn' and 'metadata')
engine, conn, metadata = connection.get_conn(fields=['engine', 'conn', 'metadata'])  
```

If you need to call stored procedure with db cursors you should use raw connection.
```
from divinegift.db import DBClient
connection = DBClient(db_conn, do_initialize=False)            # db_conn - variable which was described above
connection.set_raw_conn()
conn = connection.get_conn(fields='conn')  
```

### Get data from sript (file or just string)

After you got "connection" variable you can  get data from file or from str variable directly.

```
from divinegift.db import DBClient
connection = DBClient(db_conn)

result = connection.get_data('path/to/scripts/some_script.sql')
# or you can use str variable:
script = 'select * from dual'
result = connection.get_data(script)
print(result)
>>>[{'dummy': 'X'}]
```

You can use specific encoding for your files (by default it's 'cp1251').
Just put it into args:
```
result = connection.get_data('path/to/scripts/some_script.sql', encoding='utf8')
```

Also you can add some variables into your script (e.g. date) and then you can pass it into a function:
```
from divinegift.db import DBClient
connection = DBClient(db_conn)

script = """select * from dual
where dummy = '$param'"""
parameters = {'param': 'X'}
result = connection.get_data(script, **parameters)
# Or another variant
result = connection.get_data(script, param='X')
print(result)
>>>[{'dummy': 'X'}]
```

### Run script without getting data

You can run script without recieving data.
You should use *divinegift.db.DBClient.run_script* for this like get_data, e.g.:
```
from divinegift.db import Connection
connection = Connection(db_conn)
connection.run_script('path/to/scripts/some_script.sql')
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://gitlab.com/gng-group/dgdb.git",
    "name": "dgdb",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "sqlalchemy, client, postgresql, mssql, oracle",
    "author": "Malanris",
    "author_email": "Roman Rasputin <admin@roro.su>",
    "download_url": "https://files.pythonhosted.org/packages/f6/3d/cfd4178c5aab6dff382a5cc8bf5c0a89b299282e9d803d107bac0ca922e0/dgdb-1.0.0a3.tar.gz",
    "platform": null,
    "description": "**Separate DB client from DivineGift**\n\n# How to use it\n\n## Install this packages before use\n\n* cx_Oracle             - Oracle driver\n* sqlalchemy-pytds      - MSSQL driver\n* psycopg2-binary       - Postgres driver\n\n## Usage\n\nYou should define dict with db_conn creditional.\nFor example:\n\n### Oracle\nInstall oracle driver:\n```\npip install cx_oracle\n```\n```\ndb_conn = {\n    \"db_user\": \"dbuser\",             # username\n    \"db_pass\": \"dbpass\",             # password\n    \"db_host\": \"dbhost\",             # host (ip, fqdn). could be empty if we connect via tns\n    \"db_port\": \"\",                   # port (string). could be empty if we connect via tns\n    \"db_name\": \"dbname\",             # database name\n    \"db_schm\": \"\",                   # db scheme if not equal username\n    \"dialect\": \"oracle\"              # if use cx_Oracle or oracle+another_dialect\n}\n```\n### MSSQL\nInstall mssql driver:\n```\npip install sqlalchemy-pytds\n```\n```\ndb_conn = {\n    \"db_user\": \"dbuser\",             # username\n    \"db_pass\": \"dbpass\",             # password\n    \"db_host\": \"\",                   # host (ip, fqdn). could be empty if we connect via tns\n    \"db_port\": \"\",                   # port (string). could be empty if we connect via tns\n    \"db_name\": \"dbname\",             # database name\n    \"db_schm\": \"\",                   # db scheme if not equal username\n    \"dialect\": \"mssql+pytds\"         # mssql dialect\n}\n```\n### Postgres\nInstall postgres driver:\n```\npip install psycopg2\n```\n```\ndb_conn = {\n    \"db_user\": \"dbuser\",             # username\n    \"db_pass\": \"dbpass\",             # password\n    \"db_host\": \"\",                   # host (ip, fqdn). could be empty if we connect via tns\n    \"db_port\": \"\",                   # port (string). could be empty if we connect via tns\n    \"db_name\": \"dbname\",             # database name\n    \"db_schm\": \"\",                   # db scheme if not equal username\n    \"dialect\": \"postgresql+psycopg2\" # dialect\n}\n```\n\n### Create connection\n\nUse class DBClient to create connection to DB. Old-styled functions, which contained in *divinegift.db* module directly, are deprecated but still works.\n```\nfrom divinegift.db import DBClient\nconnection = DBClient(db_conn)            # db_conn - variable which was described above\n# Describe which fields you wants to method get_conn will returned (possible fields are 'engine', 'conn' and 'metadata')\nengine, conn, metadata = connection.get_conn(fields=['engine', 'conn', 'metadata'])  \n```\n\nIf you need to call stored procedure with db cursors you should use raw connection.\n```\nfrom divinegift.db import DBClient\nconnection = DBClient(db_conn, do_initialize=False)            # db_conn - variable which was described above\nconnection.set_raw_conn()\nconn = connection.get_conn(fields='conn')  \n```\n\n### Get data from sript (file or just string)\n\nAfter you got \"connection\" variable you can  get data from file or from str variable directly.\n\n```\nfrom divinegift.db import DBClient\nconnection = DBClient(db_conn)\n\nresult = connection.get_data('path/to/scripts/some_script.sql')\n# or you can use str variable:\nscript = 'select * from dual'\nresult = connection.get_data(script)\nprint(result)\n>>>[{'dummy': 'X'}]\n```\n\nYou can use specific encoding for your files (by default it's 'cp1251').\nJust put it into args:\n```\nresult = connection.get_data('path/to/scripts/some_script.sql', encoding='utf8')\n```\n\nAlso you can add some variables into your script (e.g. date) and then you can pass it into a function:\n```\nfrom divinegift.db import DBClient\nconnection = DBClient(db_conn)\n\nscript = \"\"\"select * from dual\nwhere dummy = '$param'\"\"\"\nparameters = {'param': 'X'}\nresult = connection.get_data(script, **parameters)\n# Or another variant\nresult = connection.get_data(script, param='X')\nprint(result)\n>>>[{'dummy': 'X'}]\n```\n\n### Run script without getting data\n\nYou can run script without recieving data.\nYou should use *divinegift.db.DBClient.run_script* for this like get_data, e.g.:\n```\nfrom divinegift.db import Connection\nconnection = Connection(db_conn)\nconnection.run_script('path/to/scripts/some_script.sql')\n```\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "DB clients",
    "version": "1.0.0a3",
    "project_urls": {
        "BugTracker": "https://gitlab.com/gng-group/dgdb/issues",
        "Homepage": "https://gitlab.com/gng-group/dgdb"
    },
    "split_keywords": [
        "sqlalchemy",
        " client",
        " postgresql",
        " mssql",
        " oracle"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f4fb8acb72bbfeb5eb65732f65407cb5e0532551747b1e3e7286d261e4f07b3b",
                "md5": "aae2fcfa876b79cf167f6ec448856dc5",
                "sha256": "09dcb6af949a176c6c417f306a83ecebe207d4fbba782737a67584208b205c15"
            },
            "downloads": -1,
            "filename": "dgdb-1.0.0a3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "aae2fcfa876b79cf167f6ec448856dc5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 9985,
            "upload_time": "2025-07-15T02:57:40",
            "upload_time_iso_8601": "2025-07-15T02:57:40.922276Z",
            "url": "https://files.pythonhosted.org/packages/f4/fb/8acb72bbfeb5eb65732f65407cb5e0532551747b1e3e7286d261e4f07b3b/dgdb-1.0.0a3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f63dcfd4178c5aab6dff382a5cc8bf5c0a89b299282e9d803d107bac0ca922e0",
                "md5": "43a296373535716405d57a046422943b",
                "sha256": "07da514f6288c6e1a95c68fdd2ebe023c4d6394b6ea739b3ba3d61bed35ace10"
            },
            "downloads": -1,
            "filename": "dgdb-1.0.0a3.tar.gz",
            "has_sig": false,
            "md5_digest": "43a296373535716405d57a046422943b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 10764,
            "upload_time": "2025-07-15T02:57:42",
            "upload_time_iso_8601": "2025-07-15T02:57:42.287788Z",
            "url": "https://files.pythonhosted.org/packages/f6/3d/cfd4178c5aab6dff382a5cc8bf5c0a89b299282e9d803d107bac0ca922e0/dgdb-1.0.0a3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-15 02:57:42",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "gng-group",
    "gitlab_project": "dgdb",
    "lcname": "dgdb"
}
        
Elapsed time: 0.43089s