-
-
Save dgierejkiewicz/dec8c5a106c3324bbb024125250b45c7 to your computer and use it in GitHub Desktop.
Revisions
-
pfigue revised this gist
Feb 15, 2015 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -42,3 +42,7 @@ Source: [PostgreSQL 9.1 - SSL Support](http://www.postgresql.org/docs/9.1/static from psycopg2.extras import (DictCursor,) dict_cur = conn.cursor(cursor_factory=DictCursor) # Reference 1. [Python DB API cheatsheet](https://wiki.python.org/moin/DbApiCheatSheet) -
pfigue revised this gist
Feb 13, 2015 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Connect and Select ## `connect()` The shortest `connect`: @@ -25,7 +25,9 @@ A little bit longer: ### Valid `sslmode` values disable, allow, prefer, require, verify-ca, verify-full Source: [PostgreSQL 9.1 - SSL Support](http://www.postgresql.org/docs/9.1/static/libpq-ssl.html) ## `select` curs = psql_conn.cursor() params = { @@ -35,8 +37,6 @@ disable, allow, prefer, require, verify-ca, verify-full is_there_a_match = False if curs.fetchone() is None else True curs.close() # Dictionary-like cursors from psycopg2.extras import (DictCursor,) -
pfigue revised this gist
Feb 13, 2015 . 1 changed file with 10 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,12 @@ # Connect and Select ## Connect The shortest `connect`: from psycopg2 import connect psql_conn = connect("dbname=XXX user=XXX password=XXX host=localhost sslmode=require") psql_conn.close() A little bit longer: @@ -17,17 +20,20 @@ A little bit longer: 'sslmode': 'require', } psql_conn = connect(**psql_creds) psql_conn.close() ### Valid `sslmode` values disable, allow, prefer, require, verify-ca, verify-full ## SELECT curs = psql_conn.cursor() params = { 'ID': the_id, } curs.execute('SELECT * FROM users WHERE id=%(ID)s;', params) is_there_a_match = False if curs.fetchone() is None else True curs.close() Source: [PostgreSQL 9.1 - SSL Support](http://www.postgresql.org/docs/9.1/static/libpq-ssl.html) -
pfigue revised this gist
Feb 13, 2015 . 1 changed file with 10 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,11 @@ # Connect and Select The shortest `connect`: from psycopg2 import connect psql_conn = connect("dbname=XXX user=XXX password=XXX host=localhost sslmode=require") A little bit longer: from psycopg2 import connect # Establish psql connection @@ -17,6 +17,14 @@ A little longer: 'sslmode': 'require', } psql_conn = connect(**psql_creds) curs = psql_conn.cursor() params = { 'ID': the_id, } curs.execute('SELECT * FROM users WHERE id=%(ID)s;', params) is_there_a_match = False if curs.fetchone() is None else True curs.close() psql_conn.close() ## Valid `sslmode` values disable, allow, prefer, require, verify-ca, verify-full -
pfigue revised this gist
Feb 13, 2015 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -14,13 +14,14 @@ A little longer: 'user': 'XXX', 'password': 'XXX', 'host': 'localhost', 'sslmode': 'require', } psql_conn = connect(**psql_creds) ## Valid `sslmode` values disable, allow, prefer, require, verify-ca, verify-full Source: [PostgreSQL 9.1 - SSL Support](http://www.postgresql.org/docs/9.1/static/libpq-ssl.html) # Dictionary-like cursors -
pfigue revised this gist
Feb 13, 2015 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -14,11 +14,13 @@ A little longer: 'user': 'XXX', 'password': 'XXX', 'host': 'localhost', 'sslmode': 'disable', } psql_conn = connect(**psql_creds) ## Valid `sslmode` values disable, allow, prefer, require, verify-ca, verify-full Source: [PostgreSQL 9,1 - SSL Support](http://www.postgresql.org/docs/9.1/static/libpq-ssl.html) # Dictionary-like cursors -
pfigue revised this gist
Feb 13, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -22,6 +22,6 @@ A little longer: # Dictionary-like cursors from psycopg2.extras import (DictCursor,) dict_cur = conn.cursor(cursor_factory=DictCursor) -
pfigue created this gist
Feb 13, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ # Connect and Select The shortest: from psycopg2 import connect psql_conn = connect("dbname=XXX user=XXX password=XXX host=localhost sslmode=require") A little longer: from psycopg2 import connect # Establish psql connection psql_creds = { 'dbname': 'XXX', 'user': 'XXX', 'password': 'XXX', 'host': 'localhost', } psql_creds_str = ' '.join(\ ['%s=%s' % (k, psql_creds[k]) for k in psql_creds.keys()]) logger.debug('psql_creds_str: %s' % psql_creds_str) psql_conn = connect(psql_creds_str) # Dictionary-like cursors from psycopg2.extras import (DictCursor,) dict_cur = conn.cursor(cursor_factory=DictCursor)