tmp_connection_psql
Its a little package to create a temporary psql database and qet a connection on it.
Install
Available as a package on pypi.
pip install tmp-connection-psql
First install all dependencies
$ poetry install
Installing dependencies from lock file
No dependencies to install or update
Installing the current project: tmp_connection_psql (1.0.1)
Usage
tmp_connection is a function who yield a connection, to use it you need to make your code in a with statement.
with tmp_connection("dummypassword") as conn:
cursor = conn.cursor()
cursor.execute("SELECT * FROM people")
record = cursor.fetchall()
print(record)
Give you an error because the database is empty. It doesn't known the table 'people'.
You can create your table and fill it after creating the database with tmp_connection("password")
with tmp_connection("dummypassword") as conn:
cursor = conn.cursor()
cursor.execute("CREATE TABLE people (id serial NOT NULL PRIMARY KEY, first_name TEXT NOT NULL, age int NOT NULL, zipcode int NOT NULL, city TEXT NOT NULL)")
cursor.execute("""INSERT INTO people VALUES
("Ulysse", 25, 75019, "Paris"), ("Jacques", 84, 42820, "Ambierle")""")
conn.commit()
and launch request on it
cursor.execute("SELECT * FROM people")
record = cursor.fetchall()
print(record)
it will give you.
[
("id": 1, "first_name": "Ulysse", "age": 25, "zipcode": 75019, "city": "Paris"),
("id": 2, "first_name": "Jacques", "age": 84, "zipcode": 42820, "city": "Ambierle"),
]
Or You can give an sql file to the function tmp_connection("password", "./sql_file.sql")
and it will create the table and fill it before giving you access to the connection.
Example:
with tmp_connection("dummypassword", "./sql_file.sql") as conn:
cursor = conn.cursor()
cursor.execute("SELECT * FROM people")
record = cursor.fetchall()
print(record)
it will give you
[
("id": 1, "first_name": "Ulysse", "age": 25, "zipcode": 75019, "city": "Paris"),
("id": 2, "first_name": "Jacques", "age": 84, "zipcode": 42820, "city": "Ambierle"),
]
with the file './sql_file.sql' .
-- Create table
CREATE TABLE people (id serial NOT NULL PRIMARY KEY, first_name TEXT NOT NULL, age int NOT NULL, zipcode int NOT NULL, city TEXT NOT NULL);
-- Insert into people
INSERT INTO people VALUES
("Ulysse", 25, 75019, "Paris"); -- id = 1
("Jacques", 84, 42820, "Ambierle"); -- id = 2
Changelog, License
Credits
- Author : CHOSSON Ulysse
- Maintainer : CHOSSON Ulysse
- Email : ulysse.chosson@obspm.fr
- Contributors :
- MARTIN Pierre-Yves pierre-yves.martin@obspm.fr
Metadata
Release files for tmp-connection-psql 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| tmp_connection_psql-1.3.0.tar.gz | 9.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tmp_connection_psql-1.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.4 kB
Release files / tmp_connection_psql-1.3.0.tar.gz
| Download URL | tmp_connection_psql-1.3.0.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0b3eb925083fcd7ab3b84d2a53f76d1215c275f2e0317193c146e7628988d17b
|
|
BLAKE2b-256 checksum How to use checksums |
dcf4d5a8c581efc26431d56a8453267d17eda7c1d1048e54d1465969cd4a63b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.10.6 Linux/5.15.0-58-generic
|
Release files / tmp_connection_psql-1.3.0-py3-none-any.whl
| Download URL | tmp_connection_psql-1.3.0-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d2f94a805dda6bcf2b60195127a087e2ff9d53674f516a1ba138c491bd7b945c
|
|
BLAKE2b-256 checksum How to use checksums |
5ab267f4f9132180a9dfa5ab912961c3470a0a71b357c7bfb9ca9171d779c54e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.10.6 Linux/5.15.0-58-generic
|
Security for tmp-connection-psql 1.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.