Skip to main content

RemotePostgres is a way to easily access a remote Postgres database and perform queries

Project description

# RemotePostgres

RemotePostgres is a way to easily access a remote Postgres database and perform queries, including SELECT and INSERT operations

See below for examples of how to use


```python
from remote_postgres import RemotePostgres
import mysecrets
db = RemotePostgres(f'postgres://{mysecrets.pg_user}:{mysecrets.pg_password}@{mysecrets.pg_host}:{mysecrets.pg_port}/{mysecrets.pg_database}')
```


```python
db.get_counts()
```




[{'tmp_1347844423': 0}, {'Employee': 0}, {'tmp_1170648801': 0}]




```python
db.con.cursor().execute("""CREATE TABLE "Shipper" ("Id" INTEGER, "CompanyName" TEXT, "Phone" TEXT) """)
```


```python
new_records = [{'Id': 1, 'CompanyName': 'Speedy Express', 'Phone': '(503) 555-9831'},
{'Id': 2, 'CompanyName': 'United Package', 'Phone': '(503) 555-3199'},
{'Id': 3, 'CompanyName': 'Federal Shipping', 'Phone': '(503) 555-9931'},
{'Id': 4, 'CompanyName': 'Speedy Express', 'Phone': '(503) 555-9831'},
{'Id': 5, 'CompanyName': 'United Package', 'Phone': '(503) 555-3199'},
{'Id': 6, 'CompanyName': 'Federal Shipping', 'Phone': '(503) 555-9931'}]
```


```python
db.insert('Shipper', new_records)
```


```python
db.select('SELECT * FROM "Shipper"')
```




[{'Id': 1, 'CompanyName': 'Speedy Express', 'Phone': '(503) 555-9831'},
{'Id': 2, 'CompanyName': 'United Package', 'Phone': '(503) 555-3199'},
{'Id': 3, 'CompanyName': 'Federal Shipping', 'Phone': '(503) 555-9931'},
{'Id': 4, 'CompanyName': 'Speedy Express', 'Phone': '(503) 555-9831'},
{'Id': 5, 'CompanyName': 'United Package', 'Phone': '(503) 555-3199'},
{'Id': 6, 'CompanyName': 'Federal Shipping', 'Phone': '(503) 555-9931'}]




```python
cur = db.con.cursor()
cur.execute("""DELETE FROM "Shipper" WHERE "Id" > 3""")
db.con.commit()
```


```python
db.generate_create_table('Shipper', new_records)
```




'CREATE TABLE "Shipper" ("Id" TEXT, "CompanyName" TEXT, "Phone" TEXT)'




```python
db.con.cursor().execute("""DROP TABLE "Shipper" """)
db.con.commit()
```


```python
del db # Close the connection
```

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

remote_postgres-1.2.5.tar.gz (2.9 kB view details)

Uploaded Source

File details

Details for the file remote_postgres-1.2.5.tar.gz.

File metadata

  • Download URL: remote_postgres-1.2.5.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.4.2 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for remote_postgres-1.2.5.tar.gz
Algorithm Hash digest
SHA256 890908dc0448499a517a26efdadf141636e5a4fb11e9f0bd6b0863b019525f5e
MD5 1ea72541a6102f98b1c4a3c847939918
BLAKE2b-256 2b760efcdbe1301341b092ce2d5528bb603bbe7dfb24a823f043835e9fed033c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page