dynajoe/tinypg

multiple sql statements in an sql script file

melbardis opened this issue · 4 comments

hi

in a script, executed using the 'sql' command.

if you have one sql statement, like select resetDB(), you get back the result of the select, very nicely

Query:  [resetDB] SELECT resetDB();

{ id: '8fdb0a61-59a5-40ea-bcc0-f3f53830ff55',
  sql:
   'SELECT resetDB();\r\n',
  start: 1529527970119,
  name: 'resetDB',
  params: undefined,
  end: 1529527970237,
  duration: 118,
  data: { row_count: 1, rows: [ [Object] ], command: 'SELECT' } }
Result: [resetDB] (118ms ) 1  row(s)
      = [ { resetdb: '' } ]

if you have more than one, you get back a result with all nulls (row_count, etc ...)

Query:  [resetDB] SELECT resetDB();
insert into types (is_type, name) values ('obj', 'e') returning * ;

result event: context
{ id: 'c8aedfe2-7da9-4220-a95e-0b993c244f2d',
  sql:
   'SELECT resetDB();\r\n',
  start: 1529527770306,
  name: 'resetDB',
  params: undefined,
  end: 1529527770408,
  duration: 102,
  error: null,
  data:
   { row_count: undefined, rows: undefined, command: undefined } }
Result: [resetDB] (102ms ) undefined  row(s)

Note: the result in the database is as expected, just the result returned to the caller is not..

I think support for multiple query results is a new thing in node pg. I will look to see how they've implemented it.

What version of postgres are you using?

Started work on supporting multiple statements:

#12