cormo
Advanced tools
Comparing version 0.19.2 to 0.19.3
@@ -46,3 +46,3 @@ "use strict"; | ||
const sql_base_1 = require("./sql_base"); | ||
function _typeToSQL(property, support_fractional_seconds) { | ||
function _typeToSQL(property, support_fractional_seconds, major_version) { | ||
if (property.array) { | ||
@@ -59,5 +59,5 @@ return 'TEXT'; | ||
case types.Integer: | ||
return 'INT(11)'; | ||
return major_version < 6 ? 'INT(11)' : 'INT'; | ||
case types.BigInteger: | ||
return 'BIGINT(20)'; | ||
return major_version < 6 ? 'BIGINT(20)' : 'BIGINT'; | ||
case types.GeoPoint: | ||
@@ -79,4 +79,4 @@ return 'POINT'; | ||
} | ||
function _propertyToSQL(property, support_fractional_seconds) { | ||
let type = _typeToSQL(property, support_fractional_seconds); | ||
function _propertyToSQL(property, support_fractional_seconds, major_version) { | ||
let type = _typeToSQL(property, support_fractional_seconds, major_version); | ||
if (type) { | ||
@@ -151,2 +151,4 @@ if (property.required) { | ||
this._read_client_index = -1; | ||
/** @internal */ | ||
this._version = { major: 0, minor: 0 }; | ||
this._connection = connection; | ||
@@ -182,3 +184,3 @@ this._query_timeout = 60000; | ||
else { | ||
let column_sql = _propertyToSQL(property, this.support_fractional_seconds); | ||
let column_sql = _propertyToSQL(property, this.support_fractional_seconds, this._version.major); | ||
if (column_sql) { | ||
@@ -237,3 +239,3 @@ if (property.description) { | ||
const table_name = model_class.table_name; | ||
let column_sql = _propertyToSQL(column_property, this.support_fractional_seconds); | ||
let column_sql = _propertyToSQL(column_property, this.support_fractional_seconds, this._version.major); | ||
if (column_property.description) { | ||
@@ -261,3 +263,3 @@ column_sql += ` COMMENT ${mysql.escape(column_property.description)}`; | ||
const table_name = model_class.table_name; | ||
let column_sql = _propertyToSQL(column_property, this.support_fractional_seconds); | ||
let column_sql = _propertyToSQL(column_property, this.support_fractional_seconds, this._version.major); | ||
if (column_property.description) { | ||
@@ -372,3 +374,3 @@ column_sql += ` COMMENT ${mysql.escape(column_property.description)}`; | ||
getAdapterTypeString(column_property) { | ||
return _typeToSQL(column_property, this.support_fractional_seconds); | ||
return _typeToSQL(column_property, this.support_fractional_seconds, this._version.major); | ||
} | ||
@@ -1055,3 +1057,3 @@ /** @internal */ | ||
const location = options.near[field]; | ||
select += `,GLENGTH(LINESTRING(\`${field}\`,POINT(${location[0]},${location[1]}))) AS \`${field}_distance\``; | ||
select += `,ST_Length(LINESTRING(\`${field}\`,POINT(${location[0]},${location[1]}))) AS \`${field}_distance\``; | ||
} | ||
@@ -1156,2 +1158,13 @@ const params = []; | ||
} | ||
try { | ||
const result = await client.queryAsync('SELECT VERSION() AS version'); | ||
const version = result[0].version; | ||
const match = version.match(/(\d+)\.(\d+)\.(\d+)/); | ||
if (match) { | ||
this._version = { major: Number(match[1]), minor: Number(match[2]) }; | ||
} | ||
} | ||
catch (error) { | ||
// ignore | ||
} | ||
} | ||
@@ -1165,3 +1178,3 @@ /** @internal */ | ||
const key = error.message.match(/for key '([^']*)'/); | ||
return new Error('duplicated ' + (key && key[1])); | ||
return new Error('duplicated ' + (key && key[1].replace(/[^.]*\./, ''))); | ||
} | ||
@@ -1168,0 +1181,0 @@ else if (error.code === 'ER_BAD_NULL_ERROR') { |
{ | ||
"name": "cormo", | ||
"description": "ORM framework for Node.js", | ||
"version": "0.19.2", | ||
"version": "0.19.3", | ||
"keywords": [ | ||
@@ -68,3 +68,4 @@ "orm", | ||
"typescript": "^4.5.5" | ||
} | ||
}, | ||
"gitHead": "0fc2a531808c22432a502dd536eae5cd8eaf0a40" | ||
} |
372116
10078