Giter VIP home page Giter VIP logo

nmi_mysql's Introduction

nmi-mysql

Build Status PyPI version Code Health

A very simple and intuitive mysql client wrapper for pymysql.

Installation

  • Run the command to install: pip install nmi_mysql
  • Make sure you install pymysql. You can check out the instructions here

Usage

Minimal and straightforward when doing queries

  • Imports the nmi-mysql client library
from nmi_mysql import nmi_mysql
  • Initialization: Accepts two parameters, first being the config object and the second specifying if autoconnect to db is enabled. If set to false, call con.connect()
try:
    con = nmi_mysql.DB(conf, True)
except Exception as err:
    print(err)
  • Query execution: Accepts two parameters. The first is the query and the second is the list of parameters to be used. See example below
data = con.query(query, params)
  • Closing connection
con.close()

Sample config object

conf = {
    'host': 'localhost',
    'user': 'root',
    'password':'',
    'db': 'mydb',
    'port': 3306    
}
SELECT operations
from nmi_mysql import nmi_mysql

connection = nmi_mysql.DB(conf, True)

data1 = connection.query('SELECT * FROM mytable WHERE name = %s', ['ninz'])
data2 = connection.query('SELECT * FROM mytable WHERE name IN (%s) AND age = %s', [['john', 'doe'], 10])

connection.close()

print(data)
print(data2)
INSERT operations
from nmi_mysql import nmi_mysql

connection = nmi_mysql.DB(conf, True)

# Throws an error upon failure
try:
    result = connection.query('INSERT INTO users VALUES(%s)', [user_object])
except Exception as err:
    print(err)
connection.close()

nmi_mysql's People

Contributors

ninnzz avatar jvmsangkal avatar sibayanjasper avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.