Merge pull request #416 from strongloop/update-readme
fix README display on the site
This commit is contained in:
commit
e4a4f0f690
88
README.md
88
README.md
|
@ -1,6 +1,6 @@
|
||||||
# loopback-connector-mysql
|
# loopback-connector-mysql
|
||||||
|
|
||||||
[MySQL](https://www.mysql.com/) is a popular open-source relational database management system (RDBMS). The `loopback-connector-mysql` module provides the MySQL connector module for the LoopBack framework.
|
[MySQL](https://www.mysql.com/) is a popular open-source relational database management system (RDBMS). The `loopback-connector-mysql` module provides the MySQL connector module for the LoopBack framework.
|
||||||
|
|
||||||
<div class="gh-only">See also <a href="http://loopback.io/doc/en/lb3/MySQL-connector.html">LoopBack MySQL Connector</a> in LoopBack documentation.
|
<div class="gh-only">See also <a href="http://loopback.io/doc/en/lb3/MySQL-connector.html">LoopBack MySQL Connector</a> in LoopBack documentation.
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
|
@ -23,7 +23,7 @@ If you create a MySQL data source using the data source generator as described b
|
||||||
|
|
||||||
Use the [Data source generator](http://loopback.io/doc/en/lb3/Data-source-generator.html) to add a MySQL data source to your application.
|
Use the [Data source generator](http://loopback.io/doc/en/lb3/Data-source-generator.html) to add a MySQL data source to your application.
|
||||||
The generator will prompt for the database server hostname, port, and other settings
|
The generator will prompt for the database server hostname, port, and other settings
|
||||||
required to connect to a MySQL database. It will also run the `npm install` command above for you.
|
required to connect to a MySQL database. It will also run the `npm install` command above for you.
|
||||||
|
|
||||||
The entry in the application's `/server/datasources.json` will look like this:
|
The entry in the application's `/server/datasources.json` will look like this:
|
||||||
|
|
||||||
|
@ -205,13 +205,13 @@ See [LoopBack types](http://loopback.io/doc/en/lb3/LoopBack-types.html) for de
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
*NOTE* as of v3.0.0 of MySQL Connector, the following flags were introduced:
|
_NOTE_ as of v3.0.0 of MySQL Connector, the following flags were introduced:
|
||||||
|
|
||||||
* `treatCHAR1AsString`
|
- `treatCHAR1AsString`
|
||||||
default `false` - treats CHAR(1) as a String instead of a Boolean
|
default `false` - treats CHAR(1) as a String instead of a Boolean
|
||||||
* `treatBIT1AsBit`
|
- `treatBIT1AsBit`
|
||||||
default `true` - treats BIT(1) as a Boolean instead of a Binary
|
default `true` - treats BIT(1) as a Boolean instead of a Binary
|
||||||
* `treatTINYINT1AsTinyInt`
|
- `treatTINYINT1AsTinyInt`
|
||||||
default `true` - treats TINYINT(1) as a Boolean instead of a Number
|
default `true` - treats TINYINT(1) as a Boolean instead of a Number
|
||||||
|
|
||||||
## Using the datatype field/column option with MySQL
|
## Using the datatype field/column option with MySQL
|
||||||
|
@ -221,6 +221,7 @@ Use the `mysql` model property to specify additional MySQL-specific properties f
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
{% include code-caption.html content="/common/models/model.json" %}
|
{% include code-caption.html content="/common/models/model.json" %}
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
"locationId":{
|
"locationId":{
|
||||||
"type":"String",
|
"type":"String",
|
||||||
|
@ -239,13 +240,13 @@ For example:
|
||||||
You can also use the dataType column/property attribute to specify what MySQL column type to use for many loopback-datasource-juggler types.
|
You can also use the dataType column/property attribute to specify what MySQL column type to use for many loopback-datasource-juggler types.
|
||||||
The following type-dataType combinations are supported:
|
The following type-dataType combinations are supported:
|
||||||
|
|
||||||
* Number
|
- Number
|
||||||
* integer
|
- integer
|
||||||
* tinyint
|
- tinyint
|
||||||
* smallint
|
- smallint
|
||||||
* mediumint
|
- mediumint
|
||||||
* int
|
- int
|
||||||
* bigint
|
- bigint
|
||||||
|
|
||||||
Use the `limit` option to alter the display width. Example:
|
Use the `limit` option to alter the display width. Example:
|
||||||
|
|
||||||
|
@ -259,7 +260,9 @@ Use the `limit` option to alter the display width. Example:
|
||||||
```
|
```
|
||||||
|
|
||||||
### Default Clause/Constant
|
### Default Clause/Constant
|
||||||
|
|
||||||
Use the `default` property to have MySQL handle setting column `DEFAULT` value.
|
Use the `default` property to have MySQL handle setting column `DEFAULT` value.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
"status": {
|
"status": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
@ -274,7 +277,9 @@ Use the `default` property to have MySQL handle setting column `DEFAULT` value.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
For the date or timestamp types use `CURRENT_TIMESTAMP` or `now`:
|
For the date or timestamp types use `CURRENT_TIMESTAMP` or `now`:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
"last_modified": {
|
"last_modified": {
|
||||||
"type": "date",
|
"type": "date",
|
||||||
|
@ -283,7 +288,9 @@ For the date or timestamp types use `CURRENT_TIMESTAMP` or `now`:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**NOTE**: The following column types do **NOT** supported [MySQL Default Values](https://dev.mysql.com/doc/refman/5.7/en/data-type-defaults.html):
|
**NOTE**: The following column types do **NOT** supported [MySQL Default Values](https://dev.mysql.com/doc/refman/5.7/en/data-type-defaults.html):
|
||||||
|
|
||||||
- BLOB
|
- BLOB
|
||||||
- TEXT
|
- TEXT
|
||||||
- GEOMETRY
|
- GEOMETRY
|
||||||
|
@ -324,14 +331,14 @@ Example:
|
||||||
|
|
||||||
Convert String / DataSource.Text / DataSource.JSON to the following MySQL types:
|
Convert String / DataSource.Text / DataSource.JSON to the following MySQL types:
|
||||||
|
|
||||||
* varchar
|
- varchar
|
||||||
* char
|
- char
|
||||||
* text
|
- text
|
||||||
* mediumtext
|
- mediumtext
|
||||||
* tinytext
|
- tinytext
|
||||||
* longtext
|
- longtext
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
{ userName :
|
{ userName :
|
||||||
|
@ -342,7 +349,7 @@ Example:
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
{ biography :
|
{ biography :
|
||||||
|
@ -354,7 +361,7 @@ Example:
|
||||||
|
|
||||||
Convert JSON Date types to datetime or timestamp
|
Convert JSON Date types to datetime or timestamp
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
{ startTime :
|
{ startTime :
|
||||||
|
@ -383,7 +390,7 @@ MOOD('sad'); // 'sad'
|
||||||
### Model discovery
|
### Model discovery
|
||||||
|
|
||||||
The MySQL connector supports _model discovery_ that enables you to create LoopBack models
|
The MySQL connector supports _model discovery_ that enables you to create LoopBack models
|
||||||
based on an existing database schema using the unified [database discovery API](http://apidocs.strongloop.com/loopback-datasource-juggler/#datasource-prototype-discoverandbuildmodels). For more information on discovery, see [Discovering models from relational databases](https://loopback.io/doc/en/lb3/Discovering-models-from-relational-databases.html).
|
based on an existing database schema using the unified [database discovery API](http://apidocs.strongloop.com/loopback-datasource-juggler/#datasource-prototype-discoverandbuildmodels). For more information on discovery, see [Discovering models from relational databases](https://loopback.io/doc/en/lb3/Discovering-models-from-relational-databases.html).
|
||||||
|
|
||||||
### Auto-migration
|
### Auto-migration
|
||||||
|
|
||||||
|
@ -399,6 +406,7 @@ MySQL handles the foreign key integrity of the related models upon auto-migrate
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
**model-definiton.json**
|
**model-definiton.json**
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"name": "Book",
|
"name": "Book",
|
||||||
|
@ -466,6 +474,7 @@ Example:
|
||||||
```
|
```
|
||||||
|
|
||||||
**boot-script.js**
|
**boot-script.js**
|
||||||
|
|
||||||
```js
|
```js
|
||||||
module.exports = function(app) {
|
module.exports = function(app) {
|
||||||
var mysqlDs = app.dataSources.mysqlDS;
|
var mysqlDs = app.dataSources.mysqlDS;
|
||||||
|
@ -485,13 +494,17 @@ module.exports = function(app) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Breaking Changes with GeoPoint since 5.x
|
#### Breaking Changes with GeoPoint since 5.x
|
||||||
|
|
||||||
Prior to `loopback-connector-mysql@5.x`, MySQL connector was saving and loading GeoPoint properties from the MySQL database in reverse.
|
Prior to `loopback-connector-mysql@5.x`, MySQL connector was saving and loading GeoPoint properties from the MySQL database in reverse.
|
||||||
MySQL expects values to be POINT(X, Y) or POINT(lng, lat), but the connector was saving them in the opposite order(i.e. POINT(lat,lng)).
|
MySQL expects values to be POINT(X, Y) or POINT(lng, lat), but the connector was saving them in the opposite order(i.e. POINT(lat,lng)).
|
||||||
If you have an application with a model that has a GeoPoint property using previous versions of this connector, you can migrate your models
|
If you have an application with a model that has a GeoPoint property using previous versions of this connector, you can migrate your models
|
||||||
using the following programmatic approach:
|
using the following programmatic approach:
|
||||||
**NOTE** Please back up the database tables that have your application data before performing any of the steps.
|
**NOTE** Please back up the database tables that have your application data before performing any of the steps.
|
||||||
|
|
||||||
1. Create a boot script under `server/boot/` directory with the following:
|
1. Create a boot script under `server/boot/` directory with the following:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
'use strict';
|
'use strict';
|
||||||
module.exports = function(app) {
|
module.exports = function(app) {
|
||||||
|
@ -501,13 +514,17 @@ module.exports = function(app) {
|
||||||
teashop.find({}, function(err, teashops) {
|
teashop.find({}, function(err, teashops) {
|
||||||
teashops.forEach(function(teashopInstance) {
|
teashops.forEach(function(teashopInstance) {
|
||||||
//what we fetch back from the db is wrong, so need to revert it here
|
//what we fetch back from the db is wrong, so need to revert it here
|
||||||
var newLocation = {lng: teashopInstance.location.lat, lat: teashopInstance.location.lng};
|
var newLocation = {
|
||||||
|
lng: teashopInstance.location.lat,
|
||||||
|
lat: teashopInstance.location.lng
|
||||||
|
};
|
||||||
//only update the GeoPoint property for the model
|
//only update the GeoPoint property for the model
|
||||||
teashopInstance.updateAttribute('location', newLocation, function(err, inst) {
|
teashopInstance.updateAttribute('location', newLocation, function(
|
||||||
if (err)
|
err,
|
||||||
console.log('update attribute failed ', err);
|
inst
|
||||||
else
|
) {
|
||||||
console.log('updateAttribute successful');
|
if (err) console.log('update attribute failed', err);
|
||||||
|
else console.log('updateAttribute successful');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -516,9 +533,11 @@ module.exports = function(app) {
|
||||||
findAndUpdate();
|
findAndUpdate();
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Run the boot script by simply running your application or `node .`
|
2. Run the boot script by simply running your application or `node .`
|
||||||
|
|
||||||
For the above example, the model definition is as follows:
|
For the above example, the model definition is as follows:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"name": "teashop",
|
"name": "teashop",
|
||||||
|
@ -546,24 +565,35 @@ For the above example, the model definition is as follows:
|
||||||
## Running tests
|
## Running tests
|
||||||
|
|
||||||
### Own instance
|
### Own instance
|
||||||
|
|
||||||
If you have a local or remote MySQL instance and would like to use that to run the test suite, use the following command:
|
If you have a local or remote MySQL instance and would like to use that to run the test suite, use the following command:
|
||||||
|
|
||||||
- Linux
|
- Linux
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
MYSQL_HOST=<HOST> MYSQL_PORT=<PORT> MYSQL_USER=<USER> MYSQL_PASSWORD=<PASSWORD> MYSQL_DATABASE=<DATABASE> CI=true npm test
|
MYSQL_HOST=<HOST> MYSQL_PORT=<PORT> MYSQL_USER=<USER> MYSQL_PASSWORD=<PASSWORD> MYSQL_DATABASE=<DATABASE> CI=true npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
- Windows
|
- Windows
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
SET MYSQL_HOST=<HOST> SET MYSQL_PORT=<PORT> SET MYSQL_USER=<USER> SET MYSQL_PASSWORD=<PASSWORD> SET MYSQL_DATABASE=<DATABASE> SET CI=true npm test
|
SET MYSQL_HOST=<HOST> SET MYSQL_PORT=<PORT> SET MYSQL_USER=<USER> SET MYSQL_PASSWORD=<PASSWORD> SET MYSQL_DATABASE=<DATABASE> SET CI=true npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
### Docker
|
### Docker
|
||||||
|
|
||||||
If you do not have a local MySQL instance, you can also run the test suite with very minimal requirements.
|
If you do not have a local MySQL instance, you can also run the test suite with very minimal requirements.
|
||||||
|
|
||||||
- Assuming you have [Docker](https://docs.docker.com/engine/installation/) installed, run the following script which would spawn a MySQL instance on your local:
|
- Assuming you have [Docker](https://docs.docker.com/engine/installation/) installed, run the following script which would spawn a MySQL instance on your local:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
source setup.sh <HOST> <PORT> <USER> <PASSWORD> <DATABASE>
|
source setup.sh <HOST> <PORT> <USER> <PASSWORD> <DATABASE>
|
||||||
```
|
```
|
||||||
|
|
||||||
where `<HOST>`, `<PORT>`, `<USER>`, `<PASSWORD>` and `<DATABASE>` are optional parameters. The default values are `localhost`, `3306`, `root`, `pass` and `testdb` respectively.
|
where `<HOST>`, `<PORT>`, `<USER>`, `<PASSWORD>` and `<DATABASE>` are optional parameters. The default values are `localhost`, `3306`, `root`, `pass` and `testdb` respectively.
|
||||||
|
|
||||||
- Run the test:
|
- Run the test:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm test
|
npm test
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue