Skip to main content

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

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

tmp_connection_psql-1.0.0b0.tar.gz (9.4 kB view hashes)

Uploaded Source

Built Distribution

tmp_connection_psql-1.0.0b0-py3-none-any.whl (8.8 kB view hashes)

Uploaded Python 3

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