RESTful-style API implementations based on MySQL and sails.js

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.