module 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
Classes¶
class |
truncated documentation |
---|---|
Abstract class to connect to a SQL server using various way. It will be used to implement magic functions |
Methods¶
method |
truncated documentation |
---|---|
add a function to the database which can be called in a SELECT statement |
|
close the connection to the database |
|
connection to the database |
|
drops a table |
|
return the resuls of a SQL query |
|
returns the list of columns in a table |
|
returns the list of tables in the database |
|
import a dataframe into the database |
|
import a flat file as a table, we assume the columns separator is |
Documentation¶
Abstract class to connect to a SQL server using various way. It will be used to implement magic functions
- 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
- 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.
- __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.
- 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
- close()¶
close the connection to the database
- connect()¶
connection to the database
- drop_table(table_name)¶
drops a table
- Parameters:
table – table name
- execute_clean_query(sql_query)¶
return the resuls of a SQL query
- Parameters:
sql_query – query to execute
- Returns:
pandas DataFrame
- 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) }
- get_table_list()¶
returns the list of tables in the database
- Returns:
list of strings
- import_dataframe(tablename, df)¶
import a dataframe into the database
- Parameters:
tablename – name of the table
df – dataframe
- Returns:
the number of added rows
- 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