Skip to content

Commit

Permalink
Empezando a validar data types
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoefe committed Dec 12, 2016
1 parent 488ce7c commit 54ff5b8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/txt-to-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ var engines = {
}
};

function createTypeValidations() {
var validations={};
engines['postgresql'].types.forEach(function(type) {
validations[type.typeName] = function(val) { return type.validates([val]); };
});
return validations;
}
txtToSql.typeValidations = createTypeValidations();

function throwIfErrors(errors) {
if(errors.length) {
var e = new Error();
Expand Down
6 changes: 6 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,9 @@ describe("stringizeStats", function(){
addStringizeTests(fixtures_es, null);
});

describe("datatype validation", function(){
it("timestamp", function(){
var ts = txtToSql.typeValidations['timestamp'];
expect(ts('2016-11-21 10:00:01')).to.be.ok();
});
});
9 changes: 9 additions & 0 deletions web/txt-to-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ var engines = {
}
};

function createTypeValidations() {
var validations={};
engines['postgresql'].types.forEach(function(type) {
validations[type.typeName] = function(val) { return type.validates([val]); };
});
return validations;
}
txtToSql.typeValidations = createTypeValidations();

function throwIfErrors(errors) {
if(errors.length) {
var e = new Error();
Expand Down

0 comments on commit 54ff5b8

Please sign in to comment.