Skip to content

Tufts-Technology-Services/analytics-database-interface

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

database-interface

Code for interfacing with the rt_analytics MySQL database.

Installation

pip install https://github.com/Tufts-Technology-Services/analytics-database-interface.git

Usage

Create a new instance:

db = DatabaseInterface(user=user, passwd=passwd)

to specify database and server values:

db = DatabaseInterface(user=user, passwd=passwd, server='localhost', database='rt_analytics', flavor='postgres')  # defaults shown

Read a table into a Pandas dataframe:

fis_df = db.read_df('fis_users')

Upsert records

db.upsert_df(dataframe=fis_df, table_name='fis_users')


Append a Pandas dataframe to a table (only with postgres):
```python
db.append_df(dataframe=fis_df, table_name='fis_users')

Replace a table with a Pandas dataframe:

db.replace_df(dataframe=fis_df, table_name='fis_users')

Execute arbitrary sql:

db.execute('truncate fis_users')

Execute sql from a file:

db.execute_sql_file("./path_to_file/file.sql")

Return the number of records in a table:

count = db.record_count('fis_users')



About

Code for interfacing with the rt_analytics database

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages