Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sql connections #113

Merged
merged 29 commits into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c8c7e27
Merge pull request #1 from codonlibrary/master
Naawww Dec 5, 2019
cc8ca2f
Create ref_decode.py
Naawww Dec 11, 2019
e811b3f
Create SQL_connections.py
Naawww Dec 11, 2019
9685979
Create test_SQL_connections.py
Naawww Dec 11, 2019
0b5b237
Update test_SQL_connections.py
Naawww Dec 11, 2019
35a2e8c
Rename test_SQL_connections.py to SQL_connections_test.py
Naawww Dec 11, 2019
9b2f52a
Update ref_decode.py
Naawww Dec 11, 2019
7076cf0
Update SQL_connections_test.py
Naawww Dec 11, 2019
917b831
Create ref_decode_test.py
Naawww Dec 11, 2019
3b7d7f3
Update ref_decode_test.py
Naawww Dec 11, 2019
851ff68
Update ref_decode_test.py
Naawww Dec 11, 2019
3e38f49
Update ref_decode.py
Naawww Dec 11, 2019
7b9678f
Update ref_decode_test.py
Naawww Dec 12, 2019
34d9176
Got unit tests for Org_col working. And first for Sno_col.
SamHollings Dec 24, 2019
dc9a4ea
Fixed the SQL connections unit test.
SamHollings Jan 6, 2020
accda9c
cleaning this branch so it only concerns SQL_connections
SamHollings Jan 6, 2020
6f79f33
Addressed comments https://github.com/codonlibrary/codonPython/pull/1…
SamHollings Jan 17, 2020
e9e5514
Build failed as Travis did not have pyodbc. Added to requirements.txt
SamHollings Jan 17, 2020
e78aba6
Merge branch 'master' into SQL_connections
Naawww Jan 17, 2020
71c3d28
Attempting to fix build error by changing sqlalchemy version
SamHollings Jan 17, 2020
70c7eb3
Another attempt to prevent build errors - pyodbc claimed as missing
SamHollings Jan 17, 2020
8e6fc98
Update .travis.yml
Naawww Jan 17, 2020
5b57e1d
Added a dummy connection and made a corresponding test.
SamHollings Jan 20, 2020
eebed6c
Merge remote-tracking branch 'origin/SQL_connections' into SQL_connec…
SamHollings Jan 20, 2020
3bf73f2
Addressed pep8 violations.
SamHollings Jan 20, 2020
6584c60
imported SQL_connections under wrong alias - corrected.
SamHollings Jan 20, 2020
f7aced4
Resolving pep8 violations
SamHollings Jan 20, 2020
99ebd8d
Removing trailing empty lines.
SamHollings Jan 20, 2020
2c91a37
Ran through flake8 and added newline at end of file.
SamHollings Jan 20, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ python:
- 3.6

install:
- sudo apt-get install unixodbc-dev
- pip install -r requirements.txt
- pip install codecov
- pip install pytest pytest-cov
Expand Down
33 changes: 33 additions & 0 deletions codonPython/SQL_connections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
''' Author(s): Sam Hollings
Desc: this module contains SQL_alchemy engines to connect to commonly used databases'''

from sqlalchemy import create_engine


def conn_dss():
'''Returns sqlalchemy Engine to connect to the DSS 2008 server (DMEDSS) DSS_CORPORATE database '''
engine = create_engine('mssql+pyodbc://DMEDSS/DSS_CORPORATE?driver=SQL+Server')
return engine


def conn_dss2016uat():
'''Returns sqlalchemy Engine to connect to the DSS 2016 server (UAT) (DSSUAT) DSS_CORPORATE database '''
conn = create_engine('mssql+pyodbc://DSSUAT/DSS_CORPORATE?driver=SQL+Server')
return conn


def conn_dummy(path=r''):
'''connect to the sqlite3 database in memory, or at specified path
parameters
----------
path : string
The location and file in which the database for conn_dummy will be stored. Default is memory (RAM)
'''

conn_string = 'sqlite://'
if path != '':
path = '/' + path

conn = create_engine(r'{0}{1}'.format(conn_string, path))

return conn
15 changes: 15 additions & 0 deletions codonPython/tests/SQL_connections_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'''test script for SQL_connections
- test the connections can run a dummy script (SELECT 1 as [Code], 'test' as [Name])'''
import pandas as pd
import pytest
import codonPython.SQL_connections as conn


@pytest.mark.parametrize("connection",
[conn.conn_dummy(),
conn.conn_dummy('test.db')
])
def test_select1(connection):
result = pd.read_sql("""SELECT 1 as [Code], 'Test' as [Name]""", connection).iloc[0, 0]
expected = pd.DataFrame([{'Code': 1, 'Name': 'Test'}]).iloc[0, 0]
assert result == expected
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
numpy>=1.16.0
scipy>=0.19.0
pandas>=0.24.0
sqlalchemy>=1.3.5
sqlalchemy>=1.3.12
pyodbc
scikit-learn>=0.21.2
statsmodels>=0.10.0
seaborn>=0.9.0
sphinx>=2.2.2
sphinx-rtd-theme>=0.4.3
flake8>=3.7.9
m2r>=0.2.1
m2r>=0.2.1