no-data-handling.js 885 B

12345678910111213141516171819202122232425262728293031323334
  1. const assert = require('assert')
  2. const pg = require('pg')
  3. const Cursor = require('../')
  4. describe('queries with no data', function () {
  5. beforeEach(function (done) {
  6. const client = (this.client = new pg.Client())
  7. client.connect(done)
  8. })
  9. afterEach(function () {
  10. this.client.end()
  11. })
  12. it('handles queries that return no data', function (done) {
  13. const cursor = new Cursor('CREATE TEMPORARY TABLE whatwhat (thing int)')
  14. this.client.query(cursor)
  15. cursor.read(100, function (err, rows) {
  16. assert.ifError(err)
  17. assert.strictEqual(rows.length, 0)
  18. done()
  19. })
  20. })
  21. it('handles empty query', function (done) {
  22. let cursor = new Cursor('-- this is a comment')
  23. cursor = this.client.query(cursor)
  24. cursor.read(100, function (err, rows) {
  25. assert.ifError(err)
  26. assert.strictEqual(rows.length, 0)
  27. done()
  28. })
  29. })
  30. })