diff --git a/README.md b/README.md index 69553f1..f0dec97 100644 --- a/README.md +++ b/README.md @@ -55,11 +55,11 @@ INSERT INTO Test2.dbo.Tweets (Lang, "Text", id, CreatedAt, Username, ScreenName) VALUES -(@lang:string, @text:string, @id:bigint, @created_at:date, @username:string, @screenname:string) +(@lang, @text, @id:bigint, @created_at:date, @username, @screenname) ``` Following types are supported: - * ``string`` + * ``string`` (also default type if type is omitted) * ``number`` (will be converted to MSSQL ``int``) * ``bigint`` * ``boolean`` (will be converted to MSSQL ``bit``) diff --git a/lib/actions/insert.js b/lib/actions/insert.js index b0768a7..42176d8 100644 --- a/lib/actions/insert.js +++ b/lib/actions/insert.js @@ -5,7 +5,7 @@ const cosql = require('co-mssql'); let pstmt; -const VARS_REGEXP = /@([\w_$][\d\w_$]*:(string|boolean|date|number|bigint|float|real|money))/g; +const VARS_REGEXP = /@([\w_$][\d\w_$]*(:(string|boolean|date|number|bigint|float|real|money))?)/g; /** * This function will be called during component intialization @@ -31,6 +31,7 @@ function init(cfg) { const [placeholder, type] = tuple.split(':'); const name = placeholder.substr(1); switch (type) { + case undefined: case 'string': pstmt.input(name, cosql.NVarChar); break; @@ -94,6 +95,15 @@ function getMetaModel(cfg, cb) { case 'bigint': jsType = 'number'; break; + case 'real': + jsType = 'number'; + break; + case 'float': + jsType = 'number'; + break; + case 'money': + jsType = 'number'; + break; } fields[key.substr(1)] = { type: jsType diff --git a/spec-integration/integration.spec.js b/spec-integration/integration.spec.js index d3bd080..74286f5 100644 --- a/spec-integration/integration.spec.js +++ b/spec-integration/integration.spec.js @@ -34,7 +34,7 @@ describe('Integration test', () => { const cfg = { uri : process.env.MSSQL_URL, query: 'INSERT INTO Test2.dbo.Tweets (Lang, Retweeted, Favorited, "Text", id, CreatedAt, Username, ScreenName) ' - + 'VALUES (@lang:string, @retweeted:boolean, @favorited:boolean, @text:string, @id:bigint, @created_at:date, @username:string, @screenname:string)' + + 'VALUES (@lang, @retweeted:boolean, @favorited:boolean, @text:string, @id:bigint, @created_at:date, @username, @screenname:string)' }; before(() => { diff --git a/spec/metadata.spec.js b/spec/metadata.spec.js index bf810f2..5f8f184 100644 --- a/spec/metadata.spec.js +++ b/spec/metadata.spec.js @@ -5,7 +5,7 @@ const insert = require('../lib/actions/insert'); describe('Metadata test', () => { const cfg = { query: 'INSERT INTO Test2.dbo.Tweets (Lang, Retweeted, Favorited, "Text", id, CreatedAt, Username, ScreenName) ' - + 'VALUES (@lang:string, @retweeted:boolean, @favorited:boolean, ' + + 'VALUES (@lang:string, @retweeted:float, @money:money, @favorited:boolean, ' + '@text:string, @id:bigint, @created_at:date, @username:string, @screenname:string)' }; @@ -28,8 +28,11 @@ describe('Metadata test', () => { lang: { type: 'string' }, + money: { + type: 'number' + }, retweeted: { - type: 'string' + type: 'number' }, screenname: { type: 'string' @@ -89,5 +92,52 @@ describe('Metadata test', () => { }); }); + it('should assume default metadata as stirng', (done) => { + insert.getMetaModel({ + query: 'INSERT INTO Test2.dbo.Tweets ' + + '(Lang, Retweeted, Favorited, "Text", id, CreatedAt, Username, ScreenName) ' + + 'VALUES (@lang, @retweeted:float, @money:money, @favorited:boolean, ' + + '@text, @id:bigint, @created_at:date, @username, @screenname)' + }, (err, result) => { + expect(err).to.be.null; + expect(result).to.deep.equal({ + in: { + properties: { + created_at: { + type: 'string' + }, + favorited: { + type: 'string' + }, + id: { + type: 'number' + }, + lang: { + type: 'string' + }, + money: { + type: 'number' + }, + retweeted: { + type: 'number' + }, + screenname: { + type: 'string' + }, + text: { + type: 'string' + }, + username: { + type: 'string' + } + }, + type: 'object' + }, + out: {} + } + ); + done(); + }); + }); });