<commit_before># sails.config.datastores

### What is this?

Datastore configurations (or simply datastores) are like "saved settings" for your adapters.

In Sails, [database adapters](http://sailsjs.com/documentation/concepts/extending-sails/adapters) are the middle man between your app and some kind of structured data storage (typically a database).  But in order for an adapter to communicate between your Sails app and a particular database, it needs some additional information.  That's where datastores come in.  Datastores are dictionaries (plain JavaScript objects) that specify an `adapter`, as well as other necessary configuration information-- stuff like `url`, or `host`, `port`, `username`, and `password`.

While this [can be overridden](http://sailsjs.com/documentation/concepts/orm/model-settings) on a per-model basis, out of the box, every model in your app uses a datastore named "default".


### The default development database
As a convenience during development, Sails provides a built-in database adapter called `sails-disk`.  This adapter simulates a real database by reading and writing database records to a JSON file on your computer's hard drive.  And while `sails-disk` makes it easy to run your Sails/Node.js app in almost any environment, with minimal setup-- it is not designed for production use.  Before deploying your app and exposing it to real users, you'll want to choose a proper database such as PostgreSQL, MySQL, MongoDB, etc.  To do that, you'll need to customize your app's default datastore.

### Setting the default datastore
Unsurprisingly, the default datastore shared by all of your app's models is named "default".  So to hook up a different database, that's the datastore you'll want to change.

For example, imagine you edited the default datastore configuration in `config/datastores.js` so that it contains `adapter: require('sails-postgresql')`, and `database: 'foo'`.  This tells Sails and Waterline that you must have [sails-postgresql](http://npmjs.com/package/sails-postgresql) installed, and that you're running a local PostgreSQL server with a database named "foo".  Assuming that's the case, then the next time you lift your app, all of your app's models will use that PostgreSQL database any time built-in model methods like `.create()` or `.find()` are executed.

### Best practices
Besides the `config/datastores.js` file, you can configure datastores in [the same way you configure anything else in Sails](http://sailsjs.com/documentation/concepts/configuration).

Some general rules of thumb:

+ To change the database you're using in development, edit the `default` key in `config/datastores.js` (or use `config/local.js` if you'd rather not check in your credentials)
+ In production, configure your database using `config/production.js` (or set environment variables if you'd rather not check in your credentials)
+ To override the database for a particular model, [set its `datastore`](http://sailsjs.com/documentation/concepts/models-and-orm/model-settings#?datastore).



### Example

To use the `sails-memory` adapter in development, first install the module with `npm install sails-memory --save`.  Then change `config/datastores.js`:

```javascript
// config/datastores.js
module.exports.datastores = {
  default: {
    adapter: require('sails-memory')<commit_msg>A little less Mr. Mystery<commit_after># sails.config.datastores

### What is this?

Datastore configurations (or simply datastores) are like "saved settings" for your adapters.

In Sails, [database adapters](http://sailsjs.com/documentation/concepts/extending-sails/adapters) are the middle man between your app and some kind of structured data storage (typically a database).  But in order for an adapter to communicate between your Sails app and a particular database, it needs some additional information.  That's where datastores come in.  Datastores are dictionaries (plain JavaScript objects) that specify an `adapter`, as well as other necessary configuration information-- stuff like `url`, or `host`, `port`, `username`, and `password`.

While this [can be overridden](http://sailsjs.com/documentation/concepts/orm/model-settings) on a per-model basis, out of the box, every model in your app uses a datastore named "default".


### The default development database
As a convenience during development, Sails provides a built-in database adapter called `sails-disk`.  This adapter simulates a real database by reading and writing database records to a JSON file on your computer's hard drive.  And while `sails-disk` makes it easy to run your Sails/Node.js app in almost any environment, with minimal setup-- it is not designed for production use.  Before deploying your app and exposing it to real users, you'll want to choose a proper database such as PostgreSQL, MySQL, MongoDB, etc.  To do that, you'll need to customize your app's default datastore.

### Setting the default datastore
Unsurprisingly, the default datastore shared by all of your app's models is named "default".  So to hook up a different database, that's the datastore you'll want to change.

For example, imagine you edited the default datastore configuration in `config/datastores.js` so that it contains `adapter: require('sails-postgresql')`, and `database: 'foo'`.  This tells Sails and Waterline that you must have [sails-postgresql](http://npmjs.com/package/sails-postgresql) installed, and that you're running a local PostgreSQL server with a database named "foo".  The next time you lift your app, all of your models will try to communicate with that PostgreSQL database any time built-in model methods like `.create()` or `.find()` are executed.

### Best practices
Besides the `config/datastores.js` file, you can configure datastores in [the same way you configure anything else in Sails](http://sailsjs.com/documentation/concepts/configuration).

Some general rules of thumb:

+ To change the database you're using in development, edit the `default` key in `config/datastores.js` (or use `config/local.js` if you'd rather not check in your credentials)
+ In production, configure your database using `config/production.js` (or set environment variables if you'd rather not check in your credentials)
+ To override the database for a particular model, [set its `datastore`](http://sailsjs.com/documentation/concepts/models-and-orm/model-settings#?datastore).



### Example

To use the `sails-memory` adapter in development, first install the module with `npm install sails-memory --save`.  Then change `config/datastores.js`:

```javascript
// config/datastores.js
module.exports.datastores = {
  default: {
    adapter: require('sails-memory')
{'fraction_non_alphanumeric': 0.08259763579230885, 'fraction_numerical': 0.0, 'mean_word_length': 4.888986784140969, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5006087', 'n_tokens_mistral': 1814, 'n_tokens_neox': 1715, 'n_words': 850}