当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Client.on方法代码示例

本文整理汇总了TypeScript中pg.Client.on方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Client.on方法的具体用法?TypeScript Client.on怎么用?TypeScript Client.on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pg.Client的用法示例。


在下文中一共展示了Client.on方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: Client

      .then((location) => {
        let client = new Client({
          host: location.hostname,
          port: location.port || 5432,
          database: database,
          user: user,
          password: password,

          parseInputDatesAsUTC: true // not in the type
        } as any);

        client.on('drain', client.end.bind(client)); // disconnect client when all queries are finished
        client.connect();

        //query is executed once connection is established and PostgreSQL server is ready for a query
        let q = client.query(new (Query as any)(query) as any);

        // ToDo: use node-pg-cursor or node-pg-query-stream here instead
        q.on('row', function(row: any) {
          stream.push(row);
        });

        q.on('error', function(err: any) {
          stream.emit('error', err);  // Pass on any errors
        });

        q.on('end', function() {
          stream.push(null);  // pushing null, indicating EOF
        });
      })
开发者ID:implydata,项目名称:plywood-postgres-requester,代码行数:30,代码来源:postgresRequester.ts

示例2: async

 const createClient = async () => {
     const pgClient = new Client({
         host: settings.host || 'localhost',
         port: options.port || 5432,
         user: settings.user,
         ssl: settings.ssl ? true : undefined,
         database: settings.database,
         password: options.password,
     })
     pgClient.on('error', err => {
         if (currentReject) {
             currentReject(err)
             currentReject = undefined
         }
     })
     await pgClient.connect()
     return pgClient
 }
开发者ID:jakobrun,项目名称:gandalf,代码行数:18,代码来源:pgConnector.ts

示例3: NOW

client.connect(err => {
    if (err) {
        return console.error("Could not connect to postgres", err);
    }
    client.query("SELECT NOW() AS 'theTime'", (err, result) => {
        if (err) {
            return console.error("Error running query", err);
        }
        console.log(result.rowCount);
        console.log(result.rows[0]["theTime"]);
        client.end();
        return null;
    });
    return null;
});
client.on('end', () => console.log("Client was disconnected."));

// client pooling

var config = {
  user: 'foo', //env var: PGUSER
  database: 'my_db', //env var: PGDATABASE
  password: 'secret', //env var: PGPASSWORD
  port: 5432, //env var: PGPORT
  max: 10, // max number of clients in the pool
  idleTimeoutMillis: 30000, // how long a client is allowed to remain idle before being closed
  Promise,
};
var pool = new pg.Pool(config);

pool.connect((err, client, done) => {
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:31,代码来源:pg-tests.ts


注:本文中的pg.Client.on方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。