I'm wondering if it is easier to initialise sql-stamp by loading all the files synchronously.
For example:
var sqlStamp = require("sql-stamp");
// Make some templates
var templates = sqlStamp(["/path/to/sql"]); // This step sync
// Use those templates
var sql = templates("/path/to/sql", {
one: "fish"
});
The advantage of this is you could easily put the template loading part into a module and require it.
/sql-templates.js
var sqlStamp = require("sql-stamp");
// Make some templates
module.exports = sqlStamp(["/path/to/sql"]); // This step sync
/model.js
var templates = require("./sql-templates");
// Use those templates
var sql = templates("/path/to/sql", {
one: "fish"
});
// use sql
With async you need some kind of initialising step to ensure all the files are loaded.
/sql-templates.js
var sqlStamp = require("sql-stamp");
// Make some templates
var templates;
function init () {
return sqlStamp(["/path/to/sql"]).then(function (sql) {
templates = sql;
return sql;
});
}
module.exports = function () {
if (templates) {
return Promise.resolve(templates);
} else {
return init();
}
}
/model.js
var templates = require("./sql-templates");
// Use those templates
templates().then(function (templates) {
var sql = templates("/path/to/sql", {
one: "fish"
});
// use sql
});
As files are loaded once on app start it would seem there is no performance reason to load async and seems more cumbersome to use.
Hopefully I've missed some easy way to initialise.
I'm wondering if it is easier to initialise sql-stamp by loading all the files synchronously.
For example:
The advantage of this is you could easily put the template loading part into a module and require it.
/sql-templates.js
/model.js
With async you need some kind of initialising step to ensure all the files are loaded.
/sql-templates.js
/model.js
As files are loaded once on app start it would seem there is no performance reason to load async and seems more cumbersome to use.
Hopefully I've missed some easy way to initialise.