How to use pg-cursor - 3 common examples

To help you get started, we’ve selected a few pg-cursor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FreeFeed / freefeed-server / app / export / gdpr.js View on Github external
}

    process.stdout.write('\n');

    const downloadUrls = [];
    process.stdout.write(`- getting user's attachments: `);

    {
      const attachmentTypes = {
        'audio':   'AudioObject',
        'general': 'DataDownload',
        'image':   'ImageObject',
      };

      const sql = `SELECT * FROM "attachments" WHERE "user_id" = $1`;  // using '$1' instead of '?' as we're VERY close to postgres in this call
      const cursor = pg.query(new PgCursor(sql, [user.id]));
      const read = promisify(cursor.read).bind(cursor);

      while (true) {  // eslint-disable-line no-constant-condition
        const rows = await read(100);

        if (rows.length === 0) {
          cursor.close(noop);
          break;
        }

        process.stdout.write('.');

        for (const attachmentRow of rows) {
          if (attachmentRow.media_type === null) {
            // skip bogus attachments
            continue;
github gajus / slonik / src / QueryStream.js View on Github external
constructor (text, values, options) {
    super({
      objectMode: true,
      ...options,
    });
    this.cursor = new Cursor(text, values);
    this._reading = false;
    this._closed = false;
    this.batchSize = (options || {}).batchSize || 100;

    // delegate Submittable callbacks to cursor
    this.handleRowDescription = this.cursor.handleRowDescription.bind(this.cursor);
    this.handleDataRow = this.cursor.handleDataRow.bind(this.cursor);
    this.handlePortalSuspended = this.cursor.handlePortalSuspended.bind(this.cursor);
    this.handleCommandComplete = this.cursor.handleCommandComplete.bind(this.cursor);
    this.handleReadyForQuery = this.cursor.handleReadyForQuery.bind(this.cursor);
    this.handleError = this.cursor.handleError.bind(this.cursor);
  }
github NodeBB / NodeBB / src / database / postgres / sorted.js View on Github external
module.exports = function (module) {
	var helpers = require('./helpers');
	const util = require('util');
	var Cursor = require('pg-cursor');
	Cursor.prototype.readAsync = util.promisify(Cursor.prototype.read);
	const sleep = util.promisify(setTimeout);

	require('./sorted/add')(module);
	require('./sorted/remove')(module);
	require('./sorted/union')(module);
	require('./sorted/intersect')(module);

	module.getSortedSetRange = async function (key, start, stop) {
		return await getSortedSetRange(key, start, stop, 1, false);
	};

	module.getSortedSetRevRange = async function (key, start, stop) {
		return await getSortedSetRange(key, start, stop, -1, false);
	};

	module.getSortedSetRangeWithScores = async function (key, start, stop) {

pg-cursor

Query cursor extension for node-postgres

MIT
Latest version published 23 days ago

Package Health Score

88 / 100
Full package analysis

Popular pg-cursor functions