Skip to content

Commit

Permalink
Date con prioridad sobre Timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoefe committed Dec 13, 2016
1 parent 4f0a9b9 commit 5149d7a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
12 changes: 6 additions & 6 deletions lib/txt-to-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ var types = [
{adapt:adaptPlain, pad:padRight, validates:isBigInteger }, // bigint
{adapt:adaptPlain, pad:padRight, validates:isNumeric , useLength:true }, // numeric
{adapt:adaptPlain, pad:padRight, validates:isDouble }, // double precision
{adapt:adaptText , pad:padRight, validates:isTimestamp }, // timestamp
{adapt:adaptText , pad:padRight, validates:isDate }, // date
{adapt:adaptText , pad:padRight, validates:isTimestamp }, // timestamp
{adapt:adaptText , pad:padLeft , validates:isVarchar , useLength:true, isTextColumn:true}, // character varying
];

Expand All @@ -99,29 +99,29 @@ function dropTable(tableName) { return "drop table "+tableName; }

var engines = {
'postgresql': {
types:mapTypes([/*'boolean',*/'integer','bigint','numeric','double precision','timestamp','date','character varying']),
types:mapTypes([/*'boolean',*/'integer','bigint','numeric','double precision','date','timestamp','character varying']),
quote:quoteDouble,
dropTable:dropTableIfExists
},
'mssql': {
types:mapTypes([/*'bit',*/'integer','bigint','numeric','real','timestamp','date','varchar']),
types:mapTypes([/*'bit',*/'integer','bigint','numeric','real','date','timestamp','varchar']),
quote:quoteBracket,
noCompactInsert:true,
dropTable:dropTable
},
'mysql': {
types:mapTypes([/*'tinyint',*/'integer','bigint','numeric','double precision','timestamp','date','varchar']),
types:mapTypes([/*'tinyint',*/'integer','bigint','numeric','double precision','date','timestamp','varchar']),
quote:quoteBackTick,
dropTable:dropTableIfExists
},
'oracle': {
types:mapTypes([/*'char',*/'integer','long','number','binary_double','timestamp','date','varchar2']),
types:mapTypes([/*'char',*/'integer','long','number','binary_double','date','timestamp','varchar2']),
quote:quoteDouble,
noCompactInsert:true,
dropTable:dropTable
},
'sqlite': {
types:mapTypes([/*'boolean',*/'integer','integer','numeric','real','timestamp','date','text']),
types:mapTypes([/*'boolean',*/'integer','integer','numeric','real','date','timestamp','text']),
quote:quoteDouble,
dropTable:dropTableIfExists,
// http://www.sqlite.org/limits.html#max_compound_select
Expand Down
54 changes: 27 additions & 27 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,16 @@ describe("stringizeStats", function(){
});

describe("datatype validation", function(){
it("boolean", function(){
var b1 = txtToSql.typeValidations['boolean'].checkOne;
var b = txtToSql.typeValidations['boolean'].checkArray;
expect(b1('null')).to.be.ok(); // coverage
// good
expect(b(0, [['1'],['1'],['0'],['1']])).to.be.ok();
expect(b(0, [['1'],['0'],[null],['0'],['1']])).to.be.ok();
// bad
expect(b(0, [['3'],['1'],['0'],['1']])).to.not.be.ok();
});
it("integer", function(){
var i = txtToSql.typeValidations['integer'].checkOne;
// good
Expand Down Expand Up @@ -336,26 +346,6 @@ describe("datatype validation", function(){
// bad
expect(dp('a1.12e-101')).to.not.be.ok();
});
it("timestamp", function(){
var ts = txtToSql.typeValidations['timestamp'].checkOne;
var tsA = txtToSql.typeValidations['timestamp'].checkArray;
expect(tsA(0, [['2010-01-21 00:10:00.009']])).to.be.ok(); // coverage
// good
expect(ts('2016-11-21 10:00:01')).to.be.ok();
expect(ts('2009-05-06 00:10:00 +4:00')).to.be.ok();
expect(ts('2009-05-06 00:00:00 -12:00')).to.be.ok();
expect(ts('2009-05-06 00:00:00 +13:00')).to.be.ok();
// bad
expect(ts('2016-11-21 0:00:01')).to.not.be.ok();
expect(ts('2016-11-21 30:00:01')).to.not.be.ok();
expect(ts('2016-21-21 30:00:01')).to.not.be.ok();
expect(ts('2016-11-32 30:00:01')).to.not.be.ok();
expect(ts('216-11-32 30:00:01')).to.not.be.ok();
expect(ts('2009-05-06 00:10:00.100 /4:00')).to.not.be.ok();
expect(ts('2009-05-06 00:10:00.100 4:00')).to.not.be.ok();
expect(ts('2009-05-06 00:00:00 +13:60')).to.not.be.ok();
expect(ts('not a timestamp')).to.not.be.ok();
});
it("date", function(){
var d = txtToSql.typeValidations['date'].checkOne;
// good
Expand All @@ -375,14 +365,24 @@ describe("datatype validation", function(){
expect(d('30/3/0969')).to.not.be.ok();
expect(d('not a date')).to.not.be.ok();
});
it("boolean", function(){
var b1 = txtToSql.typeValidations['boolean'].checkOne;
var b = txtToSql.typeValidations['boolean'].checkArray;
expect(b1('null')).to.be.ok(); // coverage
it("timestamp", function(){
var ts = txtToSql.typeValidations['timestamp'].checkOne;
var tsA = txtToSql.typeValidations['timestamp'].checkArray;
expect(tsA(0, [['2010-01-21 00:10:00.009']])).to.be.ok(); // coverage
// good
expect(b(0, [['1'],['1'],['0'],['1']])).to.be.ok();
expect(b(0, [['1'],['0'],[null],['0'],['1']])).to.be.ok();
expect(ts('2016-11-21 10:00:01')).to.be.ok();
expect(ts('2009-05-06 00:10:00 +4:00')).to.be.ok();
expect(ts('2009-05-06 00:00:00 -12:00')).to.be.ok();
expect(ts('2009-05-06 00:00:00 +13:00')).to.be.ok();
// bad
expect(b(0, [['3'],['1'],['0'],['1']])).to.not.be.ok();
expect(ts('2016-11-21 0:00:01')).to.not.be.ok();
expect(ts('2016-11-21 30:00:01')).to.not.be.ok();
expect(ts('2016-21-21 30:00:01')).to.not.be.ok();
expect(ts('2016-11-32 30:00:01')).to.not.be.ok();
expect(ts('216-11-32 30:00:01')).to.not.be.ok();
expect(ts('2009-05-06 00:10:00.100 /4:00')).to.not.be.ok();
expect(ts('2009-05-06 00:10:00.100 4:00')).to.not.be.ok();
expect(ts('2009-05-06 00:00:00 +13:60')).to.not.be.ok();
expect(ts('not a timestamp')).to.not.be.ok();
});
});
12 changes: 6 additions & 6 deletions web/txt-to-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ var types = [
{adapt:adaptPlain, pad:padRight, validates:isBigInteger }, // bigint
{adapt:adaptPlain, pad:padRight, validates:isNumeric , useLength:true }, // numeric
{adapt:adaptPlain, pad:padRight, validates:isDouble }, // double precision
{adapt:adaptText , pad:padRight, validates:isTimestamp }, // timestamp
{adapt:adaptText , pad:padRight, validates:isDate }, // date
{adapt:adaptText , pad:padRight, validates:isTimestamp }, // timestamp
{adapt:adaptText , pad:padLeft , validates:isVarchar , useLength:true, isTextColumn:true}, // character varying
];

Expand All @@ -99,29 +99,29 @@ function dropTable(tableName) { return "drop table "+tableName; }

var engines = {
'postgresql': {
types:mapTypes([/*'boolean',*/'integer','bigint','numeric','double precision','timestamp','date','character varying']),
types:mapTypes([/*'boolean',*/'integer','bigint','numeric','double precision','date','timestamp','character varying']),
quote:quoteDouble,
dropTable:dropTableIfExists
},
'mssql': {
types:mapTypes([/*'bit',*/'integer','bigint','numeric','real','timestamp','date','varchar']),
types:mapTypes([/*'bit',*/'integer','bigint','numeric','real','date','timestamp','varchar']),
quote:quoteBracket,
noCompactInsert:true,
dropTable:dropTable
},
'mysql': {
types:mapTypes([/*'tinyint',*/'integer','bigint','numeric','double precision','timestamp','date','varchar']),
types:mapTypes([/*'tinyint',*/'integer','bigint','numeric','double precision','date','timestamp','varchar']),
quote:quoteBackTick,
dropTable:dropTableIfExists
},
'oracle': {
types:mapTypes([/*'char',*/'integer','long','number','binary_double','timestamp','date','varchar2']),
types:mapTypes([/*'char',*/'integer','long','number','binary_double','date','timestamp','varchar2']),
quote:quoteDouble,
noCompactInsert:true,
dropTable:dropTable
},
'sqlite': {
types:mapTypes([/*'boolean',*/'integer','integer','numeric','real','timestamp','date','text']),
types:mapTypes([/*'boolean',*/'integer','integer','numeric','real','date','timestamp','text']),
quote:quoteDouble,
dropTable:dropTableIfExists,
// http://www.sqlite.org/limits.html#max_compound_select
Expand Down

0 comments on commit 5149d7a

Please sign in to comment.