Giter Site home page Giter Site logo

Comments (3)

wittejm avatar wittejm commented on June 1, 2024

Possibly naive question: wondering if passing the connection info from outside the wrapper object is the way to go, especially if that information is just getting picked up from env variables or an external file. If the following env variables are already defined,

PGHOST=recordexpungpdx_db 
PGUSER=docker 
PGPORT=5432
PGDATABASE=record_expunge

then you can get the connection object with

import  psycopg2
conn = psycopg2.connect(“”) 
cur = conn.cursor()

and no extra arguments. Or else the values could be provided inside the Database wrapper code , e.g.

conn = pyscopg2.connect("dbname=record_expunge user=docker port=5432 host=recordexpungpdx_db")
cur = conn.cursor()

Is there a reason not to use these approaches?

from recordexpungpdx.

maxkwallace avatar maxkwallace commented on June 1, 2024

@wittejm this is a good question about separation of concerns: we need to get the credentials from the environment somewhere, so what part of the code should be responsible for doing that?

AFAIK Erik is currently working on this so I will defer to him for the actual implementation.

But my preference is to use your second approach and pass the credentials in. Environment variables are global variables. If we access them in multiple places in our code it can be difficult to draw a clear boundary between our app and its environment. The best practice here is to only access environment variables in one place, and create one or more configuration objects to pass that data around in our code.

from recordexpungpdx.

wittejm avatar wittejm commented on June 1, 2024

closing; Database connectivity was added some time ago.

from recordexpungpdx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.