Little project to create a temparory connection to a psql database
Project description
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.0-beta)
Usage
tmp_connection is a function who yield a connection, to use it you need to make your code in a with statement.
Example:
with tmp_connection("dummypassword") as conn:
cursor = conn.cursor()
cursor.execute("SELECT * FROM people")
record = cursor.fetchall()
print(record)
Give
[]
If you doesn't give a path to the function your database was empty. You can file it after the creation or give an sql file to the function which will execute the sql commands from the file before giving you 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)
Give
[
("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
Ambierle Changelog, Contributing, License
Credits
- Author : CHOSSON Ulysse
- Maintainer : CHOSSON Ulysse
- Email : ulysse.chosson@obspm.fr
- Contributors :
- MARTIN Pierre-Yves pierre-yves.martin@obspm.fr
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tmp_connection_psql-1.0.1b0.tar.gz
.
File metadata
- Download URL: tmp_connection_psql-1.0.1b0.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.15.0-27-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d1b7d1e27c61b4aebc8f37ad0c75d5a37679a3a600b0a8024d157c3f4eedeb4 |
|
MD5 | 0c7c1249eb98ce5492f31e843450f7f3 |
|
BLAKE2b-256 | d83f013cbe1b68c04a6f395c4c649e62fe1a6f5a389e0bdf5498191e1872a3a0 |
File details
Details for the file tmp_connection_psql-1.0.1b0-py3-none-any.whl
.
File metadata
- Download URL: tmp_connection_psql-1.0.1b0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.15.0-27-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 405c1635b99c725c02758a254f8a7cc42d88325217ca1955a82a101f8dc5a8ac |
|
MD5 | 7874e92ac4d5c79bf8cc77f038d05f6c |
|
BLAKE2b-256 | 719a2bef968bf2a7eb20ae949d5aa012584933507f422e9f231eba032cae2d6c |