Skip to content
This repository was archived by the owner on Aug 18, 2023. It is now read-only.

Commit 48c247e

Browse files
committed
Connect your API to a data source
1 parent f998c47 commit 48c247e

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
"compression": "^1.0.3",
1212
"cors": "^2.5.2",
1313
"helmet": "^1.3.0",
14+
"loopback": "^2.22.0",
1415
"loopback-boot": "^2.6.5",
1516
"loopback-component-explorer": "^2.4.0",
16-
"serve-favicon": "^2.0.1",
17-
"strong-error-handler": "^1.0.1",
17+
"loopback-connector-mysql": "^2.3.0",
1818
"loopback-datasource-juggler": "^2.39.0",
19-
"loopback": "^2.22.0"
19+
"serve-favicon": "^2.0.1",
20+
"strong-error-handler": "^1.0.1"
2021
},
2122
"devDependencies": {
2223
"eslint": "^2.13.1",

server/boot/create-sample-models.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = function(app) {
2+
app.dataSources.mysqlDs.automigrate('CoffeeShop', function(err) {
3+
if (err) throw err;
4+
5+
app.models.CoffeeShop.create([
6+
{name: 'Bel Cafe', city: 'Vancouver'},
7+
{name: 'Three Bees Coffee House', city: 'San Mateo'},
8+
{name: 'Caffe Artigiano', city: 'Vancouver'},
9+
], function(err, coffeeShops) {
10+
if (err) throw err;
11+
12+
console.log('Models created: \n', coffeeShops);
13+
});
14+
});
15+
};

server/datasources.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,15 @@
22
"db": {
33
"name": "db",
44
"connector": "memory"
5+
},
6+
"mysqlDs": {
7+
"host": "demo.strongloop.com",
8+
"port": 3306,
9+
"url": "",
10+
"database": "getting_started",
11+
"password": "L00pBack",
12+
"name": "mysqlDs",
13+
"user": "demo",
14+
"connector": "mysql"
515
}
616
}

server/model-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"public": false
3434
},
3535
"CoffeeShop": {
36-
"dataSource": "db",
36+
"dataSource": "mysqlDs",
3737
"public": true
3838
}
3939
}

0 commit comments

Comments
 (0)