Skip to main content

Connect python with Mysql, MongoDB, Cassandra database

Project description

ConnectDB

Connect python with Mysql, MongoDB, Cassandra database

Installation

Run below commandto install this package

pip install connectdb

Mysql

prerequisite

mysql-connector-pythonmust be installed To install it, run below command

pip install mysql-connector-python

Connect with Mysql using python

import

from connectdb import mysql_db

connect

ob=mysql_db.sql("host","user","password")

Check database List

Function db_list is used to show databases list ob.db_list

Create Database

Function create_ db is used to create a new database

    Parameters
    ----------
    db_name: database name

ob.create_db(Data_base_name)

Drop Database

Function drop_ db is used to drop a database

    Parameters
    ----------
    db_name: database name

ob.drop_db(Data_base_name)

Create table

Function create_ table is used to create a new table

    Parameters
    ----------
    table_name: table name
    columns: columns names with data type and other discription in SQL format
    example-columns="CI_n INT(2),CI_m INT(2),IAC_u VARCHAR(10),IAC_v VARCHAR(10),IAC_w VARCHAR(10),CAC_u VARCHAR(10),CAC_v VARCHAR(10),CAC_w VARCHAR(10)"

ob.create_table(table_name,columns)

Insert into Table

Function insert is used to insert value in table

    Parameters
    ----------
    table_name: table name
    data: values to be inserted in order

ob.insert(table_name,data)

columns

Function columns is used to print columns names

    Parameters
    ----------
    t_name: table name

ob.columns(t_name)

Select DataBase

Function select_db is used to select a database

    Parameters
    ----------
    db_name: database name

ob.select_db(db_name)

Query

Function query is used to run a SQL query

    Parameters
    ----------
    query: SQL query

ob.query(query)

MongoDB

prerequisite

pymongo and pandas must be installed To install pymongo, run below command

pip install pymongo To install pandas, run below command

pip install pandas

Connect with MongoDB using python

import

from connectdb import mongodb

connect

ob=mongodb.mongo()

ob.connect(Connection URL, Database Name)

Create Collection

Function create_ table is used to create a new table

    Parameters
    ----------
    COLLECTION_NAME: collection name

ob.create_collection(COLLECTION_NAME)

Insert

Function insert is used to insert value in table

    Parameters
    ----------
    record: data to be inserted as dict, to insert many data use list of dict

ob.insert(collection_name,record)

Update

Function delete is used to delete record from collection

    Parameters
    ----------
    collection_name: collection name
    where_dict: condition as dict
    new_dict:new values

ob.update(collection_name,new_dict,where_dict)

Delete

Function delete is used to delete record from collection

    Parameters
    ----------
    collection_name: collection name
    where_dict: condition as dict

ob.delete(self, collection_name,where_dict)

Download

Function To download whole collection Parameters ---------- collection_name: collection name

ob.download(collection_name)

Cassandra

prerequisite

cassandra-driver must be installed To install cassandra-driver, run below command

pip install cassandra-driver

Connect with Cassandra using python

import

from connectdb import cassandra_db

connect

ob=cassandra_db.cass()

ob.connect(Secure Bundle Zip Path,clientID,clientSecret,keyspace)

Create Table

To create table

    Parameters
    ----------
    table:table name
    columns_with_datatype: columns name with datatypes as string

ob.create_table(table, columns_with_datatype)

Insert

To insert in table

    Parameters
    ----------
    table:table name
    columns: columns name
    values: values

ob.insert(table, columns, values)

Select

To select row in table

    Parameters
    ----------
    table:table name
    columns: columns name
    where: where condition

ob.select(table, columns, where(optional))

Update

To update row in table

    Parameters
    ----------
    table:table name
    columns_with_values: columns name with values eg age=88
    where: where condition

ob.update(table, columns_with_values, where)

Delete

To delete row in table

    Parameters
    ----------
    table:table name
    where: where condition

ob.delete(table, where)

Execute Query

To execute any Cassandra query

    Parameters
    ----------
    query:Cassandra query

ob.execute(query)

License

© 2021 Arjun Panwar

This repository is licensed under the MIT license. See LICENSE for details.

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

connectdb-1.0.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

connectdb-1.0.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file connectdb-1.0.0.tar.gz.

File metadata

  • Download URL: connectdb-1.0.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.10

File hashes

Hashes for connectdb-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8d4f58f75140ecc833bcba0a4d0e7a161b7d2b3ac11df8bd3fb440d5668eb46f
MD5 eb560ce692908728190d2949e616df44
BLAKE2b-256 b85c3994cf1aff5599cf2bf44011513e02bab2f818b6eb3b663d8ba67a5344c6

See more details on using hashes here.

File details

Details for the file connectdb-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: connectdb-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.10

File hashes

Hashes for connectdb-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 348a9451561f8f8e962ac63b7526abd33a0e8d97f5f56f82711c286792b98e8d
MD5 eefda33df3dc617ba3baa5f99a20b2ef
BLAKE2b-256 b8dc35fa2d7a5225f41707bfaba4ebb21f81f4f2539928f1926e053211f4c798

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