Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into bmc/add-test-and-deprecate-method
- Loading branch information
Showing
4 changed files
with
62 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const assert = require('assert') | ||
const Cursor = require('../') | ||
const pg = require('pg') | ||
|
||
describe('transactions', () => { | ||
it('can execute multiple statements in a transaction', async () => { | ||
const client = new pg.Client() | ||
await client.connect() | ||
await client.query('begin') | ||
await client.query('CREATE TEMP TABLE foobar(id SERIAL PRIMARY KEY)') | ||
const cursor = client.query(new Cursor('SELECT * FROM foobar')) | ||
const rows = await new Promise((resolve, reject) => { | ||
cursor.read(10, (err, rows) => (err ? reject(err) : resolve(rows))) | ||
}) | ||
assert.equal(rows.length, 0) | ||
await client.query('ALTER TABLE foobar ADD COLUMN name TEXT') | ||
await client.end() | ||
}) | ||
|
||
it('can execute multiple statements in a transaction if ending cursor early', async () => { | ||
const client = new pg.Client() | ||
await client.connect() | ||
await client.query('begin') | ||
await client.query('CREATE TEMP TABLE foobar(id SERIAL PRIMARY KEY)') | ||
const cursor = client.query(new Cursor('SELECT * FROM foobar')) | ||
await new Promise(resolve => cursor.close(resolve)) | ||
await client.query('ALTER TABLE foobar ADD COLUMN name TEXT') | ||
await client.end() | ||
}) | ||
|
||
it.only('can execute multiple statements in a transaction if no data', async () => { | ||
const client = new pg.Client() | ||
await client.connect() | ||
await client.query('begin') | ||
// create a cursor that has no data response | ||
const createText = 'CREATE TEMP TABLE foobar(id SERIAL PRIMARY KEY)' | ||
const cursor = client.query(new Cursor(createText)) | ||
const err = await new Promise(resolve => cursor.read(100, resolve)) | ||
assert.ifError(err) | ||
await client.query('ALTER TABLE foobar ADD COLUMN name TEXT') | ||
await client.end() | ||
}) | ||
}) |