diff --git a/pages/en/lb2/Basic-model-object.md b/pages/en/lb2/Basic-model-object.md index cbed32e2e..1c17abdb2 100644 --- a/pages/en/lb2/Basic-model-object.md +++ b/pages/en/lb2/Basic-model-object.md @@ -22,8 +22,7 @@ the [RelationMixin object](http://apidocs.strongloop.com/loopback-datasource-ju ## Events -{% include important.html content=" -The following events are deprecated in favor of [operation hooks](Operation-hooks.html): +{% include note.html content="The following events are deprecated in favor of [operation hooks](Operation-hooks.html): * changed * deleted @@ -31,25 +30,23 @@ The following events are deprecated in favor of [operation hooks](Operation-hook " %} The following table summarizes the events that LoopBack models can emit. +For more information, see [Events](Events.html).
| Event | -Emitted when... | +Event | +Emitted when... | Arguments | Argument type | Class methods that emit | -Instance methods that emit | +Instance methods that emit | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 'attached' | -
- Model is attached to an app. -
-
- - | Model is attached to an app. | Model class | Object | @@ -62,11 +59,8 @@ The following table summarizes the events that LoopBack models can emit.Model class | Object | - |
-
| DataSource.prototype .createModel + DataSource.prototype .define |
||||||||||||||||||||||||
| Model instance | Object | - |
- Model.prototype.setAttributes() + | Model.prototype .setAttributes() |
| Property | -Type | +Property | +Type | Description | |||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| connector | String | -
- Connector name; for example: + | Connector name; for example:
url |
String |
-
- | Combines and overrides Only valid with MongoDB connector, PostgreSQL connector, and SQL Server connector. +Combines and overrides |
host, port, user, password, and database properties.
+ Only valid with certain connectors; see connector documentation.
datasources.env.js or datasources.env.json, where _`env`_ is the value of `NODE_ENV` environment variable (typically `development` or `production`).
For example, `datasources.production.json`.
-{% include important.html content="
-The additional files can override the top-level data-source options with string and number values only. You cannot use objects or array values.
+{% include important.html content="The additional files can override the top-level data-source options with string and number values only. You cannot use objects or array values.
" %}
Example data sources:
@@ -166,9 +165,6 @@ Example data sources:
{% include code-caption.html content="datasources.json" %}
```javascript
{
- // the key is the datasource name
- // the value is the config object to pass to
- // app.dataSource(name, config).
db: {
connector: 'memory'
}
@@ -187,9 +183,9 @@ Example data sources:
}
```
-You can also configure your datasource._\_env\__.js file to use environment variables:
+You can also configure your datasource.env.js file to use environment variables:
-{% include code-caption.html content="datasources.production.json" %}
+{% include code-caption.html content="datasources.production.js" %}
```javascript
module.exports = {
db: {
@@ -207,7 +203,7 @@ the datasource.
## Getting values from environment variables
-You can easily set an environment variable when you run an application. The command you use depends on your operating system.
+You can easily get the value of an environment variable in an application. The command you use depends on your operating system.
### MacOS and Linux
diff --git a/pages/en/lb3/datasources.json.md b/pages/en/lb3/datasources.json.md
index 068533c45..ba6937b67 100644
--- a/pages/en/lb3/datasources.json.md
+++ b/pages/en/lb3/datasources.json.md
@@ -6,12 +6,13 @@ keywords: LoopBack
tags:
sidebar: lb3_sidebar
permalink: /doc/en/lb3/datasources.json.html
-summary:
+summary: Configure data sources in datasources.json.
---
## Overview
-Configure data sources in `/server/datasources.json`. You can set up as many data sources as you want in this file.
+Configure data sources in `/server/datasources.json`. You can set up as many data sources as you want in this file. The easiest way to set up a new data source is to use the [data source generator](Data-source-generator.html), which will prompt your for all the
+appropriate settings, add them to `/server/datasources.json`, and then install the connector from npm.
For example:
@@ -21,8 +22,8 @@ For example:
"name": "db",
"connector": "memory"
},
- "myDB": {
- "name": "myDB",
+ "mySQLdb": {
+ "name": "mySQLdb",
"connector": "mysql",
"host": "demo.strongloop.com",
"port": 3306,
@@ -33,22 +34,23 @@ For example:
}
```
-To access data sources in application code, use `app.datasources._datasourceName_`.
+To access data sources in application code, use app.datasources.datasourceName.
## Standard properties
All data sources support a few standard properties. Beyond that, specific properties and defaults depend on the connector being used.
- ```shell
- $ apic create --type datasource
- ? Enter the data-source name: mysql-corp
- ? Select the connector for mysql: MySQL (supported by StrongLoop)
- ```
-
- ```shell
- $ lb datasource
- ? Enter the data-source name: mysql-corp
- ? Select the connector for mysql: MySQL (supported by StrongLoop)
- ```
-
- Follow the prompts to name the datasource and select the connector to use.
- This adds the new data source to `datasources.json`
-
-2. Edit `server/datasources.json` to add the necessary authentication credentials: typically hostname, username, password, and database name.
-
- For example:
-
- **server/datasources.json**
-
- ```javascript
- "mysql-corp": {
- "name": "mysql-corp",
- "connector": "mysql",
- "host": "your-mysql-server.foo.com",
- "user": "db-username",
- "password": "db-password",
- "database": "your-db-name"
- }
- ```
-
- For information on the properties that each connector supports, see
- the specific connector documentation in [Database connectors](Database-connectors.html).
-
-3. Install the corresponding connector as a dependency of your app with `npm`, for example:
-
- ```shell
- $ cd
- ```
- $ apic create --type model
- ? Enter the model name: myModel
- ? Select the data-source to attach myModel to: mysql (mysql)
- ? Select model's base class: PersistedModel
- ? Expose myModel via the REST API? Yes
- ? Custom plural form (used to build REST URL):
- Let's add some test2 properties now.
- ...
- ```
-
- ```
- $ lb model
- ? Enter the model name: myModel
- ? Select the data-source to attach myModel to: mysql (mysql)
- ? Select model's base class: PersistedModel
- ? Expose myModel via the REST API? Yes
- ? Custom plural form (used to build REST URL):
- Let's add some test2 properties now.
- ...
- ```
-
- When prompted for the data source to attach to, select the one you just created.
-
-{% include note.html content="
-The model generator lists the [memory connector](Memory-connector.html), \"no data source,\" and data sources listed in `datasources.json`. That's why you created the data source first in step 1.
-" %}
-
-You can also create models from an existing database.
-See [Creating models](Creating-models.html) for more information.
-
-## Environment-specific configuration
-
-You can override values set in `datasources.json` in the following files:
-
-* `datasources.local.js` or `datasources.local.json`
-* `datasources._env_.js` or `datasources._env_.json`, where _`env`_ is the value of `NODE_ENV` environment variable (typically `development` or `production`).
- For example, `datasources.production.json`.
-
-{% include important.html content="
-The additional files can override the top-level data-source options with string and number values only. You cannot use objects or array values.
-" %}
-
-Example data sources:
-
-{% include code-caption.html content="datasources.json" %}
-```javascript
-{
- // the key is the datasource name
- // the value is the config object to pass to
- // app.dataSource(name, config).
- db: {
- connector: 'memory'
- }
-}
-```
+## Database connector properties
-{% include code-caption.html content="datasources.production.json" %}
-```javascript
-{
- db: {
- connector: 'mongodb',
- database: 'myapp',
- user: 'myapp',
- password: 'secret'
- }
-}
-```
+Although each data source connector has a different set of properties,
+database connectors typically have properties that include
+properties for the database server and credentials to log in to it.
+
+For information on the properties that each connector supports, see
+the specific connector documentation in [Database connectors](Database-connectors.html).
+
+{% include warning.html content="Don't put production database credentials in configuration files, where they could be a security vulnerability. Instead, load the values from environment variables. For more information, see [Specifying database credentials with environment variables](Attaching-models-to-data-sources.html#specifying-database-credentials-with-environment-variables)
+"%}
+
+The following table list common properties that most database connectors provide.
+See documentation for the specific connector for full details.
+
+
|