當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。