diff --git a/README.md b/README.md
index 4af0441..f34dae1 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,10 @@
-## JugglingDB-MySQL [![Build Status](https://travis-ci.org/jugglingdb/mysql-adapter.png)](https://travis-ci.org/jugglingdb/mysql-adapter)
+## Loopback MySQL Connector
-MySQL adapter for JugglingDB.
+MySQL connector for Loopback Data.
## Usage
-To use it you need `jugglingdb@0.2.x`.
+To use it you need `loopback-data`.
1. Setup dependencies in `package.json`:
@@ -12,8 +12,8 @@ To use it you need `jugglingdb@0.2.x`.
{
...
"dependencies": {
- "jugglingdb": "0.2.x",
- "jugglingdb-mysql": "latest"
+ "loopback-data": "latest",
+ "loopback-connector-mysql": "latest"
},
...
}
@@ -22,13 +22,13 @@ To use it you need `jugglingdb@0.2.x`.
2. Use:
```javascript
- var Schema = require('jugglingdb').Schema;
+ var Schema = require('loopback-data').Schema;
var schema = new Schema('mysql', {
database: 'myapp_test',
username: 'root'
});
```
- You can optionally pass a few additional parameters supported by `node-mysql`, most particularly `password` and `collation`. `Collation` currently defaults to `utf8mb4_general_ci`. The `collation` value will also be used to derive the connection charset.
+ You can optionally pass a few additional parameters supported by `node-mysql`, most particularly `password` and `collation`. `Collation` currently defaults to `utf8_general_ci`. The `collation` value will also be used to derive the connection charset.
## Running tests
@@ -36,7 +36,7 @@ To use it you need `jugglingdb@0.2.x`.
## Using the `dataType` field/column option with MySQL
-The jugglingdb MySQL adapter now supports using the `dataType` column/property attribute to specify what MySQL column type is used for many jugglingdb types.
+The loopback-data MySQL adapter now supports using the `dataType` column/property attribute to specify what MySQL column type is used for many loopback-data types.
The following type-dataType combinations are supported:
*
Number
diff --git a/lib/mysql.js b/lib/mysql.js
index acf4949..3620532 100644
--- a/lib/mysql.js
+++ b/lib/mysql.js
@@ -14,8 +14,8 @@ exports.initialize = function initializeSchema(schema, callback) {
if (s.collation) {
s.charset = s.collation.substr(0,s.collation.indexOf('_')); // Charset should be first 'chunk' of collation.
} else {
- s.collation = 'utf8mb4_general_ci';
- s.charset = 'utf8mb4';
+ s.collation = 'utf8_general_ci';
+ s.charset = 'utf8';
}
s.supportBigNumbers = (s.supportBigNumbers || false);
@@ -246,6 +246,9 @@ MySQL.prototype.escapeName = function (name) {
MySQL.prototype.getColumns = function(model, props){
var cols = this._models[model].properties;
+ if(!cols) {
+ return '*';
+ }
var self = this;
var keys = Object.keys(cols);
if (Array.isArray(props) && props.length > 0) {
@@ -469,7 +472,7 @@ MySQL.prototype.alterTable = function (model, actualFields, actualIndexes, done,
// change/add new fields
propNames.forEach(function (propName) {
- if (self.id(model, key)) return;
+ if (m.properties[propName] && self.id(model, propName)) return;
var found;
if (actualFields) {
actualFields.forEach(function (f) {
@@ -490,7 +493,7 @@ MySQL.prototype.alterTable = function (model, actualFields, actualIndexes, done,
if (actualFields) {
actualFields.forEach(function (f) {
var notFound = !~propNames.indexOf(f.Field);
- if (mysql.id(model, f.Field)) return;
+ if (m.properties[f.Field] && self.id(model, f.Field)) return;
if (notFound || !m.properties[f.Field]) {
sql.push('DROP COLUMN `' + f.Field + '`');
}
@@ -499,7 +502,7 @@ MySQL.prototype.alterTable = function (model, actualFields, actualIndexes, done,
// remove indexes
aiNames.forEach(function (indexName) {
- if (self.id(model, indexName) || indexName === 'PRIMARY') return;
+ if (indexName === 'PRIMARY'|| (m.properties[indexName] && self.id(model, indexName))) return;
if (indexNames.indexOf(indexName) === -1 && !m.properties[indexName] || m.properties[indexName] && !m.properties[indexName].index) {
sql.push('DROP INDEX `' + indexName + '`');
} else {
diff --git a/package.json b/package.json
index 40a2480..215ac56 100644
--- a/package.json
+++ b/package.json
@@ -19,7 +19,7 @@
},
"repository": {
"type": "git",
- "url": "https://github.com/raymondfeng/jugglingdb-mysql.git"
+ "url": "https://github.com/strongloop/loopback-connector-mysql.git"
},
"author": "Anatoliy Chakkaev ",
"maintainers": [
diff --git a/test/connection.test.js b/test/connection.test.js
index cacced1..9e57dcb 100644
--- a/test/connection.test.js
+++ b/test/connection.test.js
@@ -1,6 +1,6 @@
var should = require('./init.js');
var assert = require('assert');
-var Schema = require('jugglingdb').Schema;
+var Schema = require('loopback-data').Schema;
var db, settings, adapter, DummyModel, odb;
@@ -11,17 +11,17 @@ describe('migrations', function() {
before(function() {
require('./init.js');
- odb = getSchema({collation: 'utf8mb4_general_ci'});
+ odb = getSchema({collation: 'utf8_general_ci'});
db = odb;
});
- it('should use utf8mb4 charset', function(done) {
+ it('should use utf8 charset', function(done) {
- var test_set = /utf8mb4/;
- var test_collo = /utf8mb4_general_ci/;
- var test_set_str = 'utf8mb4';
- var test_set_collo = 'utf8mb4_general_ci';
+ var test_set = /utf8/;
+ var test_collo = /utf8_general_ci/;
+ var test_set_str = 'utf8';
+ var test_set_collo = 'utf8_general_ci';
charsetTest(test_set, test_collo, test_set_str, test_set_collo, done);
});
diff --git a/test/datatypes.test.js b/test/datatypes.test.js
index 882b39a..737651a 100644
--- a/test/datatypes.test.js
+++ b/test/datatypes.test.js
@@ -1,6 +1,6 @@
var should = require('./init.js');
var assert = require('assert');
-var Schema = require('jugglingdb').Schema;
+var Schema = require('loopback-data').Schema;
var db, settings, adapter, EnumModel, ANIMAL_ENUM;
@@ -41,7 +41,7 @@ describe('MySQL specific datatypes', function() {
it('should fail spectacularly with invalid enum values', function(done) {
var em = EnumModel.create({animal: 'horse', condition: 'sleepy', mood: 'happy'}, function(err, obj) {
assert.ok(!err);
- EnumModel.find(obj.id, function(err, found){
+ EnumModel.findById(obj.id, function(err, found){
assert.ok(!err);
assert.equal(found.animal, ''); // MySQL fun.
assert.equal(found.animal, 0);
diff --git a/test/init.js b/test/init.js
index 331b5c4..d40d50b 100644
--- a/test/init.js
+++ b/test/init.js
@@ -2,14 +2,28 @@ module.exports = require('should');
var Schema = require('loopback-data').Schema;
-global.getSchema = function() {
- var db = new Schema(require('../'), {
+global.getConfig = function(options) {
+
+ var dbConf = {
host: '127.0.0.1',
port: 3306,
- database: 'test',
+ database: 'myapp_test',
username: 'strongloop',
password: 'password'
- });
- // db.log = function (a) { console.log(a); };
+ };
+
+ if (options) {
+ for (var el in options) {
+ dbConf[el] = options[el]
+ }
+ }
+
+ return dbConf;
+}
+
+global.getSchema = function(options) {
+ var db = new Schema(require('../'), getConfig(options));
return db;
};
+
+
diff --git a/test/migration.coffee b/test/migration.coffee
index a4635dc..13ef5ba 100644
--- a/test/migration.coffee
+++ b/test/migration.coffee
@@ -1,10 +1,10 @@
-juggling = require('jugglingdb')
+juggling = require('loopback-data')
Schema = juggling.Schema
Text = Schema.Text
DBNAME = 'myapp_test'
-DBUSER = 'root'
-DBPASS = ''
+DBUSER = 'strongloop'
+DBPASS = 'password'
DBENGINE = 'mysql'
schema = new Schema __dirname + '/..', database: '', username: DBUSER, password: DBPASS
diff --git a/test/migration.test.js b/test/migration.test.js
index 5eeaa62..39b4868 100644
--- a/test/migration.test.js
+++ b/test/migration.test.js
@@ -1,6 +1,6 @@
var should = require('./init.js');
var assert = require('assert');
-var Schema = require('jugglingdb').Schema;
+var Schema = require('loopback-data').Schema;
var db, UserData, StringData, NumberData, DateData;
@@ -72,8 +72,9 @@ describe('migrations', function() {
});
it('UserData should have correct indexes', function(done) {
- // Note: getIdexes truncates multi-key indexes to the first member. Hence index1 is correct.
+ // Note: getIndexes truncates multi-key indexes to the first member. Hence index1 is correct.
getIndexes('UserData', function(err, fields) {
+ // console.log('....', fields);
assert.deepEqual(fields, { PRIMARY:
{ Table: 'UserData',
Non_unique: 0,
@@ -86,8 +87,7 @@ describe('migrations', function() {
Packed: null,
Null: '',
Index_type: 'BTREE',
- Comment: '',
- Index_comment: '' },
+ Comment: '' },
email:
{ Table: 'UserData',
Non_unique: 1,
@@ -95,13 +95,12 @@ describe('migrations', function() {
Seq_in_index: 1,
Column_name: 'email',
Collation: 'A',
- Cardinality: 0,
- Sub_part: 191,
+ Cardinality: null,
+ Sub_part: null,
Packed: null,
Null: '',
Index_type: 'BTREE',
- Comment: '',
- Index_comment: '' },
+ Comment: '' },
index0:
{ Table: 'UserData',
Non_unique: 1,
@@ -109,13 +108,12 @@ describe('migrations', function() {
Seq_in_index: 1,
Column_name: 'email',
Collation: 'A',
- Cardinality: 0,
- Sub_part: 191,
+ Cardinality: null,
+ Sub_part: null,
Packed: null,
Null: '',
Index_type: 'BTREE',
- Comment: '',
- Index_comment: '' }
+ Comment: '' }
});
done();
});
@@ -298,7 +296,7 @@ describe('migrations', function() {
NumberData.create({number: 1.1234567, tinyInt: 123456, mediumInt: -1234567, floater: 123456789.1234567 }, function(err, obj) {
assert.ok(!err);
assert.ok(obj);
- NumberData.find(obj.id, function(err, found) {
+ NumberData.findById(obj.id, function(err, found) {
assert.equal(found.number, 1.123);
assert.equal(found.tinyInt, 127);
assert.equal(found.mediumInt, 0);
@@ -315,7 +313,7 @@ describe('migrations', function() {
}, function(err, obj){
assert.ok(!err);
assert.ok(obj);
- DateData.find(obj.id, function(err, found){
+ DateData.findById(obj.id, function(err, found){
assert.equal(found.dateTime.toGMTString(), 'Fri, 09 Aug 1996 07:47:33 GMT');
assert.equal(found.timestamp.toGMTString(), 'Sat, 22 Sep 2007 17:12:22 GMT');
done();