Git Product home page Git Product logo

co-pg's Introduction

BasicDays

Interesting Ideas

co-pg's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

appuri

co-pg's Issues

Add support to return promises

Seems promises won out as the chosen mechanism to handle co-routines over thunks. Will add promise returning functions in addition to the thunk returning methods. Should both work with co.

Provide better and more helpful examples

The examples, especially when visible on the README, should at the very least be robust enough for people to copy and paste into their codebase. For example, both examples so far leak a connection upon error.

Furthermore, the examples might as well show how you would actually use the library in your projects. You would generally implement two abstractions in your db.js file: a query function that just runs one query, and a withTransaction function that wraps queries in a BEGIN/COMMIT/ROLLBACK.

Update: Here are new versions of the wrapper code I snipped out below: https://github.com/danneu/koa-skeleton/blob/4d654c8963848d171e9b2ae3e0ef91721058d1e1/src/db/util.js


<snipped out old code>

These would be much more helpful to people. What do you think?

The idea is that people should be able to copy query and withTransaction into their db.js and immediately get to work.

More of a question about running co-pg with express....

I am wondering if when running pg-co with node express server, do you connect to the database on every client connection? or keep a global connection?

In other words, here is my node module:

module.exports.set = function(app, worker_id) {

var ms = require("mslibmod"),
    co = require('co'),
    async = require('async'),
    pgconn = require('pgconn').create(),
    pg = require('co-pg')(require('pg')),
    exec = require('co-exec'),
    thunkify = require('thunkify');

app.get('/getLines', function(req, res, next) {
    var id = req.param('id');

    co(function*() {
        try {
            var pgHandle = yield pg.connect_(pgconn.dbserver('galaxy'));
            var statement = 'select business_name FROM business_info WHERE business_id = ' + '1016';
            var result = yield pgHandle[0].query_(statement);
            pgHandle[1]();  // pg queue done
            if (result.rows[0] == undefined){}
            ms.log(result.rows[0].business_name);

        } catch (e) {
            console.error('Panic: ' + e.toString());
        }
    })();

    res.send({});
});

}

notice how I run the command:
var pgHandle = yield pg.connect_(pgconn.dbserver('galaxy'));

everytime a new express client is connected, is this the correct approach?
wouldn't lead to memory leaks?

regards,

Sean.

how to config user and password in `connectionString`

Hi, I got problem when I connect my local postgreSQL on windows 7.

Here's the code(actually your demo)

var co = require('co');
var pg = require('co-pg')(require('pg'));

var connectionString = 'postgres://postgres:5432@localhost/mmocad_result';  // custom config

co(function *() {
    try {
        var client = new pg.Client(connectionString);
        yield client.connectPromise();

        var result = yield client.queryPromise('select * from public.usertable');
        console.log(result.rows[0].theTime);

        client.end();
    } catch (ex) {
        console.error(ex); 
    }
});

catch error: password authentication failed for user "postgres". I think is something wrong with my connectionString, but I hava no idea how to config my user or password.

postgresSQL version 9.6
user postgres
password root

Thanks! =]

Troubleshooting Connections

I have the following line. It fires off and I never hear anything back. It never calls back and nothing is caught in the try-catch so how else can I tell what happened if it never fails and never calls back?

var connectionResults = yield pg.connectPromise(config.connection); // this never calls back after trying to connect

Native PG not 100% wrapped yet.

Using require('pg').native when passed through co-pg, is not 100% functional yet. Pooled connections are working, single connection directly with the Client type isn't working yet. Fix should be out soon.

Setting poolSize?

Hi Paul,

I'm still new to generators and 'co' so I can't quite work this out. Is there a way to get at the original 'pg.defaults' so I can then set the poolSize?

My use-case is to allow options to be passed into the koa-pg middleware so that the user can set this to what they require. :)

Many thanks,
Andy

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.