Skip to content

Instantly share code, notes, and snippets.

@joystick
Created September 23, 2016 08:33
Show Gist options
  • Select an option

  • Save joystick/8d2e36d411ad87f6b5855c918fac40a0 to your computer and use it in GitHub Desktop.

Select an option

Save joystick/8d2e36d411ad87f6b5855c918fac40a0 to your computer and use it in GitHub Desktop.
var sql = require('seriate');
var _ = require('underscore');
var sqlconf = require('./sqlconf');
sql.setDefaultConfig(sqlconf);
var countAccounts = function(cocd) {
return sql.execute({
query: "select count(*) as count from [dbo].[accaccounts] where [account_comp] = @cocd",
params: {
cocd: {
type: sql.NVARCHAR,
val: cocd
}
}
});
};
var deleteAccounts = function(cocd) {
return sql.execute({
query: "delete from [dbo].[accaccounts] where [account_comp] = @cocd",
params: {
cocd: {
type: sql.NVARCHAR,
val: cocd
}
}
});
};
var insertAccount = function(account) {
return sql.execute({
query: sql.fromFile('./account'),
params: {
account_comp: account.account_comp,
account_code: account.account_code,
account_type: account.account_type,
account_name1: account.account_name1
}
});
};
var ObjectId = function(str) { return str };
var accounts = [{
"_id" : ObjectId("57dbc57e603db3dc9acc5d82"),
"account_comp" : "1234",
"account_code" : "224000.20103",
"account_type" : "224",
"account_name1" : "ABC Trading Ltd." }, {
"_id" : ObjectId("57dbc57e603db3dc9acc5d83"),
"account_comp" : "1234",
"account_code" : "600100",
"account_type" : "6",
"account_name1" : "Income from Accounting Fees" }];
deleteAccounts('1234')
.then(function() {
return _.map(accounts, function(account) {
return insertAccount(account);
})
})
.then(function() {
return countAccounts('1234');
})
.then(function(res) {
console.log(res);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment