Git Product home page Git Product logo

pogi'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  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  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  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pogi's Issues

How to implement middleware?

I'm sorry, but I am window shopping for ORM like library, and if it is not mentinoned, I usually ask, how to implement middleware.
My batteries included orm like product would be performant and include magic for updating records with inserted_at, updated_at and deleted_at. Also, all queries would know to ignore deleted_at IS NOT NULL records, when not specified (flag withDeleted = true etc.)
How easy is it to implement in pogi?

underscore to camelCase convertion

hi! awesome library, thanks!
Is there a possiblity to automatically camelize object keys? Or an easy way to patch find, to do it myself?

support for running initialization query

Hello,

first: I really like your work. This is a really nice library without all the orm magic and abstraction layers.

problem: when I try to execute an initialization query (table create script) on an empty database, I got an error because the database is already queried during connect() but is empty.

Is there any way to work around this connection startup queries?

best regards

debug: [QUERY] SELECT current_schemas(false)
(node:23208) UnhandledPromiseRejectionWarning: Error: No readable schema found

'max' option is missing from ConnectionOptions

Hi! This library looks cool.

I'm just trying to use it for the first time, and according to the documentation (see here: https://pogi.readthedocs.io/en/latest/connection/ ) you can set the max property in the connection options, which looks like the max number of clients in the connection pool, however this max property is not present in the ConnectionOptions interface (neither in the linked document nor in the Connections options interface definition here:

export interface ConnectionOptions {
)

And of course, my ts compiler complains about this. Is this missing by purpose?

PgDb.js depends on module extsprintf, but Pogi does not install it

A recent update to PgDb.js that fixes #14 adds a requirement for module extsprintf, but Pogi's install does not install it. That makes Pogi except my app. I suspect this is cruft from a debug session.

Additionally, PgDb.js emits a query's text (prefaced with 'GGG'). I suspect that, too, is not intended, outside the context of a logger being enabled.

support for read replica

For my daily work, it would be very nice to have an option to define read replicas.
A possible way can be to add a flag to the query execution, to mark a query as read-only, so it is not needed to have a high amount of logic for this feature. On the other hand side, the developer is able to decide what queries to route to the replica.

Pogi with cockroachDB

Is it possible to use Pgi with cockroachDB. I am getting this error pg_trigger" does not exist.

missing dependency tslib

pgDb.js requires tslib, although it's missing in package.json.

Error: Cannot find module 'tslib'
    at Function.Module._resolveFilename (module.js:536:15)
    at Function.Module._load (module.js:466:25)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/app/node_modules/pogi/lib/pgDb.js:4:17)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)

Compile error when importing PgDb to typescript file (+ question about 'await')

Hi There! I really love Pogi, it seems to be the best all around tool.

But, I'm trying to import the PgDb class into a TS file to create a connection:

import { PgDb } from 'pogi';

// set up & connect to postgres db
const dbConfig = {
  host: process.env.DB_URL,
  port: process.env.DB_PORT,
  database: process.env.DB_NAME,
  user: process.env.DB_USER,
  password: process.env.DB_PW,
  max: 10,
  idleTimeoutMillis: 10000,
  poolSize: 10
};

export let connect = async () => {
    return await PgDb.connect(dbConfig);
}

And am receiving the follow compilation error:

Node] /Users/Tyler/Projects/news-api/node_modules/pogi/lib/pgDb.js:69
[Node]     constructor(pgdb = {}) {
[Node]                      ^
[Node] 
[Node] SyntaxError: Unexpected token =

Am I not able to import the PgDb class into a typescript file? I'm currently running node v5.6.0 & npm v5.0.3, if that helps.

Side question: I see a lot of your examples use the await keyword outside of an async function. Is that intentional? Usually (at least with TS), that keyword needs to be used inside of an async function.

Thanks for the help!

PgDb.connect() dies when it sees a schema name it doesn't need

My app has begin to throw an exception in pgDb.js during connect() despite no changes to code, process, or data. I believe the addition of a new schema to the EDB variant of the PostgresSQL 9.6 database has surfaced this behavior. The new schema is not related to the app; the role for the app's schema has no access to the new schema. My guess is that the query that finds "special field types" unnecessarily reveals schema names it does not need.

I do not know whether to consider this a design issue in Pogi, or a problem in the way I use it. The first few lines in my app are:

(async () => {
    const db = await PgDb.connect({connectionString: "postgres://app_media@<host>:<port>/<db>"});
    const quotedFaculty = await db.query(assets.selectAppearingFacultyLastYear);
    ...
})();

My intellectual problem is that this behavior would affect any app using a database with more than one user-type schema. So, I look forward to another analysis -- because I don't trust mine. ;-)

Problem perhaps related to limited access rights when reading metadata

Hi,
When using pogi with a postgres user which has rather limited access rights, I get a problem in pgDb.ts, in the initFieldTypes() function.
The error I get is "Cannot read property 'fieldTypes' of undefined".

If I change this:

...
for (let r of specialTypeFields.rows) {
            this.schemas[r.schema_name][r.table_name].fieldTypes[r.column_name] =
                ([3802, 114].indexOf(r.typid) > -1) ? FieldType.JSON :
                    ([3614].indexOf(r.typid) > -1) ? FieldType.TSVECTOR :
                    ([1082, 1083, 1114, 1184, 1266].indexOf(r.typid) > -1) ? FieldType.TIME :
                        FieldType.ARRAY;
...

into something like:

...
for (let r of specialTypeFields.rows) {
   if(this.schemas[r.schema_name][r.table_name]) { 
            this.schemas[r.schema_name][r.table_name].fieldTypes[r.column_name] =
                ([3802, 114].indexOf(r.typid) > -1) ? FieldType.JSON :
                    ([3614].indexOf(r.typid) > -1) ? FieldType.TSVECTOR :
                    ([1082, 1083, 1114, 1184, 1266].indexOf(r.typid) > -1) ? FieldType.TIME :
                        FieldType.ARRAY;
   }
...

ie inserting an if test to check if we actually have the table metadata, pogi seems to work ok also in my case with limited postgres privileges.

ES2015 compiled JS files

Hello,

I'm trying to use your great library together with Meteor, but currently Meteor has an issue that it cannot use ES2015 compiled js files from NPM. And I see that you compile your ts files into ES2015 js files. My question is, can you consider maybe compiling your package to ES5 compatible js files, or maybe do you know a way to use your package together with Meteor? I have seen hints in your blog post that you were/are using also Meteor.

Thank you

Allow passing a Pool to the constructor

We're not using Pogi as the only library for connecting to our database, and for that we instantiate a pg.Pool ourselves which we share between different services. It would be dope if Pogi could be instantiated to use such a pre-existing pool, instead of getting passed connection options only and managing the pool (or actually, all the pools for each connection string).

If you still want to pool the PgDB instances, I guess it should be possible to get the (undocumented) .options from the Pool instance to create your connection string key.

upsert support

Hi I'm looking into upsert support for pogi.

API wise it could be either a seperate method like upsert and upsertAndGet or just an additional parameter on the existing insert and insertAndGet methods.

Postgres 9.5+ has native upsert support via the ON CONFLICT DO UPDATE clause which can be appended to inserts, see: https://www.postgresql.org/docs/9.5/static/sql-insert.html

What do you think of adding support for upsert into pogi?

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.