Skip to content

Commit

Permalink
Agrego timestamp y corrijo date
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoefe committed Dec 12, 2016
1 parent 9ad44ab commit 786236b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 30 deletions.
25 changes: 13 additions & 12 deletions lib/txt-to-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ function isDate(values) {
return val.match(dateRegExp);
});
}
// function isTimestamp(values) {
// var tsRegExp = new RegExp('^('+year+'-'+mon+'-'+day+'( [0-2][0-9]:[0-2][0-9]:[0-2][0-9](\.[0-9]{3})?( [-+][0-9]:[0-0]{2})?)?)$');
// return values.every(function(val) {
// return val.match(tsRegExp);
// });
// }
function isTimestamp(values) {
var tsRegExp = new RegExp('^('+year+'-'+mon+'-'+day+' [0-2][0-9]:[0-2][0-9]:[0-2][0-9](\.[0-9]{3})?( [-+][0-9]:[0-0]{2})?)$');
return values.every(function(val) {
return val.match(tsRegExp);
});
}
function isVarchar(values) {
return values.every(function(val) {
return val.match(/.?/);
Expand All @@ -76,6 +76,7 @@ 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:padLeft , validates:isVarchar , useLength:true, isTextColumn:true}, // character varying
];
Expand All @@ -94,29 +95,29 @@ function dropTable(tableName) { return "drop table "+tableName; }

var engines = {
'postgresql': {
types:mapTypes([/*'boolean',*/'integer','bigint','numeric','double precision','date','character varying']),
types:mapTypes([/*'boolean',*/'integer','bigint','numeric','double precision','timestamp','date','character varying']),
quote:quoteDouble,
dropTable:dropTableIfExists
},
'mssql': {
types:mapTypes([/*'bit',*/'integer','bigint','numeric','real','date','varchar']),
types:mapTypes([/*'bit',*/'integer','bigint','numeric','real','timestamp','date','varchar']),
quote:quoteBracket,
noCompactInsert:true,
dropTable:dropTable
},
'mysql': {
types:mapTypes([/*'tinyint',*/'integer','bigint','numeric','double precision','date','varchar']),
types:mapTypes([/*'tinyint',*/'integer','bigint','numeric','double precision','timestamp','date','varchar']),
quote:quoteBackTick,
dropTable:dropTableIfExists
},
'oracle': {
types:mapTypes([/*'char',*/'integer','long','number','binary_double','date','varchar2']),
types:mapTypes([/*'char',*/'integer','long','number','binary_double','timestamp','date','varchar2']),
quote:quoteDouble,
noCompactInsert:true,
dropTable:dropTable
},
'sqlite': {
types:mapTypes([/*'boolean',*/'integer','integer','numeric','real','date','text']),
types:mapTypes([/*'boolean',*/'integer','integer','numeric','real','timestamp','date','text']),
quote:quoteDouble,
dropTable:dropTableIfExists,
// http://www.sqlite.org/limits.html#max_compound_select
Expand Down Expand Up @@ -433,7 +434,7 @@ function determineColumnTypes(info){
return info;
}
*/
function isTextType(typeName) { return typeName.match(/(text|char)/); }
function isTextType(typeName) { return typeName.match(/(text|char|time|date)/); }
function hasCientificNotation(typeName) { return typeName==='double precision'?false:null; }

function getLengthInfo(val, typeName) {
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/dates.result.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ columns:
type: date
inPrimaryKey: true
maxLength: 10
maxScale: 0
maxScale: null
hasNullValues: false
hasCientificNotation: null
- name: date2
type: date
inPrimaryKey: false
maxLength: 9
maxScale: 0
maxScale: null
hasNullValues: false
hasCientificNotation: null
- name: date3
type: date
inPrimaryKey: false
maxLength: 9
maxScale: 0
maxScale: null
hasNullValues: true
hasCientificNotation: null
4 changes: 2 additions & 2 deletions test/fixtures/timestamps.result.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ columns:
type: timestamp
inPrimaryKey: true
maxLength: 25
maxScale: 0
maxScale: null
hasNullValues: false
hasCientificNotation: null
- name: fecha
type: date
inPrimaryKey: false
maxLength: 9
maxScale: 0
maxScale: null
hasNullValues: true
hasCientificNotation: null
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ describe("fixtures", function(){
{name:'mssql-insert-limit'}, // compactInsertLimit should be ignored (#24)
{name:'insert-limit2'},
{name:'dates'},
{/*skip:true, */name:'timestamps'},
{skip:true, name:'booleans'},
{skip:true, name:'timestamps'},
].forEach(function(fixture){
if(fixture.skip) {
it.skip("fixture: "+fixture.name);
Expand Down
25 changes: 13 additions & 12 deletions web/txt-to-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ function isDate(values) {
return val.match(dateRegExp);
});
}
// function isTimestamp(values) {
// var tsRegExp = new RegExp('^('+year+'-'+mon+'-'+day+'( [0-2][0-9]:[0-2][0-9]:[0-2][0-9](\.[0-9]{3})?( [-+][0-9]:[0-0]{2})?)?)$');
// return values.every(function(val) {
// return val.match(tsRegExp);
// });
// }
function isTimestamp(values) {
var tsRegExp = new RegExp('^('+year+'-'+mon+'-'+day+' [0-2][0-9]:[0-2][0-9]:[0-2][0-9](\.[0-9]{3})?( [-+][0-9]:[0-0]{2})?)$');
return values.every(function(val) {
return val.match(tsRegExp);
});
}
function isVarchar(values) {
return values.every(function(val) {
return val.match(/.?/);
Expand All @@ -76,6 +76,7 @@ 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:padLeft , validates:isVarchar , useLength:true, isTextColumn:true}, // character varying
];
Expand All @@ -94,29 +95,29 @@ function dropTable(tableName) { return "drop table "+tableName; }

var engines = {
'postgresql': {
types:mapTypes([/*'boolean',*/'integer','bigint','numeric','double precision','date','character varying']),
types:mapTypes([/*'boolean',*/'integer','bigint','numeric','double precision','timestamp','date','character varying']),
quote:quoteDouble,
dropTable:dropTableIfExists
},
'mssql': {
types:mapTypes([/*'bit',*/'integer','bigint','numeric','real','date','varchar']),
types:mapTypes([/*'bit',*/'integer','bigint','numeric','real','timestamp','date','varchar']),
quote:quoteBracket,
noCompactInsert:true,
dropTable:dropTable
},
'mysql': {
types:mapTypes([/*'tinyint',*/'integer','bigint','numeric','double precision','date','varchar']),
types:mapTypes([/*'tinyint',*/'integer','bigint','numeric','double precision','timestamp','date','varchar']),
quote:quoteBackTick,
dropTable:dropTableIfExists
},
'oracle': {
types:mapTypes([/*'char',*/'integer','long','number','binary_double','date','varchar2']),
types:mapTypes([/*'char',*/'integer','long','number','binary_double','timestamp','date','varchar2']),
quote:quoteDouble,
noCompactInsert:true,
dropTable:dropTable
},
'sqlite': {
types:mapTypes([/*'boolean',*/'integer','integer','numeric','real','date','text']),
types:mapTypes([/*'boolean',*/'integer','integer','numeric','real','timestamp','date','text']),
quote:quoteDouble,
dropTable:dropTableIfExists,
// http://www.sqlite.org/limits.html#max_compound_select
Expand Down Expand Up @@ -433,7 +434,7 @@ function determineColumnTypes(info){
return info;
}
*/
function isTextType(typeName) { return typeName.match(/(text|char)/); }
function isTextType(typeName) { return typeName.match(/(text|char|time|date)/); }
function hasCientificNotation(typeName) { return typeName==='double precision'?false:null; }

function getLengthInfo(val, typeName) {
Expand Down

0 comments on commit 786236b

Please sign in to comment.