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

Commit

Permalink
Connect your API to a data source
Browse files Browse the repository at this point in the history
  • Loading branch information
Amir-61 committed Nov 11, 2016
1 parent 1ef5bc9 commit e9a271a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
"compression": "^1.0.3",
"cors": "^2.5.2",
"helmet": "^1.3.0",
"loopback": "^3.0.0",
"loopback-boot": "^2.6.5",
"loopback-component-explorer": "^2.4.0",
"loopback-connector-mysql": "^2.4.0",
"serve-favicon": "^2.0.1",
"strong-error-handler": "^1.0.1",
"loopback": "^3.0.0"
"strong-error-handler": "^1.0.1"
},
"devDependencies": {
"eslint": "^2.13.1",
Expand Down
22 changes: 22 additions & 0 deletions server/boot/create-sample-models.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

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 @@ -33,7 +33,7 @@
"public": false
},
"CoffeeShop": {
"dataSource": "db",
"dataSource": "mysqlDs",
"public": true
}
}

0 comments on commit e9a271a

Please sign in to comment.