Skip to content

Commit

Permalink
Adds point support for all drivers (#221)
Browse files Browse the repository at this point in the history
Changes unknown property type error to throw a well defined code
  • Loading branch information
dresende committed Jul 8, 2013
1 parent 3da4e00 commit 26d88a9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
12 changes: 8 additions & 4 deletions lib/Drivers/DDL/mysql.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var ErrorCodes = require("../../ErrorCodes");

exports.drop = function (driver, opts, cb) {
var i, queries = [], pending;

Expand Down Expand Up @@ -172,12 +174,14 @@ function buildColumnDefinition(driver, name, prop) {
def = driver.query.escapeId(name) + " ENUM (" +
prop.values.map(driver.query.escapeVal.bind(driver.query)) +
")";
break;
case "point":
def = driver.query.escapeId(name) + " POINT";
break;
case "point":
def = driver.query.escapeId(name) + " POINT";
break;
default:
throw new Error("Unknown property type: '" + prop.type + "'");
throw ErrorCodes.generateError(ErrorCodes.NO_SUPPORT, "Unknown property type: '" + prop.type + "'", {
property : prop
});
}
if (prop.required === true) {
def += " NOT NULL";
Expand Down
9 changes: 8 additions & 1 deletion lib/Drivers/DDL/postgres.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var ErrorCodes = require("../../ErrorCodes");

exports.drop = function (driver, opts, cb) {
var i, queries = [], pending;

Expand Down Expand Up @@ -211,8 +213,13 @@ function buildColumnDefinition(driver, table, name, prop) {
case "enum":
def = driver.query.escapeId(name) + " " + driver.query.escapeId("enum_" + table + "_" + name);
break;
case "point":
def = driver.query.escapeId(name) + " POINT";
break;
default:
throw new Error("Unknown property type: '" + prop.type + "'");
throw ErrorCodes.generateError(ErrorCodes.NO_SUPPORT, "Unknown property type: '" + prop.type + "'", {
property : prop
});
}
if (prop.required === true) {
def += " NOT NULL";
Expand Down
6 changes: 5 additions & 1 deletion lib/Drivers/DDL/sqlite.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var ErrorCodes = require("../../ErrorCodes");

exports.drop = function (driver, opts, cb) {
var i, queries = [], pending;

Expand Down Expand Up @@ -154,7 +156,9 @@ function buildColumnDefinition(driver, name, prop) {
def = driver.query.escapeId(name) + " INTEGER";
break;
default:
throw new Error("Unknown property type: '" + prop.type + "'");
throw ErrorCodes.generateError(ErrorCodes.NO_SUPPORT, "Unknown property type: '" + prop.type + "'", {
property : prop
});
}
if (prop.required === true) {
def += " NOT NULL";
Expand Down
4 changes: 2 additions & 2 deletions lib/Drivers/DML/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ Driver.prototype.propertyToValue = function (value, property) {
return (value) ? 1 : 0;
case "object":
return JSON.stringify(value);
case "point":
return function() { return 'POINT(' + value.x + ', ' + value.y + ')'; };
case "point":
return function() { return 'POINT(' + value.x + ', ' + value.y + ')'; };
default:
return value;
}
Expand Down
12 changes: 12 additions & 0 deletions lib/Drivers/DML/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ Driver.prototype.valueToProperty = function (value, property) {
return null;
}
break;
case "point":
if (typeof value == "string") {
var m = value.match(/\((\-?[\d\.]+)[\s,]+(\-?[\d\.]+)\)/);
if (m) {
return { x : parseFloat(m[1], 10) , y : parseFloat(m[2], 10) };
}
}
return value;
case "number":
if (value !== null) {
return Number(value);
Expand All @@ -278,6 +286,10 @@ Driver.prototype.propertyToValue = function (value, property) {
switch (property.type) {
case "object":
return JSON.stringify(value);
case "point":
return function () {
return "POINT(" + value.x + ', ' + value.y + ")";
};
default:
return value;
}
Expand Down

0 comments on commit 26d88a9

Please sign in to comment.