Code Monkey home page Code Monkey logo

sqlantipathy's Introduction

sqlantipathy

Python facilities to work with SQL databases

Ok, I don't love work with SQL databases. But the world works with SQL, then...

During last years I wrote lot of function to work with MSSQL, MySQL, Oracle, SQLite...
This project represent my personal attempt to systematize experiences, code, and approaches in few useful classes.

Of course sqlalchemy is a sort of de facto standard in python/SQL approach, but in my opinion it is not so simple and not ever backward compatibility is guaranteed with pyodbc and other low level libraries.

At this moment master branch only implements MSSQL routines. MySQL and Oracle rootines will be added as soon as possible.

Installation

Install sqlantipathy is as easy as run pip install sqlantipathy.

Usage

A more accurate description of methods included in sqlantipathy will follow. By now, you can refers to main.py file content:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from sqlantipathy import MssqlAntipathy
import pandas as pd

if __name__ == '__main__':

    sql = MssqlAntipathy(
        hostname="sql_hostname",
        user="sql_user",
        password="sql_pwd",
        driver="sql_driver_name"
    )

    sql.connect()

    database_list = sql.show_databases()

    sql.use_database("mydb")
    mydb_tables = sql.show_tables()

    qry = """SELECT TOP 100 * FROM TABLENAME"""
    data = sql.retrieve("sql_input_db", qry)

    list_of_dict = sql.retrieve_table("sql_input_db", qry)
    df = pd.DataFrame(list_of_dict)
    
    tables = sql.show_tables(dbname='mydb')
    
    sql_exit_code = sql.bulk_insertion(
        list_of_columns=column_names,
        data_as_dict=list_of_dict,
        dbname="mydb",
        table_name="mytable",
        commit_every=15000,
        record_each_statement=500,
    )
    
    sql_exit_code = sql.insert_one(
        table_name="mytable",
        values=dictionary_of_values,
        dbname="mydb"
    )

    sql.close_connection()

    # A lot of code after...

    sql.connect()
    sql.cursor.execute("""A SIMPLE QUERY""")
    raw_data = sql.cursor.fetchall()

sqlantipathy's People

Contributors

pietrogiuffrida avatar

Stargazers

 avatar

Watchers

 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.