Skip to content

Commit

Permalink
first stab, needs testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt George committed Apr 15, 2013
0 parents commit 79373a1
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*pyc
*swp
.DS_Store
dist
*.egg-info
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2013 Matt George

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
redshift_sqlalchemy
==================

Amazon Redshift dialect for sqlalchemy.

Requirements
-------------
* pysocpg2 >= 2.5
* SQLAlchemy 0.8


Usage
-----
DSN format is simpilar to that of regular postgres:

from sqlalchemy import create_engine

engine = create_engine("redshift+psycopg2://username@localhost:5439/database"

Notes
-----

Currently, contraints and indexes return nothing when intropecting tables. This comes from the redshift implementation of the postgresql api == 8.0

6 changes: 6 additions & 0 deletions redshift_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
__version__ = '0.1'

from sqlalchemy.dialects import registry

registry.register("redshift", "redshift_sqlalchemy.dialect", "RedshiftDialect")
registry.register("redshift+psycopg2", "redshift_sqlalchemy.dialect", "RedshiftDialect")
22 changes: 22 additions & 0 deletions redshift_sqlalchemy/dialect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from sqlalchemy.dialects.postgresql.psycopg2 import PGDialect_psycopg2
from sqlalchemy.engine import reflection

class RedshiftDialect(PGDialect_psycopg2):
@reflection.cache
def get_pk_constraint(self, connection, table_name, schema=None, **kw):
"""
Constraints in redshift are informational only. This allows reflection to work
"""
return {'constrained_columns': [], 'name': ''}

@reflection.cache
def get_indexes(self, connection, table_name, schema, **kw):
"""
Redshift does not use traditional indexes.
"""
return []

def set_isolation_level(self, connection, level):
from psycopg2 import extensions
connection.set_isolation_level(extensions.ISOLATION_LEVEL_AUTOCOMMIT)

31 changes: 31 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from setuptools import setup

setup(
name='redshift-sqlalchemy',
version='0.1',
description='Amazon Redshift Dialect for sqlalchemy',
long_description=open("README.md").read(),
author='Matt George',
author_email='mgeorge@gmail.com',
license="MIT",
url='https://github.com/binarydud/redshift_sqlalchemy',
packages=['redshift_sqlalchemy'],
install_requires=['psycopg2 >= 2.4.1'],
include_package_data=True,
zip_safe=False,
classifiers=[
"Development Status :: 3 - Alpha",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
],
entry_points={
'sqlalchemy.dialects': [
'redshift = redshift_sqlalchemy.dialect:RedshiftDialect',
'redshift.psycopg2 = redshift_sqlalchemy.dialect:RedshiftDialect',
]
}
)

0 comments on commit 79373a1

Please sign in to comment.