Last active
April 8, 2016 15:45
-
-
Save sailsinaction/69642190ac025f66bfc7 to your computer and use it in GitHub Desktop.
Chapter 6 - Gists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.d8888b. 888 888 .d8888b. .d8888b. d8b 888 | |
d88P Y88b 888 888 d88P Y88b d88P Y88b Y8P 888 | |
888 888 888 888 888 888 888 888 | |
888 88888b. 8888b. 88888b. 888888 .d88b. 888d888 888d888b. 888 888 .d8888b 888888 .d8888b | |
888 888 "88b "88b 888 "88b 888 d8P Y8b 888P" 888P "Y88b 888 88888 888 88K 888 88K | |
888 888 888 888 .d888888 888 888 888 88888888 888 888 888 888888 888 888 888 "Y8888b. 888 "Y8888b. | |
Y88b d88P 888 888 888 888 888 d88P Y88b. Y8b. 888 Y88b d88P Y88b d88P 888 X88 Y88b. X88 | |
"Y8888P" 888 888 "Y888888 88888P" "Y888 "Y8888 888 "Y8888P" "Y8888P88 888 88888P' "Y888 88888P' | |
888 | |
888 | |
888 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Default model configuration | |
* (sails.config.models) | |
* | |
* Unless you override them, the following properties will be included | |
* in each of your models. | |
* | |
* For more info on Sails models, see: | |
* http://sailsjs.org/#!/documentation/concepts/ORM | |
*/ | |
module.exports.models = { | |
/*************************************************************************** | |
* * | |
* Your app's default connection. i.e. the name of one of your app's * | |
* connections (see `config/connections.js`) * | |
* * | |
***************************************************************************/ | |
// connection: 'localDiskDb', | |
/*************************************************************************** | |
* * | |
* How and whether Sails will attempt to automatically rebuild the * | |
* tables/collections/etc. in your schema. * | |
* * | |
* See http://sailsjs.org/#!/documentation/concepts/ORM/model-settings.html * | |
* * | |
***************************************************************************/ | |
migrate: 'alter' | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Connections | |
* (sails.config.connections) | |
* | |
* `Connections` are like "saved settings" for your adapters. What's the difference between | |
* a connection and an adapter, you might ask? An adapter (e.g. `sails-mysql`) is generic-- | |
* it needs some additional information to work (e.g. your database host, password, user, etc.) | |
* A `connection` is that additional information. | |
* | |
* Each model must have a `connection` property (a string) which is references the name of one | |
* of these connections. If it doesn't, the default `connection` configured in `config/models.js` | |
* will be applied. Of course, a connection can (and usually is) shared by multiple models. | |
* . | |
* Note: If you're using version control, you should put your passwords/api keys | |
* in `config/local.js`, environment variables, or use another strategy. | |
* (this is to prevent you inadvertently sensitive credentials up to your repository.) | |
* | |
* For more information on configuration, check out: | |
* http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.connections.html | |
*/ | |
module.exports.connections = { | |
/*************************************************************************** | |
* * | |
* Local disk storage for DEVELOPMENT ONLY * | |
* * | |
* Installed by default. * | |
* * | |
***************************************************************************/ | |
localDiskDb: { | |
adapter: 'sails-disk' | |
}, | |
/*************************************************************************** | |
* * | |
* MySQL is the world's most popular relational database. * | |
* http://en.wikipedia.org/wiki/MySQL * | |
* * | |
* Run: npm install sails-mysql * | |
* * | |
***************************************************************************/ | |
someMysqlServer: { | |
adapter: 'sails-mysql', | |
host: 'YOUR_MYSQL_SERVER_HOSTNAME_OR_IP_ADDRESS', | |
user: 'YOUR_MYSQL_USER', | |
password: 'YOUR_MYSQL_PASSWORD', | |
database: 'YOUR_MYSQL_DB' | |
}, | |
/*************************************************************************** | |
* * | |
* MongoDB is the leading NoSQL database. * | |
* http://en.wikipedia.org/wiki/MongoDB * | |
* * | |
* Run: npm install sails-mongo * | |
* * | |
***************************************************************************/ | |
someMongodbServer: { | |
adapter: 'sails-mongo', | |
host: 'localhost', | |
port: 27017, | |
// user: 'username', | |
// password: 'password', | |
// database: 'your_mongo_db_name_here' | |
}, | |
/*************************************************************************** | |
* * | |
* PostgreSQL is another officially supported relational database. * | |
* http://en.wikipedia.org/wiki/PostgreSQL * | |
* * | |
* Run: npm install sails-postgresql * | |
* * | |
* * | |
***************************************************************************/ | |
somePostgresqlServer: { | |
adapter: 'sails-postgresql', | |
host: 'YOUR_POSTGRES_SERVER_HOSTNAME_OR_IP_ADDRESS', | |
user: 'YOUR_POSTGRES_USER', | |
password: 'YOUR_POSTGRES_PASSWORD', | |
database: 'YOUR_POSTGRES_DB' | |
} | |
/*************************************************************************** | |
* * | |
* More adapters: https://github.com/balderdashy/sails * | |
* * | |
***************************************************************************/ | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "brushfire-chp6-end", | |
"private": true, | |
"version": "0.0.0", | |
"description": "Sails in Action - End of Chapter 6 Source Files", | |
"keywords": [], | |
"dependencies": { | |
"ejs": "2.3.4", | |
"grunt": "0.4.5", | |
"grunt-contrib-clean": "0.6.0", | |
"grunt-contrib-coffee": "0.13.0", | |
"grunt-contrib-concat": "0.5.1", | |
"grunt-contrib-copy": "0.5.0", | |
"grunt-contrib-cssmin": "0.9.0", | |
"grunt-contrib-jst": "0.6.0", | |
"grunt-contrib-less": "1.1.0", | |
"grunt-contrib-uglify": "0.7.0", | |
"grunt-contrib-watch": "0.5.3", | |
"grunt-sails-linker": "~0.10.1", | |
"grunt-sync": "0.2.4", | |
"include-all": "~0.1.6", | |
"machinepack-youtube": "^2.2.0", | |
"rc": "1.0.1", | |
"sails": "~0.12.1", | |
"sails-disk": "~0.10.9", | |
"sails-generate-static": "^0.11.3", | |
"sails-postgresql": "^0.11.3" | |
}, | |
"scripts": { | |
"debug": "node debug app.js", | |
"start": "node app.js" | |
}, | |
"main": "app.js", | |
"repository": { | |
"type": "git", | |
"url": "git://github.com/jgalt/brushfire-chp6-start.git" | |
}, | |
"author": "Mike McNeil/Irl Nathan", | |
"license": "MIT" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* User.js | |
* | |
* @description :: TODO: You might write a short summary of how this model works and what it represents here. | |
* @docs :: http://sailsjs.org/documentation/concepts/models-and-orm/models | |
*/ | |
module.exports = { | |
connection: 'myPostgresqlServer', | |
attributes: { | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Connections | |
* (sails.config.connections) | |
* | |
* `Connections` are like "saved settings" for your adapters. What's the difference between | |
* a connection and an adapter, you might ask? An adapter (e.g. `sails-mysql`) is generic-- | |
* it needs some additional information to work (e.g. your database host, password, user, etc.) | |
* A `connection` is that additional information. | |
* | |
* Each model must have a `connection` property (a string) which is references the name of one | |
* of these connections. If it doesn't, the default `connection` configured in `config/models.js` | |
* will be applied. Of course, a connection can (and usually is) shared by multiple models. | |
* . | |
* Note: If you're using version control, you should put your passwords/api keys | |
* in `config/local.js`, environment variables, or use another strategy. | |
* (this is to prevent you inadvertently sensitive credentials up to your repository.) | |
* | |
* For more information on configuration, check out: | |
* http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.connections.html | |
*/ | |
module.exports.connections = { | |
/*************************************************************************** | |
* * | |
* Local disk storage for DEVELOPMENT ONLY * | |
* * | |
* Installed by default. * | |
* * | |
***************************************************************************/ | |
localDiskDb: { | |
adapter: 'sails-disk' | |
}, | |
/*************************************************************************** | |
* * | |
* MySQL is the world's most popular relational database. * | |
* http://en.wikipedia.org/wiki/MySQL * | |
* * | |
* Run: npm install sails-mysql * | |
* * | |
***************************************************************************/ | |
someMysqlServer: { | |
adapter: 'sails-mysql', | |
host: 'YOUR_MYSQL_SERVER_HOSTNAME_OR_IP_ADDRESS', | |
user: 'YOUR_MYSQL_USER', | |
password: 'YOUR_MYSQL_PASSWORD', | |
database: 'YOUR_MYSQL_DB' | |
}, | |
/*************************************************************************** | |
* * | |
* MongoDB is the leading NoSQL database. * | |
* http://en.wikipedia.org/wiki/MongoDB * | |
* * | |
* Run: npm install sails-mongo * | |
* * | |
***************************************************************************/ | |
someMongodbServer: { | |
adapter: 'sails-mongo', | |
host: 'localhost', | |
port: 27017, | |
// user: 'username', | |
// password: 'password', | |
// database: 'your_mongo_db_name_here' | |
}, | |
/*************************************************************************** | |
* * | |
* PostgreSQL is another officially supported relational database. * | |
* http://en.wikipedia.org/wiki/PostgreSQL * | |
* * | |
* Run: npm install sails-postgresql * | |
* * | |
* * | |
***************************************************************************/ | |
somePostgresqlServer: { | |
adapter: 'sails-postgresql', | |
host: 'YOUR_POSTGRES_SERVER_HOSTNAME_OR_IP_ADDRESS', | |
user: 'YOUR_POSTGRES_USER', | |
password: 'YOUR_POSTGRES_PASSWORD', | |
database: 'YOUR_POSTGRES_DB' | |
}, | |
myPostgresqlServer: { | |
adapter: 'sails-postgresql', | |
host: 'localhost', | |
database: 'brushfire' | |
} | |
/*************************************************************************** | |
* * | |
* More adapters: https://github.com/balderdashy/sails * | |
* * | |
***************************************************************************/ | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* User.js | |
* | |
* @description :: TODO: You might write a short summary of how this model works and what it represents here. | |
* @docs :: http://sailsjs.org/documentation/concepts/models-and-orm/models | |
*/ | |
module.exports = { | |
connection: 'myPostgresqlServer', | |
attributes: { | |
email: { | |
type: 'string', | |
}, | |
username: { | |
type: 'string', | |
}, | |
encryptedPassword: { | |
type: 'string' | |
}, | |
gravatarURL: { | |
type: 'string' | |
}, | |
deleted: { | |
type: 'boolean' | |
}, | |
admin: { | |
type: 'boolean' | |
}, | |
banned: { | |
type: 'boolean' | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* User.js | |
* | |
* @description :: TODO: You might write a short summary of how this model works and what it represents here. | |
* @docs :: http://sailsjs.org/documentation/concepts/models-and-orm/models | |
*/ | |
module.exports = { | |
connection: 'myPostgresqlServer', | |
attributes: { | |
email: { | |
type: 'string', | |
email: 'true', | |
unique: 'true' | |
}, | |
username: { | |
type: 'string', | |
unique: 'true' | |
}, | |
encryptedPassword: { | |
type: 'string' | |
}, | |
gravatarURL: { | |
type: 'string' | |
}, | |
deleted: { | |
type: 'boolean' | |
}, | |
admin: { | |
type: 'boolean' | |
}, | |
banned: { | |
type: 'boolean' | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* User.js | |
* | |
* @description :: TODO: You might write a short summary of how this model works and what it represents here. | |
* @docs :: http://sailsjs.org/documentation/concepts/models-and-orm/models | |
*/ | |
module.exports = { | |
connection: 'myPostgresqlServer', | |
migrate: 'drop', | |
attributes: { | |
email: { | |
type: 'string', | |
email: 'true', | |
unique: 'true' | |
}, | |
username: { | |
type: 'string', | |
unique: 'true' | |
}, | |
encryptedPassword: { | |
type: 'string' | |
}, | |
gravatarURL: { | |
type: 'string' | |
}, | |
deleted: { | |
type: 'boolean' | |
}, | |
admin: { | |
type: 'boolean' | |
}, | |
banned: { | |
type: 'boolean' | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* User.js | |
* | |
* @description :: TODO: You might write a short summary of how this model works and what it represents here. | |
* @docs :: http://sailsjs.org/documentation/concepts/models-and-orm/models | |
*/ | |
module.exports = { | |
connection: 'myPostgresqlServer', | |
migrate: 'drop', | |
attributes: { | |
email: { | |
type: 'string', | |
email: 'true', | |
unique: 'true' | |
}, | |
username: { | |
type: 'string', | |
unique: 'true' | |
}, | |
encryptedPassword: { | |
type: 'string' | |
}, | |
gravatarURL: { | |
type: 'string' | |
}, | |
deleted: { | |
type: 'boolean' | |
}, | |
admin: { | |
type: 'boolean' | |
}, | |
banned: { | |
type: 'boolean' | |
}, | |
toJSON: function() { | |
var modelAttributes = this.toObject(); | |
delete modelAttributes .password; | |
delete modelAttributes .confirmation; | |
delete modelAttributes .encryptedPassword; | |
return modelAttributes ; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment