Skip to main content

echoss AI Bigdata Solution - Database Query Package

Project description

echoss_db


MySQL, MongoDB, Opensearch compatible query access package

Version History:

  • 1.1.0 : Add Scroll, Bulk functions in ElasticSearch

Prepare

사용 전 config(인증 정보) 의 유무를 확인한 뒤 사용해야한다. config file example:

mysql:
    user : <user_id>
    passwd : <pass code>
    host : <IP addrress or domain>
    port : :<network port number>
    db : <schema name>
    charset : utf8

mongo:
    host : <IP addrress or domain>
    port :<network port number>
    db : <database name>

elastic:
    user : <user_id>
    passwd : <pass code>
    host : <IP addrress or domain>
    port : :<network port number>
    scheme : <http or https>

Installaion


To install this package, please use Python 3.8 or higher.

    pip install -U echoss-db

Quick Start

Import package and class

    from echoss_db import MysqlQuery, MongoQuery, ElasticSearch

    mysql = MysqlQuery('CONFIG_FILE_PATH' or dict)
    mongo = MongoQuery('CONFIG_FILE_PATH' or dict)
    elastic = ElasticSearch('CONFIG_FILE_PATH' or dict)

MySQL


    # CREATE
    mysql.create('QUERY_STRING')

    # DROP
    mysql.drop('QUERY_STRING')

    # TRUNCATE
    mysql.truncate('QUERY_STRING')

    # ALTER
    mysql.alter('QUERY_STRING')

    # SELECT
    mysql.select('QUERY_STRING', params=None) -> dataframe
    mysql.select_one('QUERY_STRING', params=None) -> dict
    mysql.select_list('QUERY_STRING', params=None) -> list(dict)
    mysql.faster_select('QUERY_STRING', params=None) -> dataframe

    # INSERT without params
    mysql.insert('QUERY_STRING', params=None) -> int
    # INSERT with tuple
    mysql.insert('QUERY_STRING', params) -> int
    # INSERT with list[tuple]
    mysql.insert('QUERY_STRING', params_list) -> int

    # UPDATE
    mysql.update('QUERY_STRING', params=None) -> int

    # DELETE
    mysql.delete('QUERY_STRING', params=None) -> int

    # show Database
    mysql.databases()

    # show Tables
    mysql.tables()

    # Ping
    mysql.ping()

    # get connection cursor
    mysql.conn_cursor(cursorclass=None)

    # Close
    # crash process close
    mysql.close()

    # debug query : default True
    mysql.debug_query(False)

MongoDB


    # show Database
    mongo.databases()

    # show Collections
    mongo.collections()

    # Ping
    mongo.ping()

    # SELECT
    mongo.select('COLLECTION_NAME','QUERY_STRING or DICTIONARY') -> pd.Dataframe

    # INSERT
    mongo.insert('COLLECTION_NAME','QUERY_STRING or DICTIONARY')
    mongo.insert_many('COLLECTION_NAME','QUERY_STRING or DICTIONARY')

    # UPDATE
    mongo.update('COLLECTION_NAME','FILTER_STRING or DICTIONARY', 'UPDATE_STRING or DICTIONARY')
    mongo.update_many('COLLECTION_NAME','FILTER_STRING or DICTIONARY', 'UPDATE_STRING or DICTIONARY')

    # DELETE
    mongo.delete('COLLECTION_NAME','QUERY_STRING or DICTIONARY')
    mongo.delete_many('COLLECTION_NAME','QUERY_STRING or DICTIONARY')

ElasticSearch


    # CREATE
    elastic.index(index='INDEX_NAME')

    # DROP
    elastic.delete_index(index='INDEX_NAME')

    # SELECT
    elastic.search(body=query) -> any
    elastic.search_list(body=query, fetch_all=True) -> list
    elastic.search_dataframe(body=query, fetch_all=True) -> dataframe
    elastic.search_field(field='FIELD_NAME',value='VALUE') -> list

    # INSERT
    elastic.create(id='ID', body='JSON_BODY')

    #UPDATE
    elastic.update(id='ID', body='JSON_BODY')

    #DELETE
    elastic.delete(id='ID')

    # SCROLL
    elastic.prepare_scroll("farmers_index", query={"query": {"match_all": {}}}, source_filters=["name", "code"])
    chunk_list = elastic.next_scroll_chunk()

    # BULK 
    success, error_list = bulk_insert("farm_index", doc_list, id_field="farm_id")
    success, error_list = bulk_upsert("farm_index", doc_list, id_field="farm_id")
    
    # Ping
    elastic.ping()

    # Connection Information
    elastic.info()

Code Quality

When creating new functions, please follow the Google style Python docstrings. See example below:

def example_function(param1: int, param2: str) -> bool:
    """Example function that does something.

    Args:
        param1: The first parameter.
        param2: The second parameter.

    Returns:
        The return value. True for success, False otherwise.

    """

Version history

v0.1.0 initial version v0.1.1 echoss_logger include v0.1.7 mysql support query with params. return cursor.rowcount for insert/update/delete query v1.0.0 mysql support query with list params v1.0.1 elastic search_list fetch_all option, mongo support insert_many, delete_many, update_many method v1.0.2 mysql reuse cursor v1.0.7 echoss-query last version v1.0.8 change package name to echoss-db v1.0.11 update() check 'doc' or 'script' in body

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

echoss_db-1.1.1.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

echoss_db-1.1.1-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file echoss_db-1.1.1.tar.gz.

File metadata

  • Download URL: echoss_db-1.1.1.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.19

File hashes

Hashes for echoss_db-1.1.1.tar.gz
Algorithm Hash digest
SHA256 2c230a1234d814eeea529f58b58c4b6d2313ee7355f515b5282b9b2ce17dab7b
MD5 c30d9077d9ccd7be63d08f23cf749e3a
BLAKE2b-256 75d5085d62b4a42dd36ca0cd3035e984a7e545124e4da516756be7cb18c93bfb

See more details on using hashes here.

File details

Details for the file echoss_db-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: echoss_db-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.19

File hashes

Hashes for echoss_db-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2b551cbce77e34135f472aba82a1032a16d367b7fa7a997d8f3378cbd124c0f8
MD5 0c5a827de5ac3d7564bc1e2fda9dd83f
BLAKE2b-256 f77679f3d86a4fd4f2ed9a031694b3031d7bd9099fe31447434831c4dbce9c65

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page