-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructuring project to meet setup.py packaging standards
- Loading branch information
1 parent
e78b375
commit 4bcb37a
Showing
13 changed files
with
177 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
venv | ||
.project | ||
.pydevproject | ||
*.pyc | ||
build/ | ||
dist/ | ||
jinja2sql.egg-info/ | ||
venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* 0.1.0 | ||
* Initial Release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Please use | ||
python setup.py install | ||
|
||
To report errors, create a new issue on Github - https://github.com/hashedin/jinjasql/issues | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License | ||
|
||
Copyright (c) 2016 HashedIn Technologies Pvt. Ltd. | ||
|
||
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include CHANGES | ||
include INSTALL | ||
include LICENSE | ||
include README.textile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Generate SQL Queries using a Jinja2 Template. # | ||
|
||
JinjaSql automatically tracks bind parameters, and returns an array | ||
of all parameters that can be used to execute the query. | ||
|
||
## Installing jinjasql ## | ||
|
||
Pre-Requisites : | ||
|
||
1. python 2.x and pip. | ||
2. jinja2 | ||
|
||
To install from PyPI (recommended) : | ||
|
||
pip install jinjasql | ||
|
||
To install from source : | ||
|
||
git clone https://github.com/hashedin/jinjasql | ||
cd jinjasql | ||
sudo python setup.py install | ||
|
||
## Usage ## | ||
|
||
from jinja2sql import JinjaSql | ||
|
||
template = """ | ||
SELECT project, timesheet, hours | ||
FROM timesheet | ||
WHERE user_id = {{ user_id }} | ||
{% if project_id %} | ||
AND project_id = {{ project_id }} | ||
{% endif %} | ||
""" | ||
|
||
data = { | ||
"project_id": 123, | ||
"user_id": u"sripathi" | ||
} | ||
|
||
j = JinjaSql() | ||
query, bind_params = j.prepare_query(template, data) | ||
|
||
expected_query = """ | ||
SELECT project, timesheet, hours | ||
FROM timesheet | ||
WHERE user_id = %s | ||
AND project_id = %s | ||
""" | ||
|
||
self.assertEquals(bind_params, [u'sripathi', 123]) | ||
self.assertEquals(query.strip(), expected_query.strip()) | ||
|
||
# You can now use the query and bind parameters to execute the query | ||
# For example, in django | ||
|
||
from django.db import connection | ||
with connection.cursor() as cursor: | ||
cursor.execute(query, bind_params) | ||
for row in cursor.fetchall(): | ||
# do something with the results | ||
pass | ||
|
||
|
||
## License | ||
|
||
jinjasql is licensed under the MIT License. See [LICENSE](https://github.com/hashedin/jinjasql/blob/master/LICENSE) | ||
|
||
## Maintained By | ||
|
||
Sripathi Krishnan : @srithedabbler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from jinjasql.core import JinjaSql | ||
|
||
__version__ = '0.1.0' | ||
VERSION = tuple(map(int, __version__.split('.'))) | ||
|
||
__all__ = ['JinjaSql'] |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Jinja2==2.8 | ||
MarkupSafe==0.23 | ||
wsgiref==0.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env python | ||
|
||
import unittest | ||
from tests import all_tests | ||
|
||
if __name__ == "__main__": | ||
tests = all_tests() | ||
results = unittest.TextTestRunner().run(tests) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env python | ||
import os | ||
from rdbtools import __version__ | ||
|
||
long_description = ''' | ||
Generate SQL Queries using a Jinja2 Template. | ||
JinjaSql automatically tracks bind parameters, and returns an array | ||
of all parameters that can be used to execute the query. | ||
''' | ||
|
||
sdict = { | ||
'name' : 'jinjasql', | ||
'version' : __version__, | ||
'description' : 'Generate SQL Queries and Corresponding Bind Parameters using a Jinja2 Template', | ||
'long_description' : long_description, | ||
'url': 'https://github.com/hashedin/jinjasql', | ||
'download_url' : 'http://cloud.github.com/downloads/hashedin/jinjasql/jinjasql-%s.tar.gz' % __version__, | ||
'author' : 'Sripathi Krishnan', | ||
'author_email' : '[email protected]', | ||
'maintainer' : 'Sripathi Krishnan', | ||
'maintainer_email' : '[email protected]', | ||
'keywords' : ['Jinja2', 'SQL', 'Python', 'Template'], | ||
'license' : 'MIT', | ||
'packages' : ['jinjasql'], | ||
'test_suite' : 'tests.all_tests', | ||
'classifiers' : [ | ||
'Development Status :: 4 - Beta', | ||
'Environment :: Console', | ||
'Intended Audience :: Developers', | ||
'License :: OSI Approved :: MIT License', | ||
'Operating System :: OS Independent', | ||
'Programming Language :: Python'], | ||
} | ||
|
||
try: | ||
from setuptools import setup | ||
except ImportError: | ||
from distutils.core import setup | ||
|
||
setup(**sdict) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import unittest | ||
from tests.test_jinjasql import JinjaSqlTest | ||
|
||
def all_tests(): | ||
suite = unittest.TestSuite() | ||
suite.addTest(unittest.makeSuite(JinjaSqlTest)) | ||
return suite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters