cursor.js 525 B

12345678910111213141516171819202122232425
  1. const { Pool } = require('pg')
  2. const Cursor = require('pg-cursor')
  3. const pool = new Pool({
  4. user: 'postgres',
  5. host: 'localhost',
  6. database: 'testdb',
  7. password: '1234abcd',
  8. port: 5432,
  9. });
  10. (async () => {
  11. const client = await pool.connect();
  12. const query = 'SELECT * FROM users';
  13. const cursor = await client.query(new Cursor(query));
  14. cursor.read(1, (err, rows) => {
  15. console.log(rows);
  16. cursor.read(1, (err, rows) => {
  17. console.log(rows);
  18. });
  19. })
  20. })();