module sql.sql_interface_database

Inheritance diagram of pyensae.sql.sql_interface_database

Short summary

module pyensae.sql.sql_interface_database

Abstract class to connect to a SQL server using various way. It will be used to implement magic functions

source on GitHub

Classes

class

truncated documentation

InterfaceSQLDatabase

Abstract class to connect to a SQL server using various way. It will be used to implement magic functions

Methods

method

truncated documentation

__init__

add_function

add a function to the database which can be called in a SELECT statement

close

close the connection to the database

connect

connection to the database

drop_table

drops a table

execute_clean_query

return the resuls of a SQL query

get_table_columns

returns the list of columns in a table

get_table_list

returns the list of tables in the database

import_dataframe

import a dataframe into the database

import_flat_file

import a flat file as a table, we assume the columns separator is \t and the file name contains a header

Documentation

Abstract class to connect to a SQL server using various way. It will be used to implement magic functions

source on GitHub

class pyensae.sql.sql_interface_database.InterfaceSQLDatabase(filename)

Bases: InterfaceSQL

Abstract class to connect to a SQL server using various way. It will be used to implement magic functions

source on GitHub

Parameters:

filename – str or Database

If filename is a Database, the object is kept as is.

Changed in version 1.1: Parameter filename can be a database.

source on GitHub

__init__(filename)
Parameters:

filename – str or Database

If filename is a Database, the object is kept as is.

Changed in version 1.1: Parameter filename can be a database.

source on GitHub

add_function(code_function)

add a function to the database which can be called in a SELECT statement

Parameters:

code_function – pointer to the function

source on GitHub

close()

close the connection to the database

source on GitHub

connect()

connection to the database

source on GitHub

drop_table(table_name)

drops a table

Parameters:

table – table name

source on GitHub

execute_clean_query(sql_query)

return the resuls of a SQL query

Parameters:

sql_query – query to execute

Returns:

pandas DataFrame

source on GitHub

get_table_columns(table_name, as_dict=True)

returns the list of columns in a table

Parameters:
  • table_name – table name

  • as_dict – True, as dictionary, as a list otherwise

Returns:

dictionary { “column”: (position, type) }

source on GitHub

get_table_list()

returns the list of tables in the database

Returns:

list of strings

source on GitHub

import_dataframe(tablename, df)

import a dataframe into the database

Parameters:
  • tablename – name of the table

  • df – dataframe

Returns:

the number of added rows

source on GitHub

import_flat_file(filename, table_name)

import a flat file as a table, we assume the columns separator is \t and the file name contains a header

Parameters:
  • filename – filename

  • table – table name

Returns:

the number of added rows

source on GitHub