Skip to content

Commit 755b392

Browse files
committed
Exit with error code when create-test-tables fails
1 parent 30f67bb commit 755b392

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

script/create-test-tables.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,25 @@ var con = new pg.Client({
3838
password: args.password,
3939
database: args.database
4040
})
41-
con.connect()
42-
var query = con.query('drop table if exists person')
43-
con.query('create table person(id serial, name varchar(10), age integer)', (err, res) => {
44-
console.log('Created table person')
45-
console.log('Filling it with people')
46-
})
47-
people.map(function (person) {
48-
return con.query(new pg.Query("insert into person(name, age) values('" + person.name + "', '" + person.age + "')"))
49-
}).pop().on('end', function () {
50-
console.log('Inserted 26 people')
51-
con.end()
41+
42+
con.connect((err) => {
43+
if (err) {
44+
throw err
45+
}
46+
47+
con.query(
48+
'DROP TABLE IF EXISTS person;'
49+
+ ' CREATE TABLE person (id serial, name varchar(10), age integer);'
50+
+ people
51+
.map((person) =>
52+
` INSERT INTO person (name, age) VALUES ('${person.name}', ${person.age});`)
53+
.join(''),
54+
(err, result) => {
55+
if (err) {
56+
throw err
57+
}
58+
59+
console.log(`Inserted ${result.rowCount} people`)
60+
con.end()
61+
})
5262
})

0 commit comments

Comments
 (0)