Tag: Red style rate Plt Tor version implements engine data
Sails.js is an express-like node background framework, and her database-oriented features make database-oriented servers especially simple and quick to build.
Now most of the online tutorials on sails are based on the V0.12 version, but the latest version of Sails is now V1.0, compared to the official documentation, summarizing the simplest implementations based on MySQL and sails.
STEP1:
1. Install sails, create a new sails App, install the MySQL component for sails
1 npm install sails-g2new myApp3 npm install Sails-mysql--save
2. Create a test data table
1 CREATE TABLE' Test ' (2' ID 'int( One) not NULLAuto_increment,3' Username 'varchar(255)DEFAULT NULL,4' Password 'varchar(255)DEFAULT NULL,5 PRIMARY KEY(' id ')6) ENGINE=InnoDBDEFAULTCHARSET=UTF8;
STEP2:
1. Modify Config/datastore to
1 // Config/datastores.js 2 module.exports.datastores = {3 default: {4 Adapter:require (' Sails-mysql '),5 URL: ' user:[email protected]:p ort/database ', 6 }7 };
2. Modify Config/models to
1//Config/models.js
2 moudle.exports.models = {3 migrate: ' Safe ',4 Dataencryptionkeys: {5 default: ' k+07rp56mgas5l4pibpgnpltb+ao0o0pd8fh8upqzvc= ' 6 },7 true,8 primaryKey: ' ID '9 };
STEP3:
New API
1 sails generate API test
STEP4:
Fill data table fields into the Api/models/test
1 // Api/models/test.js 2 module.exports = {3 attributes: {4 trueTrue },5 true },6 true }, 7 },8 };
Launch the app and you are done.
RESTful-style API implementations based on MySQL and sails.js