當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript pg.Client類代碼示例

本文整理匯總了TypeScript中pg.Client的典型用法代碼示例。如果您正苦於以下問題:TypeScript Client類的具體用法?TypeScript Client怎麽用?TypeScript Client使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Client類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: Client

export async function query<T>(config: ConnectionConfig, queryText: string, values: any[] = []) {
  const client = new Client(config)
  await client.connect()
  const result = await client.query(queryText, values)
  await client.end()
  return result as QueryResult<T>
}
開發者ID:chbrown,項目名稱:pg-meta,代碼行數:7,代碼來源:index.ts

示例3: places

 return new Promise<string>((resolve, reject) => {
     const client = new pg.Client(conString)            
     client.connect()
     client.query('INSERT INTO places (description, location, place_id) VALUES ($1, $2, $3)',
         [place.description, '('+place.location.lat+','+place.location.lng+')', place.id], ( error, result) => {
         if(error) reject(error)
         if(result) resolve('OK')
         client.end()
     })
 })
開發者ID:GaryGolf,項目名稱:radar,代碼行數:10,代碼來源:estate.ts

示例4: resolve

 return new Promise<boolean>((resolve, reject) => {
     
     const client = new pg.Client(conString)            
     client.connect()
     client.query('SELECT place_id FROM places WHERE description = \'' + input + '\' LIMIT 1', ( error, result) => {
         if(error)   reject(error)
         if(result.rowCount) resolve(true)
         else resolve(false)
         client.end()
     })
 })
開發者ID:GaryGolf,項目名稱:radar,代碼行數:11,代碼來源:estate.ts

示例5: getClient

export async function getClient(): Promise<Client> {

    var client: Client;
    try {
        client = await pool.connect();
    } catch (error) {
        if (client)
            client.release();
        throw error;
    }

    return new Promise<Client>((resolve: (client: Client) => void, reject) => {
        resolve(client);
        client.release();
    });
}
開發者ID:nicholas-robson,項目名稱:dkydev_webapp,代碼行數:16,代碼來源:db.ts

示例6: start

  public async start() {
    this.counter = 0;
    this.client = new Client(this.config);
    await this.client.connect();

    console.log("Database started");
  }
開發者ID:hung-phan,項目名稱:cyclus,代碼行數:7,代碼來源:database.ts

示例7: reject

 await new Promise<void>((resolve, reject) => connection.end((err) => {
   if (err) {
     reject(err);
   } else {
     resolve();
   }
 }));
開發者ID:yruan,項目名稱:inceptum,代碼行數:7,代碼來源:PostgresClient.ts

示例8: queryPrimaryKeys

 async queryPrimaryKeys(schemaName: string): Promise<PrimaryKey[]> {
   return this.client
     .query(
       `SELECT tc.table_name, kc.column_name
      FROM information_schema.table_constraints tc
      JOIN information_schema.key_column_usage kc 
        ON kc.table_name = tc.table_name 
        AND kc.table_schema = tc.table_schema
        AND kc.constraint_name = tc.constraint_name
      WHERE tc.constraint_type = 'PRIMARY KEY'
      AND tc.table_schema = $1::text
      AND kc.ordinal_position IS NOT NULL
      ORDER BY tc.table_name, kc.position_in_unique_constraint;`,
       [schemaName.toLowerCase()],
     )
     .then(keys => {
       const grouped = _.groupBy(keys.rows, 'table_name')
       return _.map(grouped, (pks, key) => {
         return {
           tableName: key,
           fields: pks.map(x => x.column_name),
         } as PrimaryKey
       })
     })
 }
開發者ID:dhruvcodeword,項目名稱:prisma,代碼行數:25,代碼來源:postgresConnector.ts

示例9: createPersons

function createPersons() {
    const persons = createArray(numberOfPersons, i => {
        return [
            i,
            faker.name.findName(),
            faker.address.streetAddress(),
            faker.phone.phoneNumber(),
            faker.date.past(),
        ]
    })
    return client
        .query(
            'create table person (personid decimal(9), name varchar(400), address varchar(400), phone varchar(100), stamp TIMESTAMP, primary key(personid))'
        )
        .then(
            commentColumns('person', [
                ['personid', 'Person id test'],
                ['name', 'Full name'],
                ['address', 'Home address'],
                ['phone', 'Phonenumber'],
                ['stamp', 'Timestamp'],
            ])
        )
        .then(
            innsertArray('insert into person values($1,$2,$3,$4,$5)', persons)
        )
}
開發者ID:jakobrun,項目名稱:gandalf,代碼行數:27,代碼來源:generatePgData.ts


注:本文中的pg.Client類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。