You will have to use readFileSync if you want to pass the return value of
sql_file directly to the reader function. Something like this should work
for you.

function sql_file(sql_file) {
    var fileName = "./SQLs/" + sql_file;
    return fs.readFileSync(fileName, { encoding: 'utf8' });
}

Colin


On Fri, Mar 7, 2014 at 9:32 AM, Bob Spero <[email protected]> wrote:

> I am trying to create a utility that will read the select statements from
> the raw sql files, putting them in a string and executing the  
> connection.reader.
> with something like var reader =
> connection.reader(sql_file(inventory.sql), []);, Is this possible?
>
> Util.js
> var fs = require('fs');
> function sql_file(sql_file, cb) {
>     var fileName = "./SQLs/" + sql_file;
>     fs.readFile(fileName, function(err, buffer) {
>         if (err) return cb(err);
>         return cb(null, buffer.toString());
>     });
> }
> module.exports.sql_file = sql_file;
>
> Main.js
> var sqlUtil = require('./sqlUtil');
>
> var reader = connection.reader(sql_file(inventory.sql), []);
>
> --
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to