Skip to content

Commit

Permalink
Connect an API to a data source
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Ho authored and gunjpan committed Dec 24, 2015
1 parent 349e311 commit eb9a0f4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"loopback": "^2.5.0",
"loopback-boot": "^2.2.0",
"loopback-component-explorer": "^2.1.0",
"loopback-connector-mysql": "^1.4.7",
"loopback-datasource-juggler": "^2.7.0",
"serve-favicon": "^2.0.1"
},
Expand Down
15 changes: 15 additions & 0 deletions server/boot/create-sample-models.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = function(app) {
app.dataSources.mysqlDs.automigrate('CoffeeShop', function(err) {
if (err) throw err;

app.models.CoffeeShop.create([
{name: 'Bel Cafe', city: 'Vancouver'},
{name: 'Three Bees Coffee House', city: 'San Mateo'},
{name: 'Caffe Artigiano', city: 'Vancouver'},
], function(err, coffeeShops) {
if (err) throw err;

console.log('Models created: \n', coffeeShops);
});
});
};
9 changes: 9 additions & 0 deletions server/datasources.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,14 @@
"db": {
"name": "db",
"connector": "memory"
},
"mysqlDs": {
"name": "mysqlDs",
"connector": "mysql",
"host": "demo.strongloop.com",
"port": 3306,
"database": "getting_started",
"username": "demo",
"password": "L00pBack"
}
}
2 changes: 1 addition & 1 deletion server/model-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"public": false
},
"CoffeeShop": {
"dataSource": "db",
"dataSource": "mysqlDs",
"public": true
}
}

0 comments on commit eb9a0f4

Please sign in to comment.