Skip to content

Commit 79373a1

Browse files
author
Matt George
committed
first stab, needs testing
0 parents  commit 79373a1

File tree

6 files changed

+95
-0
lines changed

6 files changed

+95
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*pyc
2+
*swp
3+
.DS_Store
4+
dist
5+
*.egg-info

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2013 Matt George
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
redshift_sqlalchemy
2+
==================
3+
4+
Amazon Redshift dialect for sqlalchemy.
5+
6+
Requirements
7+
-------------
8+
* pysocpg2 >= 2.5
9+
* SQLAlchemy 0.8
10+
11+
12+
Usage
13+
-----
14+
DSN format is simpilar to that of regular postgres:
15+
16+
from sqlalchemy import create_engine
17+
18+
engine = create_engine("redshift+psycopg2://username@localhost:5439/database"
19+
20+
Notes
21+
-----
22+
23+
Currently, contraints and indexes return nothing when intropecting tables. This comes from the redshift implementation of the postgresql api == 8.0
24+

redshift_sqlalchemy/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
__version__ = '0.1'
2+
3+
from sqlalchemy.dialects import registry
4+
5+
registry.register("redshift", "redshift_sqlalchemy.dialect", "RedshiftDialect")
6+
registry.register("redshift+psycopg2", "redshift_sqlalchemy.dialect", "RedshiftDialect")

redshift_sqlalchemy/dialect.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from sqlalchemy.dialects.postgresql.psycopg2 import PGDialect_psycopg2
2+
from sqlalchemy.engine import reflection
3+
4+
class RedshiftDialect(PGDialect_psycopg2):
5+
@reflection.cache
6+
def get_pk_constraint(self, connection, table_name, schema=None, **kw):
7+
"""
8+
Constraints in redshift are informational only. This allows reflection to work
9+
"""
10+
return {'constrained_columns': [], 'name': ''}
11+
12+
@reflection.cache
13+
def get_indexes(self, connection, table_name, schema, **kw):
14+
"""
15+
Redshift does not use traditional indexes.
16+
"""
17+
return []
18+
19+
def set_isolation_level(self, connection, level):
20+
from psycopg2 import extensions
21+
connection.set_isolation_level(extensions.ISOLATION_LEVEL_AUTOCOMMIT)
22+

setup.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from setuptools import setup
2+
3+
setup(
4+
name='redshift-sqlalchemy',
5+
version='0.1',
6+
description='Amazon Redshift Dialect for sqlalchemy',
7+
long_description=open("README.md").read(),
8+
author='Matt George',
9+
author_email='[email protected]',
10+
license="MIT",
11+
url='https://github.com/binarydud/redshift_sqlalchemy',
12+
packages=['redshift_sqlalchemy'],
13+
install_requires=['psycopg2 >= 2.4.1'],
14+
include_package_data=True,
15+
zip_safe=False,
16+
classifiers=[
17+
"Development Status :: 3 - Alpha",
18+
"Environment :: Console",
19+
"Intended Audience :: Developers",
20+
"License :: OSI Approved :: MIT License",
21+
"Operating System :: OS Independent",
22+
"Programming Language :: Python",
23+
],
24+
entry_points={
25+
'sqlalchemy.dialects': [
26+
'redshift = redshift_sqlalchemy.dialect:RedshiftDialect',
27+
'redshift.psycopg2 = redshift_sqlalchemy.dialect:RedshiftDialect',
28+
]
29+
}
30+
)
31+

0 commit comments

Comments
 (0)